Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support cross debugging and runners on Android. #725

Merged
merged 1 commit into from
May 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

- #725 - support `CROSS_DEBUG` and `CROSS_RUNNER` on android images.
- #722 - boolean environment variables are evaluated as truthy or falsey.
- #721 - add support for running doctests on nightly if `CROSS_UNSTABLE_ENABLE_DOCTESTS=true`.
- #720 - add android runner to preload `libc++_shared.so`.
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile.armv7-linux-androideabi
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ RUN cp /android-ndk/sysroot/usr/lib/arm-linux-androideabi/28/libz.so /system/lib
# Libz is distributed in the android ndk, but for some unknown reason it is not
# found in the build process of some crates, so we explicit set the DEP_Z_ROOT
ENV CARGO_TARGET_ARMV7_LINUX_ANDROIDEABI_LINKER=arm-linux-androideabi-gcc \
CARGO_TARGET_ARMV7_LINUX_ANDROIDEABI_RUNNER=qemu-arm \
CARGO_TARGET_ARMV7_LINUX_ANDROIDEABI_RUNNER="/android-runner arm" \
CC_armv7_linux_androideabi=arm-linux-androideabi-gcc \
CXX_armv7_linux_androideabi=arm-linux-androideabi-g++ \
BINDGEN_EXTRA_CLANG_ARGS_armv7_linux_androideabi="--sysroot=/android-ndk/sysroot" \
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile.i686-linux-android
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ COPY android-runner /
# Libz is distributed in the android ndk, but for some unknown reason it is not
# found in the build process of some crates, so we explicit set the DEP_Z_ROOT
ENV CARGO_TARGET_I686_LINUX_ANDROID_LINKER=i686-linux-android-gcc \
CARGO_TARGET_I686_LINUX_ANDROID_RUNNER="/android-runner i686 -cpu n270" \
CARGO_TARGET_I686_LINUX_ANDROID_RUNNER="/android-runner i686" \
CC_i686_linux_android=i686-linux-android-gcc \
CXX_i686_linux_android=i686-linux-android-g++ \
BINDGEN_EXTRA_CLANG_ARGS_i686_linux_android="--sysroot=/android-ndk/sysroot" \
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile.x86_64-linux-android
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ COPY android-runner /
# Libz is distributed in the android ndk, but for some unknown reason it is not
# found in the build process of some crates, so we explicit set the DEP_Z_ROOT
ENV CARGO_TARGET_X86_64_LINUX_ANDROID_LINKER=x86_64-linux-android-gcc \
CARGO_TARGET_X86_64_LINUX_ANDROID_RUNNER="/android-runner x86_64 -cpu qemu64,+mmx,+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+popcnt" \
CARGO_TARGET_X86_64_LINUX_ANDROID_RUNNER="/android-runner x86_64" \
CC_x86_64_linux_android=x86_64-linux-android-gcc \
CXX_x86_64_linux_android=x86_64-linux-android-g++ \
BINDGEN_EXTRA_CLANG_ARGS_x86_64_linux_android="--sysroot=/android-ndk/sysroot" \
Expand Down
27 changes: 26 additions & 1 deletion docker/android-runner
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ set -e
arch="${1}"
shift

if [ -n "${CROSS_DEBUG}" ]; then
set -x
fi

if [ "${CROSS_RUNNER}" = "" ]; then
CROSS_RUNNER=qemu-user
fi

# select android abi, and find the shared libc++ library
android_abi="${arch}-linux-android"
qarch="${arch}"
Expand All @@ -15,8 +23,25 @@ case "${arch}" in
;;
i686)
qarch="i386"
qemu_args=("-cpu" "n270")
;;
x86_64)
qemu_args=("-cpu" "qemu64,+mmx,+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+popcnt")
;;
esac
libdir="/android-ndk/sysroot/usr/lib/${android_abi}"

LD_PRELOAD="${libdir}/libc++_shared.so" exec qemu-"${qarch}" "${@}"
export LD_PRELOAD="${libdir}/libc++_shared.so"
case "${CROSS_RUNNER}" in
native)
exec "${@}"
;;
qemu-user)
exec "qemu-${qarch}" "${qemu_args[@]}" "${@}"
;;
*)
echo "Invalid runner: \"${CROSS_RUNNER}\"";
echo "Valid runners are: native and qemu-user"
exit 1
;;
esac