Skip to content

Commit 3de557c

Browse files
committed
Auto merge of #132 - malbarbo:android-test, r=malbarbo
Add limited android test support We could provide android test support by launching an android emulator and running tests in the emulator (like how it is done in libc and rust), but there is licenses issues in redistributing the sdk (see 3.4 of https://developer.android.com/studio/terms.html). Off course, I maybe be wrong about this. So we download and build bionic libc from source, which I think allows we to distribute the binaries. Having the android libc allows running native binaries using qemu, which can be enough for projects like, nix, ripgrep, etc. Related #82
2 parents 359c3bb + 140aff3 commit 3de557c

File tree

9 files changed

+253
-18
lines changed

9 files changed

+253
-18
lines changed

.travis.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ matrix:
2727
- env: TARGET=x86_64-unknown-linux-musl STD=1 OPENSSL=0.5.5 RUN=1 DEPLOY=1
2828

2929
# Android
30-
- env: TARGET=aarch64-linux-android CPP=1 STD=1 OPENSSL=0.5.5
31-
- env: TARGET=arm-linux-androideabi CPP=1 STD=1 OPENSSL=0.5.5
32-
- env: TARGET=armv7-linux-androideabi CPP=1 STD=1 OPENSSL=0.5.5
33-
- env: TARGET=i686-linux-android CPP=1 STD=1 OPENSSL=0.5.5
34-
- env: TARGET=x86_64-linux-android CPP=1 STD=1 OPENSSL=0.5.5
30+
- env: TARGET=aarch64-linux-android CPP=1 STD=1 OPENSSL=0.5.5 RUN=1
31+
- env: TARGET=arm-linux-androideabi CPP=1 STD=1 OPENSSL=0.5.5 RUN=1
32+
- env: TARGET=armv7-linux-androideabi CPP=1 STD=1 OPENSSL=0.5.5 RUN=1
33+
- env: TARGET=i686-linux-android CPP=1 STD=1 OPENSSL=0.5.5 RUN=1
34+
- env: TARGET=x86_64-linux-android CPP=1 STD=1 OPENSSL=0.5.5 RUN=1
3535

3636
# OSX
3737
- env: TARGET=i686-apple-darwin DYLIB=1 STD=1 RUN=1

README.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,16 +189,16 @@ worst, "hang" (never terminate).
189189

190190
| Target | libc | GCC | OpenSSL | C++ | QEMU | `test` |
191191
|--------------------------------------|--------|---------|---------|:---:|-------|:------:|
192-
| `aarch64-linux-android` | N/A | 4.9 | 1.0.2k || N/A | |
192+
| `aarch64-linux-android` [5] | N/A | 4.9 | 1.0.2k || N/A | |
193193
| `aarch64-unknown-linux-gnu` | 2.19 | 4.8.2 | 1.0.2k || 2.8.0 ||
194-
| `arm-linux-androideabi` | N/A | 4.9 | 1.0.2k || N/A | |
194+
| `arm-linux-androideabi` [5] | N/A | 4.9 | 1.0.2k || N/A | |
195195
| `arm-unknown-linux-gnueabi` | 2.19 | 4.8.2 | 1.0.2k || 2.8.0 ||
196196
| `arm-unknown-linux-musleabi` | 1.1.15 | 5.3.1 | N/A | | 2.8.0 ||
197-
| `armv7-linux-androideabi` | N/A | 4.9 | 1.0.2k || N/A | |
197+
| `armv7-linux-androideabi` [5] | N/A | 4.9 | 1.0.2k || N/A | |
198198
| `armv7-unknown-linux-gnueabihf` | 2.15 | 4.6.2 | 1.0.2k || 2.8.0 ||
199199
| `armv7-unknown-linux-musleabihf` | 1.1.15 | 5.3.1 | N/A | | 2.8.0 ||
200200
| `asmjs-unknown-emscripten` [4] | 1.1.15 | 1.37.13 | N/A || N/A ||
201-
| `i686-linux-android` | N/A | 4.9 | 1.0.2k || N/A | |
201+
| `i686-linux-android` [5] | N/A | 4.9 | 1.0.2k || N/A | |
202202
| `i686-pc-windows-gnu` | N/A | 6.2.0 | N/A || N/A ||
203203
| `i686-unknown-freebsd` [1] | 10.2 | 5.3.0 | 1.0.2k | | N/A | |
204204
| `i686-unknown-linux-gnu` | 2.15 | 4.6.2 | 1.0.2k || N/A ||
@@ -218,7 +218,7 @@ worst, "hang" (never terminate).
218218
| `thumbv7em-none-eabihf` [3] | 2.2.0 | 5.3.1 | N/A | | N/A | |
219219
| `thumbv7m-none-eabi` [3] | 2.2.0 | 5.3.1 | N/A | | N/A | |
220220
| `wasm32-unknown-emscripten` [4] | 1.1.15 | 1.37.13 | N/A || N/A ||
221-
| `x86_64-linux-android` | N/A | 4.9 | 1.0.2k || N/A | |
221+
| `x86_64-linux-android` [5] | N/A | 4.9 | 1.0.2k || N/A | |
222222
| `x86_64-pc-windows-gnu` | N/A | 6.2.0 | N/A || N/A ||
223223
| `x86_64-sun-solaris` [1] | 2.11 | 5.3.0 | 1.0.2k | | N/A | |
224224
| `x86_64-unknown-dragonfly` [1] [2] | 4.6.0 | 5.3.0 | 1.0.2k | | N/A ||
@@ -237,6 +237,12 @@ where libc was extracted.
237237
[4] libc = musl, gcc = emcc; Some projects that use libc may fail due to wrong
238238
definitions (will be fixed by https://github.com/rust-lang/libc/pull/610)
239239

240+
[5] Only works with native tests, that is, tests that do not depends on the
241+
Android Runtime. For i686 some tests may fails with the error `assertion
242+
failed: signal(libc::SIGPIPE, libc::SIG_IGN) != libc::SIG_ERR`, see
243+
[issue #140](https://github.com/japaric/cross/issues/140) for more
244+
information.
245+
240246
## Debugging
241247

242248
### QEMU_STRACE (v0.1.9+)

docker/aarch64-linux-android/Dockerfile

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,23 @@ RUN apt-get update && \
1212
COPY xargo.sh /
1313
RUN bash /xargo.sh
1414

15+
COPY qemu.sh /
16+
RUN bash /qemu.sh aarch64 android
17+
1518
COPY android-ndk.sh /
1619
RUN bash /android-ndk.sh arm64 21
1720
ENV PATH=$PATH:/android-ndk/bin
1821

1922
COPY openssl.sh /
2023
RUN bash /openssl.sh linux-generic64 aarch64-linux-android- -mandroid -fomit-frame-pointer
2124

25+
COPY android-system.sh /
26+
RUN bash /android-system.sh arm64
27+
2228
# Libz is distributed in the android ndk, but for some unknown reason it is not
2329
# found in the build process of some crates, so we explicit set the DEP_Z_ROOT
2430
ENV CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER=aarch64-linux-android-gcc \
31+
CARGO_TARGET_AARCH64_LINUX_ANDROID_RUNNER=qemu-aarch64 \
2532
CC_aarch64_linux_android=aarch64-linux-android-gcc \
2633
CXX_aarch64_linux_android=aarch64-linux-android-g++ \
2734
DEP_Z_ROOT=/android-ndk/sysroot/usr/ \
@@ -30,4 +37,7 @@ ENV CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER=aarch64-linux-android-gcc \
3037
OPENSSL_INCLUDE_DIR=/openssl/include \
3138
OPENSSL_LIB_DIR=/openssl/lib \
3239
RUST_TEST_THREADS=1 \
33-
HOME=/tmp/
40+
HOME=/tmp/ \
41+
TMPDIR=/tmp/ \
42+
ANDROID_ROOT=/system \
43+
ANDROID_DATA=/

docker/android-system.sh

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
set -ex
2+
3+
main() {
4+
local arch=$1
5+
local td=$(mktemp -d)
6+
pushd $td
7+
8+
local dependencies=(
9+
ca-certificates
10+
curl
11+
gcc-multilib
12+
git
13+
g++-multilib
14+
make
15+
python
16+
)
17+
18+
# fake java and javac, it is not necessary for what we build, but the build
19+
# script ask for it
20+
cat << EOF > /usr/bin/java
21+
#!/bin/bash
22+
echo "java version \"1.7.0\""
23+
echo "OpenJDK Runtime Environment (IcedTea 2.6.9)"
24+
echo "OpenJDK 64-Bit Server VM (build 24.131-b00, mixed mode)"
25+
EOF
26+
27+
cat << EOF > /usr/bin/javac
28+
#!/bin/bash
29+
echo "javac 1.7.0"
30+
EOF
31+
32+
chmod +x /usr/bin/java
33+
chmod +x /usr/bin/javac
34+
35+
# more faking
36+
export ANDROID_JAVA_HOME=/tmp
37+
mkdir /tmp/lib/
38+
touch /tmp/lib/tools.jar
39+
40+
apt-get update
41+
local purge_list=(default-jre)
42+
for dep in ${dependencies[@]}; do
43+
if ! dpkg -L $dep; then
44+
apt-get install --no-install-recommends -y $dep
45+
purge_list+=( $dep )
46+
fi
47+
done
48+
49+
curl -O https://storage.googleapis.com/git-repo-downloads/repo
50+
chmod +x repo
51+
52+
# this is the minimum set of modules that are need to build bionic
53+
# this was created by trial and error
54+
./repo init -u https://android.googlesource.com/platform/manifest -b android-5.0.0_r1
55+
./repo sync bionic
56+
./repo sync build
57+
./repo sync external/compiler-rt
58+
./repo sync external/jemalloc
59+
./repo sync external/libcxx
60+
./repo sync external/libcxxabi
61+
./repo sync external/stlport
62+
./repo sync prebuilts/clang/linux-x86/host/3.5
63+
./repo sync system/core
64+
case $arch in
65+
arm)
66+
./repo sync prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.8
67+
;;
68+
arm64)
69+
./repo sync prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.8
70+
./repo sync prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9
71+
;;
72+
x86)
73+
./repo sync prebuilts/gcc/linux-x86/x86/x86_64-linux-android-4.8
74+
;;
75+
x86_64)
76+
./repo sync prebuilts/gcc/linux-x86/x86/x86_64-linux-android-4.8
77+
;;
78+
esac
79+
80+
# avoid build tests
81+
rm bionic/linker/tests/Android.mk bionic/tests/Android.mk
82+
83+
source build/envsetup.sh
84+
lunch aosp_$arch-user
85+
mmma bionic/
86+
87+
if [ $arch = "arm" ]; then
88+
mv out/target/product/generic/system/ /
89+
else
90+
mv out/target/product/generic_$arch/system/ /
91+
fi
92+
93+
# clean up
94+
apt-get purge --auto-remove -y ${purge_list[@]}
95+
96+
popd
97+
98+
rm -rf $td
99+
rm $0
100+
}
101+
102+
main "${@}"

