Skip to content

Commit 35a1e17

Browse files
Merge #1023
1023: Add support for Android versions 5-11. r=Emilgardis a=Alexhuszagh **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. Co-authored-by: Alex Huszagh <[email protected]>
2 parents 1d72f53 + 25c7121 commit 35a1e17

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

+4047
-159
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=r25b
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: 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 arm
15+
16+
ARG ANDROID_NDK=r25b
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

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

20-
COPY qemu.sh /
21-
RUN /qemu.sh arm
22-
2335
ENV CROSS_SYSROOT=/android-ndk/sysroot
24-
RUN cp $CROSS_SYSROOT/usr/lib/arm-linux-androideabi/28/libz.so /system/lib/
36+
COPY android-symlink.sh /
37+
RUN /android-symlink.sh arm arm-linux-androideabi
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_ARM_LINUX_ANDROIDEABI_LINKER=arm-linux-androideabi-gcc \
3144
CARGO_TARGET_ARM_LINUX_ANDROIDEABI_RUNNER="/android-runner arm" \
45+
AR_arm_linux_androideabi=arm-linux-androideabi-ar \
46+
AS_arm_linux_androideabi=arm-linux-androideabi-as \
3247
CC_arm_linux_androideabi=arm-linux-androideabi-gcc \
3348
CXX_arm_linux_androideabi=arm-linux-androideabi-g++ \
49+
LD_arm_linux_androideabi=arm-linux-androideabi-ld \
50+
NM_arm_linux_androideabi=arm-linux-androideabi-nm \
51+
OBJCOPY_arm_linux_androideabi=arm-linux-androideabi-objcopy \
52+
OBJDUMP_arm_linux_androideabi=arm-linux-androideabi-objdump \
53+
RANLIB_arm_linux_androideabi=arm-linux-androideabi-ranlib \
54+
READELF_arm_linux_androideabi=arm-linux-androideabi-readelf \
55+
SIZE_arm_linux_androideabi=arm-linux-androideabi-size \
56+
STRINGS_arm_linux_androideabi=arm-linux-androideabi-strings \
57+
STRIP_arm_linux_androideabi=arm-linux-androideabi-strip \
3458
BINDGEN_EXTRA_CLANG_ARGS_arm_linux_androideabi="--sysroot=$CROSS_SYSROOT" \
3559
DEP_Z_INCLUDE="$CROSS_SYSROOT/usr/include/" \
3660
RUST_TEST_THREADS=1 \

docker/Dockerfile.armv7-linux-androideabi

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 arm
15+
16+
ARG ANDROID_NDK=r25b
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

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

20-
COPY qemu.sh /
21-
RUN /qemu.sh arm
22-
2335
ENV CROSS_SYSROOT=/android-ndk/sysroot
24-
RUN cp $CROSS_SYSROOT/usr/lib/arm-linux-androideabi/28/libz.so /system/lib/
36+
COPY android-symlink.sh /
37+
RUN /android-symlink.sh arm arm-linux-androideabi
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_ARMV7_LINUX_ANDROIDEABI_LINKER=arm-linux-androideabi-gcc \
3144
CARGO_TARGET_ARMV7_LINUX_ANDROIDEABI_RUNNER="/android-runner arm" \
45+
AR_armv7_linux_androideabi=arm-linux-androideabi-ar \
46+
AS_armv7_linux_androideabi=arm-linux-androideabi-as \
3247
CC_armv7_linux_androideabi=arm-linux-androideabi-gcc \
3348
CXX_armv7_linux_androideabi=arm-linux-androideabi-g++ \
49+
LD_armv7_linux_androideabi=arm-linux-androideabi-ld \
50+
NM_armv7_linux_androideabi=arm-linux-androideabi-nm \
51+
OBJCOPY_armv7_linux_androideabi=arm-linux-androideabi-objcopy \
52+
OBJDUMP_armv7_linux_androideabi=arm-linux-androideabi-objdump \
53+
RANLIB_armv7_linux_androideabi=arm-linux-androideabi-ranlib \
54+
READELF_armv7_linux_androideabi=arm-linux-androideabi-readelf \
55+
SIZE_armv7_linux_androideabi=arm-linux-androideabi-size \
56+
STRINGS_armv7_linux_androideabi=arm-linux-androideabi-strings \
57+
STRIP_armv7_linux_androideabi=arm-linux-androideabi-strip \
3458
BINDGEN_EXTRA_CLANG_ARGS_armv7_linux_androideabi="--sysroot=$CROSS_SYSROOT" \
3559
DEP_Z_INCLUDE="$CROSS_SYSROOT/usr/include/" \
3660
RUST_TEST_THREADS=1 \

docker/Dockerfile.i686-linux-android

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,34 +10,59 @@ 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 that only supports 32-bit x86 systems.
2721
COPY qemu.sh /
2822
RUN /qemu.sh i386
2923

