From bc01841ff30c8adaee7fb655c5f75c7911af56f3 Mon Sep 17 00:00:00 2001 From: LongYinan Date: Fri, 20 Nov 2020 11:10:05 +0800 Subject: [PATCH] Fix windows i686 --- .github/workflows/CI.yaml | 3 --- Cargo.toml | 8 ++++---- npm/win32-x64-msvc/package.json | 2 +- simple-test.js | 14 ++++++++++---- src/lib.rs | 15 ++++++--------- 5 files changed, 21 insertions(+), 21 deletions(-) diff --git a/.github/workflows/CI.yaml b/.github/workflows/CI.yaml index 8d86b35..8458303 100644 --- a/.github/workflows/CI.yaml +++ b/.github/workflows/CI.yaml @@ -188,9 +188,6 @@ jobs: build-win32-ia686: runs-on: windows-latest - env: - CARGO_PROFILE_napi_OPT_LEVEL: 0 - CARGO_PROFILE_napi_OPT_LTO: false steps: - uses: actions/checkout@v2 diff --git a/Cargo.toml b/Cargo.toml index 373d2f2..45f21a4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,8 +10,8 @@ version = "0.1.0" crate-type = ["cdylib"] [dependencies] -napi = {git = "https://github.com/napi-rs/napi-rs", branch = "cstring-issues"} -napi-derive = {git = "https://github.com/napi-rs/napi-rs", branch = "cstring-issues"} +napi = {git = "https://github.com/napi-rs/napi-rs", branch = "rust-codegen-win32"} +napi-derive = {git = "https://github.com/napi-rs/napi-rs", branch = "rust-codegen-win32"} [target.'cfg(all(unix, not(target_env = "musl")))'.dependencies] jemallocator = {version = "0.3", features = ["disable_initial_exec_tls"]} @@ -20,7 +20,7 @@ jemallocator = {version = "0.3", features = ["disable_initial_exec_tls"]} mimalloc = {version = "0.1"} [build-dependencies] -napi-build = {git = "https://github.com/napi-rs/napi-rs", branch = "cstring-issues"} +napi-build = {git = "https://github.com/napi-rs/napi-rs", branch = "rust-codegen-win32"} [profile.release] -lto = true +opt-level = 's' diff --git a/npm/win32-x64-msvc/package.json b/npm/win32-x64-msvc/package.json index 1291db6..816296e 100644 --- a/npm/win32-x64-msvc/package.json +++ b/npm/win32-x64-msvc/package.json @@ -9,7 +9,7 @@ "keywords": ["napi-rs", "NAPI", "N-API", "Rust", "node-addon", "node-addon-api"], "license": "MIT", "engines": { - "node": ">= 8.9" + "node": ">= 10" }, "publishConfig": { "registry": "https://registry.npmjs.org/", diff --git a/simple-test.js b/simple-test.js index 2937210..ee29c87 100644 --- a/simple-test.js +++ b/simple-test.js @@ -1,5 +1,11 @@ -const { sync } = require('./index') +const { exec } = require('child_process') +const { stderr } = require('process') -console.assert(sync(0) === 100, 'Simple test failed') - -console.info('Simple test passed') +exec(`node -e "console.log(require('./index.js'))"`, (err, stdout, stderr) => { + if (err) { + console.error(err) + process.exit(1) + } + console.info(stdout) + console.info(stderr) +}) diff --git a/src/lib.rs b/src/lib.rs index d169350..aff0a75 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,22 +1,18 @@ #[macro_use] -extern crate napi; -#[macro_use] extern crate napi_derive; use std::convert::TryInto; -use napi::{CallContext, Env, JsNumber, JsObject, Module, Result, Task}; +use napi::{CallContext, Env, JsNumber, JsObject, Result, Task}; #[cfg(all(unix, not(target_env = "musl")))] #[global_allocator] static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc; -#[cfg(all(windows, target_arch = "x86_64"))] +#[cfg(windows)] #[global_allocator] static ALLOC: mimalloc::MiMalloc = mimalloc::MiMalloc; -register_module!(example, init); - struct AsyncTask(u32); impl Task for AsyncTask { @@ -35,10 +31,11 @@ impl Task for AsyncTask { } } -fn init(module: &mut Module) -> Result<()> { - module.create_named_method("sync", sync_fn)?; +#[module_exports] +fn init(mut exports: JsObject) -> Result<()> { + exports.create_named_method("sync", sync_fn)?; - module.create_named_method("sleep", sleep)?; + exports.create_named_method("sleep", sleep)?; Ok(()) }