Skip to content

Commit bf7f1ca

Browse files
committed
Update CI to use Android NDK r25b
This commit updates the CI definitions to use the most recent Android LTS NDK release: r25b. Changes since the last NDK used by Rust negate the need to generate "standalone toolchains" and newer NDKs can be used in-place. See https://developer.android.com/ndk/guides/other_build_systems#overview
1 parent 33d3519 commit bf7f1ca

File tree

4 files changed

+29
-43
lines changed

4 files changed

+29
-43
lines changed

src/bootstrap/cc_detect.rs

+18-7
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ fn cc2ar(cc: &Path, target: TargetSelection) -> Option<PathBuf> {
4747
Some(PathBuf::from("ar"))
4848
} else if target.contains("vxworks") {
4949
Some(PathBuf::from("wr-ar"))
50+
} else if target.contains("android") {
51+
Some(cc.parent().unwrap().join(PathBuf::from("llvm-ar")))
5052
} else {
5153
let parent = cc.parent().unwrap();
5254
let file = cc.file_name().unwrap().to_str().unwrap();
@@ -166,13 +168,22 @@ fn set_compiler(
166168
// compiler already takes into account the triple in question.
167169
t if t.contains("android") => {
168170
if let Some(ndk) = config.and_then(|c| c.ndk.as_ref()) {
169-
let target = target
170-
.triple
171-
.replace("armv7neon", "arm")
172-
.replace("armv7", "arm")
173-
.replace("thumbv7neon", "arm")
174-
.replace("thumbv7", "arm");
175-
let compiler = format!("{}-{}", target, compiler.clang());
171+
let mut triple_iter = target.triple.split("-");
172+
let triple_translated = if let Some(arch) = triple_iter.next() {
173+
let arch_new = match arch {
174+
"arm" | "armv7" | "armv7neon" | "thumbv7" | "thumbv7neon" => "armv7a",
175+
other => other,
176+
};
177+
std::iter::once(arch_new).chain(triple_iter).collect::<Vec<&str>>().join("-")
178+
} else {
179+
target.triple.to_string()
180+
};
181+
182+
// API 19 is the earliest API level supported by NDK r25b but AArch64 and x86_64 support
183+
// begins at API level 21.
184+
let api_level =
185+
if t.contains("aarch64") || t.contains("x86_64") { "21" } else { "19" };
186+
let compiler = format!("{}{}-{}", triple_translated, api_level, compiler.clang());
176187
cfg.compiler(ndk.join("bin").join(compiler));
177188
}
178189
}

src/ci/docker/host-x86_64/arm-android/Dockerfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ RUN sh /scripts/android-base-apt-get.sh
66

77
COPY scripts/android-ndk.sh /scripts/
88
RUN . /scripts/android-ndk.sh && \
9-
download_and_make_toolchain android-ndk-r15c-linux-x86_64.zip arm 14
9+
download_ndk android-ndk-r25b-linux.zip
1010

1111
RUN dpkg --add-architecture i386 && \
1212
apt-get update && \
@@ -30,7 +30,7 @@ ENV PATH=$PATH:/android/sdk/platform-tools
3030

3131
ENV TARGETS=arm-linux-androideabi
3232

33-
ENV RUST_CONFIGURE_ARGS --arm-linux-androideabi-ndk=/android/ndk/arm-14
33+
ENV RUST_CONFIGURE_ARGS --arm-linux-androideabi-ndk=/android/ndk/toolchains/llvm/prebuilt/linux-x86_64/
3434

3535
ENV SCRIPT python3 ../x.py --stage 2 test --host='' --target $TARGETS
3636

src/ci/docker/host-x86_64/dist-android/Dockerfile

+7-14
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,7 @@ RUN sh /scripts/android-base-apt-get.sh
66
# ndk
77
COPY scripts/android-ndk.sh /scripts/
88
RUN . /scripts/android-ndk.sh && \
9-
download_ndk android-ndk-r15c-linux-x86_64.zip && \
10-
make_standalone_toolchain arm 14 && \
11-
make_standalone_toolchain x86 14 && \
12-
make_standalone_toolchain arm 21 && \
13-
make_standalone_toolchain x86 21 && \
14-
make_standalone_toolchain arm64 21 && \
15-
make_standalone_toolchain x86_64 21 && \
16-
remove_ndk
9+
download_ndk android-ndk-r25b-linux.zip
1710

1811
# env
1912
ENV TARGETS=arm-linux-androideabi
@@ -26,12 +19,12 @@ ENV TARGETS=$TARGETS,x86_64-linux-android
2619
ENV RUST_CONFIGURE_ARGS \
2720
--enable-extended \
2821
--enable-profiler \
29-
--arm-linux-androideabi-ndk=/android/ndk/arm-14 \
30-
--armv7-linux-androideabi-ndk=/android/ndk/arm-14 \
31-
--thumbv7neon-linux-androideabi-ndk=/android/ndk/arm-14 \
32-
--i686-linux-android-ndk=/android/ndk/x86-14 \
33-
--aarch64-linux-android-ndk=/android/ndk/arm64-21 \
34-
--x86_64-linux-android-ndk=/android/ndk/x86_64-21 \
22+
--arm-linux-androideabi-ndk=/android/ndk/toolchains/llvm/prebuilt/linux-x86_64/ \
23+
--armv7-linux-androideabi-ndk=/android/ndk/toolchains/llvm/prebuilt/linux-x86_64/ \
24+
--thumbv7neon-linux-androideabi-ndk=/android/ndk/toolchains/llvm/prebuilt/linux-x86_64/ \
25+
--i686-linux-android-ndk=/android/ndk/toolchains/llvm/prebuilt/linux-x86_64/ \
26+
--aarch64-linux-android-ndk=/android/ndk/toolchains/llvm/prebuilt/linux-x86_64/ \
27+
--x86_64-linux-android-ndk=/android/ndk/toolchains/llvm/prebuilt/linux-x86_64/ \
3528
--disable-docs
3629

3730
ENV SCRIPT python3 ../x.py dist --host='' --target $TARGETS

src/ci/docker/scripts/android-ndk.sh

+2-20
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,10 @@ set -ex
44
URL=https://dl.google.com/android/repository
55

66
download_ndk() {
7-
mkdir -p /android/ndk
8-
cd /android/ndk
7+
mkdir /android/
8+
cd /android
99
curl -fO $URL/$1
1010
unzip -q $1
1111
rm $1
1212
mv android-ndk-* ndk
1313
}
14-
15-
make_standalone_toolchain() {
16-
# See https://developer.android.com/ndk/guides/standalone_toolchain.htm
17-
python3 /android/ndk/ndk/build/tools/make_standalone_toolchain.py \
18-
--install-dir /android/ndk/$1-$2 \
19-
--arch $1 \
20-
--api $2
21-
}
22-
23-
remove_ndk() {
24-
rm -rf /android/ndk/ndk
25-
}
26-
27-
download_and_make_toolchain() {
28-
download_ndk $1 && \
29-
make_standalone_toolchain $2 $3 && \
30-
remove_ndk
31-
}

0 commit comments

Comments
 (0)