Merge pull request #228 from napi-rs/bsd

ci: add freebsd ci
This commit is contained in:
LongYinan 2020-10-14 12:09:50 +08:00 committed by GitHub
commit 58977c89d2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 151 additions and 83 deletions

27
.cirrus.yml Normal file
View file

@ -0,0 +1,27 @@
freebsd_instance:
image: freebsd-12-1-release-amd64
task:
name: FreeBSD 12.1
env:
DEBUG: 'napi:*'
setup_script:
- pkg update
- 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
- |
echo "~~~~ rustc --version ~~~~"
rustc --version
echo "~~~~ node -v ~~~~"
node -v
echo "~~~~ yarn --version ~~~~"
yarn --version
test_script:
- . $HOME/.cargo/env
- yarn install --ignore-platform --frozen-lockfile --registry https://registry.npmjs.org
- yarn build
- cargo test -p napi-sys --lib -- --nocapture
- yarn build:test
- yarn test

View file

@ -5,6 +5,7 @@ parserOptions:
jsx: true
ecmaVersion: 2020
sourceType: module
extraFileExtensions: ['.cjs']
project: ./tsconfig.json
env:
@ -220,3 +221,10 @@ overrides:
- '@typescript-eslint'
parserOptions:
project: ./bench/tsconfig.json
- files:
- ./*.{cjs,js}
plugins:
- '@typescript-eslint'
parserOptions:
project: ./tsconfig.root-lint.json

View file

@ -73,6 +73,11 @@ jobs:
command: test
args: -p napi-sys --lib -- --nocapture
- name: Write ava.config.js for ava@2
run: |
node write-ava-config.js
cat ava.config.js
- name: Unit tests
run: |
yarn --cwd ./test_module --ignore-engines build

View file

@ -1,9 +1,13 @@
const configuration = {
extensions: ['ts', 'tsx'],
files: ['test_module/__test__/**/*.spec.ts'],
require: ['@swc-node/register'],
require: [
require('os').platform() === 'freebsd'
? 'ts-node/register/transpile-only'
: '@swc-node/register',
],
environmentVariables: {
SWC_NODE_PROJECT: './test_module/tsconfig.json',
TS_NODE_PROJECT: './test_module/tsconfig.json',
},
}
@ -11,4 +15,4 @@ if (parseInt(process.versions.napi, 10) < 4) {
configuration.compileEnhancements = false
}
export default configuration
module.exports = configuration

View file

@ -154,11 +154,8 @@ macro_rules! register_module {
_ => Err(Error::from_status(status)),
}
}
#[no_mangle]
#[cfg_attr(target_os = "linux", link_section = ".ctors")]
#[cfg_attr(target_os = "macos", link_section = "__DATA,__mod_init_func")]
#[cfg_attr(target_os = "windows", link_section = ".CRT$XCU")]
pub static __REGISTER_MODULE: extern "C" fn() = {
extern "C" fn register_module() {
use std::ffi::CString;
use std::io::Write;
use std::os::raw::c_char;
@ -167,15 +164,13 @@ macro_rules! register_module {
#[cfg(all(feature = "tokio_rt", napi4))]
use $crate::shutdown_tokio_rt;
extern "C" fn register_module() {
static mut MODULE_DESCRIPTOR: Option<sys::napi_module> = None;
unsafe {
MODULE_DESCRIPTOR = Some(sys::napi_module {
nm_version: 1,
nm_flags: 0,
nm_filename: concat!(file!(), "\0").as_ptr() as *const c_char,
nm_register_func: Some(init_module),
nm_register_func: Some(napi_register_module_v1),
nm_modname: concat!(stringify!($module_name), "\0").as_ptr() as *const c_char,
nm_priv: 0 as *mut _,
reserved: [0 as *mut _; 4],
@ -184,7 +179,8 @@ macro_rules! register_module {
sys::napi_module_register(MODULE_DESCRIPTOR.as_mut().unwrap() as *mut sys::napi_module);
}
extern "C" fn init_module(
#[no_mangle]
pub unsafe extern "C" fn napi_register_module_v1(
raw_env: sys::napi_env,
raw_exports: sys::napi_value,
) -> sys::napi_value {
@ -217,8 +213,5 @@ macro_rules! register_module {
}
}
}
register_module
};
};
}

View file

@ -84,6 +84,7 @@ export class BuildCommand extends Command {
libExt = '.dll'
break
case 'linux':
case 'freebsd':
dylibName = `lib${dylibName}`
libExt = '.so'
break

View file

@ -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_).+")

4
tsconfig.root-lint.json Normal file
View file

@ -0,0 +1,4 @@
{
"extends": "./tsconfig.json",
"files": ["./ava.config.cjs", "./write-ava-config.js"]
}

10
write-ava-config.js Normal file
View file

@ -0,0 +1,10 @@
const { writeFileSync } = require('fs')
const { join } = require('path')
const config = require('./ava.config.cjs')
const code = `
export default ${JSON.stringify(config, null, 2)}
`
writeFileSync(join(__dirname, 'ava.config.js'), code)