Skip to content

Commit 333ee6c

Browse files
committed
Auto merge of #105716 - chriswailes:ndk-update-redux, r=pietroalbini
Ndk update redux Blocked on rust-lang/blog.rust-lang.org#1055
2 parents 6d46b1e + 0fb426a commit 333ee6c

File tree

4 files changed

+31
-44
lines changed

4 files changed

+31
-44
lines changed

src/bootstrap/cc_detect.rs

+18-6
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();
@@ -219,12 +221,22 @@ fn set_compiler(
219221
}
220222

221223
pub(crate) fn ndk_compiler(compiler: Language, triple: &str, ndk: &Path) -> PathBuf {
222-
let triple_translated = triple
223-
.replace("armv7neon", "arm")
224-
.replace("armv7", "arm")
225-
.replace("thumbv7neon", "arm")
226-
.replace("thumbv7", "arm");
227-
let compiler = format!("{}-{}", triple_translated, compiler.clang());
224+
let mut triple_iter = triple.split("-");
225+
let triple_translated = if let Some(arch) = triple_iter.next() {
226+
let arch_new = match arch {
227+
"arm" | "armv7" | "armv7neon" | "thumbv7" | "thumbv7neon" => "armv7a",
228+
other => other,
229+
};
230+
std::iter::once(arch_new).chain(triple_iter).collect::<Vec<&str>>().join("-")
231+
} else {
232+
triple.to_string()
233+
};
234+
235+
// API 19 is the earliest API level supported by NDK r25b but AArch64 and x86_64 support
236+
// begins at API level 21.
237+
let api_level =
238+
if triple.contains("aarch64") || triple.contains("x86_64") { "21" } else { "19" };
239+
let compiler = format!("{}{}-{}", triple_translated, api_level, compiler.clang());
228240
ndk.join("bin").join(compiler)
229241
}
230242

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
FROM ubuntu:22.04
1+
FROM ubuntu:22.10
22

33
ARG DEBIAN_FRONTEND=noninteractive
44
COPY scripts/android-base-apt-get.sh /scripts/
55
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

+8-15
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,12 @@
1-
FROM ubuntu:22.04
1+
FROM ubuntu:22.10
22

33
COPY scripts/android-base-apt-get.sh /scripts/
44
RUN sh /scripts/android-base-apt-get.sh
55

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)