Skip to content

Commit 75870b7

Browse files
committed
Improve support for different Android versions.
We provide the following arguments to configure the Android version: - `ANDROID_NDK` - `ANDROID_SDK` (note that this is dependent on `ANDROID_VERSION) - `ANDROID_VERSION` - `ANDROID_SYSTEM_COMPLETE`: do a complete Android build Next, we've improved the removal of unittests during the build process, to ensure fast builds while maintaining compatibility with various newer Android versions. To do this, we've implemented a Python library and a script. The Python library contains a complete parser (correctly parses all valid input) for Soong blueprint files, using an LALR grammar, and a rudimentary parser for Makefiles. The Soong parser removes any `gtest` dependencies, as well as any subdirectories or scope names containing `test`. For example: ``` cc_library { name: "lib", srcs: ["lib.cc",], } cc_test { name: "test", defaults: ["target"], srcs: ["test.cc"], } ``` Will become: ``` cc_library { name: "lib", srcs: ["lib.cc",], } ``` The Makefile parser first splits the file based on conditional directives (`ifeq`, `endif`, etc.) to ensure any subsequent processing doesn't lead to unbalanced directives. Next, we split the text within each directive based on comment sections used in the Android source tree. For example: ``` test_tags := tests include $(call subdir,$(LOCAL_PATH)) c_flags := \ -g \ -Wall ``` We can therefore remove the `Benchmarks` and `Unit tests` sections without removing the `Other section`. The Python library is reasonably performant (it adds no noticeable overhead to the build process) and is compact (in total, < 60KB). Also, it is much more resilient than a series of `sed` scripts. Finally, extensive unittests have been added for the Python library, for both code linting (`flake8`) and unittests (via `tox`). Since we cannot assume the presence of Python on the host machine, the tests can be optionally enabled via the `--python` flag (or `PYTHON` environment variable, to hook into the git hooks), and custom overrides for the `flake8` and `tox` commands are provided (since the user may wish to specify a specific Python version, such as `python3.7 -m flake8`).
1 parent 79eeb91 commit 75870b7

37 files changed

+3512
-178
lines changed

.changes/1023.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"description": "support different Android NDK, API, and Android versions using Docker build args.",
3+
"type": "added"
4+
}

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,12 @@
44
**/*.log
55
/cargo-timing*.html
66
CHANGELOG.md.draft
7+
8+
# python stuff
9+
__pycache__/
10+
.pytest_cache/
11+
*.py[cod]
12+
*$py.class
13+
*.egg-info/
14+
*.egg
15+
.tox

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docker/.dockerignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# don't copy any of the python artifacts to the docker context
2+
__pycache__/
3+
.pytest_cache/
4+
*.py[cod]
5+
*$py.class
6+
**/*.egg-info/
7+
*.egg
8+
.tox
9+
10+
# also skip our test suite
11+
android/tests/

docker/Dockerfile.aarch64-linux-android

Lines changed: 44 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,52 @@ RUN /cmake.sh
1010
COPY xargo.sh /
1111
RUN /xargo.sh
1212

13-
COPY android-ndk.sh /
14-
RUN /android-ndk.sh arm64 28
15-
ENV PATH=$PATH:/android-ndk/bin
16-
17-
COPY android-system.sh /
18-
RUN /android-system.sh arm64
19-
2013
COPY qemu.sh /
2114
RUN /qemu.sh aarch64
2215

23-
RUN cp /android-ndk/sysroot/usr/lib/aarch64-linux-android/28/libz.so /system/lib/
16+
ARG ANDROID_NDK=r21d
17+
ARG ANDROID_SDK=28
18+
ARG ANDROID_VERSION=9.0.0_r1
19+
ARG ANDROID_SYSTEM_COMPLETE=0
20+
ARG PYTHON_TMPDIR=/tmp/android
2421

25-
COPY android-runner /
22+
COPY android-ndk.sh /
23+
RUN /android-ndk.sh arm64
24+
ENV PATH=$PATH:/android-ndk/bin
2625

27-
# Libz is distributed in the android ndk, but for some unknown reason it is not
28-
# found in the build process of some crates, so we explicit set the DEP_Z_ROOT
29-
ENV CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER=aarch64-linux-android-gcc \
30-
CARGO_TARGET_AARCH64_LINUX_ANDROID_RUNNER="/android-runner aarch64" \
31-
CC_aarch64_linux_android=aarch64-linux-android-gcc \
32-
CXX_aarch64_linux_android=aarch64-linux-android-g++ \
33-
BINDGEN_EXTRA_CLANG_ARGS_aarch64_linux_android="--sysroot=/android-ndk/sysroot" \
34-
DEP_Z_INCLUDE=/android-ndk/sysroot/usr/include/ \
35-
RUST_TEST_THREADS=1 \
36-
HOME=/tmp/ \
37-
TMPDIR=/tmp/ \
38-
ANDROID_DATA=/ \
39-
ANDROID_DNS_MODE=local \
40-
ANDROID_ROOT=/system
26+
# TODO(ahuszagh) Restore...
27+
COPY android-system.sh /
28+
RUN mkdir -p $PYTHON_TMPDIR
29+
COPY android $PYTHON_TMPDIR
30+
#RUN /android-system.sh arm64
31+
#
32+
#COPY android-symlink.sh /
33+
#RUN /android-symlink.sh aarch64 aarch64-linux-android
34+
#
35+
#COPY android-runner /
36+
#
37+
## Libz is distributed in the android ndk, but for some unknown reason it is not
38+
## found in the build process of some crates, so we explicit set the DEP_Z_ROOT
39+
#ENV CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER=aarch64-linux-android-gcc \
40+
# CARGO_TARGET_AARCH64_LINUX_ANDROID_RUNNER="/android-runner aarch64" \
41+
# AR_aarch64_linux_android=aarch64-linux-android-ar \
42+
# AS_aarch64_linux_android=aarch64-linux-android-as \
43+
# CC_aarch64_linux_android=aarch64-linux-android-gcc \
44+
# CXX_aarch64_linux_android=aarch64-linux-android-g++ \
45+
# LD_aarch64_linux_android=aarch64-linux-android-ld \
46+
# NM_aarch64_linux_android=aarch64-linux-android-nm \
47+
# OBJCOPY_aarch64_linux_android=aarch64-linux-android-objcopy \
48+
# OBJDUMP_aarch64_linux_android=aarch64-linux-android-objdump \
49+
# RANLIB_aarch64_linux_android=aarch64-linux-android-ranlib \
50+
# READELF_aarch64_linux_android=aarch64-linux-android-readelf \
51+
# SIZE_aarch64_linux_android=aarch64-linux-android-size \
52+
# STRINGS_aarch64_linux_android=aarch64-linux-android-strings \
53+
# STRIP_aarch64_linux_android=aarch64-linux-android-strip \
54+
# BINDGEN_EXTRA_CLANG_ARGS_aarch64_linux_android="--sysroot=/android-ndk/sysroot" \
55+
# DEP_Z_INCLUDE=/android-ndk/sysroot/usr/include/ \
56+
# RUST_TEST_THREADS=1 \
57+
# HOME=/tmp/ \
58+
# TMPDIR=/tmp/ \
59+
# ANDROID_DATA=/ \
60+
# ANDROID_DNS_MODE=local \
61+
# ANDROID_ROOT=/system
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
FROM ubuntu:20.04
2+
ARG DEBIAN_FRONTEND=noninteractive
3+
4+
COPY common.sh lib.sh /
5+
RUN /common.sh
6+
7+
COPY cmake.sh /
8+
RUN /cmake.sh
9+
10+
COPY xargo.sh /
11+
RUN /xargo.sh
12+
13+
COPY qemu.sh /
14+
RUN /qemu.sh aarch64
15+
16+
ARG ANDROID_NDK=r21d
17+
ARG ANDROID_SDK=28
18+
ARG ANDROID_VERSION=9.0.0_r1
19+
ARG ANDROID_SYSTEM_COMPLETE=0
20+
21+
COPY android-ndk.sh /
22+
RUN /android-ndk.sh arm64
23+
ENV PATH=$PATH:/android-ndk/bin
24+
25+
COPY android-system.sh remove_android_tests.py /
26+
RUN /android-system.sh arm64
27+
28+
COPY android-symlink.sh /
29+
RUN /android-symlink.sh aarch64 aarch64-linux-android
30+
31+
COPY android-runner /
32+
33+
# Libz is distributed in the android ndk, but for some unknown reason it is not
34+
# found in the build process of some crates, so we explicit set the DEP_Z_ROOT
35+
ENV CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER=aarch64-linux-android-gcc \
36+
CARGO_TARGET_AARCH64_LINUX_ANDROID_RUNNER="/android-runner aarch64" \
37+
AR_aarch64_linux_android=aarch64-linux-android-ar \
38+
AS_aarch64_linux_android=aarch64-linux-android-as \
39+
CC_aarch64_linux_android=aarch64-linux-android-gcc \
40+
CXX_aarch64_linux_android=aarch64-linux-android-g++ \
41+
LD_aarch64_linux_android=aarch64-linux-android-ld \
42+
NM_aarch64_linux_android=aarch64-linux-android-nm \
43+
OBJCOPY_aarch64_linux_android=aarch64-linux-android-objcopy \
44+
OBJDUMP_aarch64_linux_android=aarch64-linux-android-objdump \
45+
RANLIB_aarch64_linux_android=aarch64-linux-android-ranlib \
46+
READELF_aarch64_linux_android=aarch64-linux-android-readelf \
47+
SIZE_aarch64_linux_android=aarch64-linux-android-size \
48+
STRINGS_aarch64_linux_android=aarch64-linux-android-strings \
49+
STRIP_aarch64_linux_android=aarch64-linux-android-strip \
50+
BINDGEN_EXTRA_CLANG_ARGS_aarch64_linux_android="--sysroot=/android-ndk/sysroot" \
51+
DEP_Z_INCLUDE=/android-ndk/sysroot/usr/include/ \
52+
RUST_TEST_THREADS=1 \
53+
HOME=/tmp/ \
54+
TMPDIR=/tmp/ \
55+
ANDROID_DATA=/ \
56+
ANDROID_DNS_MODE=local \
57+
ANDROID_ROOT=/system

docker/Dockerfile.arm-linux-androideabi

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,43 @@ RUN /cmake.sh
1010
COPY xargo.sh /
1111
RUN /xargo.sh
1212

13+
COPY qemu.sh /
14+
RUN /qemu.sh arm
15+
16+
ARG ANDROID_NDK=r21d
17+
ARG ANDROID_SDK=28
18+
ARG ANDROID_VERSION=9.0.0_r1
19+
ARG ANDROID_SYSTEM_COMPLETE=0
20+
1321
COPY android-ndk.sh /
14-
RUN /android-ndk.sh arm 28
22+
RUN /android-ndk.sh arm
1523
ENV PATH=$PATH:/android-ndk/bin
1624

17-
COPY android-system.sh /
25+
COPY android-system.sh remove_android_tests.py /
1826
RUN /android-system.sh arm
1927

20-
COPY qemu.sh /
21-
RUN /qemu.sh arm
22-
23-
RUN cp /android-ndk/sysroot/usr/lib/arm-linux-androideabi/28/libz.so /system/lib/
28+
COPY android-symlink.sh /
29+
RUN /android-symlink.sh arm arm-linux-androideabi
2430

2531
COPY android-runner /
2632

2733
# Libz is distributed in the android ndk, but for some unknown reason it is not
2834
# found in the build process of some crates, so we explicit set the DEP_Z_ROOT
2935
ENV CARGO_TARGET_ARM_LINUX_ANDROIDEABI_LINKER=arm-linux-androideabi-gcc \
3036
CARGO_TARGET_ARM_LINUX_ANDROIDEABI_RUNNER="/android-runner arm" \
37+
AR_arm_linux_androideabi=arm-linux-androideabi-ar \
38+
AS_arm_linux_androideabi=arm-linux-androideabi-as \
3139
CC_arm_linux_androideabi=arm-linux-androideabi-gcc \
3240
CXX_arm_linux_androideabi=arm-linux-androideabi-g++ \
41+
LD_arm_linux_androideabi=arm-linux-androideabi-ld \
42+
NM_arm_linux_androideabi=arm-linux-androideabi-nm \
43+
OBJCOPY_arm_linux_androideabi=arm-linux-androideabi-objcopy \
44+
OBJDUMP_arm_linux_androideabi=arm-linux-androideabi-objdump \
45+
RANLIB_arm_linux_androideabi=arm-linux-androideabi-ranlib \
46+
READELF_arm_linux_androideabi=arm-linux-androideabi-readelf \
47+
SIZE_arm_linux_androideabi=arm-linux-androideabi-size \
48+
STRINGS_arm_linux_androideabi=arm-linux-androideabi-strings \
49+
STRIP_arm_linux_androideabi=arm-linux-androideabi-strip \
3350
BINDGEN_EXTRA_CLANG_ARGS_arm_linux_androideabi="--sysroot=/android-ndk/sysroot" \
3451
DEP_Z_INCLUDE=/android-ndk/sysroot/usr/include/ \
3552
RUST_TEST_THREADS=1 \

docker/Dockerfile.armv7-linux-androideabi

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,43 @@ RUN /cmake.sh
1010
COPY xargo.sh /
1111
RUN /xargo.sh
1212

13+
COPY qemu.sh /
14+
RUN /qemu.sh arm
15+
16+
ARG ANDROID_NDK=r21d
17+
ARG ANDROID_SDK=28
18+
ARG ANDROID_VERSION=9.0.0_r1
19+
ARG ANDROID_SYSTEM_COMPLETE=0
20+
1321
COPY android-ndk.sh /
14-
RUN /android-ndk.sh arm 28
22+
RUN /android-ndk.sh arm
1523
ENV PATH=$PATH:/android-ndk/bin
1624

17-
COPY android-system.sh /
25+
COPY android-system.sh remove_android_tests.py /
1826
RUN /android-system.sh arm
1927

20-
COPY qemu.sh /
21-
RUN /qemu.sh arm
22-
23-
RUN cp /android-ndk/sysroot/usr/lib/arm-linux-androideabi/28/libz.so /system/lib/
28+
COPY android-symlink.sh /
29+
RUN /android-symlink.sh arm arm-linux-androideabi
2430

2531
COPY android-runner /
2632

2733
# Libz is distributed in the android ndk, but for some unknown reason it is not
2834
# found in the build process of some crates, so we explicit set the DEP_Z_ROOT
2935
ENV CARGO_TARGET_ARMV7_LINUX_ANDROIDEABI_LINKER=arm-linux-androideabi-gcc \
3036
CARGO_TARGET_ARMV7_LINUX_ANDROIDEABI_RUNNER="/android-runner arm" \
37+
AR_armv7_linux_androideabi=arm-linux-androideabi-ar \
38+
AS_armv7_linux_androideabi=arm-linux-androideabi-as \
3139
CC_armv7_linux_androideabi=arm-linux-androideabi-gcc \
3240
CXX_armv7_linux_androideabi=arm-linux-androideabi-g++ \
41+
LD_armv7_linux_androideabi=arm-linux-androideabi-ld \
42+
NM_armv7_linux_androideabi=arm-linux-androideabi-nm \
43+
OBJCOPY_armv7_linux_androideabi=arm-linux-androideabi-objcopy \
44+
OBJDUMP_armv7_linux_androideabi=arm-linux-androideabi-objdump \
45+
RANLIB_armv7_linux_androideabi=arm-linux-androideabi-ranlib \
46+
READELF_armv7_linux_androideabi=arm-linux-androideabi-readelf \
47+
SIZE_armv7_linux_androideabi=arm-linux-androideabi-size \
48+
STRINGS_armv7_linux_androideabi=arm-linux-androideabi-strings \
49+
STRIP_armv7_linux_androideabi=arm-linux-androideabi-strip \
3350
BINDGEN_EXTRA_CLANG_ARGS_armv7_linux_androideabi="--sysroot=/android-ndk/sysroot" \
3451
DEP_Z_INCLUDE=/android-ndk/sysroot/usr/include/ \
3552
RUST_TEST_THREADS=1 \

docker/Dockerfile.i686-linux-android

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,51 @@ RUN /cmake.sh
1010
COPY xargo.sh /
1111
RUN /xargo.sh
1212

13-
COPY android-ndk.sh /
14-
RUN /android-ndk.sh x86 28
15-
ENV PATH=$PATH:/android-ndk/bin
16-
17-
COPY android-system.sh /
18-
RUN /android-system.sh x86
19-
2013
# We could supposedly directly run i686 binaries like we do for x86_64, but
2114
# doing so generates an assertion failure:
2215
# ... assertion failed: signal(libc::SIGPIPE, libc::SIG_IGN) != libc::SIG_ERR
2316
# ... src/libstd/sys/unix/mod.rs
2417
# fatal runtime error: failed to initiate panic, error 5
2518
#
26-
# Running with qemu works as expected
19+
# Running with qemu works as expected. it also ensures that're we're
20+
# running on a CPU common 32-bit x86 systems.
2721
COPY qemu.sh /
2822
RUN /qemu.sh i386
2923

30-
RUN cp /android-ndk/sysroot/usr/lib/i686-linux-android/28/libz.so /system/lib/
24+
ARG ANDROID_NDK=r21d
25+
ARG ANDROID_SDK=28
26+
ARG ANDROID_VERSION=9.0.0_r1
27+
ARG ANDROID_SYSTEM_COMPLETE=0
28+
29+
COPY android-ndk.sh /
30+
RUN /android-ndk.sh x86
31+
ENV PATH=$PATH:/android-ndk/bin
32+
33+
COPY android-system.sh remove_android_tests.py /
34+
RUN /android-system.sh x86
35+
36+
COPY android-symlink.sh /
37+
RUN /android-symlink.sh i386 i686-linux-android
3138

3239
COPY android-runner /
3340

3441
# Libz is distributed in the android ndk, but for some unknown reason it is not
3542
# found in the build process of some crates, so we explicit set the DEP_Z_ROOT
3643
ENV CARGO_TARGET_I686_LINUX_ANDROID_LINKER=i686-linux-android-gcc \
3744
CARGO_TARGET_I686_LINUX_ANDROID_RUNNER="/android-runner i686" \
45+
AR_i686_linux_android=i686-linux-android-ar \
46+
AS_i686_linux_android=i686-linux-android-as \
3847
CC_i686_linux_android=i686-linux-android-gcc \
3948
CXX_i686_linux_android=i686-linux-android-g++ \
49+
LD_i686_linux_android=i686-linux-android-ld \
50+
NM_i686_linux_android=i686-linux-android-nm \
51+
OBJCOPY_i686_linux_android=i686-linux-android-objcopy \
52+
OBJDUMP_i686_linux_android=i686-linux-android-objdump \
53+
RANLIB_i686_linux_android=i686-linux-android-ranlib \
54+
READELF_i686_linux_android=i686-linux-android-readelf \
55+
SIZE_i686_linux_android=i686-linux-android-size \
56+
STRINGS_i686_linux_android=i686-linux-android-strings \
57+
STRIP_i686_linux_android=i686-linux-android-strip \
4058
BINDGEN_EXTRA_CLANG_ARGS_i686_linux_android="--sysroot=/android-ndk/sysroot" \
4159
DEP_Z_INCLUDE=/android-ndk/sysroot/usr/include/ \
4260
LIBZ_SYS_STATIC=1 \

docker/Dockerfile.thumbv7neon-linux-androideabi

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,23 @@ RUN /cmake.sh
1010
COPY xargo.sh /
1111
RUN /xargo.sh
1212

13+
COPY qemu.sh /
14+
RUN /qemu.sh arm
15+
16+
ARG ANDROID_NDK=r21d
17+
ARG ANDROID_SDK=28
18+
ARG ANDROID_VERSION=9.0.0_r1
19+
ARG ANDROID_SYSTEM_COMPLETE=0
20+
1321
COPY android-ndk.sh /
14-
RUN /android-ndk.sh arm 28
22+
RUN /android-ndk.sh arm
1523
ENV PATH=$PATH:/android-ndk/bin
1624

17-
COPY android-system.sh /
25+
COPY android-system.sh remove_android_tests.py /
1826
RUN /android-system.sh arm
1927

20-
COPY qemu.sh /
21-
RUN /qemu.sh arm
22-
23-
RUN cp /android-ndk/sysroot/usr/lib/arm-linux-androideabi/28/libz.so /system/lib/
28+
COPY android-symlink.sh /
29+
RUN /android-symlink.sh arm arm-linux-androideabi
2430

2531
COPY android-runner /
2632

0 commit comments

Comments
 (0)