Skip to content

Commit

Permalink
Add android build support
Browse files Browse the repository at this point in the history
  • Loading branch information
malbarbo committed Mar 22, 2017
1 parent 3130db9 commit e865975
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 10 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
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

0 comments on commit e865975

Please sign in to comment.