Merge pull request #238 from napi-rs/reduce-aarch64-running-time

ci: reduce aarch64 running time by cross compile in host machine
This commit is contained in:
LongYinan 2020-10-15 16:41:01 +08:00 committed by GitHub
commit 9783284e5d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 90 additions and 16 deletions

View file

@ -1,5 +1,8 @@
name: Benchmark
env:
DEBUG: 'napi:*'
on:
push:
branches:

View file

@ -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
"

View file

@ -1,5 +1,8 @@
name: Linux musl
env:
DEBUG: 'napi:*'
on:
push:
branches: [master, develop]

View file

@ -1,5 +1,8 @@
name: Linux N-API@3
env:
DEBUG: 'napi:*'
on:
push:
branches: [master, develop]

View file

@ -1,5 +1,8 @@
name: macOS/Windows/Linux x64
env:
DEBUG: 'napi:*'
on:
push:
branches: [master, develop]

View file

@ -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'",

View file

@ -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`)

View file

@ -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()

View file

@ -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"
}