24+
ARG ANDROID_NDK=r25b
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 /
39+
RUN mkdir -p $PYTHON_TMPDIR
40+
COPY android $PYTHON_TMPDIR
41+
RUN /android-system.sh x86
42+
3043
ENV CROSS_SYSROOT=/android-ndk/sysroot
31-
RUN cp $CROSS_SYSROOT/usr/lib/i686-linux-android/28/libz.so /system/lib/
44+
COPY android-symlink.sh /
45+
RUN /android-symlink.sh i386 i686-linux-android
3246

3347
COPY android-runner /
3448

3549
# Libz is distributed in the android ndk, but for some unknown reason it is not
3650
# found in the build process of some crates, so we explicit set the DEP_Z_ROOT
3751
ENV CARGO_TARGET_I686_LINUX_ANDROID_LINKER=i686-linux-android-gcc \
3852
CARGO_TARGET_I686_LINUX_ANDROID_RUNNER="/android-runner i686" \
53+
AR_i686_linux_android=i686-linux-android-ar \
54+
AS_i686_linux_android=i686-linux-android-as \
3955
CC_i686_linux_android=i686-linux-android-gcc \
4056
CXX_i686_linux_android=i686-linux-android-g++ \
57+
LD_i686_linux_android=i686-linux-android-ld \
58+
NM_i686_linux_android=i686-linux-android-nm \
59+
OBJCOPY_i686_linux_android=i686-linux-android-objcopy \
60+
OBJDUMP_i686_linux_android=i686-linux-android-objdump \
61+
RANLIB_i686_linux_android=i686-linux-android-ranlib \
62+
READELF_i686_linux_android=i686-linux-android-readelf \
63+
SIZE_i686_linux_android=i686-linux-android-size \
64+
STRINGS_i686_linux_android=i686-linux-android-strings \
65+
STRIP_i686_linux_android=i686-linux-android-strip \
4166
BINDGEN_EXTRA_CLANG_ARGS_i686_linux_android="--sysroot=$CROSS_SYSROOT" \
4267
DEP_Z_INCLUDE="$CROSS_SYSROOT/usr/include/" \
4368
LIBZ_SYS_STATIC=1 \

docker/Dockerfile.thumbv7neon-linux-androideabi

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,31 @@ 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=r25b
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

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

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

2639
COPY android-runner /
2740

docker/Dockerfile.x86_64-linux-android

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,52 @@ 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=r25b
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

1731
COPY android-system.sh /
32+
RUN mkdir -p $PYTHON_TMPDIR
33+
COPY android $PYTHON_TMPDIR
1834
RUN /android-system.sh x86_64
1935

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-
2436
ENV CROSS_SYSROOT=/android-ndk/sysroot
25-
RUN cp $CROSS_SYSROOT/usr/lib/x86_64-linux-android/28/libz.so /system/lib/
37+
COPY android-symlink.sh /
38+
RUN /android-symlink.sh x86_64 x86_64-linux-android
2639

2740
COPY android-runner /
2841

2942
# Libz is distributed in the android ndk, but for some unknown reason it is not
3043
# found in the build process of some crates, so we explicit set the DEP_Z_ROOT
3144
ENV CARGO_TARGET_X86_64_LINUX_ANDROID_LINKER=x86_64-linux-android-gcc \
3245
CARGO_TARGET_X86_64_LINUX_ANDROID_RUNNER="/android-runner x86_64" \
46+
AR_x86_64_linux_android=x86_64-linux-android-ar \
47+
AS_x86_64_linux_android=x86_64-linux-android-as \
3348
CC_x86_64_linux_android=x86_64-linux-android-gcc \
3449
CXX_x86_64_linux_android=x86_64-linux-android-g++ \
50+
LD_x86_64_linux_android=x86_64-linux-android-ld \
51+
NM_x86_64_linux_android=x86_64-linux-android-nm \
52+
OBJCOPY_x86_64_linux_android=x86_64-linux-android-objcopy \
53+
OBJDUMP_x86_64_linux_android=x86_64-linux-android-objdump \
54+
RANLIB_x86_64_linux_android=x86_64-linux-android-ranlib \
55+
READELF_x86_64_linux_android=x86_64-linux-android-readelf \
56+
SIZE_x86_64_linux_android=x86_64-linux-android-size \
57+
STRINGS_x86_64_linux_android=x86_64-linux-android-strings \
58+
STRIP_x86_64_linux_android=x86_64-linux-android-strip \
3559
BINDGEN_EXTRA_CLANG_ARGS_x86_64_linux_android="--sysroot=$CROSS_SYSROOT" \
3660
DEP_Z_INCLUDE="$CROSS_SYSROOT/usr/include/" \
3761
RUST_TEST_THREADS=1 \

0 commit comments

Comments
 (0)