Skip to content

Commit 943d37a

Browse files
committed
Add support for Android versions 5-11.
**Configuration** 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 - `ANDROID_SYSTEM_NONE`: do not build the Android system, disables runner support **Version Support** We now support NDK versions r10e-r25b, SDK versions 21-33, and Android versions 5.0, 5.1, 6.0, 7.0, 8.0, 8.1, 9.0, 10.0, and 11.0. We also validate that the NDK, SDK, and Android versions are compatible. For Android 12+, we do support using the NDK with the proper API level, allowing cross-compilation for the desired target, however, running or testing the generated binary is currently not supported without a complete build. Note that support for non-complete builds with Android versions 12+ is unlikely to ever occur, due to issues with APEX in the build system. **Implementation Details** 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: ```go cc_library { name: "lib", srcs: ["lib.cc",], } cc_test { name: "test", defaults: ["target"], srcs: ["test.cc"], } ``` Will become: ```go 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: ```Makefile 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`). **Linker** For Android 10+, since we use a minimal Android build, we only support the bootstrap and ASAN linkers unless using a complete Android build. Supporting the APEX linker requires a nearly complete Android runtime, requiring 60+GB image sizes, slow builds, and other prohibitive factors. **Complete Builds** Complete builds are currently untested, for Androids version 12+ they exceed the default storage capacity of WSL2 images (250GB). They should work and properly install both the `/system` and `/apex` directories, however, the builds are slow and untested.
1 parent d5c08da commit 943d37a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+4053
-163
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: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,51 @@ RUN /cmake.sh
1010
COPY xargo.sh /
1111
RUN /xargo.sh
1212

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_NONE=0
20+
ARG ANDROID_SYSTEM_COMPLETE=0
21+
ARG PYTHON_TMPDIR=/tmp/android
22+
23+
COPY validate-android-args.sh /
24+
RUN /validate-android-args.sh arm64
25+
1326
COPY android-ndk.sh /
14-
RUN /android-ndk.sh arm64 28
27+
RUN /android-ndk.sh arm64
1528
ENV PATH=$PATH:/android-ndk/bin
1629

1730
COPY android-system.sh /
31+
RUN mkdir -p $PYTHON_TMPDIR
32+
COPY android $PYTHON_TMPDIR
1833
RUN /android-system.sh arm64
1934

20-
COPY qemu.sh /
21-
RUN /qemu.sh aarch64
22-
2335
ENV CROSS_SYSROOT=/android-ndk/sysroot
24-
RUN cp $CROSS_SYSROOT/usr/lib/aarch64-linux-android/28/libz.so /system/lib/
36+
COPY android-symlink.sh /
37+
RUN /android-symlink.sh aarch64 aarch64-linux-android
2538

2639
COPY android-runner /
2740

2841
# Libz is distributed in the android ndk, but for some unknown reason it is not
2942
# found in the build process of some crates, so we explicit set the DEP_Z_ROOT
3043
ENV CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER=aarch64-linux-android-gcc \
3144
CARGO_TARGET_AARCH64_LINUX_ANDROID_RUNNER="/android-runner aarch64" \
45+
AR_aarch64_linux_android=aarch64-linux-android-ar \
46+
AS_aarch64_linux_android=aarch64-linux-android-as \
3247
CC_aarch64_linux_android=aarch64-linux-android-gcc \
3348
CXX_aarch64_linux_android=aarch64-linux-android-g++ \
49+
LD_aarch64_linux_android=aarch64-linux-android-ld \
50+
NM_aarch64_linux_android=aarch64-linux-android-nm \
51+
OBJCOPY_aarch64_linux_android=aarch64-linux-android-objcopy \
52+
OBJDUMP_aarch64_linux_android=aarch64-linux-android-objdump \
53+
RANLIB_aarch64_linux_android=aarch64-linux-android-ranlib \
54+
READELF_aarch64_linux_android=aarch64-linux-android-readelf \
55+
SIZE_aarch64_linux_android=aarch64-linux-android-size \
56+
STRINGS_aarch64_linux_android=aarch64-linux-android-strings \
57+
STRIP_aarch64_linux_android=aarch64-linux-android-strip \
3458
BINDGEN_EXTRA_CLANG_ARGS_aarch64_linux_android="--sysroot=$CROSS_SYSROOT" \
3559
DEP_Z_INCLUDE="$CROSS_SYSROOT/usr/include"/ \
3660
RUST_TEST_THREADS=1 \

docker/Dockerfile.arm-linux-androideabi

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,49 @@ 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_NONE=0
20+
ARG ANDROID_SYSTEM_COMPLETE=0
21+
ARG PYTHON_TMPDIR=/tmp/android
22+
23+
COPY validate-android-args.sh /
24+
RUN /validate-android-args.sh arm
25+
1326
COPY android-ndk.sh /
14-
RUN /android-ndk.sh arm 28
27+
RUN /android-ndk.sh arm
1528
ENV PATH=$PATH:/android-ndk/bin
1629

17-
COPY android-system.sh /
30+
COPY android-system.sh remove_android_tests.py /
1831
RUN /android-system.sh arm
1932

20-
COPY qemu.sh /
21-
RUN /qemu.sh arm
22-
2333
ENV CROSS_SYSROOT=/android-ndk/sysroot
24-
RUN cp $CROSS_SYSROOT/usr/lib/arm-linux-androideabi/28/libz.so /system/lib/
34+
COPY android-symlink.sh /
35+
RUN /android-symlink.sh arm arm-linux-androideabi
2536

2637
COPY android-runner /
2738

2839
# Libz is distributed in the android ndk, but for some unknown reason it is not
2940
# found in the build process of some crates, so we explicit set the DEP_Z_ROOT
3041
ENV CARGO_TARGET_ARM_LINUX_ANDROIDEABI_LINKER=arm-linux-androideabi-gcc \
3142
CARGO_TARGET_ARM_LINUX_ANDROIDEABI_RUNNER="/android-runner arm" \
43+
AR_arm_linux_androideabi=arm-linux-androideabi-ar \
44+
AS_arm_linux_androideabi=arm-linux-androideabi-as \
3245
CC_arm_linux_androideabi=arm-linux-androideabi-gcc \
3346
CXX_arm_linux_androideabi=arm-linux-androideabi-g++ \
47+
LD_arm_linux_androideabi=arm-linux-androideabi-ld \
48+
NM_arm_linux_androideabi=arm-linux-androideabi-nm \
49+
OBJCOPY_arm_linux_androideabi=arm-linux-androideabi-objcopy \
50+
OBJDUMP_arm_linux_androideabi=arm-linux-androideabi-objdump \
51+
RANLIB_arm_linux_androideabi=arm-linux-androideabi-ranlib \
52+
READELF_arm_linux_androideabi=arm-linux-androideabi-readelf \
53+
SIZE_arm_linux_androideabi=arm-linux-androideabi-size \
54+
STRINGS_arm_linux_androideabi=arm-linux-androideabi-strings \
55+
STRIP_arm_linux_androideabi=arm-linux-androideabi-strip \
3456
BINDGEN_EXTRA_CLANG_ARGS_arm_linux_androideabi="--sysroot=$CROSS_SYSROOT" \
3557
DEP_Z_INCLUDE="$CROSS_SYSROOT/usr/include/" \
3658
RUST_TEST_THREADS=1 \

docker/Dockerfile.armv7-linux-androideabi

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,49 @@ 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_NONE=0
20+
ARG ANDROID_SYSTEM_COMPLETE=0
21+
ARG PYTHON_TMPDIR=/tmp/android
22+
23+
COPY validate-android-args.sh /
24+
RUN /validate-android-args.sh arm
25+
1326
COPY android-ndk.sh /
14-
RUN /android-ndk.sh arm 28
27+
RUN /android-ndk.sh arm
1528
ENV PATH=$PATH:/android-ndk/bin
1629

17-
COPY android-system.sh /
30+
COPY android-system.sh remove_android_tests.py /
1831
RUN /android-system.sh arm
1932

20-
COPY qemu.sh /
21-
RUN /qemu.sh arm
22-
2333
ENV CROSS_SYSROOT=/android-ndk/sysroot
24-
RUN cp $CROSS_SYSROOT/usr/lib/arm-linux-androideabi/28/libz.so /system/lib/
34+
COPY android-symlink.sh /
35+
RUN /android-symlink.sh arm arm-linux-androideabi
2536

2637
COPY android-runner /
2738

2839
# Libz is distributed in the android ndk, but for some unknown reason it is not
2940
# found in the build process of some crates, so we explicit set the DEP_Z_ROOT
3041
ENV CARGO_TARGET_ARMV7_LINUX_ANDROIDEABI_LINKER=arm-linux-androideabi-gcc \
3142
CARGO_TARGET_ARMV7_LINUX_ANDROIDEABI_RUNNER="/android-runner arm" \
43+
AR_armv7_linux_androideabi=arm-linux-androideabi-ar \
44+
AS_armv7_linux_androideabi=arm-linux-androideabi-as \
3245
CC_armv7_linux_androideabi=arm-linux-androideabi-gcc \
3346
CXX_armv7_linux_androideabi=arm-linux-androideabi-g++ \
47+
LD_armv7_linux_androideabi=arm-linux-androideabi-ld \
48+
NM_armv7_linux_androideabi=arm-linux-androideabi-nm \
49+
OBJCOPY_armv7_linux_androideabi=arm-linux-androideabi-objcopy \
50+
OBJDUMP_armv7_linux_androideabi=arm-linux-androideabi-objdump \
51+
RANLIB_armv7_linux_androideabi=arm-linux-androideabi-ranlib \
52+
READELF_armv7_linux_androideabi=arm-linux-androideabi-readelf \
53+
SIZE_armv7_linux_androideabi=arm-linux-androideabi-size \
54+
STRINGS_armv7_linux_androideabi=arm-linux-androideabi-strings \
55+
STRIP_armv7_linux_androideabi=arm-linux-androideabi-strip \
3456
BINDGEN_EXTRA_CLANG_ARGS_armv7_linux_androideabi="--sysroot=$CROSS_SYSROOT" \
3557
DEP_Z_INCLUDE="$CROSS_SYSROOT/usr/include/" \
3658
RUST_TEST_THREADS=1 \

docker/Dockerfile.i686-linux-android

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,34 +10,57 @@ 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

24+
ARG ANDROID_NDK=r21d
25+
ARG ANDROID_SDK=28
26+
ARG ANDROID_VERSION=9.0.0_r1
27+
ARG ANDROID_SYSTEM_NONE=0
28+
ARG ANDROID_SYSTEM_COMPLETE=0
29+
ARG PYTHON_TMPDIR=/tmp/android
30+
31+
COPY validate-android-args.sh /
32+
RUN /validate-android-args.sh x86
33+
34+
COPY android-ndk.sh /
35+
RUN /android-ndk.sh x86
36+
ENV PATH=$PATH:/android-ndk/bin
37+
38+
COPY android-system.sh remove_android_tests.py /
39+
RUN /android-system.sh x86
40+
3041
ENV CROSS_SYSROOT=/android-ndk/sysroot
31-
RUN cp $CROSS_SYSROOT/usr/lib/i686-linux-android/28/libz.so /system/lib/
42+
COPY android-symlink.sh /
43+
RUN /android-symlink.sh i386 i686-linux-android
3244

3345
COPY android-runner /
3446

3547
# Libz is distributed in the android ndk, but for some unknown reason it is not
3648
# found in the build process of some crates, so we explicit set the DEP_Z_ROOT
3749
ENV CARGO_TARGET_I686_LINUX_ANDROID_LINKER=i686-linux-android-gcc \
3850
CARGO_TARGET_I686_LINUX_ANDROID_RUNNER="/android-runner i686" \
51+
AR_i686_linux_android=i686-linux-android-ar \
52+
AS_i686_linux_android=i686-linux-android-as \
3953
CC_i686_linux_android=i686-linux-android-gcc \
4054
CXX_i686_linux_android=i686-linux-android-g++ \
55+
LD_i686_linux_android=i686-linux-android-ld \
56+
NM_i686_linux_android=i686-linux-android-nm \
57+
OBJCOPY_i686_linux_android=i686-linux-android-objcopy \
58+
OBJDUMP_i686_linux_android=i686-linux-android-objdump \
59+
RANLIB_i686_linux_android=i686-linux-android-ranlib \
60+
READELF_i686_linux_android=i686-linux-android-readelf \
61+
SIZE_i686_linux_android=i686-linux-android-size \
62+
STRINGS_i686_linux_android=i686-linux-android-strings \
63+
STRIP_i686_linux_android=i686-linux-android-strip \
4164
BINDGEN_EXTRA_CLANG_ARGS_i686_linux_android="--sysroot=$CROSS_SYSROOT" \
4265
DEP_Z_INCLUDE="$CROSS_SYSROOT/usr/include/" \
4366
LIBZ_SYS_STATIC=1 \

docker/Dockerfile.thumbv7neon-linux-androideabi

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,29 @@ 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_NONE=0
20+
ARG ANDROID_SYSTEM_COMPLETE=0
21+
ARG PYTHON_TMPDIR=/tmp/android
22+
23+
COPY validate-android-args.sh /
24+
RUN /validate-android-args.sh arm
25+
1326
COPY android-ndk.sh /
14-
RUN /android-ndk.sh arm 28
27+
RUN /android-ndk.sh arm
1528
ENV PATH=$PATH:/android-ndk/bin
1629

17-
COPY android-system.sh /
30+
COPY android-system.sh remove_android_tests.py /
1831
RUN /android-system.sh arm
1932

20-
COPY qemu.sh /
21-
RUN /qemu.sh arm
22-
2333
ENV CROSS_SYSROOT=/android-ndk/sysroot
24-
RUN cp $CROSS_SYSROOT/usr/lib/arm-linux-androideabi/28/libz.so /system/lib/
34+
COPY android-symlink.sh /
35+
RUN /android-symlink.sh arm arm-linux-androideabi
2536

2637
COPY android-runner /
2738

docker/Dockerfile.x86_64-linux-android

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,50 @@ RUN /cmake.sh
1010
COPY xargo.sh /
1111
RUN /xargo.sh
1212

13+
# Using qemu allows older host cpus (without sse4) to execute the target binaries
14+
COPY qemu.sh /
15+
RUN /qemu.sh x86_64
16+
17+
ARG ANDROID_NDK=r21d
18+
ARG ANDROID_SDK=28
19+
ARG ANDROID_VERSION=9.0.0_r1
20+
ARG ANDROID_SYSTEM_NONE=0
21+
ARG ANDROID_SYSTEM_COMPLETE=0
22+
ARG PYTHON_TMPDIR=/tmp/android
23+
24+
COPY validate-android-args.sh /
25+
RUN /validate-android-args.sh x86_64
26+
1327
COPY android-ndk.sh /
14-
RUN /android-ndk.sh x86_64 28
28+
RUN /android-ndk.sh x86_64
1529
ENV PATH=$PATH:/android-ndk/bin
1630

17-
COPY android-system.sh /
31+
COPY android-system.sh remove_android_tests.py /
1832
RUN /android-system.sh x86_64
1933

20-
# Using qemu allows older host cpus (without sse4) to execute the target binaries
21-
COPY qemu.sh /
22-
RUN /qemu.sh x86_64
23-
2434
ENV CROSS_SYSROOT=/android-ndk/sysroot
25-
RUN cp $CROSS_SYSROOT/usr/lib/x86_64-linux-android/28/libz.so /system/lib/
35+
COPY android-symlink.sh /
36+
RUN /android-symlink.sh x86_64 x86_64-linux-android
2637

2738
COPY android-runner /
2839

2940
# Libz is distributed in the android ndk, but for some unknown reason it is not
3041
# found in the build process of some crates, so we explicit set the DEP_Z_ROOT
3142
ENV CARGO_TARGET_X86_64_LINUX_ANDROID_LINKER=x86_64-linux-android-gcc \
3243
CARGO_TARGET_X86_64_LINUX_ANDROID_RUNNER="/android-runner x86_64" \
44+
AR_x86_64_linux_android=x86_64-linux-android-ar \
45+
AS_x86_64_linux_android=x86_64-linux-android-as \
3346
CC_x86_64_linux_android=x86_64-linux-android-gcc \
3447
CXX_x86_64_linux_android=x86_64-linux-android-g++ \
48+
LD_x86_64_linux_android=x86_64-linux-android-ld \
49+
NM_x86_64_linux_android=x86_64-linux-android-nm \
50+
OBJCOPY_x86_64_linux_android=x86_64-linux-android-objcopy \
51+
OBJDUMP_x86_64_linux_android=x86_64-linux-android-objdump \
52+
RANLIB_x86_64_linux_android=x86_64-linux-android-ranlib \
53+
READELF_x86_64_linux_android=x86_64-linux-android-readelf \
54+
SIZE_x86_64_linux_android=x86_64-linux-android-size \
55+
STRINGS_x86_64_linux_android=x86_64-linux-android-strings \
56+
STRIP_x86_64_linux_android=x86_64-linux-android-strip \
3557
BINDGEN_EXTRA_CLANG_ARGS_x86_64_linux_android="--sysroot=$CROSS_SYSROOT" \
3658
DEP_Z_INCLUDE="$CROSS_SYSROOT/usr/include/" \
3759
RUST_TEST_THREADS=1 \

0 commit comments

Comments
 (0)