Skip to content

Commit 32e007f

Browse files
committed
Use Android NDK 25 and work around Rust/Android incompatibilities.
Use Android NDK 25 since that's GitHub Actions is moving to. SDK level is the minimum supported, and there are no longer target-specific allases for `llvm-ar`; update cargo.sh accordingly. Use the environment variables recommended by the Android documentation. Work around compatibility issue with Rust and Android NDKs. Remove out-of-date documentation aboud building for Android.
1 parent 6204702 commit 32e007f

File tree

3 files changed

+20
-15
lines changed

3 files changed

+20
-15
lines changed

BUILDING.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,6 @@ Note in particular that if you are cross-compiling an x86 build on a 64-bit
7676
version of Linux, then you need to have the proper gcc-multilibs and
7777
g++-multilibs packages or equivalent installed.
7878

79-
If you generate a standalone NDK toolchain in order to compile your project,
80-
the wrapper automatically passes flags to the actual compiler to define the
81-
`__ANDROID_API__` macro. Otherwise, the macro `__ANDROID_API__` must be
82-
defined with a value of at least 21 on 64-bit targets or 18 on 32-bit targets;
83-
e.g. export `CFLAGS=-D__ANDROID_API__=21`.
84-
8579

8680
Building for Windows ARM64
8781
--------------------------

mk/cargo.sh

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,12 @@ qemu_arm="qemu-arm -L /usr/arm-linux-gnueabihf"
2424
# Avoid putting the Android tools in `$PATH` because there are tools in this
2525
# directory like `clang` that would conflict with the same-named tools that may
2626
# be needed to compile the build script, or to compile for other targets.
27-
if [ -n "${ANDROID_SDK_ROOT-}" ]; then
28-
android_tools=$ANDROID_SDK_ROOT/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin
27+
if [ -n "${ANDROID_HOME-}" ]; then
28+
ndk_version=25.1.8937393
29+
ANDROID_NDK_ROOT=${ANDROID_NDK_ROOT:-${ANDROID_HOME}/ndk/$ndk_version}
30+
fi
31+
if [ -n "${ANDROID_NDK_ROOT-}" ]; then
32+
android_tools=${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/linux-x86_64/bin
2933
fi
3034

3135
for arg in $*; do
@@ -44,7 +48,7 @@ llvm_version=14
4448
case $target in
4549
aarch64-linux-android)
4650
export CC_aarch64_linux_android=$android_tools/aarch64-linux-android21-clang
47-
export AR_aarch64_linux_android=$android_tools/aarch64-linux-android-ar
51+
export AR_aarch64_linux_android=$android_tools/llvm-ar
4852
export CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER=$android_tools/aarch64-linux-android21-clang
4953
;;
5054
aarch64-unknown-linux-gnu)
@@ -67,9 +71,9 @@ case $target in
6771
export CARGO_TARGET_ARM_UNKNOWN_LINUX_GNUEABIHF_RUNNER="$qemu_arm"
6872
;;
6973
armv7-linux-androideabi)
70-
export CC_armv7_linux_androideabi=$android_tools/armv7a-linux-androideabi18-clang
71-
export AR_armv7_linux_androideabi=$android_tools/arm-linux-androideabi-ar
72-
export CARGO_TARGET_ARMV7_LINUX_ANDROIDEABI_LINKER=$android_tools/armv7a-linux-androideabi18-clang
74+
export CC_armv7_linux_androideabi=$android_tools/armv7a-linux-androideabi19-clang
75+
export AR_armv7_linux_androideabi=$android_tools/llvm-ar
76+
export CARGO_TARGET_ARMV7_LINUX_ANDROIDEABI_LINKER=$android_tools/armv7a-linux-androideabi19-clang
7377
;;
7478
armv7-unknown-linux-musleabihf)
7579
export CC_armv7_unknown_linux_musleabihf=clang-$llvm_version

mk/install-build-tools.sh

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,19 @@ function install_packages {
2727
use_clang=
2828
case $target in
2929
--target*android*)
30-
mkdir -p "${ANDROID_SDK_ROOT}/licenses"
31-
android_license_file="${ANDROID_SDK_ROOT}/licenses/android-sdk-license"
30+
mkdir -p "${ANDROID_HOME}/licenses"
31+
ndk_version=25.1.8937393
32+
android_license_file="${ANDROID_HOME}/licenses/android-sdk-license"
3233
accept_android_license=24333f8a63b6825ea9c5514f83c2829b004d1fee
3334
grep --quiet --no-messages "$accept_android_license" "$android_license_file" \
3435
|| echo $accept_android_license >> "$android_license_file"
35-
"${ANDROID_SDK_ROOT}/cmdline-tools/latest/bin/sdkmanager" ndk-bundle
36+
"${ANDROID_HOME}/cmdline-tools/latest/bin/sdkmanager" "ndk;$ndk_version"
37+
38+
ANDROID_NDK_ROOT=
39+
# XXX: Older Rust toolchain versions link with `-lgcc` instead of `-lunwind`;
40+
# see https://github.com/rust-lang/rust/pull/85806.
41+
find -L ${ANDROID_NDK_ROOT:-${ANDROID_HOME}/ndk/$ndk_version} -name libunwind.a \
42+
-execdir sh -c 'echo "INPUT(-lunwind)" > libgcc.a' \;
3643
;;
3744
esac
3845

0 commit comments

Comments
 (0)