Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ jobs:
- uses: actions/checkout@v7
- name: Build
id: build
uses: cross-platform-actions/action@v1.4.0
uses: cross-platform-actions/action@v1.6.0
env:
DEBUG: napi:*
RUSTUP_IO_THREADS: 1
Expand Down
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ version = "0.1.0"
crate-type = ["cdylib"]

[dependencies]
napi = "3.0.0"
napi-derive = "3.0.0"
napi = "3.12.4"
napi-derive = "3.6.5"

[build-dependencies]
napi-build = "2"
napi-build = "2.4.2"

[profile.release]
lto = true
Expand Down
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* auto-generated by NAPI-RS */
/* eslint-disable */

export declare function plus100(input: number): number
63 changes: 31 additions & 32 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// prettier-ignore
/* eslint-disable */
// @ts-nocheck
/* auto-generated by NAPI-RS */
Expand Down Expand Up @@ -63,7 +62,7 @@ const isMuslFromChildProcess = () => {
function requireNative() {
if (process.env.NAPI_RS_NATIVE_LIBRARY_PATH) {
try {
return require(process.env.NAPI_RS_NATIVE_LIBRARY_PATH);
return require(process.env.NAPI_RS_NATIVE_LIBRARY_PATH)
} catch (err) {
loadErrors.push(err)
}
Expand Down Expand Up @@ -107,36 +106,36 @@ function requireNative() {
if (process.arch === 'x64') {
if ((process.config && process.config.variables && process.config.variables.shlib_suffix === 'dll.a') || (process.config && process.config.variables && process.config.variables.node_target_type === 'shared_library')) {
try {
return require('./package-template.win32-x64-gnu.node')
} catch (e) {
loadErrors.push(e)
}
try {
const binding = require('@napi-rs/package-template-win32-x64-gnu')
const bindingPackageVersion = require('@napi-rs/package-template-win32-x64-gnu/package.json').version
if (bindingPackageVersion !== '1.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 1.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
return require('./package-template.win32-x64-gnu.node')
} catch (e) {
loadErrors.push(e)
}
try {
const binding = require('@napi-rs/package-template-win32-x64-gnu')
const bindingPackageVersion = require('@napi-rs/package-template-win32-x64-gnu/package.json').version
if (bindingPackageVersion !== '1.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 1.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}
return binding
} catch (e) {
loadErrors.push(e)
}
return binding
} catch (e) {
loadErrors.push(e)
}
} else {
try {
return require('./package-template.win32-x64-msvc.node')
} catch (e) {
loadErrors.push(e)
}
try {
const binding = require('@napi-rs/package-template-win32-x64-msvc')
const bindingPackageVersion = require('@napi-rs/package-template-win32-x64-msvc/package.json').version
if (bindingPackageVersion !== '1.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 1.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
return require('./package-template.win32-x64-msvc.node')
} catch (e) {
loadErrors.push(e)
}
try {
const binding = require('@napi-rs/package-template-win32-x64-msvc')
const bindingPackageVersion = require('@napi-rs/package-template-win32-x64-msvc/package.json').version
if (bindingPackageVersion !== '1.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
throw new Error(`Native binding package version mismatch, expected 1.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
}
return binding
} catch (e) {
loadErrors.push(e)
}
return binding
} catch (e) {
loadErrors.push(e)
}
}
} else if (process.arch === 'ia32') {
try {
Expand Down Expand Up @@ -550,7 +549,7 @@ function createLoadErrorChain(errors) {
//
// NAPI_RS_WASI_FLAVOR selects one exact generated flavor and implies strict
// WASI loading. It never crosses into another flavor or falls back to native.
const __napiWasiFlavors = ["wasm32-wasi"]
const __napiWasiFlavors = ['wasm32-wasi']
const __napiWasiFlavor = process.env.NAPI_RS_WASI_FLAVOR
const __napiWasiFlavorRequested =
typeof __napiWasiFlavor === 'string' && __napiWasiFlavor.length > 0
Expand Down Expand Up @@ -619,11 +618,11 @@ if (!nativeBinding || forceWasi) {
}
return null
}
if (!wasiBindingLoaded && (!__napiWasiFlavorRequested || __napiWasiFlavor === "wasm32-wasi")) {
if (!wasiBindingLoaded && (!__napiWasiFlavorRequested || __napiWasiFlavor === 'wasm32-wasi')) {
let candidateError = null
let candidateFailed = false
try {
candidateError = __napiWasiResolveCandidate('./package-template.wasi.cjs', false, ["./package-template.wasm32-wasi.debug.wasm","./package-template.wasm32-wasi.wasm"])
candidateError = __napiWasiResolveCandidate('./package-template.wasi.cjs', false, ['./package-template.wasm32-wasi.debug.wasm', './package-template.wasm32-wasi.wasm'])
candidateFailed = candidateError !== null
if (!candidateFailed) {
wasiBinding = require('./package-template.wasi.cjs')
Expand All @@ -639,7 +638,7 @@ if (!nativeBinding || forceWasi) {
loadErrors.push(candidateError)
}
}
if (!wasiBindingLoaded && (!__napiWasiFlavorRequested || __napiWasiFlavor === "wasm32-wasi")) {
if (!wasiBindingLoaded && (!__napiWasiFlavorRequested || __napiWasiFlavor === 'wasm32-wasi')) {
let candidateError = null
let candidateFailed = false
try {
Expand Down
4 changes: 2 additions & 2 deletions package-template.wasi-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ let __emnapiWasmEnvCleanupDrained = false
let __emnapiWasmEnvCleanupDrainPromise
let __wasiDisposed = false
let __wasiDisposePromise
let __completeWasiDisposal = function() {}
let __completeWasiDisposal = function () {}
// Overridden by loader flavors that have a last-resort reclaim for a rollback
// that stopped short of destroying the context. See
// `__rollbackWasiInitialization`.
let __retainWasiRollbackForRetry = function() {}
let __retainWasiRollbackForRetry = function () {}

function __isThenable(value) {
return (
Expand Down
37 changes: 20 additions & 17 deletions package-template.wasi.cjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// napi-rs-artifact-metadata:{"version":2,"rootEntry":"index.js","exports":["plus100"],"managedRootEntries":["browser.js","index.js","package-template.wasm","package-template.debug.wasm"]}
/* eslint-disable */
/* prettier-ignore */

/* auto-generated by NAPI-RS */

const __nodeFs = require('node:fs')
Expand Down Expand Up @@ -91,6 +89,7 @@ function __createWasiWorker(filename) {
return new Worker(filename, {
env: process.env,
execArgv: __workerExecArgv,
workerData: { hostRoot: __hostRoot, rootDir: __rootDir },
})
} catch (error) {
if (!error || error.code !== 'ERR_WORKER_INVALID_EXEC_ARGV') {
Expand All @@ -106,14 +105,18 @@ function __createWasiWorker(filename) {
}
}

const __rootDir = __nodePath.parse(process.cwd()).root
const __cwd = process.cwd()
const __rootDir = __nodePath.parse(__cwd).root
const __hostRoot =
process.platform === 'android' ? __cwd : __rootDir

const __wasi = new __nodeWASI({
version: 'preview1',
env: process.env,
preopens: {
[__rootDir]: __rootDir,
}
[__rootDir]: __hostRoot,
[__hostRoot]: __hostRoot,
},
})

const __sharedMemory = new WebAssembly.Memory({
Expand Down Expand Up @@ -155,11 +158,11 @@ let __emnapiWasmEnvCleanupDrained = false
let __emnapiWasmEnvCleanupDrainPromise
let __wasiDisposed = false
let __wasiDisposePromise
let __completeWasiDisposal = function() {}
let __completeWasiDisposal = function () {}
// Overridden by loader flavors that have a last-resort reclaim for a rollback
// that stopped short of destroying the context. See
// `__rollbackWasiInitialization`.
let __retainWasiRollbackForRetry = function() {}
let __retainWasiRollbackForRetry = function () {}

function __isThenable(value) {
return (
Expand Down Expand Up @@ -846,7 +849,7 @@ try {
napiModule: __napiModule,
} = __emnapiInstantiateNapiModuleSync(__wasmFile, {
context: __emnapiContext,
asyncWorkPoolSize: (function() {
asyncWorkPoolSize: (function () {
const threadsSizeFromEnv = Number(process.env.NAPI_RS_ASYNC_WORK_POOL_SIZE ?? process.env.UV_THREADPOOL_SIZE)
// NaN > 0 is false
if (threadsSizeFromEnv > 0) {
Expand All @@ -871,21 +874,21 @@ try {
// According to https://github.com/nodejs/node/blob/19e0d472728c79d418b74bddff588bea70a403d0/lib/internal/worker.js#L415,
// a worker is consist of two handles: kPublicPort and kHandle.
{
const kPublicPort = Object.getOwnPropertySymbols(worker).find(s =>
s.toString().includes("kPublicPort")
);
const kPublicPort = Object.getOwnPropertySymbols(worker).find((s) =>
s.toString().includes('kPublicPort'),
)
if (kPublicPort) {
worker[kPublicPort].ref = () => {};
worker[kPublicPort].ref = () => {}
}

const kHandle = Object.getOwnPropertySymbols(worker).find(s =>
s.toString().includes("kHandle")
);
const kHandle = Object.getOwnPropertySymbols(worker).find((s) =>
s.toString().includes('kHandle'),
)
if (kHandle) {
worker[kHandle].ref = () => {};
worker[kHandle].ref = () => {}
}

worker.unref();
worker.unref()
}
return worker
},
Expand Down
1 change: 1 addition & 0 deletions package-template.wasi.d.cts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* auto-generated by NAPI-RS */
/* eslint-disable */

export declare function plus100(input: number): number
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,22 +64,22 @@
"prepare": "husky"
},
"devDependencies": {
"@emnapi/core": "^2.0.0-alpha.4",
"@emnapi/runtime": "^2.0.0-alpha.4",
"@napi-rs/cli": "^3.8.6",
"@napi-rs/wasm-runtime": "^1.2.3",
"@oxc-node/core": "^0.1.0",
"@tybys/wasm-util": "^0.10.3",
"@emnapi/core": "^2.0.0-alpha.5",
"@emnapi/runtime": "^2.0.0-alpha.5",
"@napi-rs/cli": "^3.9.1",
"@napi-rs/wasm-runtime": "^1.2.4",
"@oxc-node/core": "^0.1.2",
"@tybys/wasm-util": "^0.10.4",
"ava": "^8.0.1",
"chalk": "^6.0.0",
"emnapi": "^2.0.0-alpha.4",
"emnapi": "^2.0.0-alpha.5",
"husky": "^9.1.7",
"lint-staged": "^17.3.0",
"lint-staged": "^17.5.1",
"npm-run-all2": "^9.0.3",
"oxfmt": "^0.64.0",
"oxlint": "^1.79.0",
"oxfmt": "^0.68.0",
"oxlint": "^1.83.0",
"prettier": "^3.9.6",
"tinybench": "^6.1.3",
"tinybench": "^6.2.0",
"typescript": "^7.0.2"
},
"lint-staged": {
Expand Down
4 changes: 1 addition & 3 deletions wasi-worker-browser.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ const handler = new MessageHandler({
// eslint-disable-next-line no-console
console.log.apply(console, arguments)
},
printErr: function() {
printErr: function () {
// eslint-disable-next-line no-console
console.error.apply(console, arguments)

},
})
return instantiateNapiModuleSync(wasmModule, {
Expand All @@ -37,7 +36,6 @@ const handler = new MessageHandler({
},
})
},

})

globalThis.onmessage = function (e) {
Expand Down
Loading
Loading