Skip to content

Commit

Permalink
Auto merge of #45580 - kennytm:sdkmanager, r=alexcrichton
Browse files Browse the repository at this point in the history
ci: Upgrade Android SDK/NDK and refactor to use sdkmanager/avdmanager.

* SDK tools is upgraded to 27.0.0.

* Stopped using the deprecated `android` tool, instead use the recommended `sdkmanager` and `avdmanager`.

* NDK is upgrade to r15c.

    The r15 series [dropped support for android-9](https://github.com/android-ndk/ndk/wiki/Changelog-r15) (2.3 / Gingerbread), the minimal supported version is now android-14 (4.0 / Ice Cream Sandwich).

r? @alexcrichton

(WIP, haven't confirmed if the change really works yet)
  • Loading branch information
bors committed Oct 28, 2017
2 parents 269cf50 + c46b04c commit 49edcbd
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 52 deletions.
35 changes: 31 additions & 4 deletions src/bootstrap/cc_detect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ pub fn find(build: &mut Build) {
if let Some(cc) = config.and_then(|c| c.cc.as_ref()) {
cfg.compiler(cc);
} else {
set_compiler(&mut cfg, "gcc", target, config, build);
set_compiler(&mut cfg, Language::C, target, config, build);
}

let compiler = cfg.get_compiler();
Expand Down Expand Up @@ -112,7 +112,7 @@ pub fn find(build: &mut Build) {
if let Some(cxx) = config.and_then(|c| c.cxx.as_ref()) {
cfg.compiler(cxx);
} else {
set_compiler(&mut cfg, "g++", host, config, build);
set_compiler(&mut cfg, Language::CPlusPlus, host, config, build);
}
let compiler = cfg.get_compiler();
build.verbose(&format!("CXX_{} = {:?}", host, compiler.path()));
Expand All @@ -121,7 +121,7 @@ pub fn find(build: &mut Build) {
}

fn set_compiler(cfg: &mut cc::Build,
gnu_compiler: &str,
compiler: Language,
target: Interned<String>,
config: Option<&Target>,
build: &Build) {
Expand All @@ -132,7 +132,7 @@ fn set_compiler(cfg: &mut cc::Build,
t if t.contains("android") => {
if let Some(ndk) = config.and_then(|c| c.ndk.as_ref()) {
let target = target.replace("armv7", "arm");
let compiler = format!("{}-{}", target, gnu_compiler);
let compiler = format!("{}-{}", target, compiler.clang());
cfg.compiler(ndk.join("bin").join(compiler));
}
}
Expand All @@ -141,6 +141,7 @@ fn set_compiler(cfg: &mut cc::Build,
// which is a gcc version from ports, if this is the case.
t if t.contains("openbsd") => {
let c = cfg.get_compiler();
let gnu_compiler = compiler.gcc();
if !c.path().ends_with(gnu_compiler) {
return
}
Expand Down Expand Up @@ -183,3 +184,29 @@ fn set_compiler(cfg: &mut cc::Build,
_ => {}
}
}

/// The target programming language for a native compiler.
enum Language {
/// The compiler is targeting C.
C,
/// The compiler is targeting C++.
CPlusPlus,
}

impl Language {
/// Obtains the name of a compiler in the GCC collection.
fn gcc(self) -> &'static str {
match self {
Language::C => "gcc",
Language::CPlusPlus => "g++",
}
}

/// Obtains the name of a compiler in the clang suite.
fn clang(self) -> &'static str {
match self {
Language::C => "clang",
Language::CPlusPlus => "clang++",
}
}
}
14 changes: 10 additions & 4 deletions src/ci/docker/arm-android/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,35 @@ 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-r13b-linux-x86_64.zip arm 9
download_and_make_toolchain android-ndk-r15c-linux-x86_64.zip arm 14

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

COPY scripts/android-sdk.sh /scripts/
RUN . /scripts/android-sdk.sh && \
download_and_create_avd tools_r25.2.5-linux.zip armeabi-v7a 18
download_and_create_avd 4333796 armeabi-v7a 18

ENV PATH=$PATH:/android/sdk/emulator
ENV PATH=$PATH:/android/sdk/tools
ENV PATH=$PATH:/android/sdk/platform-tools

ENV TARGETS=arm-linux-androideabi

ENV RUST_CONFIGURE_ARGS \
--target=$TARGETS \
--arm-linux-androideabi-ndk=/android/ndk/arm-9
--arm-linux-androideabi-ndk=/android/ndk/arm-14

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

Expand Down
2 changes: 1 addition & 1 deletion src/ci/docker/disabled/dist-aarch64-android/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ 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-r13b-linux-x86_64.zip arm64 21
download_and_make_toolchain android-ndk-r15c-linux-x86_64.zip arm64 21

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

Expand Down
16 changes: 8 additions & 8 deletions src/ci/docker/disabled/dist-armv7-android/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ RUN sh /scripts/android-base-apt-get.sh

COPY scripts/android-ndk.sh /scripts/
RUN . /scripts/android-ndk.sh && \
download_ndk android-ndk-r13b-linux-x86_64.zip && \
make_standalone_toolchain arm 9 && \
download_ndk android-ndk-r15c-linux-x86_64.zip && \
make_standalone_toolchain arm 14 && \
make_standalone_toolchain arm 21 && \
remove_ndk

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

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

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

ENV HOSTS=armv7-linux-androideabi

Expand All @@ -27,18 +27,18 @@ ENV RUST_CONFIGURE_ARGS \
--enable-extended \
--enable-cargo-openssl-static

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

COPY scripts/sccache.sh /scripts/
Expand Down
16 changes: 8 additions & 8 deletions src/ci/docker/disabled/dist-i686-android/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ RUN sh /scripts/android-base-apt-get.sh

COPY scripts/android-ndk.sh /scripts/
RUN . /scripts/android-ndk.sh && \
download_ndk android-ndk-r13b-linux-x86_64.zip && \
make_standalone_toolchain x86 9 && \
download_ndk android-ndk-r15c-linux-x86_64.zip && \
make_standalone_toolchain x86 14 && \
make_standalone_toolchain x86 21 && \
remove_ndk

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

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

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

ENV HOSTS=i686-linux-android

Expand All @@ -27,18 +27,18 @@ ENV RUST_CONFIGURE_ARGS \
--enable-extended \
--enable-cargo-openssl-static

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

COPY scripts/sccache.sh /scripts/
Expand Down
2 changes: 1 addition & 1 deletion src/ci/docker/disabled/dist-x86_64-android/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ 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-r13b-linux-x86_64.zip x86_64 21
download_and_make_toolchain android-ndk-r15c-linux-x86_64.zip x86_64 21

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

Expand Down
12 changes: 6 additions & 6 deletions src/ci/docker/dist-android/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ RUN sh /scripts/android-base-apt-get.sh
# ndk
COPY scripts/android-ndk.sh /scripts/
RUN . /scripts/android-ndk.sh && \
download_ndk android-ndk-r13b-linux-x86_64.zip && \
make_standalone_toolchain arm 9 && \
make_standalone_toolchain x86 9 && \
download_ndk android-ndk-r15c-linux-x86_64.zip && \
make_standalone_toolchain arm 14 && \
make_standalone_toolchain x86 14 && \
make_standalone_toolchain arm64 21 && \
make_standalone_toolchain x86_64 21 && \
remove_ndk
Expand All @@ -23,9 +23,9 @@ ENV TARGETS=$TARGETS,x86_64-linux-android
ENV RUST_CONFIGURE_ARGS \
--target=$TARGETS \
--enable-extended \
--arm-linux-androideabi-ndk=/android/ndk/arm-9 \
--armv7-linux-androideabi-ndk=/android/ndk/arm-9 \
--i686-linux-android-ndk=/android/ndk/x86-9 \
--arm-linux-androideabi-ndk=/android/ndk/arm-14 \
--armv7-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

Expand Down
52 changes: 32 additions & 20 deletions src/ci/docker/scripts/android-sdk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,44 +10,56 @@

set -ex

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

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

download_sysimage() {
# See https://developer.android.com/studio/tools/help/android.html
abi=$1
api=$2

filter="platform-tools,android-$api"
filter="$filter,sys-img-$abi-android-$api"

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

create_avd() {
# See https://developer.android.com/studio/tools/help/android.html
abi=$1
api=$2

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

download_and_create_avd() {
download_sdk $1
download_sysimage $2 $3
create_avd $2 $3
}

# Usage:
#
# setup_android_sdk 4333796 armeabi-v7a 18
#
# 4333796 =>
# SDK tool version.
# Copy from https://developer.android.com/studio/index.html#command-tools
# armeabi-v7a =>
# System image ABI
# 18 =>
# Android API Level (18 = Android 4.3 = Jelly Bean MR2)

0 comments on commit 49edcbd

Please sign in to comment.