-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Makefile for Android NDK cross-compile #3901
Fix Makefile for Android NDK cross-compile #3901
Conversation
For cross-compiling to Android, the Makefile needs some tweaks. Tested with Android NDK 23.1.7779620 and 21.4.7075529, using Windows 10 with clean MSYS2 environment (i.e. no MINGW/GCC/Clang toolchain in PATH) and Fedora 35, with build target: build ARCH=armv8 COMP=ndk The resulting binary runs fine inside Droidfish on my Samsung Galaxy Note20 Ultra and Samsung Galaxy Tab S7+ Other builds tested to exclude regressions: MINGW64/Clang64 build on Windows; MINGW64 cross build, native Clang and GCC builds on Fedora. No functional change
Improvements are:
|
Hooray, this was my first self compiled Android app, BTW 😉😎 |
The wiki is lacking a "Building SF with NDK" page :) It seems that it's easy to cross build from any system to any system with clang (and toolsets using clang like NDK, zig). If I'm not wrong it seems possible to build from Windows to Windows using NDK (supposing that this makes sense), but this will require some Makefile editing after this PR: |
I'll try to write something up in the evening or tomorrow (but it was really trivial: use the MSYS2 env, just put the NDK compiler bin/ directory first in your path, and there you go!) |
I have added a Wiki page on cross-compiling for Android. Please review and let me know whether I should improve something, or whether it's good enough and easy to follow. Maybe too detailed!? I'm looking forward to any kind of feedback. |
Great job! Fixed some typos. |
Thanks! I'm glad it's OK and usable! |
@pschneider1968 try I cross compiled from MSYS and Ubuntu 20.04. export PATH=/c/zig/:$PATH
git clone https://github.com/official-stockfish/Stockfish.git
cd Stockfish/src
# dynamic build with gnu glibc
make build ARCH=armv8 COMP=gcc CXX="zig c++ -target aarch64-linux-gnu"
mv stockfish stockfish_armv8
make clean
make build ARCH=x86-64-modern COMP=gcc CXX="zig c++ -target x86_64-linux-gnu"
mv stockfish stockfish_x86-64-modern
# static build with musl libc
make build ARCH=armv8 COMP=gcc CXX="zig c++ -target aarch64-linux-musl"
mv stockfish stockfish_armv8-musl
make build ARCH=x86-64-modern COMP=gcc CXX="zig c++ -target x86_64-linux-musl"
mv stockfish stockfish_x86-64-modern-musl |
|
Cross compile for aarch64 with NEON on a clean Ubuntu 20.04: # one time configuration
sudo apt update && sudo apt install -y make git
sudo snap install zig --classic --edge
sudo apt install -y qemu-user
# static build with musl libc
git clone https://github.com/official-stockfish/Stockfish.git
cd Stockfish/src
make -j build ARCH=armv8 CXX="zig c++ -target aarch64-linux-musl"
# test with qemu-aarch64 (loaded automatically)
stockfish bench Build with make -j build ARCH=armv8 COMP=ndk CXX="zig c++ -target aarch64-linux-musl" diff --git a/src/Makefile b/src/Makefile
index 5f3e739f..cc3c5650 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -457,7 +457,7 @@ ifeq ($(COMP),ndk)
CXX=aarch64-linux-android21-clang++
STRIP=aarch64-linux-android-strip
endif
- LDFLAGS += -static-libstdc++ -pie -lm -latomic
+ LDFLAGS += -static-libstdc++ -pie -lm
endif |
I've never heard of zig before. That looks really interesting! I will have a look and play around with it. |
zig + qemu etc looks nice, will give an easy way to test e.g. the ARM code on linux. I wonder if we can somehow fix the pthreads issue cleanly. |
I read of I learned about Here is a interesting
|
EDIT_000: drunk monkey test, our Makefile already detect that
|
That's really impressive! |
On discord Torom on a core i7-6700K tested I never played with Android, does the |
I couldn't try it yet, but I hope to do next weekend at the latest. |
This my workstation Dual Intel(R) Xeon(R) CPU E5-2680 v3 @ 2.50GHz, 2501 Mhz, 12 Core(s), 24 Logical Processor(s) make -j ARCH=x86-64-bmi2 CXX="zig c++ -target x86_64-linux-musl"
|
So I was too curious, I had to try this out NOW ;-) Although I'd better go to sleep... I built with: Seems to be equally fast as that built with the NDK, but it was just a short test: running in Droidfish analyse mode, I played 3 plies into a King's gambit and let SF think about a move for black. With 4 Threads, it's starts at 1600k nps, and at about depth 30 is at 1200k nps. Unfortunately, zig could not build a Windows executable, because the pthreads.h and libpthreads.a library is missing?! Seems to still be work in progress... EDIT: Ah, I just saw that @vondele already mentioned that issue. Will try out the Linux version next. |
I suspect that the speed of |
Adding some info about the libc shipped with Zig:
Filed a bug Issue on Zig: The Zig instructions to update mingw-64 seems to be naïve and broken, they configure/install This bash script configures and builds mingw-64 in a proper way ( Update Zig mingw-w64 with: zig_path=${HOME}/zig-linux-x86_64-0.9.0/lib/libc
mingw_path=${HOME}/.zeranoe/mingw-w64
mv ${zig_path}/mingw ${zig_path}/mingw-orig
cp -r ${mingw_path}/src/mingw-w64/mingw-w64-crt ${zig_path}/mingw
mv ${zig_path}/include/any-windows-any ${zig_path}/include/any-windows-any-orig
cp -r ${mingw_path}/x86_64/x86_64-w64-mingw32/include ${zig_path}/include/any-windows-any
cp ${mingw_path}/bld/x86_64/mingw-w64-crt/config.h ${zig_path}/include/any-windows-any/config.h When building Stockfish with
|
For cross-compiling to Android on windows, the Makefile needs some tweaks. Tested with Android NDK 23.1.7779620 and 21.4.7075529, using Windows 10 with clean MSYS2 environment (i.e. no MINGW/GCC/Clang toolchain in PATH) and Fedora 35, with build target: build ARCH=armv8 COMP=ndk The resulting binary runs fine inside Droidfish on my Samsung Galaxy Note20 Ultra and Samsung Galaxy Tab S7+ Other builds tested to exclude regressions: MINGW64/Clang64 build on Windows; MINGW64 cross build, native Clang and GCC builds on Fedora. wiki docs https://github.com/glinscott/fishtest/wiki/Cross-compiling-Stockfish-for-Android-on-Windows-and-Linux closes official-stockfish#3901 No functional change
For cross-compiling to Android on windows, the Makefile needs some tweaks. Tested with Android NDK 23.1.7779620 and 21.4.7075529, using Windows 10 with clean MSYS2 environment (i.e. no MINGW/GCC/Clang toolchain in PATH) and Fedora 35, with build target: build ARCH=armv8 COMP=ndk The resulting binary runs fine inside Droidfish on my Samsung Galaxy Note20 Ultra and Samsung Galaxy Tab S7+ Other builds tested to exclude regressions: MINGW64/Clang64 build on Windows; MINGW64 cross build, native Clang and GCC builds on Fedora. wiki docs https://github.com/glinscott/fishtest/wiki/Cross-compiling-Stockfish-for-Android-on-Windows-and-Linux closes official-stockfish#3901 No functional change
For cross-compiling to Android, the Makefile needs some tweaks.
Tested with Android NDK 23.1.7779620 and 21.4.7075529, using
Windows 10 with clean MSYS2 environment (i.e. no MINGW/GCC/Clang
toolchain in PATH) and Fedora 35, with build target:
build ARCH=armv8 COMP=ndk
The resulting binary runs fine inside Droidfish on my Samsung
Galaxy Note20 Ultra and Samsung Galaxy Tab S7+
Other builds tested to exclude regressions: MINGW64/Clang64 build
on Windows; MINGW64 cross build, native Clang and GCC builds on Fedora.
No functional change