From 0c5c827e6df2ad10f84c614ab1242c4bd15ecf1e Mon Sep 17 00:00:00 2001 From: YAMAMOTO Yuji Date: Wed, 11 Mar 2020 18:39:59 +0900 Subject: [PATCH] enable testing on Android x86_64 Currently, at the time of 2020/03/11, testing on AArch64 is not supported in the upstream repository --- Cargo.lock | 3 +- Cargo.toml | 1 + ci/README.md | 3 + ci/android-install-ndk.sh | 19 ++ ci/android-install-sdk.sh | 73 ++++++ ci/android-sysimage.sh | 56 +++++ ci/azure-install-rust.yml | 82 +++++++ ci/azure-master.yml | 22 ++ ci/azure.yml | 230 +++++++++++++++++ ci/build.sh | 271 +++++++++++++++++++++ ci/docker/aarch64-linux-android/Dockerfile | 53 ++++ ci/docker/x86_64-linux-android/Dockerfile | 31 +++ ci/run-docker.sh | 37 +++ ci/runtest-android.rs | 61 +++++ 14 files changed, 940 insertions(+), 2 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/azure-install-rust.yml create mode 100644 ci/azure-master.yml create mode 100644 ci/azure.yml create mode 100644 ci/build.sh create mode 100644 ci/docker/aarch64-linux-android/Dockerfile create mode 100644 ci/docker/x86_64-linux-android/Dockerfile create mode 100644 ci/run-docker.sh create mode 100644 ci/runtest-android.rs diff --git a/Cargo.lock b/Cargo.lock index 3b3937bf6c3..1a3941d0a28 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1776,8 +1776,7 @@ dependencies = [ [[package]] name = "wabt-sys" version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af5d153dc96aad7dc13ab90835b892c69867948112d95299e522d370c4e13a08" +source = "git+https://github.com/pepyakin/wabt-rs.git#604574b2af6c3526370bfd846a36d88552bf31e1" dependencies = [ "cc", "cmake", diff --git a/Cargo.toml b/Cargo.toml index 6f3ccb2c030..38c1d98a0e0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -119,3 +119,4 @@ crate-type = ["bin"] [patch.crates-io] libc = { git = "https://github.com/rust-lang/libc.git" } +wabt-sys = { git = "https://github.com/pepyakin/wabt-rs.git" } 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/azure-install-rust.yml b/ci/azure-install-rust.yml new file mode 100644 index 00000000000..e78fe32faf6 --- /dev/null +++ b/ci/azure-install-rust.yml @@ -0,0 +1,82 @@ +steps: + - bash: | + set -ex + toolchain=$TOOLCHAIN + if [ "$toolchain" = "" ]; then + toolchain=nightly + fi + if command -v rustup; then + # Uncomment when rustup on Azure is updated + #rustup set profile minimal + rustup update $toolchain + rustup default $toolchain + else + curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain $toolchain --profile=minimal + echo "##vso[task.prependpath]$HOME/.cargo/bin" + fi + displayName: Install rust (unix) + condition: ne( variables['Agent.OS'], 'Windows_NT' ) + - script: | + @echo on + if not defined TOOLCHAIN set TOOLCHAIN=nightly + :: Uncomment when rustup on Azure is updated + ::rustup set profile minimal + rustup update --no-self-update %TOOLCHAIN%-%TARGET% + rustup default %TOOLCHAIN%-%TARGET% + displayName: Install rust (windows) + condition: eq( variables['Agent.OS'], 'Windows_NT' ) + - script: | + set -ex + if [ -n "${TARGET}" ]; then + rustup target add $TARGET + fi + condition: ne( variables['Agent.OS'], 'Windows_NT' ) + displayName: Install target (unix) + - script: | + @echo on + if defined TARGET rustup target add %TARGET% + condition: eq( variables['Agent.OS'], 'Windows_NT' ) + displayName: Install target (windows) + - script: | + @echo on + if "%ARCH%" == "i686" choco install mingw --x86 --force + condition: eq( variables['Agent.OS'], 'Windows_NT' ) + displayName: Install MinGW32 (windows) + - bash: | + set -ex + gcc -print-search-dirs + find "C:\ProgramData\Chocolatey" -name "crt2*" + find "C:\ProgramData\Chocolatey" -name "dllcrt2*" + find "C:\ProgramData\Chocolatey" -name "libmsvcrt*" + condition: eq( variables['Agent.OS'], 'Windows_NT' ) + displayName: Find GCC libraries (windows) + - bash: | + set -ex + if [[ -n ${ARCH_BITS} ]]; then + for i in crt2.o dllcrt2.o libmingwex.a libmsvcrt.a ; do + cp -f "/C/ProgramData/Chocolatey/lib/mingw/tools/install/mingw${ARCH_BITS}/${ARCH}-w64-mingw32/lib/$i" "`rustc --print sysroot`/lib/rustlib/${TARGET}/lib" + done + fi + condition: eq( variables['Agent.OS'], 'Windows_NT' ) + displayName: Fix MinGW (windows) + - bash: | + set -ex + rustc -Vv + cargo -V + rustup -Vv + rustup show + which rustc + which cargo + which rustup + displayName: Query rust and cargo versions + - script: | + @echo on + where gcc + condition: eq( variables['Agent.OS'], 'Windows_NT' ) + displayName: Query gcc path + - bash: | + set -ex + cargo generate-lockfile + cargo generate-lockfile --manifest-path libc-test/Cargo.toml + displayName: Generate lockfiles + diff --git a/ci/azure-master.yml b/ci/azure-master.yml new file mode 100644 index 00000000000..d7bcb7c617e --- /dev/null +++ b/ci/azure-master.yml @@ -0,0 +1,22 @@ +variables: + - group: secrets +resources: + repositories: + - repository: rustinfra + type: github + name: rust-lang/simpleinfra + endpoint: gnzlbg +trigger: ["master"] +pr: ["master"] + +jobs: + - job: StyleAndDocs + pool: + vmImage: ubuntu-16.04 + steps: + - template: azure-install-rust.yml + - script: LIBC_CI=1 sh ci/dox.sh + displayName: Generate documentation + - template: azure-configs/static-websites.yml@rustinfra + parameters: + deploy_dir: target/doc diff --git a/ci/azure.yml b/ci/azure.yml new file mode 100644 index 00000000000..074589f39a3 --- /dev/null +++ b/ci/azure.yml @@ -0,0 +1,230 @@ +# This is copied from libc + +variables: + - group: secrets +resources: + repositories: + - repository: rustinfra + type: github + name: rust-lang/simpleinfra + endpoint: gnzlbg +trigger: ["auto-libc","try"] +pr: ["master"] + +jobs: + - job: DockerLinuxTier1 + pool: + vmImage: ubuntu-16.04 + steps: + - template: azure-install-rust.yml + - bash: LIBC_CI=1 sh ./ci/run-docker.sh $TARGET + displayName: Execute run-docker.sh + strategy: + matrix: + i686-unknown-linux-gnu: + TARGET: i686-unknown-linux-gnu + x86_64-unknown-linux-gnu: + TARGET: x86_64-unknown-linux-gnu + + - job: DockerLinuxTier2 + #dependsOn: DockerLinuxTier1 + pool: + vmImage: ubuntu-16.04 + steps: + - template: azure-install-rust.yml + - bash: LIBC_CI=1 sh ./ci/run-docker.sh $TARGET + displayName: Execute run-docker.sh + strategy: + matrix: + aarch64-unknown-linux-android: + TARGET: aarch64-linux-android + aarch64-unknown-linux-gnu: + TARGET: aarch64-unknown-linux-gnu + aarch64-unknown-linux-musl: + TARGET: aarch64-unknown-linux-musl + arm-linux-androideabi: + TARGET: arm-linux-androideabi + arm-unknown-linux-gnueabihf: + TARGET: arm-unknown-linux-gnueabihf + arm-unknown-linux-musleabihf: + TARGET: arm-unknown-linux-musleabihf + # Disabled because currently broken, see: + # https://github.com/rust-lang/libc/issues/1591 + # asmjs-unknown-emscripten: + # TARGET: asmjs-unknown-emscripten + i686-linux-android: + TARGET: i686-linux-android + i686-unknown-linux-musl: + TARGET: i686-unknown-linux-musl + mips-unknown-linux-gnu: + TARGET: mips-unknown-linux-gnu + mips-unknown-linux-musl: + TARGET: mips-unknown-linux-musl + mips64-unknown-linux-gnuabi64: + TARGET: mips64-unknown-linux-gnuabi64 + mips64el-unknown-linux-gnuabi64: + TARGET: mips64el-unknown-linux-gnuabi64 + mipsel-unknown-linux-musl: + TARGET: mipsel-unknown-linux-musl + #powerpc-unknown-linux-gnu: + # TARGET: powerpc-unknown-linux-gnu + powerpc64-unknown-linux-gnu: + TARGET: powerpc64-unknown-linux-gnu + powerpc64le-unknown-linux-gnu: + TARGET: powerpc64le-unknown-linux-gnu + #s390x-unknown-linux-gnu: + # TARGET: s390x-unknown-linux-gnu + #wasm32-wasi + # TARGET: wasm32-wasi + sparc64-unknown-linux-gnu: + TARGET: sparc64-unknown-linux-gnu + # Disabled because currently broken, see: + # https://github.com/rust-lang/libc/issues/1591 + # wasm32-unknown-emscripten: + # TARGET: wasm32-unknown-emscripten + x86_64-linux-android: + TARGET: x86_64-linux-android + x86_64-unknown-linux-gnux32: + TARGET: x86_64-unknown-linux-gnux32 + x86_64-unknown-linux-musl: + TARGET: x86_64-unknown-linux-musl + + - job: DockerOSX64 + pool: + vmImage: macos-10.14 + steps: + - template: azure-install-rust.yml + - bash: LIBC_CI=1 sh ./ci/run.sh $TARGET + displayName: Execute run.sh + strategy: + matrix: + x86_64-apple-darwin: + TARGET: x86_64-apple-darwin + + - job: DockerOSX32 + pool: + vmImage: macos-10.13 + steps: + - template: azure-install-rust.yml + - bash: LIBC_CI=1 sh ./ci/run.sh $TARGET + displayName: Execute run.sh + strategy: + matrix: + i686-apple-darwin: + TARGET: i686-apple-darwin + + - job: Windows + pool: + vmImage: vs2017-win2016 + steps: + - template: azure-install-rust.yml + - bash: LIBC_CI=1 sh ./ci/run.sh $TARGET + displayName: Execute run.sh + strategy: + matrix: + x86_64-pc-windows-gnu: + TARGET: x86_64-pc-windows-gnu + ARCH_BITS: 64 + ARCH: x86_64 + x86_64-pc-windows-msvc: + TARGET: x86_64-pc-windows-msvc + # Disabled because broken: + # https://github.com/rust-lang/libc/issues/1592 + #i686-pc-windows-gnu: + # TARGET: i686-pc-windows-gnu + # ARCH_BITS: 32 + # ARCH: i686 + i686-pc-windows-msvc: + TARGET: i686-pc-windows-msvc + + - job: StyleAndDocs + pool: + vmImage: ubuntu-16.04 + steps: + - template: azure-install-rust.yml + - script: sh ci/style.sh + displayName: Check style + - script: LIBC_CI=1 sh ci/dox.sh + displayName: Generate documentation + - template: azure-configs/static-websites.yml@rustinfra + parameters: + deploy_dir: target/doc + + # FIXME: re-enable these after the next release + #- job: SemverLinux + # dependsOn: BuildChannelsLinux + # continueOnError: true + # pool: + # vmImage: ubuntu-16.04 + # steps: + # - template: azure-install-rust.yml + # - script: sh ci/semver.sh linux + # displayName: Check breaking changes + + #- job: SemverOSX + # dependsOn: BuildChannelsOSX + # continueOnError: true + # pool: + # vmImage: macos-10.14 + # steps: + # - template: azure-install-rust.yml + # - script: sh ci/semver.sh osx + # displayName: Check breaking changes + + - job: BuildChannelsLinux + dependsOn: StyleAndDocs + pool: + vmImage: ubuntu-16.04 + steps: + - template: azure-install-rust.yml + - script: LIBC_CI=1 sh ./ci/build.sh + displayName: Execute build.sh + strategy: + matrix: + stable: + TOOLCHAIN: stable + beta: + TOOLCHAIN: beta + nightly: + TOOLCHAIN: nightly + 1.13.0: + TOOLCHAIN: 1.13.0 + 1.19.0: + TOOLCHAIN: 1.19.0 + 1.24.0: + TOOLCHAIN: 1.24.0 + 1.25.0: + TOOLCHAIN: 1.25.0 + 1.30.0: + TOOLCHAIN: 1.30.0 + variables: + OS: linux + + - job: BuildChannelsOSX + dependsOn: StyleAndDocs + pool: + vmImage: macos-10.13 + steps: + - template: azure-install-rust.yml + - script: LIBC_CI=1 sh ./ci/build.sh + displayName: Execute build.sh + strategy: + matrix: + stable: + TOOLCHAIN: stable + beta: + TOOLCHAIN: beta + nightly: + TOOLCHAIN: nightly + 1.13.0: + TOOLCHAIN: 1.13.0 + 1.19.0: + TOOLCHAIN: 1.19.0 + 1.24.0: + TOOLCHAIN: 1.24.0 + 1.25.0: + TOOLCHAIN: 1.25.0 + 1.30.0: + TOOLCHAIN: 1.30.0 + variables: + OS: osx diff --git a/ci/build.sh b/ci/build.sh new file mode 100644 index 00000000000..cde46cb451b --- /dev/null +++ b/ci/build.sh @@ -0,0 +1,271 @@ +#!/usr/bin/env sh + +# Checks that libc builds properly for all supported targets on a particular +# Rust version: +# The FILTER environment variable can be used to select which target(s) to build. +# For example: set FILTER to vxworks to select the targets that has vxworks in name + +set -ex + +: "${TOOLCHAIN?The TOOLCHAIN environment variable must be set.}" +: "${OS?The OS environment variable must be set.}" + +RUST=${TOOLCHAIN} + +echo "Testing Rust ${RUST} on ${OS}" + +if [ "${TOOLCHAIN}" = "nightly" ] ; then + cargo +nightly install cargo-xbuild -Z install-upgrade + rustup component add rust-src +fi + +test_target() { + BUILD_CMD="${1}" + TARGET="${2}" + NO_STD="${3}" + + opt= + if [ "${TARGET}" = "x86_64-unknown-linux-gnux32" ]; then + # FIXME: x86_64-unknown-linux-gnux32 fail to compile without + # --release + # + # See https://github.com/rust-lang/rust/issues/45417 + opt="--release" + fi + # FIXME: https://github.com/rust-lang/rust/issues/61174 + if [ "${TARGET}" = "sparcv9-sun-solaris" ] || + [ "${TARGET}" = "x86_64-sun-solaris" ]; then + return 0 + fi + + # If there is a std component, fetch it: + if [ "${NO_STD}" != "1" ]; then + # FIXME: rustup often fails to download some artifacts due to network + # issues, so we retry this N times. + N=5 + n=0 + until [ $n -ge $N ] + do + if rustup target add "${TARGET}" --toolchain "${RUST}" ; then + break + fi + n=$((n+1)) + sleep 1 + done + fi + + # Test that libc builds without any default features (no libstd) + cargo "+${RUST}" "${BUILD_CMD}" -vv $opt --no-default-features --target "${TARGET}" + + # Test that libc builds with default features (e.g. libstd) + # if the target supports libstd + if [ "$NO_STD" != "1" ]; then + cargo "+${RUST}" "${BUILD_CMD}" -vv $opt --target "${TARGET}" + fi + + # Test that libc builds with the `extra_traits` feature + cargo "+${RUST}" "${BUILD_CMD}" -vv $opt --no-default-features --target "${TARGET}" \ + --features extra_traits + + # Test the 'const-extern-fn' feature on nightly + if [ "${RUST}" = "nightly" ]; then + cargo "+${RUST}" "${BUILD_CMD}" -vv $opt --no-default-features --target "${TARGET}" \ + --features const-extern-fn + fi + + + # Also test that it builds with `extra_traits` and default features: + if [ "$NO_STD" != "1" ]; then + cargo "+${RUST}" "${BUILD_CMD}" -vv $opt --target "${TARGET}" \ + --features extra_traits + fi +} + +RUST_LINUX_TARGETS="\ +aarch64-linux-android \ +aarch64-unknown-linux-gnu \ +arm-linux-androideabi \ +arm-unknown-linux-gnueabi \ +arm-unknown-linux-gnueabihf \ +armv7-linux-androideabi \ +armv7-unknown-linux-gnueabihf \ +i586-unknown-linux-gnu \ +i686-linux-android \ +i686-unknown-freebsd \ +i686-unknown-linux-gnu \ +i686-unknown-linux-musl \ +mips-unknown-linux-gnu \ +mips-unknown-linux-musl \ +mips64-unknown-linux-gnuabi64 \ +mips64el-unknown-linux-gnuabi64 \ +mipsel-unknown-linux-gnu \ +mipsel-unknown-linux-musl \ +powerpc-unknown-linux-gnu \ +powerpc64-unknown-linux-gnu \ +powerpc64le-unknown-linux-gnu \ +s390x-unknown-linux-gnu \ +x86_64-unknown-freebsd \ +x86_64-unknown-linux-gnu \ +x86_64-unknown-linux-musl \ +x86_64-unknown-netbsd \ +" + +RUST_GT_1_13_LINUX_TARGETS="\ +arm-unknown-linux-musleabi \ +arm-unknown-linux-musleabihf \ +armv7-unknown-linux-musleabihf \ +sparc64-unknown-linux-gnu \ +wasm32-unknown-emscripten \ +x86_64-linux-android \ +x86_64-rumprun-netbsd \ +" +RUST_GT_1_19_LINUX_TARGETS="\ +aarch64-unknown-linux-musl \ +sparcv9-sun-solaris \ +wasm32-unknown-unknown \ +x86_64-sun-solaris \ +" +RUST_GT_1_24_LINUX_TARGETS="\ +i586-unknown-linux-musl \ +x86_64-unknown-cloudabi \ +" + +# FIXME: temporarirly disable the redox target +# https://github.com/rust-lang/libc/issues/1457 +# x86_64-unknown-redox +RUST_NIGHTLY_LINUX_TARGETS="\ +aarch64-fuchsia \ +armv5te-unknown-linux-gnueabi \ +armv5te-unknown-linux-musleabi \ +i686-pc-windows-gnu \ +wasm32-wasi \ +x86_64-fortanix-unknown-sgx \ +x86_64-fuchsia \ +x86_64-pc-windows-gnu \ +x86_64-unknown-linux-gnux32 \ +" + +RUST_OSX_TARGETS="\ +aarch64-apple-ios \ +armv7-apple-ios \ +armv7s-apple-ios \ +i386-apple-ios \ +i686-apple-darwin \ +x86_64-apple-darwin \ +x86_64-apple-ios \ +" + +# The targets are listed here alphabetically +TARGETS="" +case "${OS}" in + linux*) + TARGETS="${RUST_LINUX_TARGETS}" + + if [ "${RUST}" != "1.13.0" ]; then + TARGETS="${TARGETS} ${RUST_GT_1_13_LINUX_TARGETS}" + if [ "${RUST}" != "1.19.0" ]; then + TARGETS="${TARGETS} ${RUST_GT_1_19_LINUX_TARGETS}" + if [ "${RUST}" != "1.24.0" ]; then + TARGETS="${TARGETS} ${RUST_GT_1_24_LINUX_TARGETS}" + fi + fi + fi + + if [ "${RUST}" = "nightly" ]; then + TARGETS="${TARGETS} ${RUST_NIGHTLY_LINUX_TARGETS}" + fi + + ;; + osx*) + TARGETS="${RUST_OSX_TARGETS}" + ;; + *) + ;; +esac + +for TARGET in $TARGETS; do + if echo "$TARGET"|grep -q "$FILTER";then + test_target build "$TARGET" + fi +done + +# FIXME: https://github.com/rust-lang/rust/issues/58564 +# sparc-unknown-linux-gnu +# FIXME: https://github.com/rust-lang/rust/issues/62932 +# thumbv6m-none-eabi +RUST_LINUX_NO_CORE_TARGETS="\ +aarch64-pc-windows-msvc \ +aarch64-unknown-cloudabi \ +aarch64-unknown-freebsd \ +aarch64-unknown-hermit \ +aarch64-unknown-netbsd \ +aarch64-unknown-openbsd \ +armebv7r-none-eabi \ +armebv7r-none-eabihf \ +armv7-unknown-cloudabi-eabihf \ +armv7r-none-eabi \ +armv7r-none-eabihf \ +hexagon-unknown-linux-musl \ +i586-pc-windows-msvc \ +i686-pc-windows-msvc \ +i686-unknown-cloudabi \ +i686-unknown-haiku \ +i686-unknown-netbsd \ +i686-unknown-openbsd \ +mips-unknown-linux-uclibc \ +mipsel-unknown-linux-uclibc \ +mips64-unknown-linux-muslabi64 \ +mips64el-unknown-linux-muslabi64 \ +nvptx64-nvidia-cuda \ +powerpc-unknown-linux-gnuspe \ +powerpc-unknown-netbsd \ +powerpc64-unknown-freebsd \ +riscv32imac-unknown-none-elf \ +riscv32imc-unknown-none-elf \ +sparc64-unknown-netbsd \ + +thumbv7em-none-eabi \ +thumbv7em-none-eabihf \ +thumbv7m-none-eabi \ +thumbv7neon-linux-androideabi \ +thumbv7neon-unknown-linux-gnueabihf \ +thumbv8m.main-none-eabi \ +x86_64-pc-windows-msvc +x86_64-unknown-dragonfly \ +x86_64-unknown-haiku \ +x86_64-unknown-hermit \ +x86_64-unknown-l4re-uclibc \ +x86_64-unknown-openbsd \ +armv7-wrs-vxworks-eabihf \ +aarch64-wrs-vxworks \ +i686-wrs-vxworks \ +x86_64-wrs-vxworks \ +powerpc-wrs-vxworks \ +powerpc-wrs-vxworks-spe \ +powerpc64-wrs-vxworks \ +" + +if [ "${RUST}" = "nightly" ] && [ "${OS}" = "linux" ]; then + for TARGET in $RUST_LINUX_NO_CORE_TARGETS; do + if echo "$TARGET"|grep -q "$FILTER";then + test_target xbuild "$TARGET" 1 + fi + done + + # Nintendo switch + cargo clean + mkdir -p target + ( + cd target + wget https://github.com/devkitPro/pacman/releases/download/devkitpro-pacman-1.0.1/devkitpro-pacman.deb + sudo dpkg -i devkitpro-pacman.deb + sudo dkp-pacman -Sy + sudo dkp-pacman -Syu + sudo dkp-pacman -S -v --noconfirm switch-dev devkitA64 + ) + cp ci/switch.json switch.json + PATH="$PATH:/opt/devkitpro/devkitA64/bin" + PATH="$PATH:/opt/devkitpro/tools/bin" + cargo xbuild --target switch.json +fi + 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 100644 index 00000000000..78cbde75941 --- /dev/null +++ b/ci/run-docker.sh @@ -0,0 +1,37 @@ +#!/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 \ + -ti \ + --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} $@" + #bash diff --git a/ci/runtest-android.rs b/ci/runtest-android.rs new file mode 100644 index 00000000000..1bbc239594e --- /dev/null +++ b/ci/runtest-android.rs @@ -0,0 +1,61 @@ +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 libcpp_shared = { + 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); + Path::new(path) + }; + + let dst = Path::new("/data/local/tmp"); + + 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) + .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"); + }); +}