From 3c3a5b6fdb98235ffc8e771811b4e1d89960f029 Mon Sep 17 00:00:00 2001 From: LongYinan Date: Thu, 15 Oct 2020 16:14:11 +0800 Subject: [PATCH] ci: reduce aarch64 running time by cross compile in host machine --- .github/workflows/bench.yaml | 3 ++ .github/workflows/linux-aarch64.yaml | 75 +++++++++++++++++++++++----- .github/workflows/linux-musl.yaml | 3 ++ .github/workflows/napi3.yaml | 3 ++ .github/workflows/test.yaml | 3 ++ package.json | 1 + src/build.ts | 8 ++- sys/build.rs | 9 ++-- test_module/package.json | 1 + 9 files changed, 90 insertions(+), 16 deletions(-) diff --git a/.github/workflows/bench.yaml b/.github/workflows/bench.yaml index b6d6b51b..3af3281c 100644 --- a/.github/workflows/bench.yaml +++ b/.github/workflows/bench.yaml @@ -1,5 +1,8 @@ name: Benchmark +env: + DEBUG: 'napi:*' + on: push: branches: diff --git a/.github/workflows/linux-aarch64.yaml b/.github/workflows/linux-aarch64.yaml index 70ebf4dc..9794e351 100644 --- a/.github/workflows/linux-aarch64.yaml +++ b/.github/workflows/linux-aarch64.yaml @@ -1,5 +1,10 @@ name: Linux-aarch64 +env: + DEBUG: 'napi:*' + CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: 'aarch64-linux-gnu-gcc' + NAPI_RS_INCLUDE_PATH: '/usr/aarch64-linux-gnu/include' + on: push: branches: [master, develop] @@ -12,25 +17,71 @@ jobs: steps: - run: docker run --rm --privileged multiarch/qemu-user-static:register --reset + - uses: actions/checkout@v2 - - name: 'Setup and run tests' + - name: Setup node + uses: actions/setup-node@v1 + with: + node-version: 14 + + - name: Install + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + profile: minimal + override: true + + - name: Install aarch64 toolchain + run: rustup target add aarch64-unknown-linux-gnu + + - name: Generate Cargo.lock + uses: actions-rs/cargo@v1 + with: + command: generate-lockfile + + - name: Cache cargo registry + uses: actions/cache@v1 + with: + path: ~/.cargo/registry + key: stable-linux-aarch64-node@14-cargo-registry-trimmed-${{ hashFiles('**/Cargo.lock') }} + + - name: Cache cargo index + uses: actions/cache@v1 + with: + path: ~/.cargo/git + key: stable-linux-aarch64gnu-node@14-cargo-index-trimmed-${{ hashFiles('**/Cargo.lock') }} + + - name: Cache NPM dependencies + uses: actions/cache@v1 + with: + path: node_modules + key: npm-cache-linux-aarch64-node@14-${{ hashFiles('yarn.lock') }} + restore-keys: | + npm-cache- + + - name: Install cross compile toolchain + run: | + sudo apt-get update + sudo apt-get install gcc-aarch64-linux-gnu g++-6-aarch64-linux-gnu -y + + - name: Install dependencies + run: yarn install --frozen-lockfile --registry https://registry.npmjs.org + + - name: 'Build TypeScript' + run: yarn build + + - name: Cross build native tests + run: yarn build:test:aarch64 + + - name: Setup and run tests uses: docker://multiarch/ubuntu-core:arm64-focal with: args: > sh -c " apt-get update && \ - apt-get install -y ca-certificates gnupg2 llvm clang curl && \ + apt-get install -y ca-certificates gnupg2 curl && \ curl -sL https://deb.nodesource.com/setup_14.x | bash - && \ apt-get install -y nodejs && \ - curl https://sh.rustup.rs -sSf --output rustup.sh && \ - sh rustup.sh -y --profile minimal --default-toolchain stable && \ - . $HOME/.cargo/env && \ - npm install -g yarn && \ - yarn --ignore-optional && \ - yarn build && \ - cargo check -vvv && \ - cargo test -p napi-sys --lib -- --nocapture && \ - yarn build:test && \ - yarn test + npm test " diff --git a/.github/workflows/linux-musl.yaml b/.github/workflows/linux-musl.yaml index bda32b76..bdfc31ba 100644 --- a/.github/workflows/linux-musl.yaml +++ b/.github/workflows/linux-musl.yaml @@ -1,5 +1,8 @@ name: Linux musl +env: + DEBUG: 'napi:*' + on: push: branches: [master, develop] diff --git a/.github/workflows/napi3.yaml b/.github/workflows/napi3.yaml index ac47eb6a..c029fb10 100644 --- a/.github/workflows/napi3.yaml +++ b/.github/workflows/napi3.yaml @@ -1,5 +1,8 @@ name: Linux N-API@3 +env: + DEBUG: 'napi:*' + on: push: branches: [master, develop] diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index b331cab6..798d3fd1 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -1,5 +1,8 @@ name: macOS/Windows/Linux x64 +env: + DEBUG: 'napi:*' + on: push: branches: [master, develop] diff --git a/package.json b/package.json index c7c4ccd1..66c9b4eb 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "build": "tsc -p tsconfig.json && chmod 777 scripts/index.js", "build:bench": "yarn --cwd ./bench build", "build:test": "yarn --cwd ./test_module build", + "build:test:aarch64": "yarn --cwd ./test_module build-aarch64", "format": "run-p format:md format:json format:yaml format:source format:rs", "format:md": "prettier --parser markdown --write './**/*.md'", "format:json": "prettier --parser json --write './**/*.json'", diff --git a/src/build.ts b/src/build.ts index 06667d36..3cdb993b 100644 --- a/src/build.ts +++ b/src/build.ts @@ -31,6 +31,9 @@ export class BuildCommand extends Command { @Command.String('--cargo-name') cargoName?: string + @Command.String('--target-triple') + targetTripleDir = '' + @Command.String({ required: false, }) @@ -94,7 +97,10 @@ export class BuildCommand extends Command { ) } - const targetDir = this.isRelease ? 'release' : 'debug' + const targetDir = join( + this.targetTripleDir, + this.isRelease ? 'release' : 'debug', + ) if (this.isMusl && !this.appendPlatformToFilename) { throw new TypeError(`Musl flag must be used with platform flag`) diff --git a/sys/build.rs b/sys/build.rs index 110bb6ff..3853349f 100644 --- a/sys/build.rs +++ b/sys/build.rs @@ -47,11 +47,14 @@ fn main() { let mut bindgen_builder = bindgen::Builder::default() .derive_default(true) .header(sys_bindings_path.to_str().unwrap().to_owned()) - .clang_arg(format!("-I{}", node_include_path)); + .clang_arg(format!("-I{}", node_include_path)) + .clang_arg("-target") + .clang_arg(env::var("TARGET").unwrap()); - if let Ok(uv_include_path) = env::var("UV_INCLUDE_PATH") { + if let Ok(uv_include_path) = env::var("NAPI_RS_INCLUDE_PATH") { bindgen_builder = bindgen_builder.clang_arg(format!("-I{}", uv_include_path)); - } else if cfg!(target_os = "freebsd") { + } + if cfg!(target_os = "freebsd") { bindgen_builder = bindgen_builder.clang_arg(format!( "-I{}", node_include_path_buf.parent().unwrap().to_str().unwrap() diff --git a/test_module/package.json b/test_module/package.json index f71ffd34..24684379 100644 --- a/test_module/package.json +++ b/test_module/package.json @@ -3,6 +3,7 @@ "version": "1.0.0", "scripts": { "build": "cargo build && node ../scripts/index.js build", + "build-aarch64": "cargo build --target aarch64-unknown-linux-gnu && node ../scripts/index.js build --target-triple aarch64-unknown-linux-gnu", "build-release": "cargo build --release && node ../scripts/index.js build --release", "test": "node ./index.js" }