Skip to content
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

Ndk update redux #105716

Merged
merged 1 commit into from
Jan 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions src/bootstrap/cc_detect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ fn cc2ar(cc: &Path, target: TargetSelection) -> Option<PathBuf> {
Some(PathBuf::from("ar"))
} else if target.contains("vxworks") {
Some(PathBuf::from("wr-ar"))
} else if target.contains("android") {
Some(cc.parent().unwrap().join(PathBuf::from("llvm-ar")))
} else {
let parent = cc.parent().unwrap();
let file = cc.file_name().unwrap().to_str().unwrap();
Expand Down Expand Up @@ -219,12 +221,22 @@ fn set_compiler(
}

pub(crate) fn ndk_compiler(compiler: Language, triple: &str, ndk: &Path) -> PathBuf {
let triple_translated = triple
.replace("armv7neon", "arm")
.replace("armv7", "arm")
.replace("thumbv7neon", "arm")
.replace("thumbv7", "arm");
let compiler = format!("{}-{}", triple_translated, compiler.clang());
let mut triple_iter = triple.split("-");
let triple_translated = if let Some(arch) = triple_iter.next() {
let arch_new = match arch {
"arm" | "armv7" | "armv7neon" | "thumbv7" | "thumbv7neon" => "armv7a",
other => other,
};
std::iter::once(arch_new).chain(triple_iter).collect::<Vec<&str>>().join("-")
} else {
triple.to_string()
};

// API 19 is the earliest API level supported by NDK r25b but AArch64 and x86_64 support
// begins at API level 21.
let api_level =
if triple.contains("aarch64") || triple.contains("x86_64") { "21" } else { "19" };
let compiler = format!("{}{}-{}", triple_translated, api_level, compiler.clang());
ndk.join("bin").join(compiler)
}

Expand Down
6 changes: 3 additions & 3 deletions src/ci/docker/host-x86_64/arm-android/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
FROM ubuntu:22.04
FROM ubuntu:22.10

ARG DEBIAN_FRONTEND=noninteractive
COPY scripts/android-base-apt-get.sh /scripts/
RUN sh /scripts/android-base-apt-get.sh

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

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

ENV TARGETS=arm-linux-androideabi

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

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

Expand Down
23 changes: 8 additions & 15 deletions src/ci/docker/host-x86_64/dist-android/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
FROM ubuntu:22.04
FROM ubuntu:22.10

COPY scripts/android-base-apt-get.sh /scripts/
RUN sh /scripts/android-base-apt-get.sh

# ndk
COPY scripts/android-ndk.sh /scripts/
RUN . /scripts/android-ndk.sh && \
download_ndk android-ndk-r15c-linux-x86_64.zip && \
make_standalone_toolchain arm 14 && \
make_standalone_toolchain x86 14 && \
make_standalone_toolchain arm 21 && \
make_standalone_toolchain x86 21 && \
make_standalone_toolchain arm64 21 && \
make_standalone_toolchain x86_64 21 && \
remove_ndk
download_ndk android-ndk-r25b-linux.zip

# env
ENV TARGETS=arm-linux-androideabi
Expand All @@ -26,12 +19,12 @@ ENV TARGETS=$TARGETS,x86_64-linux-android
ENV RUST_CONFIGURE_ARGS \
--enable-extended \
--enable-profiler \
--arm-linux-androideabi-ndk=/android/ndk/arm-14 \
--armv7-linux-androideabi-ndk=/android/ndk/arm-14 \
--thumbv7neon-linux-androideabi-ndk=/android/ndk/arm-14 \
--i686-linux-android-ndk=/android/ndk/x86-14 \
--aarch64-linux-android-ndk=/android/ndk/arm64-21 \
--x86_64-linux-android-ndk=/android/ndk/x86_64-21 \
--arm-linux-androideabi-ndk=/android/ndk/toolchains/llvm/prebuilt/linux-x86_64/ \
--armv7-linux-androideabi-ndk=/android/ndk/toolchains/llvm/prebuilt/linux-x86_64/ \
--thumbv7neon-linux-androideabi-ndk=/android/ndk/toolchains/llvm/prebuilt/linux-x86_64/ \
--i686-linux-android-ndk=/android/ndk/toolchains/llvm/prebuilt/linux-x86_64/ \
--aarch64-linux-android-ndk=/android/ndk/toolchains/llvm/prebuilt/linux-x86_64/ \
--x86_64-linux-android-ndk=/android/ndk/toolchains/llvm/prebuilt/linux-x86_64/ \
--disable-docs

ENV SCRIPT python3 ../x.py dist --host='' --target $TARGETS
Expand Down
22 changes: 2 additions & 20 deletions src/ci/docker/scripts/android-ndk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,10 @@ set -ex
URL=https://dl.google.com/android/repository

download_ndk() {
mkdir -p /android/ndk
cd /android/ndk
mkdir /android/
cd /android
curl -fO $URL/$1
unzip -q $1
rm $1
mv android-ndk-* ndk
}

make_standalone_toolchain() {
# See https://developer.android.com/ndk/guides/standalone_toolchain.htm
python3 /android/ndk/ndk/build/tools/make_standalone_toolchain.py \
--install-dir /android/ndk/$1-$2 \
--arch $1 \
--api $2
}

remove_ndk() {
rm -rf /android/ndk/ndk
}

download_and_make_toolchain() {
download_ndk $1 && \
make_standalone_toolchain $2 $3 && \
remove_ndk
}