From ffdf69bd0074bb0b03aceeb76b521ab869d13a2f Mon Sep 17 00:00:00 2001 From: Andy Finch Date: Wed, 12 Feb 2020 21:43:38 -0500 Subject: [PATCH] Add AArch64/ARM64 builds and tests (#266) --- .github/workflows/ci.yml | 48 +++++++++++++++++++++++++++++----------- .gn | 1 - build.rs | 22 ++++++++++++++++++ 3 files changed, 57 insertions(+), 14 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e2ce10c0..ea45f460 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,18 +6,23 @@ on: jobs: build: - name: ${{ matrix.kind }} ${{ matrix.os }} + name: ${{ matrix.config.os }} ${{ matrix.config.target }} if: | github.event_name == 'push' || !startsWith(github.event.pull_request.head.label, 'denoland:') - runs-on: ${{ matrix.os }} + runs-on: ${{ matrix.config.os }} timeout-minutes: 120 strategy: matrix: - os: - - macos-latest - - ubuntu-16.04 - - windows-2019 + config: + - os: macOS-latest + target: x86_64-apple-darwin + - os: ubuntu-16.04 + target: "x86_64-unknown-linux-gnu" + - os: ubuntu-16.04 + target: aarch64-unknown-linux-gnu + - os: windows-2019 + target: x86_64-pc-windows-msvc steps: - name: Configure git @@ -34,12 +39,31 @@ jobs: with: rust-version: "1.41.0" + - name: Install rust tools + run: rustup component add clippy rustfmt + - name: Install python uses: actions/setup-python@v1 with: python-version: "2.7.x" architecture: x64 + - name: Install cross compilation toolchain + if: matrix.config.target == 'aarch64-unknown-linux-gnu' + run: | + rustup target add aarch64-unknown-linux-gnu + + sudo apt install -yq --no-install-suggests --no-install-recommends \ + binfmt-support g++-5-aarch64-linux-gnu g++-5-multilib \ + gcc-5-aarch64-linux-gnu libc6-arm64-cross qemu qemu-user \ + qemu-user-binfmt + + sudo ln -s /usr/aarch64-linux-gnu/lib/ld-linux-aarch64.so.1 \ + /lib/ld-linux-aarch64.so.1 + + echo "::set-env name=CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER::/usr/bin/aarch64-linux-gnu-gcc-5" + echo "::set-env name=QEMU_LD_PREFIX::/usr/aarch64-linux-gnu" + - name: Install and start sccache shell: pwsh working-directory: ${{ runner.temp }} @@ -67,17 +91,15 @@ jobs: echo "::set-env name=RUSTC_WRAPPER::sccache" - name: Test - run: cargo test -vv --locked --all-targets + run: cargo test -vv --all-targets --locked + --target ${{ matrix.config.target }} - name: Clippy - run: | - rustup component add clippy - cargo clippy --all-targets --locked -- -D clippy::all + run: cargo clippy --all-targets --locked + --target ${{ matrix.config.target }} -- -D clippy::all - name: Rustfmt - run: | - rustup component add rustfmt - cargo fmt -- --check + run: cargo fmt -- --check # TODO: add clang-format and maybe cpplint. diff --git a/.gn b/.gn index 488d7288..f7229633 100644 --- a/.gn +++ b/.gn @@ -18,7 +18,6 @@ secondary_source = "//v8/" default_args = { linux_use_bundled_binutils = false - use_sysroot = false # TODO(ry) We may want to turn on CFI at some point. Disabling for simplicity # for now. See http://clang.llvm.org/docs/ControlFlowIntegrity.html diff --git a/build.rs b/build.rs index 22535318..d0f323a4 100644 --- a/build.rs +++ b/build.rs @@ -83,6 +83,16 @@ fn build_v8() { } } + match env::var("CARGO_CFG_TARGET_ARCH").unwrap().as_str() { + "aarch64" => { + gn_args.push("target_cpu=\"arm64\"".to_string()); + maybe_install_sysroot("arm64"); + maybe_install_sysroot("amd64"); + } + "x86_64" => gn_args.push("use_sysroot=false".to_string()), + _ => unimplemented!(), + }; + let gn_root = env::var("CARGO_MANIFEST_DIR").unwrap(); let gn_out = cargo_gn::maybe_gen(&gn_root, gn_args); @@ -91,6 +101,18 @@ fn build_v8() { cargo_gn::build("rusty_v8", None); } +fn maybe_install_sysroot(arch: &str) { + let sysroot_path = format!("build/linux/debian_sid_{}-sysroot", arch); + if !PathBuf::from(sysroot_path).is_dir() { + let status = Command::new("python") + .arg("./build/linux/sysroot_scripts/install-sysroot.py") + .arg(format!("--arch={}", arch)) + .status() + .expect(&format!("sysroot download failed: {}", arch)); + assert!(status.success()); + } +} + fn platform() -> &'static str { #[cfg(target_os = "windows")] {