Skip to content

Commit c4158f1

Browse files
committed
Fix windows i686
1 parent 66a9b1e commit c4158f1

File tree

6 files changed

+29
-55
lines changed

6 files changed

+29
-55
lines changed

.github/workflows/CI.yaml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,6 @@ jobs:
188188

189189
build-win32-ia686:
190190
runs-on: windows-latest
191-
env:
192-
CARGO_PROFILE_napi_OPT_LEVEL: 0
193-
CARGO_PROFILE_napi_OPT_LTO: false
194191
steps:
195192
- uses: actions/checkout@v2
196193

@@ -246,9 +243,7 @@ jobs:
246243
run: yarn build --target i686-pc-windows-msvc
247244

248245
- name: Test binary
249-
run: |
250-
node -v
251-
node simple-test.js
246+
run: yarn test
252247

253248
- name: Upload artifact
254249
uses: actions/upload-artifact@v2

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ version = "0.1.0"
1010
crate-type = ["cdylib"]
1111

1212
[dependencies]
13-
napi = {git = "https://github.com/napi-rs/napi-rs", branch = "cstring-issues"}
14-
napi-derive = {git = "https://github.com/napi-rs/napi-rs", branch = "cstring-issues"}
13+
napi = {git = "https://github.com/napi-rs/napi-rs", branch = "rust-codegen-win32"}
14+
napi-derive = {git = "https://github.com/napi-rs/napi-rs", branch = "rust-codegen-win32"}
1515

1616
[target.'cfg(all(unix, not(target_env = "musl")))'.dependencies]
1717
jemallocator = {version = "0.3", features = ["disable_initial_exec_tls"]}
@@ -20,7 +20,7 @@ jemallocator = {version = "0.3", features = ["disable_initial_exec_tls"]}
2020
mimalloc = {version = "0.1"}
2121

2222
[build-dependencies]
23-
napi-build = {git = "https://github.com/napi-rs/napi-rs", branch = "cstring-issues"}
23+
napi-build = {git = "https://github.com/napi-rs/napi-rs", branch = "rust-codegen-win32"}
2424

2525
[profile.release]
2626
lto = true

npm/win32-x64-msvc/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"keywords": ["napi-rs", "NAPI", "N-API", "Rust", "node-addon", "node-addon-api"],
1010
"license": "MIT",
1111
"engines": {
12-
"node": ">= 8.9"
12+
"node": ">= 10"
1313
},
1414
"publishConfig": {
1515
"registry": "https://registry.npmjs.org/",

package.json

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,8 @@
55
"main": "index.js",
66
"repository": "[email protected]:napi-rs/package-template.git",
77
"license": "MIT",
8-
"keywords": [
9-
"napi-rs",
10-
"NAPI",
11-
"N-API",
12-
"Rust",
13-
"node-addon",
14-
"node-addon-api"
15-
],
16-
"files": [
17-
"index.d.ts",
18-
"index.js"
19-
],
8+
"keywords": ["napi-rs", "NAPI", "N-API", "Rust", "node-addon", "node-addon-api"],
9+
"files": ["index.d.ts", "index.js"],
2010
"napi": {
2111
"name": "package-template",
2212
"triples": {
@@ -75,27 +65,14 @@
7565
"@node-rs/helper": "^1.0.0-alpha.1"
7666
},
7767
"lint-staged": {
78-
"*.@(js|ts|tsx)": [
79-
"prettier --write",
80-
"eslint -c .eslintrc.yml --fix"
81-
],
82-
"*.@(yml|yaml)": [
83-
"prettier --parser yaml --write"
84-
],
85-
"*.md": [
86-
"prettier --parser markdown --write"
87-
],
88-
"*.json": [
89-
"prettier --parser json --write"
90-
]
68+
"*.@(js|ts|tsx)": ["prettier --write", "eslint -c .eslintrc.yml --fix"],
69+
"*.@(yml|yaml)": ["prettier --parser yaml --write"],
70+
"*.md": ["prettier --parser markdown --write"],
71+
"*.json": ["prettier --parser json --write"]
9172
},
9273
"ava": {
93-
"require": [
94-
"ts-node/register/transpile-only"
95-
],
96-
"extensions": [
97-
"ts"
98-
],
74+
"require": ["ts-node/register/transpile-only"],
75+
"extensions": ["ts"],
9976
"environmentVariables": {
10077
"TS_NODE_PROJECT": "./tsconfig.json"
10178
}
@@ -113,4 +90,4 @@
11390
"pre-commit": "lint-staged"
11491
}
11592
}
116-
}
93+
}

simple-test.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
const { sync } = require('./index')
1+
const { exec } = require('child_process')
22

3-
console.assert(sync(0) === 100, 'Simple test failed')
4-
5-
console.info('Simple test passed')
3+
exec(`node -e "console.log(require('./index.js'))"`, (err, stdout, stderr) => {
4+
console.info(stdout)
5+
console.info(stderr)
6+
if (err) {
7+
console.error(err)
8+
process.exit(1)
9+
}
10+
})

src/lib.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
11
#[macro_use]
2-
extern crate napi;
3-
#[macro_use]
42
extern crate napi_derive;
53

64
use std::convert::TryInto;
75

8-
use napi::{CallContext, Env, JsNumber, JsObject, Module, Result, Task};
6+
use napi::{CallContext, Env, JsNumber, JsObject, Result, Task};
97

108
#[cfg(all(unix, not(target_env = "musl")))]
119
#[global_allocator]
1210
static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc;
1311

14-
#[cfg(all(windows, target_arch = "x86_64"))]
12+
#[cfg(windows)]
1513
#[global_allocator]
1614
static ALLOC: mimalloc::MiMalloc = mimalloc::MiMalloc;
1715

18-
register_module!(example, init);
19-
2016
struct AsyncTask(u32);
2117

2218
impl Task for AsyncTask {
@@ -35,10 +31,11 @@ impl Task for AsyncTask {
3531
}
3632
}
3733

38-
fn init(module: &mut Module) -> Result<()> {
39-
module.create_named_method("sync", sync_fn)?;
34+
#[module_exports]
35+
fn init(mut exports: JsObject) -> Result<()> {
36+
exports.create_named_method("sync", sync_fn)?;
4037

41-
module.create_named_method("sleep", sleep)?;
38+
exports.create_named_method("sleep", sleep)?;
4239
Ok(())
4340
}
4441

0 commit comments

Comments
 (0)