From 0df0a1cccb3a02f2b6a3dae4420e84ad09321e14 Mon Sep 17 00:00:00 2001 From: Yuji Yamamoto Date: Thu, 19 Dec 2019 11:08:43 +0900 Subject: [PATCH 1/7] Support Android I'll send a PR after https://github.com/rust-lang/libc/pull/1622 is merged and released --- lib/clif-backend/src/libcalls.rs | 2 +- lib/clif-backend/src/signal/unix.rs | 12 ++++++++++-- lib/runtime-core/Cargo.toml | 3 ++- lib/runtime-core/build.rs | 2 +- lib/runtime-core/src/fault.rs | 10 ++++++++-- lib/singlepass-backend/src/lib.rs | 2 ++ lib/wasi/src/syscalls/mod.rs | 14 ++++++++++++-- 7 files changed, 36 insertions(+), 9 deletions(-) diff --git a/lib/clif-backend/src/libcalls.rs b/lib/clif-backend/src/libcalls.rs index bfc1ceca643..b15d4dc32bc 100644 --- a/lib/clif-backend/src/libcalls.rs +++ b/lib/clif-backend/src/libcalls.rs @@ -78,7 +78,7 @@ pub extern "C" fn nearbyintf64(x: f64) -> f64 { // FIXME: Is there a replacement on AArch64? #[cfg(all( - any(target_os = "freebsd", target_os = "linux"), + any(target_os = "freebsd", target_os = "linux", target_os = "android"), target_arch = "aarch64" ))] #[no_mangle] diff --git a/lib/clif-backend/src/signal/unix.rs b/lib/clif-backend/src/signal/unix.rs index 81f751f37b5..98571cbbff3 100644 --- a/lib/clif-backend/src/signal/unix.rs +++ b/lib/clif-backend/src/signal/unix.rs @@ -229,7 +229,10 @@ unsafe fn get_faulting_addr_and_ip( (si_addr, rip as _) } -#[cfg(all(target_os = "linux", target_arch = "aarch64"))] +#[cfg(all( + any(target_os = "linux", target_os = "android"), + target_arch = "aarch64" +))] unsafe fn get_faulting_addr_and_ip( _siginfo: *const c_void, _ucontext: *const c_void, @@ -237,7 +240,10 @@ unsafe fn get_faulting_addr_and_ip( (::std::ptr::null(), ::std::ptr::null()) } -#[cfg(all(target_os = "linux", target_arch = "x86_64"))] +#[cfg(all( + any(target_os = "linux", target_os = "android"), + target_arch = "x86_64" +))] unsafe fn get_faulting_addr_and_ip( siginfo: *const c_void, ucontext: *const c_void, @@ -332,5 +338,7 @@ unsafe fn get_faulting_addr_and_ip( all(target_os = "macos", target_arch = "x86_64"), all(target_os = "linux", target_arch = "x86_64"), all(target_os = "linux", target_arch = "aarch64"), + all(target_os = "android", target_arch = "x86_64"), + all(target_os = "android", target_arch = "aarch64"), )))] compile_error!("This crate doesn't yet support compiling on operating systems other than linux and macos and architectures other than x86_64"); diff --git a/lib/runtime-core/Cargo.toml b/lib/runtime-core/Cargo.toml index 51fcb6f3a2f..e826cbe4bc3 100644 --- a/lib/runtime-core/Cargo.toml +++ b/lib/runtime-core/Cargo.toml @@ -16,7 +16,8 @@ wasmparser = "0.51.3" parking_lot = "0.10.0" lazy_static = "1.4" errno = "0.2" -libc = "0.2.60" +#libc = "0.2.60" +libc = { path = "../../../libc", version = "0.2.65" } hex = "0.4" smallvec = "0.6" bincode = "1.1" diff --git a/lib/runtime-core/build.rs b/lib/runtime-core/build.rs index b774057780a..2a2c99bf216 100644 --- a/lib/runtime-core/build.rs +++ b/lib/runtime-core/build.rs @@ -37,7 +37,7 @@ fn main() { .file("image-loading-freebsd-x86-64.s") .compile("image-loading"); } - ("linux", "x86_64") => { + ("linux", "x86_64") | ("android", "x86_64") => { cc::Build::new() .file("image-loading-linux-x86-64.s") .compile("image-loading"); diff --git a/lib/runtime-core/src/fault.rs b/lib/runtime-core/src/fault.rs index c1ab4cdf700..d8c985e09b9 100644 --- a/lib/runtime-core/src/fault.rs +++ b/lib/runtime-core/src/fault.rs @@ -743,7 +743,10 @@ pub unsafe fn get_fault_info(siginfo: *const c_void, ucontext: *mut c_void) -> F } } -#[cfg(all(target_os = "linux", target_arch = "aarch64"))] +#[cfg(all( + any(target_os = "linux", target_os = "android"), + target_arch = "aarch64" +))] /// Get fault info from siginfo and ucontext. pub unsafe fn get_fault_info(siginfo: *const c_void, ucontext: *mut c_void) -> FaultInfo { #[allow(dead_code)] @@ -810,7 +813,10 @@ pub unsafe fn get_fault_info(siginfo: *const c_void, ucontext: *mut c_void) -> F } } -#[cfg(all(target_os = "linux", target_arch = "x86_64"))] +#[cfg(all( + any(target_os = "linux", target_os = "android"), + target_arch = "x86_64" +))] /// Get fault info from siginfo and ucontext. pub unsafe fn get_fault_info(siginfo: *const c_void, ucontext: *mut c_void) -> FaultInfo { use libc::{ diff --git a/lib/singlepass-backend/src/lib.rs b/lib/singlepass-backend/src/lib.rs index 98339cca304..fd4f94c716d 100644 --- a/lib/singlepass-backend/src/lib.rs +++ b/lib/singlepass-backend/src/lib.rs @@ -17,6 +17,8 @@ all(target_os = "macos", target_arch = "x86_64"), all(target_os = "linux", target_arch = "x86_64"), all(target_os = "linux", target_arch = "aarch64"), + all(target_os = "android", target_arch = "x86_64"), + all(target_os = "android", target_arch = "aarch64"), )))] compile_error!("This crate doesn't yet support compiling on operating systems other than FreeBSD, linux and macos and architectures other than x86_64"); diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index f8216afdb0e..fcf9536aa2c 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -1,6 +1,11 @@ #![allow(unused, clippy::too_many_arguments)] pub mod types; -#[cfg(any(target_os = "freebsd", target_os = "linux", target_os = "macos"))] +#[cfg(any( + target_os = "freebsd", + target_os = "linux", + target_os = "android", + target_os = "macos" +))] pub mod unix; #[cfg(any(target_os = "windows"))] pub mod windows; @@ -23,7 +28,12 @@ use std::convert::{Infallible, TryInto}; use std::io::{self, Read, Seek, Write}; use wasmer_runtime_core::{memory::Memory, vm::Ctx}; -#[cfg(any(target_os = "freebsd", target_os = "linux", target_os = "macos"))] +#[cfg(any( + target_os = "freebsd", + target_os = "linux", + target_os = "android", + target_os = "macos" +))] pub use unix::*; #[cfg(any(target_os = "windows"))] From b23436d1bb7a007c2b4a05e9500e256e614ae4a5 Mon Sep 17 00:00:00 2001 From: Yuji Yamamoto Date: Fri, 27 Dec 2019 11:10:25 +0900 Subject: [PATCH 2/7] :bug: Correct error message when trying to build on non-supported targets --- lib/singlepass-backend/src/lib.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/singlepass-backend/src/lib.rs b/lib/singlepass-backend/src/lib.rs index fd4f94c716d..d9f61d68e4a 100644 --- a/lib/singlepass-backend/src/lib.rs +++ b/lib/singlepass-backend/src/lib.rs @@ -20,7 +20,14 @@ all(target_os = "android", target_arch = "x86_64"), all(target_os = "android", target_arch = "aarch64"), )))] -compile_error!("This crate doesn't yet support compiling on operating systems other than FreeBSD, linux and macos and architectures other than x86_64"); +compile_error!("This crate doesn't yet support compiling on operating systems and architectures other than these: + - FreeBSD and x86_64 + - FreeBSD and AArch64 + - macOS and x86_64 + - Linux and x86_64 + - Linux and AArch64 + - Android and x86_64 + - Android and AArch64"); extern crate dynasmrt; From 96a0f851c23626c9240f327e92397ba0bae8a079 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Yuji Date: Mon, 2 Mar 2020 14:45:29 +0900 Subject: [PATCH 3/7] Update libc The new version of libc contains changes necessary to build wasmer-runtime-core for Android. See https://github.com/rust-lang/libc/pull/1622 for details. --- Cargo.lock | 3 +-- lib/runtime-core/Cargo.toml | 3 +-- lib/singlepass-backend/Cargo.toml | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 27d723ce849..c2dda2348e4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -749,8 +749,7 @@ dependencies = [ [[package]] name = "libc" version = "0.2.67" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb147597cdf94ed43ab7a9038716637d2d1bf2bc571da995d0028dec06bd3018" +source = "git+https://github.com/rust-lang/libc.git#b22922f7d86a7e5cccc7bc039a375b23d11436b4" [[package]] name = "llvm-sys" diff --git a/lib/runtime-core/Cargo.toml b/lib/runtime-core/Cargo.toml index e826cbe4bc3..51a2c5f06a2 100644 --- a/lib/runtime-core/Cargo.toml +++ b/lib/runtime-core/Cargo.toml @@ -16,8 +16,7 @@ wasmparser = "0.51.3" parking_lot = "0.10.0" lazy_static = "1.4" errno = "0.2" -#libc = "0.2.60" -libc = { path = "../../../libc", version = "0.2.65" } +libc = "0.2.68" hex = "0.4" smallvec = "0.6" bincode = "1.1" diff --git a/lib/singlepass-backend/Cargo.toml b/lib/singlepass-backend/Cargo.toml index 8894922878f..85fb7dbf252 100644 --- a/lib/singlepass-backend/Cargo.toml +++ b/lib/singlepass-backend/Cargo.toml @@ -17,7 +17,7 @@ dynasmrt = "0.5" lazy_static = "1.4" byteorder = "1.3" nix = "0.15" -libc = "0.2.60" +libc = "0.2.68" smallvec = "0.6" serde = "1.0" serde_derive = "1.0" From 93f6a9b91b7ea3e100a9e5ef2d108d3950fa0202 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Yuji Date: Wed, 11 Mar 2020 18:39:59 +0900 Subject: [PATCH 4/7] enable testing on Android x86_64 Currently, at the time of 2020/03/11, testing on AArch64 is not supported in the upstream repository --- .gitignore | 4 ++ Cargo.lock | 9 +-- ci/README.md | 3 + ci/android-install-ndk.sh | 19 ++++++ ci/android-install-sdk.sh | 73 ++++++++++++++++++++++ ci/android-sysimage.sh | 56 +++++++++++++++++ ci/docker/aarch64-linux-android/Dockerfile | 53 ++++++++++++++++ ci/docker/x86_64-linux-android/Dockerfile | 31 +++++++++ ci/run-docker.sh | 35 +++++++++++ ci/runtest-android.rs | 60 ++++++++++++++++++ 10 files changed, 339 insertions(+), 4 deletions(-) create mode 100644 ci/README.md create mode 100644 ci/android-install-ndk.sh create mode 100644 ci/android-install-sdk.sh create mode 100644 ci/android-sysimage.sh create mode 100644 ci/docker/aarch64-linux-android/Dockerfile create mode 100644 ci/docker/x86_64-linux-android/Dockerfile create mode 100755 ci/run-docker.sh create mode 100644 ci/runtest-android.rs diff --git a/.gitignore b/.gitignore index 1dfea1e5edd..fc0b3b14321 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,7 @@ install/ capi/ api-docs/ api-docs-repo/ + +# Generated by tests on Android +/avd +/core diff --git a/Cargo.lock b/Cargo.lock index c2dda2348e4..d2c14fc3428 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -748,8 +748,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.67" -source = "git+https://github.com/rust-lang/libc.git#b22922f7d86a7e5cccc7bc039a375b23d11436b4" +version = "0.2.68" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dea0c0405123bba743ee3f91f49b1c7cfb684eef0da0a50110f758ccf24cdff0" [[package]] name = "llvm-sys" @@ -1775,9 +1776,9 @@ dependencies = [ [[package]] name = "wabt-sys" -version = "0.7.0" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af5d153dc96aad7dc13ab90835b892c69867948112d95299e522d370c4e13a08" +checksum = "23d7043ebb3e5d96fad7a8d3ca22ee9880748ff8c3e18092cfb2a49d3b8f9084" dependencies = [ "cc", "cmake", diff --git a/ci/README.md b/ci/README.md new file mode 100644 index 00000000000..429bc7915b9 --- /dev/null +++ b/ci/README.md @@ -0,0 +1,3 @@ +# About this directory + +This directory is originally copied from [rust-lang/libc/ci](https://github.com/rust-lang/libc/tree/master/ci). diff --git a/ci/android-install-ndk.sh b/ci/android-install-ndk.sh new file mode 100644 index 00000000000..59d3a1bbbc6 --- /dev/null +++ b/ci/android-install-ndk.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env sh +# Copyright 2016 The Rust Project Developers. See the COPYRIGHT +# file at the top-level directory of this distribution and at +# http://rust-lang.org/COPYRIGHT. +# +# Licensed under the Apache License, Version 2.0 or the MIT license +# , at your +# option. This file may not be copied, modified, or distributed +# except according to those terms. + +set -ex + +NDK=android-ndk-r19c +curl --retry 20 -O https://dl.google.com/android/repository/${NDK}-linux-x86_64.zip +unzip -q -d ndk ${NDK}-linux-x86_64.zip +mv ./ndk/"$NDK"/* ./ndk/ + +rm -rf ./${NDK}-linux-x86_64.zip diff --git a/ci/android-install-sdk.sh b/ci/android-install-sdk.sh new file mode 100644 index 00000000000..7f2104000fd --- /dev/null +++ b/ci/android-install-sdk.sh @@ -0,0 +1,73 @@ +#!/usr/bin/env sh +# Copyright 2016 The Rust Project Developers. See the COPYRIGHT +# file at the top-level directory of this distribution and at +# http://rust-lang.org/COPYRIGHT. +# +# Licensed under the Apache License, Version 2.0 or the MIT license +# , at your +# option. This file may not be copied, modified, or distributed +# except according to those terms. + +set -ex + +# Prep the SDK and emulator +# +# Note that the update process requires that we accept a bunch of licenses, and +# we can't just pipe `yes` into it for some reason, so we take the same strategy +# located in https://github.com/appunite/docker by just wrapping it in a script +# which apparently magically accepts the licenses. + +SDK=4333796 +mkdir sdk +curl --retry 20 https://dl.google.com/android/repository/sdk-tools-linux-${SDK}.zip -O +unzip -q -d sdk sdk-tools-linux-${SDK}.zip + +case "$1" in + arm | armv7) + api=24 + image="system-images;android-${api};google_apis;armeabi-v7a" + ;; + aarch64) + api=24 + image="system-images;android-${api};google_apis;arm64-v8a" + ;; + i686) + api=28 + image="system-images;android-${api};default;x86" + ;; + x86_64) + api=28 + image="system-images;android-${api};default;x86_64" + ;; + *) + echo "invalid arch: $1" + exit 1 + ;; +esac; + +# Try to fix warning about missing file. +# See https://askubuntu.com/a/1078784 +mkdir -p /root/.android/ +echo '### User Sources for Android SDK Manager' >> /root/.android/repositories.cfg +echo '#Fri Nov 03 10:11:27 CET 2017 count=0' >> /root/.android/repositories.cfg + +# Print all available packages +# yes | ./sdk/tools/bin/sdkmanager --list --verbose + +# --no_https avoids +# javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: No trusted certificate found +# +# | grep -v = || true removes the progress bar output from the sdkmanager +# which produces an insane amount of output. +yes | ./sdk/tools/bin/sdkmanager --licenses --no_https | grep -v = || true +yes | ./sdk/tools/bin/sdkmanager --no_https \ + "emulator" \ + "platform-tools" \ + "platforms;android-${api}" \ + "${image}" | grep -v = || true + +echo "no" | + ./sdk/tools/bin/avdmanager create avd \ + --name "${1}" \ + --package "${image}" | grep -v = || true diff --git a/ci/android-sysimage.sh b/ci/android-sysimage.sh new file mode 100644 index 00000000000..9eabd7c8d94 --- /dev/null +++ b/ci/android-sysimage.sh @@ -0,0 +1,56 @@ +#!/usr/bin/env bash + +# Copyright 2017 The Rust Project Developers. See the COPYRIGHT +# file at the top-level directory of this distribution and at +# http://rust-lang.org/COPYRIGHT. +# +# Licensed under the Apache License, Version 2.0 or the MIT license +# , at your +# option. This file may not be copied, modified, or distributed +# except according to those terms. + +set -ex + +URL=https://dl.google.com/android/repository/sys-img/android + +main() { + local arch="${1}" + local name="${2}" + local dest=/system + local td + td="$(mktemp -d)" + + apt-get install --no-install-recommends e2tools + + pushd "${td}" + curl --retry 5 -O "${URL}/${name}" + unzip -q "${name}" + + local system + system="$(find . -name system.img)" + mkdir -p ${dest}/{bin,lib,lib64} + + # Extract android linker and libraries to /system + # This allows android executables to be run directly (or with qemu) + if [ "${arch}" = "x86_64" ] || [ "${arch}" = "arm64" ]; then + e2cp -p "${system}:/bin/linker64" "${dest}/bin/" + e2cp -p "${system}:/lib64/libdl.so" "${dest}/lib64/" + e2cp -p "${system}:/lib64/libc.so" "${dest}/lib64/" + e2cp -p "${system}:/lib64/libm.so" "${dest}/lib64/" + else + e2cp -p "${system}:/bin/linker" "${dest}/bin/" + e2cp -p "${system}:/lib/libdl.so" "${dest}/lib/" + e2cp -p "${system}:/lib/libc.so" "${dest}/lib/" + e2cp -p "${system}:/lib/libm.so" "${dest}/lib/" + fi + + # clean up + apt-get purge --auto-remove -y e2tools + + popd + + rm -rf "${td}" +} + +main "${@}" diff --git a/ci/docker/aarch64-linux-android/Dockerfile b/ci/docker/aarch64-linux-android/Dockerfile new file mode 100644 index 00000000000..31a21112fcd --- /dev/null +++ b/ci/docker/aarch64-linux-android/Dockerfile @@ -0,0 +1,53 @@ +FROM ubuntu:19.04 + +RUN dpkg --add-architecture i386 && \ + apt-get update && \ + apt-get install -y --no-install-recommends \ + file \ + curl \ + ca-certificates \ + python \ + unzip \ + expect \ + openjdk-8-jre \ + libstdc++6:i386 \ + libpulse0 \ + gcc \ + libc6-dev \ + make \ + cmake # cmake is necessary to build wabt + +WORKDIR /android/ +COPY android* /android/ + +ENV ANDROID_ARCH=aarch64 +ENV PATH=$PATH:/android/sdk/tools:/android/sdk/platform-tools + +RUN sh /android/android-install-ndk.sh $ANDROID_ARCH +RUN sh /android/android-install-sdk.sh $ANDROID_ARCH +ENV ANDROID_NDK_HOME=/android/ndk + +RUN mv /root/.android /tmp +RUN chmod 777 -R /tmp/.android +RUN chmod 755 /android/sdk/tools/* /android/sdk/emulator/qemu/linux-x86_64/* + +ENV PATH=$PATH:/rust/bin:$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin \ + CARGO_TARGET_AARCH64_LINUX_ANDROID_AR=aarch64-linux-android-ar \ + CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER=aarch64-linux-android28-clang++ \ + CC_aarch64_linux_android=aarch64-linux-android28-clang \ + CXX_aarch64_linux_android=aarch64-linux-android28-clang++ \ + CARGO_TARGET_AARCH64_LINUX_ANDROID_RUNNER=/tmp/runtest \ + HOME=/tmp + +ADD runtest-android.rs /tmp/runtest.rs + +ENTRYPOINT [ \ + "bash", \ + "-c", \ + # set SHELL so android can detect a 64bits system, see + # http://stackoverflow.com/a/41789144 + "SHELL=/bin/dash /android/sdk/emulator/emulator @aarch64 -no-window & \ + rustc /tmp/runtest.rs -o /tmp/runtest && \ + exec \"$@\"", \ + "--" \ +] diff --git a/ci/docker/x86_64-linux-android/Dockerfile b/ci/docker/x86_64-linux-android/Dockerfile new file mode 100644 index 00000000000..d8f89b13f6d --- /dev/null +++ b/ci/docker/x86_64-linux-android/Dockerfile @@ -0,0 +1,31 @@ +FROM ubuntu:19.04 + +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + ca-certificates \ + curl \ + gcc \ + libc-dev \ + python \ + unzip \ + make \ + cmake # cmake is necessary to build wabt + +WORKDIR /android/ +ENV ANDROID_ARCH=x86_64 +COPY android-install-ndk.sh /android/ +RUN sh /android/android-install-ndk.sh $ANDROID_ARCH +ENV ANDROID_NDK_HOME=/android/ndk/ + +# We do not run x86_64-linux-android tests on an android emulator. +# See ci/android-sysimage.sh for informations about how tests are run. +COPY android-sysimage.sh /android/ +RUN bash /android/android-sysimage.sh x86_64 x86_64-24_r07.zip + +ENV PATH=$PATH:/rust/bin:$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin \ + CARGO_TARGET_X86_64_LINUX_ANDROID_AR=x86_64-linux-android-ar \ + CARGO_TARGET_X86_64_LINUX_ANDROID_LINKER=x86_64-linux-android28-clang++ \ + CC_x86_64_linux_android=x86_64-linux-android28-clang \ + CXX_x86_64_linux_android=x86_64-linux-android28-clang++ \ + LD_LIBRARY_PATH=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/x86_64-linux-android/ \ + HOME=/tmp diff --git a/ci/run-docker.sh b/ci/run-docker.sh new file mode 100755 index 00000000000..7746e370f92 --- /dev/null +++ b/ci/run-docker.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env sh + +# Small script to run tests for a target (or all targets) inside all the +# respective docker images. + +set -e + +echo "${HOME}" +pwd + +TARGET="${1}" +shift + +echo "Building docker container for target $target" + +# use -f so we can use ci/ as build context +image_tag=test-"$TARGET" +docker build -t "$image_tag" -f "ci/docker/${TARGET}/Dockerfile" ci/ +mkdir -p target + +set -x + +docker run \ + --rm \ + --user "$(id -u)":"$(id -g)" \ + --env CARGO_HOME=/cargo \ + --env CARGO_TARGET_DIR=/checkout/target \ + --volume "$(dirname "$(dirname "$(command -v cargo)")")":/cargo \ + --volume "$(rustc --print sysroot)":/rust:ro \ + --volume "$(pwd)":/checkout:ro \ + --volume "$(pwd)"/target:/checkout/target \ + --init \ + --workdir /checkout \ + "$image_tag" \ + sh -c "HOME=/tmp PATH=\$PATH:/rust/bin exec cargo test --target ${TARGET} $@" diff --git a/ci/runtest-android.rs b/ci/runtest-android.rs new file mode 100644 index 00000000000..490440e7c84 --- /dev/null +++ b/ci/runtest-android.rs @@ -0,0 +1,60 @@ +use std::env; +use std::path::{Path, PathBuf}; +use std::process::Command; + +fn main() { + let args = env::args_os() + .skip(1) + .filter(|arg| arg != "--quiet") + .collect::>(); + assert_eq!(args.len(), 1); + let test = PathBuf::from(&args[0]); + + // required to run an executable depending on wabt-rs + let android_ndk_home = env::var("ANDROID_NDK_HOME").expect("Can't get ANDROID_NDK_HOME!"); + let path = format!("{}/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/x86_64-linux-android/libc++_shared.so", android_ndk_home); + let libcpp_shared = Path::new(&path); + + let dst = Path::new("/data/local/tmp"); + let dst_exec = Path::new("/data/local/tmp").join(test.file_name().unwrap()); + + let status = Command::new("adb") + .arg("wait-for-device") + .status() + .expect("failed to run: adb wait-for-device"); + assert!(status.success()); + + let status = Command::new("adb") + .arg("push") + .arg(&test) + .arg(&libcpp_shared) + .arg(&dst) + .status() + .expect("failed to run: adb pushr"); + assert!(status.success()); + + let output = Command::new("adb") + .arg("shell") + .arg("LD_LIBRARY_PATH=/data/local/tmp/") + .arg(&dst_exec) + .output() + .expect("failed to run: adb shell"); + assert!(status.success()); + + println!( + "status: {}\nstdout ---\n{}\nstderr ---\n{}", + output.status, + String::from_utf8_lossy(&output.stdout), + String::from_utf8_lossy(&output.stderr) + ); + + let stdout = String::from_utf8_lossy(&output.stdout); + stdout + .lines() + .find(|l| { + (l.starts_with("PASSED ") && l.contains(" tests")) || l.starts_with("test result: ok") + }) + .unwrap_or_else(|| { + panic!("failed to find successful test run"); + }); +} From 056e9cf88ce8182b68cc91252bfde3325863b7ee Mon Sep 17 00:00:00 2001 From: YAMAMOTO Yuji Date: Fri, 13 Mar 2020 16:57:10 +0900 Subject: [PATCH 5/7] Add the android test script to the CI pipeline --- Makefile | 3 +++ azure-pipelines.yml | 11 +++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 2a8625052ed..23c038514ab 100644 --- a/Makefile +++ b/Makefile @@ -172,6 +172,9 @@ test-rest: test: spectests emtests middleware wasitests test-rest examples +test-android: + ci/run-docker.sh x86_64-linux-android --manifest-path=lib/singlepass-backend/Cargo.toml + ci/run-docker.sh x86_64-linux-android --manifest-path=lib/runtime-core-tests/Cargo.toml # Integration tests integration-tests: release-clif examples diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 8665c1dba3a..8e3bcf9d2b7 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -46,6 +46,10 @@ jobs: linux: imageName: "ubuntu-16.04" rust_toolchain: nightly-2019-12-19 + android: + imageName: "ubuntu-16.04" + rust_toolchain: nightly-2019-12-19 + ANDROID: true mac: imageName: "macos-10.14" rust_toolchain: nightly-2019-12-19 @@ -81,10 +85,13 @@ jobs: condition: and(succeeded(), eq(variables['Agent.OS'], 'Darwin')) - bash: make test displayName: Tests (*nix) - condition: and(succeeded(), not(eq(variables['Agent.OS'], 'Windows_NT'))) + condition: and(succeeded(), not(eq(variables['Agent.OS'], 'Windows_NT')), not(variables['ANDROID'])) + - bash: make test-android + displayName: Tests (Android) + condition: and(succeeded(), variables['ANDROID']) - bash: make spectests-cranelift displayName: Tests (Windows) - condition: and(succeeded(), eq(variables['Agent.OS'], 'Windows_NT')) + condition: and(succeeded(), eq(variables['Agent.OS'], 'Windows_NT'), not(variables['ANDROID'])) - job: Check pool: From a114b77fe98a05dae0557dc0104d7e330a544939 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Yuji Date: Wed, 18 Mar 2020 11:31:17 +0900 Subject: [PATCH 6/7] Add https://github.com/wasmerio/wasmer/pull/1292 to changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 581789f4f53..55f36466f00 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - [#1320](https://github.com/wasmerio/wasmer/pull/1320) Change `custom_sections` field in `ModuleInfo` to be more standards compliant by allowing multiple custom sections with the same name. To get the old behavior with the new API, you can add `.last().unwrap()` to accesses. For example, `module_info.custom_sections["custom_section_name"].last().unwrap()`. - [#1303](https://github.com/wasmerio/wasmer/pull/1303) NaN canonicalization for singlepass backend. +- [#1292](https://github.com/wasmerio/wasmer/pull/1292) Experimental Support for Android (x86_64 and AArch64) - [#1305](https://github.com/wasmerio/wasmer/pull/1305) Handle panics from DynamicFunc. - [#1301](https://github.com/wasmerio/wasmer/pull/1301) Update supported stable Rust version to 1.41.1. - [#1300](https://github.com/wasmerio/wasmer/pull/1300) Add support for multiple versions of WASI tests: wasitests now test all versions of WASI. From 18be0f2baee0cc5da0a5473859ea0abc913fc9f5 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Yuji Date: Mon, 23 Mar 2020 11:55:02 +0900 Subject: [PATCH 7/7] Fix build on CI for Android --- .azure/install-rust.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.azure/install-rust.yml b/.azure/install-rust.yml index c6fe4cc6f4a..28b291d8c95 100644 --- a/.azure/install-rust.yml +++ b/.azure/install-rust.yml @@ -45,6 +45,10 @@ steps: rustup default $RUST_TOOLCHAIN rustup target add x86_64-unknown-linux-musl + if [ -n "$ANDROID" ]; then + rustup target add x86_64-linux-android --toolchain $RUST_TOOLCHAIN + fi + rustc -Vv cargo -V displayName: Install Rust