docker/arm-linux-androideabi/Dockerfile

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,23 @@ RUN apt-get update && \
1212
COPY xargo.sh /
1313
RUN bash /xargo.sh
1414

15+
COPY qemu.sh /
16+
RUN bash /qemu.sh arm android
17+
1518
COPY android-ndk.sh /
1619
RUN bash /android-ndk.sh arm 21
1720
ENV PATH=$PATH:/android-ndk/bin
1821

1922
COPY openssl.sh /
2023
RUN bash /openssl.sh android arm-linux-androideabi-
2124

25+
COPY android-system.sh /
26+
RUN bash /android-system.sh arm
27+
2228
# Libz is distributed in the android ndk, but for some unknown reason it is not
2329
# found in the build process of some crates, so we explicit set the DEP_Z_ROOT
2430
ENV CARGO_TARGET_ARM_LINUX_ANDROIDEABI_LINKER=arm-linux-androideabi-gcc \
31+
CARGO_TARGET_ARM_LINUX_ANDROIDEABI_RUNNER=qemu-arm \
2532
CC_arm_linux_androideabi=arm-linux-androideabi-gcc \
2633
CXX_arm_linux_androideabi=arm-linux-androideabi-g++ \
2734
DEP_Z_ROOT=/android-ndk/sysroot/usr/ \
@@ -30,4 +37,7 @@ ENV CARGO_TARGET_ARM_LINUX_ANDROIDEABI_LINKER=arm-linux-androideabi-gcc \
3037
OPENSSL_INCLUDE_DIR=/openssl/include \
3138
OPENSSL_LIB_DIR=/openssl/lib \
3239
RUST_TEST_THREADS=1 \
33-
HOME=/tmp/
40+
HOME=/tmp/ \
41+
TMPDIR=/tmp/ \
42+
ANDROID_ROOT=/system \
43+
ANDROID_DATA=/

