Skip to content

Commit baa33ca

Browse files
committed
ci: Upgrade Android SDK/NDK and refactor to use sdkmanager/avdmanager.
* SDK tools is upgraded to 27.0.0. - Refactored to use `sdkmanager`/`avdmanager` instead of the deprecated `android` tool. * The Java version used by Android SDK is downgraded to OpenJDK-8, in order to download the SDK through HTTPS. * NDK is upgrade to r15c. - Dropped support for android-9 (2.3 / Gingerbread), the minimal supported version is now android-14 (4.0 / Ice Cream Sandwich). - Changed the default Android compiler from GCC to clang. - For details of change introduced by NDK r15, see https://github.com/android-ndk/ndk/wiki/Changelog-r15.
1 parent 49d5276 commit baa33ca

File tree

8 files changed

+97
-52
lines changed

8 files changed

+97
-52
lines changed

src/bootstrap/cc_detect.rs

+31-4
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub fn find(build: &mut Build) {
5353
if let Some(cc) = config.and_then(|c| c.cc.as_ref()) {
5454
cfg.compiler(cc);
5555
} else {
56-
set_compiler(&mut cfg, "gcc", target, config, build);
56+
set_compiler(&mut cfg, Language::C, target, config, build);
5757
}
5858

5959
let compiler = cfg.get_compiler();
@@ -74,7 +74,7 @@ pub fn find(build: &mut Build) {
7474
if let Some(cxx) = config.and_then(|c| c.cxx.as_ref()) {
7575
cfg.compiler(cxx);
7676
} else {
77-
set_compiler(&mut cfg, "g++", host, config, build);
77+
set_compiler(&mut cfg, Language::CPlusPlus, host, config, build);
7878
}
7979
let compiler = cfg.get_compiler();
8080
build.verbose(&format!("CXX_{} = {:?}", host, compiler.path()));
@@ -83,7 +83,7 @@ pub fn find(build: &mut Build) {
8383
}
8484

8585
fn set_compiler(cfg: &mut cc::Build,
86-
gnu_compiler: &str,
86+
compiler: Language,
8787
target: Interned<String>,
8888
config: Option<&Target>,
8989
build: &Build) {
@@ -94,7 +94,7 @@ fn set_compiler(cfg: &mut cc::Build,
9494
t if t.contains("android") => {
9595
if let Some(ndk) = config.and_then(|c| c.ndk.as_ref()) {
9696
let target = target.replace("armv7", "arm");
97-
let compiler = format!("{}-{}", target, gnu_compiler);
97+
let compiler = format!("{}-{}", target, compiler.clang());
9898
cfg.compiler(ndk.join("bin").join(compiler));
9999
}
100100
}
@@ -103,6 +103,7 @@ fn set_compiler(cfg: &mut cc::Build,
103103
// which is a gcc version from ports, if this is the case.
104104
t if t.contains("openbsd") => {
105105
let c = cfg.get_compiler();
106+
let gnu_compiler = compiler.gcc();
106107
if !c.path().ends_with(gnu_compiler) {
107108
return
108109
}
@@ -145,3 +146,29 @@ fn set_compiler(cfg: &mut cc::Build,
145146
_ => {}
146147
}
147148
}
149+
150+
/// The target programming language for a native compiler.
151+
enum Language {
152+
/// The compiler is targeting C.
153+
C,
154+
/// The compiler is targeting C++.
155+
CPlusPlus,
156+
}
157+
158+
impl Language {
159+
/// Obtains the name of a compiler in the GCC collection.
160+
fn gcc(self) -> &'static str {
161+
match self {
162+
Language::C => "gcc",
163+
Language::CPlusPlus => "g++",
164+
}
165+
}
166+
167+
/// Obtains the name of a compiler in the clang suite.
168+
fn clang(self) -> &'static str {
169+
match self {
170+
Language::C => "clang",
171+
Language::CPlusPlus => "clang++",
172+
}
173+
}
174+
}

src/ci/docker/arm-android/Dockerfile

+10-4
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,35 @@ RUN sh /scripts/android-base-apt-get.sh
55

66
COPY scripts/android-ndk.sh /scripts/
77
RUN . /scripts/android-ndk.sh && \
8-
download_and_make_toolchain android-ndk-r13b-linux-x86_64.zip arm 9
8+
download_and_make_toolchain android-ndk-r15c-linux-x86_64.zip arm 14
99

10+
# Note:
11+
# Do not upgrade to `openjdk-9-jre-headless`, as it will cause certificate error
12+
# when installing the Android SDK (see PR #45193). This is unfortunate, but
13+
# every search result suggested either disabling HTTPS or replacing JDK 9 by
14+
# JDK 8 as the solution (e.g. https://stackoverflow.com/q/41421340). :|
1015
RUN dpkg --add-architecture i386 && \
1116
apt-get update && \
1217
apt-get install -y --no-install-recommends \
1318
libgl1-mesa-glx \
1419
libpulse0 \
1520
libstdc++6:i386 \
16-
openjdk-9-jre-headless \
21+
openjdk-8-jre-headless \
1722
tzdata
1823

1924
COPY scripts/android-sdk.sh /scripts/
2025
RUN . /scripts/android-sdk.sh && \
21-
download_and_create_avd tools_r25.2.5-linux.zip armeabi-v7a 18
26+
download_and_create_avd 4333796 armeabi-v7a 18
2227

28+
ENV PATH=$PATH:/android/sdk/emulator
2329
ENV PATH=$PATH:/android/sdk/tools
2430
ENV PATH=$PATH:/android/sdk/platform-tools
2531

2632
ENV TARGETS=arm-linux-androideabi
2733

2834
ENV RUST_CONFIGURE_ARGS \
2935
--target=$TARGETS \
30-
--arm-linux-androideabi-ndk=/android/ndk/arm-9
36+
--arm-linux-androideabi-ndk=/android/ndk/arm-14
3137

3238
ENV SCRIPT python2.7 ../x.py test --target $TARGETS
3339

src/ci/docker/disabled/dist-aarch64-android/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ RUN sh /scripts/android-base-apt-get.sh
55

66
COPY scripts/android-ndk.sh /scripts/
77
RUN . /scripts/android-ndk.sh && \
8-
download_and_make_toolchain android-ndk-r13b-linux-x86_64.zip arm64 21
8+
download_and_make_toolchain android-ndk-r15c-linux-x86_64.zip arm64 21
99

1010
ENV PATH=$PATH:/android/ndk/arm64-21/bin
1111

src/ci/docker/disabled/dist-armv7-android/Dockerfile

+8-8
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ RUN sh /scripts/android-base-apt-get.sh
55

66
COPY scripts/android-ndk.sh /scripts/
77
RUN . /scripts/android-ndk.sh && \
8-
download_ndk android-ndk-r13b-linux-x86_64.zip && \
9-
make_standalone_toolchain arm 9 && \
8+
download_ndk android-ndk-r15c-linux-x86_64.zip && \
9+
make_standalone_toolchain arm 14 && \
1010
make_standalone_toolchain arm 21 && \
1111
remove_ndk
1212

1313
RUN chmod 777 /android/ndk && \
1414
ln -s /android/ndk/arm-21 /android/ndk/arm
1515

16-
ENV PATH=$PATH:/android/ndk/arm-9/bin
16+
ENV PATH=$PATH:/android/ndk/arm-14/bin
1717

18-
ENV DEP_Z_ROOT=/android/ndk/arm-9/sysroot/usr/
18+
ENV DEP_Z_ROOT=/android/ndk/arm-14/sysroot/usr/
1919

2020
ENV HOSTS=armv7-linux-androideabi
2121

@@ -27,18 +27,18 @@ ENV RUST_CONFIGURE_ARGS \
2727
--enable-extended \
2828
--enable-cargo-openssl-static
2929

30-
# We support api level 9, but api level 21 is required to build llvm. To
30+
# We support api level 14, but api level 21 is required to build llvm. To
3131
# overcome this problem we use a ndk with api level 21 to build llvm and then
32-
# switch to a ndk with api level 9 to complete the build. When the linker is
32+
# switch to a ndk with api level 14 to complete the build. When the linker is
3333
# invoked there are missing symbols (like sigsetempty, not available with api
34-
# level 9), the default linker behavior is to generate an error, to allow the
34+
# level 14), the default linker behavior is to generate an error, to allow the
3535
# build to finish we use --warn-unresolved-symbols. Note that the missing
3636
# symbols does not affect std, only the compiler (llvm) and cargo (openssl).
3737
ENV SCRIPT \
3838
python2.7 ../x.py build src/llvm --host $HOSTS --target $HOSTS && \
3939
(export RUSTFLAGS="\"-C link-arg=-Wl,--warn-unresolved-symbols\""; \
4040
rm /android/ndk/arm && \
41-
ln -s /android/ndk/arm-9 /android/ndk/arm && \
41+
ln -s /android/ndk/arm-14 /android/ndk/arm && \
4242
python2.7 ../x.py dist --host $HOSTS --target $HOSTS)
4343

4444
COPY scripts/sccache.sh /scripts/

src/ci/docker/disabled/dist-i686-android/Dockerfile

+8-8
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ RUN sh /scripts/android-base-apt-get.sh
55

66
COPY scripts/android-ndk.sh /scripts/
77
RUN . /scripts/android-ndk.sh && \
8-
download_ndk android-ndk-r13b-linux-x86_64.zip && \
9-
make_standalone_toolchain x86 9 && \
8+
download_ndk android-ndk-r15c-linux-x86_64.zip && \
9+
make_standalone_toolchain x86 14 && \
1010
make_standalone_toolchain x86 21 && \
1111
remove_ndk
1212

1313
RUN chmod 777 /android/ndk && \
1414
ln -s /android/ndk/x86-21 /android/ndk/x86
1515

16-
ENV PATH=$PATH:/android/ndk/x86-9/bin
16+
ENV PATH=$PATH:/android/ndk/x86-14/bin
1717

18-
ENV DEP_Z_ROOT=/android/ndk/x86-9/sysroot/usr/
18+
ENV DEP_Z_ROOT=/android/ndk/x86-14/sysroot/usr/
1919

2020
ENV HOSTS=i686-linux-android
2121

@@ -27,18 +27,18 @@ ENV RUST_CONFIGURE_ARGS \
2727
--enable-extended \
2828
--enable-cargo-openssl-static
2929

30-
# We support api level 9, but api level 21 is required to build llvm. To
30+
# We support api level 14, but api level 21 is required to build llvm. To
3131
# overcome this problem we use a ndk with api level 21 to build llvm and then
32-
# switch to a ndk with api level 9 to complete the build. When the linker is
32+
# switch to a ndk with api level 14 to complete the build. When the linker is
3333
# invoked there are missing symbols (like sigsetempty, not available with api
34-
# level 9), the default linker behavior is to generate an error, to allow the
34+
# level 14), the default linker behavior is to generate an error, to allow the
3535
# build to finish we use --warn-unresolved-symbols. Note that the missing
3636
# symbols does not affect std, only the compiler (llvm) and cargo (openssl).
3737
ENV SCRIPT \
3838
python2.7 ../x.py build src/llvm --host $HOSTS --target $HOSTS && \
3939
(export RUSTFLAGS="\"-C link-arg=-Wl,--warn-unresolved-symbols\""; \
4040
rm /android/ndk/x86 && \
41-
ln -s /android/ndk/x86-9 /android/ndk/x86 && \
41+
ln -s /android/ndk/x86-14 /android/ndk/x86 && \
4242
python2.7 ../x.py dist --host $HOSTS --target $HOSTS)
4343

4444
COPY scripts/sccache.sh /scripts/

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ RUN sh /scripts/android-base-apt-get.sh
55

66
COPY scripts/android-ndk.sh /scripts/
77
RUN . /scripts/android-ndk.sh && \
8-
download_and_make_toolchain android-ndk-r13b-linux-x86_64.zip x86_64 21
8+
download_and_make_toolchain android-ndk-r15c-linux-x86_64.zip x86_64 21
99

1010
ENV PATH=$PATH:/android/ndk/x86_64-21/bin
1111

src/ci/docker/dist-android/Dockerfile

+6-6
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ 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-r13b-linux-x86_64.zip && \
10-
make_standalone_toolchain arm 9 && \
11-
make_standalone_toolchain x86 9 && \
9+
download_ndk android-ndk-r15c-linux-x86_64.zip && \
10+
make_standalone_toolchain arm 14 && \
11+
make_standalone_toolchain x86 14 && \
1212
make_standalone_toolchain arm64 21 && \
1313
make_standalone_toolchain x86_64 21 && \
1414
remove_ndk
@@ -23,9 +23,9 @@ ENV TARGETS=$TARGETS,x86_64-linux-android
2323
ENV RUST_CONFIGURE_ARGS \
2424
--target=$TARGETS \
2525
--enable-extended \
26-
--arm-linux-androideabi-ndk=/android/ndk/arm-9 \
27-
--armv7-linux-androideabi-ndk=/android/ndk/arm-9 \
28-
--i686-linux-android-ndk=/android/ndk/x86-9 \
26+
--arm-linux-androideabi-ndk=/android/ndk/arm-14 \
27+
--armv7-linux-androideabi-ndk=/android/ndk/arm-14 \
28+
--i686-linux-android-ndk=/android/ndk/x86-14 \
2929
--aarch64-linux-android-ndk=/android/ndk/arm64-21 \
3030
--x86_64-linux-android-ndk=/android/ndk/x86_64-21
3131

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

+32-20
Original file line numberDiff line numberDiff line change
@@ -10,44 +10,56 @@
1010

1111
set -ex
1212

13-
URL=https://dl.google.com/android/repository
13+
export ANDROID_HOME=/android/sdk
14+
PATH=$PATH:"${ANDROID_HOME}/tools/bin"
1415

1516
download_sdk() {
16-
mkdir -p /android/sdk
17-
cd /android/sdk
18-
curl -fO $URL/$1
19-
unzip -q $1
20-
rm -rf $1
17+
mkdir -p /android
18+
curl -fo sdk.zip "https://dl.google.com/android/repository/sdk-tools-linux-$1.zip"
19+
unzip -q sdk.zip -d "$ANDROID_HOME"
20+
rm -f sdk.zip
2121
}
2222

2323
download_sysimage() {
24-
# See https://developer.android.com/studio/tools/help/android.html
2524
abi=$1
2625
api=$2
2726

28-
filter="platform-tools,android-$api"
29-
filter="$filter,sys-img-$abi-android-$api"
30-
31-
# Keep printing yes to accept the licenses
32-
while true; do echo yes; sleep 10; done | \
33-
/android/sdk/tools/android update sdk -a --no-ui \
34-
--filter "$filter" --no-https
27+
# See https://developer.android.com/studio/command-line/sdkmanager.html for
28+
# usage of `sdkmanager`.
29+
#
30+
# The output from sdkmanager is so noisy that it will occupy all of the 4 MB
31+
# log extremely quickly. Thus we must silence all output.
32+
yes | sdkmanager --licenses > /dev/null
33+
sdkmanager platform-tools emulator \
34+
"platforms;android-$api" \
35+
"system-images;android-$api;default;$abi" > /dev/null
3536
}
3637

3738
create_avd() {
38-
# See https://developer.android.com/studio/tools/help/android.html
3939
abi=$1
4040
api=$2
4141

42-
echo no | \
43-
/android/sdk/tools/android create avd \
44-
--name $abi-$api \
45-
--target android-$api \
46-
--abi $abi
42+
# See https://developer.android.com/studio/command-line/avdmanager.html for
43+
# usage of `avdmanager`.
44+
echo no | avdmanager create avd \
45+
-n "$abi-$api" \
46+
-k "system-images;android-$api;default;$abi"
4747
}
4848

4949
download_and_create_avd() {
5050
download_sdk $1
5151
download_sysimage $2 $3
5252
create_avd $2 $3
5353
}
54+
55+
# Usage:
56+
#
57+
# setup_android_sdk 4333796 armeabi-v7a 18
58+
#
59+
# 4333796 =>
60+
# SDK tool version.
61+
# Copy from https://developer.android.com/studio/index.html#command-tools
62+
# armeabi-v7a =>
63+
# System image ABI
64+
# 18 =>
65+
# Android API Level (18 = Android 4.3 = Jelly Bean MR2)

0 commit comments

Comments
 (0)