-
Notifications
You must be signed in to change notification settings - Fork 382
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
Conversation
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.
Awesome, @malbarbo.
I think this is a great start towards supporting testing on android targets.
I'm wondering if we can workaround this potential redistribution issue by downloading the SDK on user machine (and cache it somehow) instead of distributing it with our docker images. But that's something we can look into later.
So, I left some questions in the comments. But, other than that this looks good to me. Excellent work as usual. 💯
@@ -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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
This was unintentional, sorry.
# 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 comment
The 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 java --version
) at runtime or something like that?
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.
Yes, you are right.
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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
lunch is a command of the android build system.
@@ -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 comment
The 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 comment
The 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 cross test --target i686-unknown-linux-musl
in the ripgrep repository worked as expected. I tested a simple program that panics, and it also worked.
Maybe this is a std issue? How should we proceed?
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.
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.
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 comment
The 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 comment
The 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 comment
The 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) .
docker/qemu.sh
Outdated
# 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 comment
The 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 comment
The 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.
docker/qemu.sh
Outdated
|
||
local arch=$1 \ | ||
target=$2 \ |
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.
maybe this should be named os
?
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.
Much better!
@@ -41,7 +41,7 @@ matrix: | |||
|
|||
# BSD | |||
- env: TARGET=i686-unknown-freebsd DYLIB=1 STD=1 OPENSSL=0.7.17 | |||
- env: TARGET=x86_64-unknown-dragonfly DYLIB=1 OPENSSL=0.5.5 |
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?
Also fix openssl arch for armv7-linux-androideabi
An alternative is to build the docker image in the user machine. In a more general away, we can pack all Docker files inside the cross binary and give the user the option of downloading the pre-build docker image or build it locally. We can also let the user specify a Docker file. |
I submitted the qemu patch upstream. Running ripgrep tests in an i686 android emulator works as expected. So I think std is correct. Anyway, the error seems only to happen when Command is used. @japaric Anything else? Can we test this? |
Sorry for the delay @malbarbo. Could you please add:
After that you can r+ this. @homunkulus delegate+ |
✌️ @malbarbo can now approve this pull request |
Thanks @japaric! @homunkulus +r |
Ops, let's try again. @homunkulus r+ |
📌 Commit 140aff3 has been approved by |
Add limited android test support We could provide android test support by launching an android emulator and running tests in the emulator (like how it is done in libc and rust), but there is licenses issues in redistributing the sdk (see 3.4 of https://developer.android.com/studio/terms.html). Off course, I maybe be wrong about this. So we download and build bionic libc from source, which I think allows we to distribute the binaries. Having the android libc allows running native binaries using qemu, which can be enough for projects like, nix, ripgrep, etc. Related #82
☀️ Test successful - status-travis |
We could provide android test support by launching an android emulator and running tests in the emulator (like how it is done in libc and rust), but there is licenses issues in redistributing the sdk (see 3.4 of https://developer.android.com/studio/terms.html). Off course, I maybe be wrong about this.
So we download and build bionic libc from source, which I think allows we to distribute the binaries. Having the android libc allows running native binaries using qemu, which can be enough for projects like, nix, ripgrep, etc.
Related #82