From b651be1becb33a4889ab93816045307990b90bcb Mon Sep 17 00:00:00 2001 From: LongYinan Date: Tue, 13 Oct 2020 22:58:29 +0800 Subject: [PATCH] ci: pass tests on the freebsd platform --- .cirrus.yml | 4 ++-- ava.config.js | 10 +++++++++- sys/build.rs | 24 ++++++++++++++++++++---- 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/.cirrus.yml b/.cirrus.yml index cb38f1b4..31b90518 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -7,7 +7,7 @@ task: DEBUG: 'napi:*' setup_script: - pkg update - - pkg install -y -f curl node yarn npm libnghttp2 + - pkg install -y -f curl node yarn npm libnghttp2 llvm - curl https://sh.rustup.rs -sSf --output rustup.sh - sh rustup.sh -y --profile minimal --default-toolchain stable - . $HOME/.cargo/env @@ -20,7 +20,7 @@ task: yarn --version test_script: - . $HOME/.cargo/env - - yarn install --frozen-lockfile --registry https://registry.npmjs.org + - yarn install --ignore-platform --frozen-lockfile --registry https://registry.npmjs.org - yarn build - cargo test -p napi-sys --lib -- --nocapture - yarn build:test diff --git a/ava.config.js b/ava.config.js index 38b8725c..dfc3550c 100644 --- a/ava.config.js +++ b/ava.config.js @@ -1,7 +1,15 @@ +import { platform } from 'os' + +const platformName = platform() + const configuration = { extensions: ['ts', 'tsx'], files: ['test_module/__test__/**/*.spec.ts'], - require: ['@swc-node/register'], + require: [ + platformName === 'freebsd' + ? 'ts-node/register/transpile-only' + : '@swc-node/register', + ], environmentVariables: { SWC_NODE_PROJECT: './test_module/tsconfig.json', }, diff --git a/sys/build.rs b/sys/build.rs index 7959c3c8..110bb6ff 100644 --- a/sys/build.rs +++ b/sys/build.rs @@ -28,21 +28,37 @@ fn main() { ); } - if node_major_version < 10 { + if node_major_version < 8 && node_version.minor < 9 { panic!("node version is too low") } - let node_include_path = find_node_include_path(node_full_version.trim_end()); + let node_include_path_buf = find_node_include_path(node_full_version.trim_end()); + + let node_include_path = match env::var("NODE_INCLUDE_PATH") { + Ok(node_include_path) => node_include_path, + Err(_) => node_include_path_buf.to_str().unwrap().to_owned(), + }; let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); let mut sys_bindings_path = PathBuf::from("src"); sys_bindings_path.push("bindings.h"); - bindgen::Builder::default() + let mut bindgen_builder = bindgen::Builder::default() .derive_default(true) .header(sys_bindings_path.to_str().unwrap().to_owned()) - .clang_arg(String::from("-I") + node_include_path.to_str().unwrap()) + .clang_arg(format!("-I{}", node_include_path)); + + if let Ok(uv_include_path) = env::var("UV_INCLUDE_PATH") { + bindgen_builder = bindgen_builder.clang_arg(format!("-I{}", uv_include_path)); + } else if cfg!(target_os = "freebsd") { + bindgen_builder = bindgen_builder.clang_arg(format!( + "-I{}", + node_include_path_buf.parent().unwrap().to_str().unwrap() + )); + } + + bindgen_builder .rustified_enum("(napi_|uv_).+") .whitelist_function("(napi_|uv_|extras_).+") .whitelist_type("(napi_|uv_|extras_).+")