Skip to content

Commit e4d429d

Browse files
Merge #720
720: Add android runner to run android binaries. r=Emilgardis a=Alexhuszagh Android binaries currently fail to run linking against certain dependencies, because `libc++_shared.so` is not found, so ensure the library is preloaded via `LD_PRELOAD`. This creates a simple `android-runner` file, so any additional changes can be added there. This merely links to the proper `libc++_shared.so`, so it doesn't fix other issues. The [hello world project](https://github.com/cross-rs/rust-cpp-hello-word) now compiles and runs on `aarch64-linux-android`, but not `i686-linux-android`, which seems to be entirely unrelated (likely a permission error on the cloud Fedora server I'm running). ```text error getting old personality value: Operation not permitted libc: error getting old personality value: Operation not permitted Aborted (core dumped) ``` Linked Issues: #82 Co-authored-by: Alex Huszagh <[email protected]>
2 parents 459e03e + 8788c7d commit e4d429d

7 files changed

+40
-9
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,11 @@ jobs:
147147
- { target: i686-unknown-linux-musl, os: ubuntu-latest, std: 1, run: 1 }
148148
- { target: mips-unknown-linux-musl, os: ubuntu-latest, cpp: 1, std: 1, run: 1 }
149149
- { target: mipsel-unknown-linux-musl, os: ubuntu-latest, cpp: 1, std: 1, run: 1 }
150-
- { target: aarch64-linux-android, os: ubuntu-latest, cpp: 1, std: 1, run: 1 }
151-
- { target: arm-linux-androideabi, os: ubuntu-latest, cpp: 1, std: 1, run: 1 }
152-
- { target: armv7-linux-androideabi, os: ubuntu-latest, cpp: 1, std: 1, run: 1 }
153-
- { target: i686-linux-android, os: ubuntu-latest, cpp: 1, std: 1, run: 1 }
154-
- { target: x86_64-linux-android, os: ubuntu-latest, cpp: 1, std: 1, run: 1 }
150+
- { target: aarch64-linux-android, os: ubuntu-latest, cpp: 1, std: 1, run: 1, cpp: 1, runners: qemu-user }
151+
- { target: arm-linux-androideabi, os: ubuntu-latest, cpp: 1, std: 1, run: 1, cpp: 1, runners: qemu-user }
152+
- { target: armv7-linux-androideabi, os: ubuntu-latest, cpp: 1, std: 1, run: 1, cpp: 1, runners: qemu-user }
153+
- { target: i686-linux-android, os: ubuntu-latest, cpp: 1, std: 1, run: 1, cpp: 1, runners: qemu-user }
154+
- { target: x86_64-linux-android, os: ubuntu-latest, cpp: 1, std: 1, run: 1, cpp: 1, runners: qemu-user }
155155
- { target: x86_64-pc-windows-gnu, os: ubuntu-latest, cpp: 1, std: 1, run: 1 }
156156
- { target: i686-pc-windows-gnu, os: ubuntu-latest, cpp: 1, std: 1, run: 1 }
157157
# Disabled for now, see https://github.com/rust-lang/rust/issues/85821

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
77

88
- #722 - boolean environment variables are evaluated as truthy or falsey.
99
- #721 - add support for running doctests on nightly if `CROSS_UNSTABLE_ENABLE_DOCTESTS=true`.
10+
- #719 - add android runner to preload `libc++_shared.so`.
1011
- #718 - remove deb subcommand.
1112
- #714 - use host target directory when falling back to host cargo.
1213
- #713 - convert relative target directories to absolute paths.

docker/Dockerfile.aarch64-linux-android

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ RUN /qemu.sh aarch64
2222

2323
RUN cp /android-ndk/sysroot/usr/lib/aarch64-linux-android/28/libz.so /system/lib/
2424

25+
COPY android-runner /
26+
2527
# Libz is distributed in the android ndk, but for some unknown reason it is not
2628
# found in the build process of some crates, so we explicit set the DEP_Z_ROOT
2729
ENV CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER=aarch64-linux-android-gcc \
28-
CARGO_TARGET_AARCH64_LINUX_ANDROID_RUNNER=qemu-aarch64 \
30+
CARGO_TARGET_AARCH64_LINUX_ANDROID_RUNNER="/android-runner aarch64" \
2931
CC_aarch64_linux_android=aarch64-linux-android-gcc \
3032
CXX_aarch64_linux_android=aarch64-linux-android-g++ \
3133
BINDGEN_EXTRA_CLANG_ARGS_aarch64_linux_android="--sysroot=/android-ndk/sysroot" \