docker/armv7-linux-androideabi/Dockerfile

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,23 @@ RUN apt-get update && \
1212
COPY xargo.sh /
1313
RUN bash /xargo.sh
1414

15+
COPY qemu.sh /
16+
RUN bash /qemu.sh arm android
17+
1518
COPY android-ndk.sh /
1619
RUN bash /android-ndk.sh arm 21
1720
ENV PATH=$PATH:/android-ndk/bin
1821

1922
COPY openssl.sh /
2023
RUN bash /openssl.sh android-armv7 arm-linux-androideabi-
2124

25+
COPY android-system.sh /
26+
RUN bash /android-system.sh arm
27+
2228
# Libz is distributed in the android ndk, but for some unknown reason it is not
2329
# found in the build process of some crates, so we explicit set the DEP_Z_ROOT
2430
ENV CARGO_TARGET_ARMV7_LINUX_ANDROIDEABI_LINKER=arm-linux-androideabi-gcc \
31+
CARGO_TARGET_ARMV7_LINUX_ANDROIDEABI_RUNNER=qemu-arm \
2532
CC_armv7_linux_androideabi=arm-linux-androideabi-gcc \
2633
CXX_armv7_linux_androideabi=arm-linux-androideabi-g++ \
2734
DEP_Z_ROOT=/android-ndk/sysroot/usr/ \
@@ -30,4 +37,7 @@ ENV CARGO_TARGET_ARMV7_LINUX_ANDROIDEABI_LINKER=arm-linux-androideabi-gcc \
3037
OPENSSL_INCLUDE_DIR=/openssl/include \
3138
OPENSSL_LIB_DIR=/openssl/lib \
3239
RUST_TEST_THREADS=1 \
33-
HOME=/tmp/
40+
HOME=/tmp/ \
41+
TMPDIR=/tmp/ \
42+
ANDROID_ROOT=/system \
43+
ANDROID_DATA=/

