-
Notifications
You must be signed in to change notification settings - Fork 377
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
Add limited android test support #132
Changes from 2 commits
cff2ebc
03d0187
5d8d75b
dd33f39
44aa61a
4aed911
140aff3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,13 +12,19 @@ RUN apt-get update && \ | |
COPY xargo.sh / | ||
RUN bash /xargo.sh | ||
|
||
COPY qemu.sh / | ||
RUN bash /qemu.sh aarch64 android | ||
|
||
COPY android-ndk.sh / | ||
RUN bash /android-ndk.sh arm64 21 | ||
ENV PATH=$PATH:/android-ndk/bin | ||
|
||
COPY openssl.sh / | ||
RUN bash /openssl.sh linux-generic64 aarch64-linux-android- -mandroid -fomit-frame-pointer | ||
|
||
COPY android-system.sh / | ||
RUN bash /android-system.sh arm64 | ||
|
||
# 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_AARCH64_LINUX_ANDROID_LINKER=aarch64-linux-android-gcc \ | ||
|
@@ -29,5 +35,7 @@ ENV CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER=aarch64-linux-android-gcc \ | |
OPENSSL_DIR=/openssl \ | ||
OPENSSL_INCLUDE_DIR=/openssl/include \ | ||
OPENSSL_LIB_DIR=/openssl/lib \ | ||
RUST_TEST_THREADS=1 \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this intentional? Does QEMU have good threading support for android / bionic? Or are all Rust (or bionic?) applications single threaded? (This comment applies to all the RUST_TEST_THREADS removals) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was unintentional, sorry. |
||
HOME=/tmp/ | ||
HOME=/tmp/ \ | ||
TMPDIR=/tmp/ \ | ||
ANDROID_ROOT=/system \ | ||
ANDROID_DATA=/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
set -ex | ||
|
||
main() { | ||
local arch=$1 | ||
local td=$(mktemp -d) | ||
pushd $td | ||
|
||
local dependencies=( | ||
ca-certificates | ||
curl | ||
gcc-multilib | ||
git | ||
g++-multilib | ||
make | ||
python | ||
) | ||
|
||
# fake java and javac, it is not necessary for what we build, but the build | ||
# script ask for it | ||
cat << EOF > /usr/bin/java | ||
#!/bin/bash | ||
echo "java version \"1.7.0\"" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is an interesting hack. I suppose that all android programs read the java version (e.g. by calling There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, you are right. |
||
echo "OpenJDK Runtime Environment (IcedTea 2.6.9)" | ||
echo "OpenJDK 64-Bit Server VM (build 24.131-b00, mixed mode)" | ||
EOF | ||
|
||
cat << EOF > /usr/bin/javac | ||
#!/bin/bash | ||
echo "javac 1.7.0" | ||
EOF | ||
|
||
chmod +x /usr/bin/java | ||
chmod +x /usr/bin/javac | ||
|
||
# more faking | ||
export ANDROID_JAVA_HOME=/tmp | ||
mkdir /tmp/lib/ | ||
touch /tmp/lib/tools.jar | ||
|
||
apt-get update | ||
local purge_list=(default-jre) | ||
for dep in ${dependencies[@]}; do | ||
if ! dpkg -L $dep; then | ||
apt-get install --no-install-recommends -y $dep | ||
purge_list+=( $dep ) | ||
fi | ||
done | ||
|
||
curl -O https://storage.googleapis.com/git-repo-downloads/repo | ||
chmod +x repo | ||
|
||
# this is the minimum set of modules that are need to build bionic | ||
# this was created by trial and error | ||
./repo init -u https://android.googlesource.com/platform/manifest -b android-5.0.0_r1 | ||
./repo sync bionic | ||
./repo sync build | ||
./repo sync external/compiler-rt | ||
./repo sync external/jemalloc | ||
./repo sync external/libcxx | ||
./repo sync external/libcxxabi | ||
./repo sync external/stlport | ||
./repo sync prebuilts/clang/linux-x86/host/3.5 | ||
./repo sync system/core | ||
case $arch in | ||
arm) | ||
./repo sync prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.8 | ||
;; | ||
arm64) | ||
./repo sync prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.8 | ||
./repo sync prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9 | ||
;; | ||
x86) | ||
./repo sync prebuilts/gcc/linux-x86/x86/x86_64-linux-android-4.8 | ||
;; | ||
x86_64) | ||
./repo sync prebuilts/gcc/linux-x86/x86/x86_64-linux-android-4.8 | ||
;; | ||
esac | ||
|
||
# avoid build tests | ||
rm bionic/linker/tests/Android.mk bionic/tests/Android.mk | ||
|
||
source build/envsetup.sh | ||
lunch aosp_$arch-user | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lunch? not launch? (probably intentional) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lunch is a command of the android build system. |
||
mmma bionic/ | ||
|
||
if [ $arch = "arm" ]; then | ||
mv out/target/product/generic/system/ / | ||
else | ||
mv out/target/product/generic_$arch/system/ / | ||
fi | ||
|
||
# clean up | ||
apt-get purge --auto-remove -y ${purge_list[@]} | ||
|
||
popd | ||
|
||
rm -rf $td | ||
rm $0 | ||
} | ||
|
||
main "${@}" |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,22 +12,39 @@ RUN apt-get update && \ | |
COPY xargo.sh / | ||
RUN bash /xargo.sh | ||
|
||
# We could supposedly directly run i686 binaries like we do for x86_64, but | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is ... interesting. Any idea why this happen? IIRC, this also happens with the i686-musl target. A panicking program cross compiled for this target will fail in a similar way when executed on x86_64. But I never tried running running that binary under qemu-i386. Cross compiling that binary for i686-gnu and running it on x86_64 works fine though. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, it seams I got this wrong. Using qemu is enough to pass the ci/script.sh testing, but it fails in in the ripgrep tests. I was unable to reproduce the i686-musl failure... Running Maybe this is a std issue? How should we proceed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, it seems that unwinding on i686-unknown-linux-musl was fixed a while ago but didn't notice. i686-unknown-linux-musl is not tested in rust-lang/rust so what you are reporting may indeed be a std bug. |
||
# doing so generates an assertion failure: | ||
# ... assertion failed: signal(libc::SIGPIPE, libc::SIG_IGN) != libc::SIG_ERR | ||
# ... src/libstd/sys/unix/mod.rs | ||
# fatal runtime error: failed to initiate panic, error 5 | ||
# | ||
# Running with qemu works as expected | ||
COPY qemu.sh / | ||
RUN bash /qemu.sh i386 android | ||
|
||
COPY android-ndk.sh / | ||
RUN bash /android-ndk.sh x86 21 | ||
ENV PATH=$PATH:/android-ndk/bin | ||
|
||
# Build with no-asm to make openssl linked binaries position-independent (PIE) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interesting finding. I wonder if no-asm would fix OpenSSL builds on i686-musl. IIRC, when cross compiling OpenSSL for i686-musl caused some PIC/PIE errors later on in the linking process. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've tried and it didn't work... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK. Doesn't matter; it seems that there may be a solution for that issue in #27 (comment) . |
||
COPY openssl.sh / | ||
RUN bash /openssl.sh android-x86 i686-linux-android- | ||
RUN bash /openssl.sh android-x86 i686-linux-android- no-asm | ||
|
||
COPY android-system.sh / | ||
RUN bash /android-system.sh x86 | ||
|
||
# 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=qemu-i386 \ | ||
CC_i686_linux_android=i686-linux-android-gcc \ | ||
CXX_i686_linux_android=i686-linux-android-g++ \ | ||
DEP_Z_ROOT=/android-ndk/sysroot/usr/ \ | ||
OPENSSL_STATIC=1 \ | ||
OPENSSL_DIR=/openssl \ | ||
OPENSSL_INCLUDE_DIR=/openssl/include \ | ||
OPENSSL_LIB_DIR=/openssl/lib \ | ||
RUST_TEST_THREADS=1 \ | ||
HOME=/tmp/ | ||
HOME=/tmp/ \ | ||
TMPDIR=/tmp/ \ | ||
ANDROID_ROOT=/system \ | ||
ANDROID_DATA=/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
set -ex | ||
|
||
main() { | ||
local version=2.9.0 | ||
local version=2.10.0 | ||
|
||
local arch=$1 \ | ||
target=$2 \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe this should be named There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Much better! |
||
td=$(mktemp -d) | ||
|
||
local dependencies=( | ||
|
@@ -15,6 +16,7 @@ main() { | |
libglib2.0-dev | ||
libtool | ||
make | ||
patch | ||
pkg-config | ||
zlib1g-dev | ||
) | ||
|
@@ -32,6 +34,67 @@ main() { | |
|
||
curl -L http://wiki.qemu-project.org/download/qemu-$version.tar.bz2 | \ | ||
tar --strip-components=1 -xj | ||
|
||
# Allow qemu to run android (bionic libc) binaries | ||
if [[ "$target" == "android" ]]; then | ||
patch -p1 <<'EOF' | ||
diff -ur qemu-2.10.0/linux-user/elfload.c qemu-2.10.0.new/linux-user/elfload.c | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this an upstream QEMU commit that was not part of the 2.10.0 release? Or did you come up with this patch yourself? If the latter is there any change you could upstream it. If the former could you include a link to the commit change? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wrote this patch my self some time ago. I updated qemu to 2.10 to keep it up to date. I thought to send it upstream, but I gave up reading https://wiki.qemu.org/Contribute/SubmitAPatch (Later I found https://wiki.qemu.org/Contribute/TrivialPatches but I was already tired...). I will soon ask in the users list why qemu does not support ioctl with RNDGETENTCNT. |
||
--- qemu-2.10.0/linux-user/elfload.c 2017-09-27 11:27:13.866595788 -0300 | ||
+++ qemu-2.10.0.new/linux-user/elfload.c 2017-09-27 11:58:30.662613425 -0300 | ||
@@ -1354,7 +1354,7 @@ | ||
~(abi_ulong)(TARGET_ELF_EXEC_PAGESIZE-1)) | ||
#define TARGET_ELF_PAGEOFFSET(_v) ((_v) & (TARGET_ELF_EXEC_PAGESIZE-1)) | ||
|
||
-#define DLINFO_ITEMS 14 | ||
+#define DLINFO_ITEMS 15 | ||
|
||
static inline void memcpy_fromfs(void * to, const void * from, unsigned long n) | ||
{ | ||
@@ -1782,6 +1782,7 @@ | ||
NEW_AUX_ENT(AT_HWCAP, (abi_ulong) ELF_HWCAP); | ||
NEW_AUX_ENT(AT_CLKTCK, (abi_ulong) sysconf(_SC_CLK_TCK)); | ||
NEW_AUX_ENT(AT_RANDOM, (abi_ulong) u_rand_bytes); | ||
+ NEW_AUX_ENT(AT_SECURE, (abi_ulong)0); | ||
|
||
#ifdef ELF_HWCAP2 | ||
NEW_AUX_ENT(AT_HWCAP2, (abi_ulong) ELF_HWCAP2); | ||
diff -ur qemu-2.10.0/linux-user/ioctls.h qemu-2.10.0.new/linux-user/ioctls.h | ||
--- qemu-2.10.0/linux-user/ioctls.h 2017-09-27 11:27:13.858595669 -0300 | ||
+++ qemu-2.10.0.new/linux-user/ioctls.h 2017-09-27 11:43:40.613299859 -0300 | ||
@@ -430,6 +430,7 @@ | ||
MK_PTR(MK_STRUCT(STRUCT_rtentry))) | ||
IOCTL_SPECIAL(SIOCDELRT, IOC_W, do_ioctl_rt, | ||
MK_PTR(MK_STRUCT(STRUCT_rtentry))) | ||
+ IOCTL(RNDGETENTCNT, IOC_R, MK_PTR(TYPE_INT)) | ||
|
||
#ifdef TARGET_TIOCSTART | ||
IOCTL_IGNORE(TIOCSTART) | ||
diff -ur qemu-2.10.0/linux-user/syscall.c qemu-2.10.0.new/linux-user/syscall.c | ||
--- qemu-2.10.0/linux-user/syscall.c 2017-09-27 11:27:13.862595729 -0300 | ||
+++ qemu-2.10.0.new/linux-user/syscall.c 2017-09-27 11:44:26.133987660 -0300 | ||
@@ -55,6 +55,7 @@ | ||
//#include <sys/user.h> | ||
#include <netinet/ip.h> | ||
#include <netinet/tcp.h> | ||
+#include <linux/random.h> | ||
#include <linux/wireless.h> | ||
#include <linux/icmp.h> | ||
#include <linux/icmpv6.h> | ||
diff -ur qemu-2.10.0/linux-user/syscall_defs.h qemu-2.10.0.new/linux-user/syscall_defs.h | ||
--- qemu-2.10.0/linux-user/syscall_defs.h 2017-09-27 11:27:13.862595729 -0300 | ||
+++ qemu-2.10.0.new/linux-user/syscall_defs.h 2017-09-27 11:46:09.303545817 -0300 | ||
@@ -971,6 +971,8 @@ | ||
short revents; /* returned events */ | ||
}; | ||
|
||
+#define TARGET_RNDGETENTCNT TARGET_IOR('R', 0x00, int) | ||
+ | ||
/* virtual terminal ioctls */ | ||
#define TARGET_KIOCSOUND 0x4B2F /* start sound generation (0 for off) */ | ||
#define TARGET_KDMKTONE 0x4B30 /* generate tone */ | ||
EOF | ||
fi | ||
|
||
./configure \ | ||
--disable-kvm \ | ||
--disable-vnc \ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: alignment regression :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a fix, isn't it?