Skip to content

Commit

Permalink
Merge pull request #1000 from malbarbo/build-android
Browse files Browse the repository at this point in the history
Add android build support
  • Loading branch information
brson authored Mar 23, 2017
2 parents a1287b6 + e865975 commit ebd92af
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 21 deletions.
29 changes: 19 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,24 @@ matrix:
DOCKER=alexcrichton/rust-slave-linux-cross:2016-11-11
SKIP_TESTS=1

# Android use a local docker image
- os: linux
env: TARGET=arm-linux-androideabi
DOCKER=android
SKIP_TESTS=1
- os: linux
env: TARGET=armv7-linux-androideabi
DOCKER=android
SKIP_TESTS=1
- os: linux
env: TARGET=aarch64-linux-android
DOCKER=android
SKIP_TESTS=1
- os: linux
env: TARGET=i686-linux-android
DOCKER=android
SKIP_TESTS=1

# On OSX we want to target 10.7 so we ensure that the appropriate
# environment variable is set to tell the linker what we want.
- os: osx
Expand Down Expand Up @@ -101,16 +119,7 @@ install:
script:
- mkdir target
- if [ ! -z "$DOCKER" ]; then
docker run
--entrypoint bash
-u `id -u`:`id -g`
-v $HOME/rust:/travis-rust:ro
-v `pwd`:/buildslave:ro
-v `pwd`/target:/buildslave/target
-e TARGET=$TARGET
-e SKIP_TESTS=$SKIP_TESTS
-it $DOCKER
ci/run-docker.sh;
sh ci/build-run-docker.sh "$DOCKER" "$TARGET" "$SKIP_TESTS";
else
PATH=$HOME/rust/bin:$PATH sh ci/run.sh;
fi
Expand Down
20 changes: 10 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions ci/build-run-docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/sh

set -ex

mkdir -p target

DOCKER="$1"
TARGET="$2"
SKIP_TESTS="$3"

if [ -f "ci/docker/$DOCKER/Dockerfile" ]; then
docker build -t "$DOCKER" "ci/docker/$DOCKER/"
fi

docker run \
--entrypoint bash \
-u `id -u`:`id -g` \
-v $HOME/rust:/travis-rust:ro \
-v `pwd`:/buildslave:ro \
-v `pwd`/target:/buildslave/target \
-e TARGET=$TARGET \
-e SKIP_TESTS=$SKIP_TESTS \
-it $DOCKER \
ci/run-docker.sh
35 changes: 35 additions & 0 deletions ci/docker/android/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
FROM ubuntu:16.04

RUN apt-get update && \
apt-get install -y --no-install-recommends \
ca-certificates \
cmake \
curl \
gcc \
libc6-dev \
make \
pkg-config

RUN apt-get install -y --no-install-recommends \
unzip \
python && \
curl -O https://dl.google.com/android/repository/android-ndk-r13b-linux-x86_64.zip && \
unzip -q android-ndk-r13b-linux-x86_64.zip && \
./android-ndk-r13b/build/tools/make_standalone_toolchain.py \
--install-dir /android-ndk/arm \
--arch arm \
--api 21 && \
./android-ndk-r13b/build/tools/make_standalone_toolchain.py \
--install-dir /android-ndk/arm64 \
--arch arm64 \
--api 21 && \
./android-ndk-r13b/build/tools/make_standalone_toolchain.py \
--install-dir /android-ndk/x86 \
--arch x86 \
--api 21 && \
rm -rf ./android-ndk-r13b-linux-x86_64.zip ./android-ndk-r13b && \
apt-get purge --auto-remove -y unzip python

ENV PATH=$PATH:/android-ndk/arm/bin:/android-ndk/arm64/bin:/android-ndk/x86/bin

WORKDIR /buildslave
34 changes: 34 additions & 0 deletions ci/run-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@

set -ex

# For some unknown reason libz is not found in the android docker image, so we
# use this workaround
case $TARGET in
arm-linux-androideabi | armv7-linux-androideabi )
export DEP_Z_ROOT=/android-ndk/arm/sysroot/usr/;;

aarch64-linux-android )
export DEP_Z_ROOT=/android-ndk/arm64/sysroot/usr/;;

i686-linux-android )
export DEP_Z_ROOT=/android-ndk/x86/sysroot/usr/;;
esac

upper_target=$(echo $TARGET | tr '[a-z]' '[A-Z]' | tr '-' '_')
export PATH=/travis-rust/bin:$PATH
export LD_LIBRARY_PATH=/travis-rust/lib:$LD_LIBRARY_PATH
Expand Down Expand Up @@ -34,6 +47,27 @@ case $TARGET in
OPENSSL_SETARCH='setarch i386'
OPENSSL_CFLAGS=-m32
;;
arm-linux-androideabi)
OPENSSL_OS=android
OPENSSL_CC=arm-linux-androideabi-gcc
OPENSSL_AR=arm-linux-androideabi-ar
;;
armv7-linux-androideabi)
OPENSSL_OS=android-armv7
OPENSSL_CC=arm-linux-androideabi-gcc
OPENSSL_AR=arm-linux-androideabi-ar
;;
aarch64-linux-android)
OPENSSL_OS=linux-generic64
OPENSSL_CC=aarch64-linux-android-gcc
OPENSSL_AR=aarch64-linux-android-ar
OPENSSL_CFLAGS="-mandroid -fomit-frame-pointer"
;;
i686-linux-android)
OPENSSL_OS=android-x86
OPENSSL_CC=i686-linux-android-gcc
OPENSSL_AR=i686-linux-android-ar
;;
arm-*-linux-gnueabi)
OPENSSL_OS=linux-armv4
OPENSSL_CC=arm-linux-gnueabi-gcc
Expand Down
6 changes: 5 additions & 1 deletion src/rustup-dist/src/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ static LIST_OSES: &'static [&'static str] = &["pc-windows",
"rumprun-netbsd",
"unknown-freebsd"];
static LIST_ENVS: &'static [&'static str] =
&["gnu", "msvc", "gnueabi", "gnueabihf", "gnuabi64", "androideabi", "musl"];
&["gnu", "msvc", "gnueabi", "gnueabihf", "gnuabi64", "androideabi", "android", "musl"];

// MIPS platforms don't indicate endianness in uname, however binaries only
// run on boxes with the same endianness, as expected.
Expand Down Expand Up @@ -161,6 +161,10 @@ impl TargetTriple {
};

let host_triple = match (sysname, machine) {
(_, b"arm") if cfg!(target_os = "android") => Some("arm-linux-androideabi"),
(_, b"armv7l") if cfg!(target_os = "android") => Some("armv7-linux-androideabi"),
(_, b"aarch64") if cfg!(target_os = "android") => Some("aarch64-linux-android"),
(_, b"i686") if cfg!(target_os = "android") => Some("i686-linux-android"),
(b"Linux", b"x86_64") => Some("x86_64-unknown-linux-gnu"),
(b"Linux", b"i686") => Some("i686-unknown-linux-gnu"),
(b"Linux", b"mips") => Some(TRIPLE_MIPS_UNKNOWN_LINUX_GNU),
Expand Down

0 comments on commit ebd92af

Please sign in to comment.