docker/i686-linux-android/Dockerfile

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,31 @@ RUN apt-get update && \
1212
COPY xargo.sh /
1313
RUN bash /xargo.sh
1414

15+
# We could supposedly directly run i686 binaries like we do for x86_64, but
16+
# doing so generates an assertion failure:
17+
# ... assertion failed: signal(libc::SIGPIPE, libc::SIG_IGN) != libc::SIG_ERR
18+
# ... src/libstd/sys/unix/mod.rs
19+
# fatal runtime error: failed to initiate panic, error 5
20+
#
21+
# Running with qemu works as expected
22+
COPY qemu.sh /
23+
RUN bash /qemu.sh i386 android
24+
1525
COPY android-ndk.sh /
1626
RUN bash /android-ndk.sh x86 21
1727
ENV PATH=$PATH:/android-ndk/bin
1828

29+
# Build with no-asm to make openssl linked binaries position-independent (PIE)
1930
COPY openssl.sh /
20-
RUN bash /openssl.sh android-x86 i686-linux-android-
31+
RUN bash /openssl.sh android-x86 i686-linux-android- no-asm
32+
33+
COPY android-system.sh /
34+
RUN bash /android-system.sh x86
2135

2236
# Libz is distributed in the android ndk, but for some unknown reason it is not
2337
# found in the build process of some crates, so we explicit set the DEP_Z_ROOT
2438
ENV CARGO_TARGET_I686_LINUX_ANDROID_LINKER=i686-linux-android-gcc \
39+
CARGO_TARGET_I686_LINUX_ANDROID_RUNNER=qemu-i386 \
2540
CC_i686_linux_android=i686-linux-android-gcc \
2641
CXX_i686_linux_android=i686-linux-android-g++ \
2742
DEP_Z_ROOT=/android-ndk/sysroot/usr/ \
@@ -30,4 +45,7 @@ ENV CARGO_TARGET_I686_LINUX_ANDROID_LINKER=i686-linux-android-gcc \
3045
OPENSSL_INCLUDE_DIR=/openssl/include \
3146
OPENSSL_LIB_DIR=/openssl/lib \
3247
RUST_TEST_THREADS=1 \
33-
HOME=/tmp/
48+
HOME=/tmp/ \
49+
TMPDIR=/tmp/ \
50+
ANDROID_ROOT=/system \
51+
ANDROID_DATA=/

0 commit comments

Comments
 (0)