docker/Dockerfile.arm-linux-androideabi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ RUN /qemu.sh arm
2222

2323
RUN cp /android-ndk/sysroot/usr/lib/arm-linux-androideabi/28/libz.so /system/lib/
2424

25+
COPY android-runner /
26+
2527
# Libz is distributed in the android ndk, but for some unknown reason it is not
2628
# found in the build process of some crates, so we explicit set the DEP_Z_ROOT
2729
ENV CARGO_TARGET_ARM_LINUX_ANDROIDEABI_LINKER=arm-linux-androideabi-gcc \
28-
CARGO_TARGET_ARM_LINUX_ANDROIDEABI_RUNNER=qemu-arm \
30+
CARGO_TARGET_ARM_LINUX_ANDROIDEABI_RUNNER="/android-runner arm" \
2931
CC_arm_linux_androideabi=arm-linux-androideabi-gcc \
3032
CXX_arm_linux_androideabi=arm-linux-androideabi-g++ \
3133
BINDGEN_EXTRA_CLANG_ARGS_arm_linux_androideabi="--sysroot=/android-ndk/sysroot" \

docker/Dockerfile.i686-linux-android

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,12 @@ RUN /qemu.sh i386
2929

3030
RUN cp /android-ndk/sysroot/usr/lib/i686-linux-android/28/libz.so /system/lib/
3131

32+
COPY android-runner /
33+
3234
# Libz is distributed in the android ndk, but for some unknown reason it is not
3335
# found in the build process of some crates, so we explicit set the DEP_Z_ROOT
3436
ENV CARGO_TARGET_I686_LINUX_ANDROID_LINKER=i686-linux-android-gcc \
35-
CARGO_TARGET_I686_LINUX_ANDROID_RUNNER="qemu-i386 -cpu n270" \
37+
CARGO_TARGET_I686_LINUX_ANDROID_RUNNER="/android-runner i686 -cpu n270" \
3638
CC_i686_linux_android=i686-linux-android-gcc \
3739
CXX_i686_linux_android=i686-linux-android-g++ \
3840
BINDGEN_EXTRA_CLANG_ARGS_i686_linux_android="--sysroot=/android-ndk/sysroot" \

docker/Dockerfile.x86_64-linux-android

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@ RUN /qemu.sh x86_64
2323

2424
RUN cp /android-ndk/sysroot/usr/lib/x86_64-linux-android/28/libz.so /system/lib/
2525

26+
COPY android-runner /
27+
2628
# Libz is distributed in the android ndk, but for some unknown reason it is not
2729
# found in the build process of some crates, so we explicit set the DEP_Z_ROOT
2830
ENV CARGO_TARGET_X86_64_LINUX_ANDROID_LINKER=x86_64-linux-android-gcc \
29-
CARGO_TARGET_X86_64_LINUX_ANDROID_RUNNER="qemu-x86_64 -cpu qemu64,+mmx,+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+popcnt" \
31+
CARGO_TARGET_X86_64_LINUX_ANDROID_RUNNER="/android-runner x86_64 -cpu qemu64,+mmx,+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+popcnt" \
3032
CC_x86_64_linux_android=x86_64-linux-android-gcc \
3133
CXX_x86_64_linux_android=x86_64-linux-android-g++ \
3234
BINDGEN_EXTRA_CLANG_ARGS_x86_64_linux_android="--sysroot=/android-ndk/sysroot" \

docker/android-runner

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
# arch in the rust target
6+
arch="${1}"
7+
shift
8+
9+
# select android abi, and find the shared libc++ library
10+
android_abi="${arch}-linux-android"
11+
qarch="${arch}"
12+
case "${arch}" in
13+
arm)
14+
android_abi="arm-linux-androideabi"
15+
;;
16+
i686)
17+
qarch="i386"
18+
;;
19+
esac
20+
libdir="/android-ndk/sysroot/usr/lib/${android_abi}"
21+
22+
LD_PRELOAD="${libdir}/libc++_shared.so" exec qemu-"${qarch}" "${@}"

0 commit comments

Comments
 (0)