Skip to content

Commit e8122e2

Browse files
committed
Fix for the Android x86-64 megazord with Android NDK-25
The new NDK doesn't link to `libgcc` anymore, which breaks our our NSS and SQLCipher libraries since they depended on the symbols from libclang_rt.builtins-x86_64-android` like `__extenddftf2`. See mozilla#5436 for more details. The change works around this by manually linking to the libclang_rt.builtins-x86_64-android library in this case. Added a doc on how to upgrade the Android NDK which hopefully will help us in the future. Extracted some common code from the the `build-*-android.sh` scripts to make these directions simpler.
1 parent 04fa49d commit e8122e2

File tree

5 files changed

+44
-22
lines changed

5 files changed

+44
-22
lines changed

components/support/rc_crypto/nss/nss_build_common/src/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,15 @@ fn link_nss_libs(kind: LinkingKind) {
8989
} else {
9090
println!("cargo:rustc-link-lib=c++");
9191
}
92+
let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap();
93+
if target_arch == "x86_64" && target_os == "android" {
94+
let android_home = env::var("ANDROID_HOME").expect("ANDROID_HOME not set");
95+
const ANDROID_NDK_VERSION: &str = "25.2.9519653";
96+
const LINUX_X86_64_LIB_DIR: &str =
97+
"/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/14.0.7/lib/linux/";
98+
println!("cargo:rustc-link-search={android_home}/ndk/{ANDROID_NDK_VERSION}/{LINUX_X86_64_LIB_DIR}");
99+
println!("cargo:rustc-link-lib=static=clang_rt.builtins-x86_64-android");
100+
}
92101
}
93102

94103
fn get_nss_libs(kind: LinkingKind) -> Vec<&'static str> {

docs/howtos/upgrades/android-ndk.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Here's how to upgrade the Android NDK version:
2+
3+
* Update the version number in:
4+
* `build.gradle` (search for `ndkVersion`)
5+
* `taskcluster/docker/linux/Dockerfile` (search for `ANDROID_NDK_VERSION`)
6+
* `components/support/rc_crypto/nss/nss_build_common/src/lib.rs` (search for `ANDROID_NDK_VERSION`)
7+
* Update these docs by replacing the old version with the new one:
8+
* docs/building.md
9+
* docs/howtos/locally-building-jna.md
10+
* These may need updating if the directory structure changed between this version and the last
11+
* `libs/build-android-common.sh`: ensure the paths to the various binaries are correct.
12+
* `components/support/rc_crypto/nss/nss_build_common/src/lib.rs`: search for
13+
`LINUX_X86_64_LIB_DIR` and ensure this correctly points to the correct lib directory containing
14+
`libclang_rt.builtins-x86_64-android.a`.

libs/build-android-common.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
# This script is sourced by the `build-*-android.sh` scripts. The shbang above
3+
# is to make shellcheck happy.
4+
5+
export AR="${TOOLCHAIN_PATH}/bin/llvm-ar"
6+
export CC="${TOOLCHAIN_PATH}/bin/${TOOLCHAIN}${ANDROID_NDK_API_VERSION}-clang"
7+
export CXX="${TOOLCHAIN_PATH}/bin/${TOOLCHAIN}${ANDROID_NDK_API_VERSION}-clang++"
8+
# For 32-bit ARM, the compiler is prefixed with armv7a-linux-androideabi
9+
if [[ "${TOOLCHAIN}" == "arm-linux-androideabi" ]]; then
10+
export CC="${TOOLCHAIN_PATH}/bin/armv7a-linux-androideabi${ANDROID_NDK_API_VERSION}-clang"
11+
export CXX="${TOOLCHAIN_PATH}/bin/armv7a-linux-androideabi${ANDROID_NDK_API_VERSION}-clang++"
12+
fi
13+
export LD="${TOOLCHAIN_PATH}/bin/ld"
14+
export NM="${TOOLCHAIN_PATH}/bin/llvm-nm"
15+
export RANLIB="${TOOLCHAIN_PATH}/bin/llvm-ranlib"
16+
export READELF="${TOOLCHAIN_PATH}/bin/llvm-readelf"
17+

libs/build-nss-android.sh

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,8 @@ else
4242
fi
4343
NSPR_64="${NSPR_64:-""}"
4444

45-
export AR="${TOOLCHAIN_PATH}/bin/llvm-ar"
46-
export CC="${TOOLCHAIN_PATH}/bin/${TOOLCHAIN}${ANDROID_NDK_API_VERSION}-clang"
47-
export CXX="${TOOLCHAIN_PATH}/bin/${TOOLCHAIN}${ANDROID_NDK_API_VERSION}-clang++"
48-
# For 32-bit ARM, the compiler is prefixed with armv7a-linux-androideabi
49-
if [[ "${TOOLCHAIN}" == "arm-linux-androideabi" ]]; then
50-
export CC="${TOOLCHAIN_PATH}/bin/armv7a-linux-androideabi${ANDROID_NDK_API_VERSION}-clang"
51-
export CXX="${TOOLCHAIN_PATH}/bin/armv7a-linux-androideabi${ANDROID_NDK_API_VERSION}-clang++"
52-
fi
53-
export LD="${TOOLCHAIN_PATH}/bin/ld"
54-
export NM="${TOOLCHAIN_PATH}/bin/llvm-nm"
55-
export RANLIB="${TOOLCHAIN_PATH}/bin/llvm-ranlib"
56-
export READELF="${TOOLCHAIN_PATH}/bin/llvm-readelf"
45+
# shellcheck source=libs/build-android-common.sh
46+
source ./build-android-common.sh
5747

5848
# Build NSPR
5949
NSPR_BUILD_DIR=$(mktemp -d)

libs/build-sqlcipher-android.sh

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,8 @@ if [[ -d "${DIST_DIR}" ]]; then
2323
exit 0
2424
fi
2525

26-
export AR="${TOOLCHAIN_PATH}/bin/llvm-ar"
27-
export CC="${TOOLCHAIN_PATH}/bin/${TOOLCHAIN}${ANDROID_NDK_API_VERSION}-clang"
28-
export CXX="${TOOLCHAIN_PATH}/bin/${TOOLCHAIN}${ANDROID_NDK_API_VERSION}-clang++"
29-
# For 32-bit ARM, the compiler is prefixed with armv7a-linux-androideabi
30-
if [[ "${TOOLCHAIN}" == "arm-linux-androideabi" ]]; then
31-
export CC="${TOOLCHAIN_PATH}/bin/armv7a-linux-androideabi${ANDROID_NDK_API_VERSION}-clang"
32-
export CXX="${TOOLCHAIN_PATH}/bin/armv7a-linux-androideabi${ANDROID_NDK_API_VERSION}-clang++"
33-
fi
34-
export LD="${TOOLCHAIN_PATH}/bin/ld"
35-
export RANLIB="${TOOLCHAIN_PATH}/bin/llvm-ranlib"
26+
# shellcheck source=libs/build-android-common.sh
27+
source ./build-android-common.sh
3628

3729
if [[ "${TOOLCHAIN}" == "x86_64-linux-android" ]]
3830
then

0 commit comments

Comments
 (0)