Skip to content

Commit

Permalink
patch
Browse files Browse the repository at this point in the history
  • Loading branch information
Brooooooklyn committed Dec 31, 2023
1 parent 9517af9 commit 874e336
Show file tree
Hide file tree
Showing 36 changed files with 290 additions and 167 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ jobs:
- host: windows-latest
target: 'aarch64-pc-windows-msvc'
build: yarn build --target aarch64-pc-windows-msvc
- host: ubuntu-latest
target: 'wasm32-wasi-preview1-threads'
build: yarn workspaces foreach -A --no-private -j 1 --exclude @node-rs/jsonwebtoken --exclude @node-rs/denolint run build --target wasm32-wasi-preview1-threads

name: stable - ${{ matrix.settings.target }} - node@20
runs-on: ${{ matrix.settings.host }}
Expand Down Expand Up @@ -133,11 +136,20 @@ jobs:

- name: Upload artifact
uses: actions/upload-artifact@v4
if: ${{ matrix.settings.target != 'wasm32-wasi-preview1-threads' }}
with:
name: bindings-${{ matrix.settings.target }}
path: packages/*/*.node
if-no-files-found: error

- name: Upload artifact
uses: actions/upload-artifact@v4
if: ${{ matrix.settings.target == 'wasm32-wasi-preview1-threads' }}
with:
name: bindings-${{ matrix.settings.target }}
path: packages/*/*.wasm
if-no-files-found: error

build-freebsd:
runs-on: macos-12
name: Build FreeBSD
Expand Down Expand Up @@ -520,6 +532,40 @@ jobs:
yarn test -s
ls -la
test-wasi-nodejs:
name: Test bindings on wasi - node@${{ matrix.node }}
needs:
- build
strategy:
fail-fast: false
matrix:
node: ['18', '20']
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: bindings-wasm32-wasi-preview1-threads
path: artifacts
- name: Move artifacts
run: yarn artifacts
shell: bash
- name: List packages
run: ls -R .
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
cache: yarn
- name: 'Install dependencies'
run: yarn install --immutable --mode=skip-build
- name: Test
run: |
yarn build:ts
yarn test -s
env:
NAPI_RS_FORCE_WASI: 'true'

publish:
name: Publish
runs-on: ubuntu-latest
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
"postinstall": "husky install"
},
"devDependencies": {
"@emnapi/core": "^0.44.0",
"@emnapi/runtime": "^0.44.0",
"@napi-rs/cli": "^3.0.0-alpha.25",
"@emnapi/core": "^0.45.0",
"@emnapi/runtime": "^0.45.0",
"@napi-rs/cli": "^3.0.0-alpha.28",
"@swc-node/core": "^1.10.6",
"@swc-node/register": "^1.6.8",
"@swc/core": "^1.3.101",
Expand Down
22 changes: 20 additions & 2 deletions packages/argon2/argon2.wasi.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,27 @@ const __sharedMemory = new WebAssembly.Memory({
shared: true,
})

const { instance: __napiInstance, module: __wasiModule, napiModule: __napiModule } = __emnapiInstantiateNapiModuleSync(__nodeFs.readFileSync(__nodePath.join(__dirname, 'argon2.wasm32-wasi.wasm')), {
let __wasmFilePath = __nodePath.join(__dirname, 'argon2.wasm32-wasi.wasm')

if (!__nodeFs.existsSync(__wasmFilePath)) {
try {
__wasmFilePath = __nodePath.resolve('@node-rs/argon2-wasm32-wasi')
} catch {
throw new Error('Cannot find argon2.wasm32-wasi.wasm file, and @node-rs/argon2-wasm32-wasi package is not installed.')
}
}

const { instance: __napiInstance, module: __wasiModule, napiModule: __napiModule } = __emnapiInstantiateNapiModuleSync(__nodeFs.readFileSync(__wasmFilePath), {
context: __emnapiContext,
asyncWorkPoolSize: 4,
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) {
return threadsSizeFromEnv
} else {
return 4
}
})(),
wasi: __wasi,
onCreateWorker() {
return new Worker(__nodePath.join(__dirname, 'wasi-worker.mjs'), {
Expand Down
9 changes: 1 addition & 8 deletions packages/argon2/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,14 +308,7 @@ switch (platform) {

if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
try {
localFileExisted = existsSync(
join(__dirname, 'argon2.wasm32-wasi.wasm')
) && existsSync(join(__dirname, 'argon2.wasi.cjs'))
if (localFileExisted) {
nativeBinding = require('./argon2.wasi.cjs')
} else {
nativeBinding = require('@node-rs/argon2-wasm32-wasi')
}
nativeBinding = require('./argon2.wasi.cjs')
} catch {
// ignore
}
Expand Down
10 changes: 8 additions & 2 deletions packages/argon2/npm/wasm32-wasi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
"cpu": [
"wasm32"
],
"main": "argon2.wasm32-wasi.wasm",
"main": "argon2.wasi.cjs",
"files": [
"argon2.wasm32-wasi.wasm"
"argon2.wasm32-wasi.wasm",
"argon2.wasi.cjs",
"wasi-worker.mjs"
],
"description": "RustCrypto: Argon2 binding for Node.js",
"keywords": [
Expand All @@ -32,5 +34,9 @@
"repository": {
"type": "git",
"url": "git+https://github.com/napi-rs/node-rs.git"
},
"dependencies": {
"@emnapi/core": "^0.45.0",
"@emnapi/runtime": "^0.45.0"
}
}
2 changes: 1 addition & 1 deletion packages/argon2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"version": "napi version"
},
"devDependencies": {
"@napi-rs/cli": "^3.0.0-alpha.25",
"@napi-rs/cli": "^3.0.0-alpha.28",
"argon2": "^0.31.2",
"cross-env": "^7.0.3"
}
Expand Down
22 changes: 20 additions & 2 deletions packages/bcrypt/bcrypt.wasi.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,27 @@ const __sharedMemory = new WebAssembly.Memory({
shared: true,
})

const { instance: __napiInstance, module: __wasiModule, napiModule: __napiModule } = __emnapiInstantiateNapiModuleSync(__nodeFs.readFileSync(__nodePath.join(__dirname, 'bcrypt.wasm32-wasi.wasm')), {
let __wasmFilePath = __nodePath.join(__dirname, 'bcrypt.wasm32-wasi.wasm')

if (!__nodeFs.existsSync(__wasmFilePath)) {
try {
__wasmFilePath = __nodePath.resolve('@node-rs/bcrypt-wasm32-wasi')
} catch {
throw new Error('Cannot find bcrypt.wasm32-wasi.wasm file, and @node-rs/bcrypt-wasm32-wasi package is not installed.')
}
}

const { instance: __napiInstance, module: __wasiModule, napiModule: __napiModule } = __emnapiInstantiateNapiModuleSync(__nodeFs.readFileSync(__wasmFilePath), {
context: __emnapiContext,
asyncWorkPoolSize: 4,
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) {
return threadsSizeFromEnv
} else {
return 4
}
})(),
wasi: __wasi,
onCreateWorker() {
return new Worker(__nodePath.join(__dirname, 'wasi-worker.mjs'), {
Expand Down
8 changes: 1 addition & 7 deletions packages/bcrypt/binding.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,13 +286,7 @@ switch (platform) {

if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
try {
localFileExisted =
existsSync(join(__dirname, 'bcrypt.wasm32-wasi.wasm')) && existsSync(join(__dirname, 'bcrypt.wasi.cjs'))
if (localFileExisted) {
nativeBinding = require('./bcrypt.wasi.cjs')
} else {
nativeBinding = require('@node-rs/bcrypt-wasm32-wasi')
}
nativeBinding = require('./bcrypt.wasi.cjs')
} catch {
// ignore
}
Expand Down
10 changes: 8 additions & 2 deletions packages/bcrypt/npm/wasm32-wasi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
"cpu": [
"wasm32"
],
"main": "bcrypt.wasm32-wasi.wasm",
"main": "bcrypt.wasi.cjs",
"files": [
"bcrypt.wasm32-wasi.wasm"
"bcrypt.wasm32-wasi.wasm",
"bcrypt.wasi.cjs",
"wasi-worker.mjs"
],
"description": "Rust bcrypt binding",
"keywords": [
Expand Down Expand Up @@ -36,5 +38,9 @@
},
"bugs": {
"url": "https://github.com/napi-rs/node-rs/issues"
},
"dependencies": {
"@emnapi/core": "^0.45.0",
"@emnapi/runtime": "^0.45.0"
}
}
2 changes: 1 addition & 1 deletion packages/bcrypt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"url": "https://github.com/napi-rs/node-rs/issues"
},
"devDependencies": {
"@napi-rs/cli": "^3.0.0-alpha.25",
"@napi-rs/cli": "^3.0.0-alpha.28",
"@types/bcrypt": "^5.0.2",
"bcrypt": "^5.1.1",
"bcryptjs": "^2.4.3",
Expand Down
6 changes: 6 additions & 0 deletions packages/crc32/__tests__/__snapshots__/index.spec.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ Generated by [AVA](https://avajs.dev).
2608757237

## crc32c result should be equal with sse4_crc32 when calculate with initial crc

> Snapshot 1
614479218

## crc32c result should be equal with sse4_crc32 when caclulate with initial crc

> Snapshot 1
Expand Down
Binary file modified packages/crc32/__tests__/__snapshots__/index.spec.ts.snap
Binary file not shown.
2 changes: 1 addition & 1 deletion packages/crc32/__tests__/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ test('crc32c result should be equal with sse4_crc32', (t) => {
t.snapshot(crc32c(fx))
})

test('crc32c result should be equal with sse4_crc32 when caclulate with initial crc', (t) => {
test('crc32c result should be equal with sse4_crc32 when calculate with initial crc', (t) => {
const initialCrc = crc32c(fx)
t.snapshot(crc32c(fx, initialCrc))
})
Expand Down
22 changes: 20 additions & 2 deletions packages/crc32/crc32.wasi.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,27 @@ const __sharedMemory = new WebAssembly.Memory({
shared: true,
})

const { instance: __napiInstance, module: __wasiModule, napiModule: __napiModule } = __emnapiInstantiateNapiModuleSync(__nodeFs.readFileSync(__nodePath.join(__dirname, 'crc32.wasm32-wasi.wasm')), {
let __wasmFilePath = __nodePath.join(__dirname, 'crc32.wasm32-wasi.wasm')

if (!__nodeFs.existsSync(__wasmFilePath)) {
try {
__wasmFilePath = __nodePath.resolve('@node-rs/crc32-wasm32-wasi')
} catch {
throw new Error('Cannot find crc32.wasm32-wasi.wasm file, and @node-rs/crc32-wasm32-wasi package is not installed.')
}
}

const { instance: __napiInstance, module: __wasiModule, napiModule: __napiModule } = __emnapiInstantiateNapiModuleSync(__nodeFs.readFileSync(__wasmFilePath), {
context: __emnapiContext,
asyncWorkPoolSize: 4,
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) {
return threadsSizeFromEnv
} else {
return 4
}
})(),
wasi: __wasi,
onCreateWorker() {
return new Worker(__nodePath.join(__dirname, 'wasi-worker.mjs'), {
Expand Down
9 changes: 1 addition & 8 deletions packages/crc32/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,14 +308,7 @@ switch (platform) {

if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
try {
localFileExisted = existsSync(
join(__dirname, 'crc32.wasm32-wasi.wasm')
) && existsSync(join(__dirname, 'crc32.wasi.cjs'))
if (localFileExisted) {
nativeBinding = require('./crc32.wasi.cjs')
} else {
nativeBinding = require('@node-rs/crc32-wasm32-wasi')
}
nativeBinding = require('./crc32.wasi.cjs')
} catch {
// ignore
}
Expand Down
10 changes: 8 additions & 2 deletions packages/crc32/npm/wasm32-wasi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
"cpu": [
"wasm32"
],
"main": "crc32.wasm32-wasi.wasm",
"main": "crc32.wasi.cjs",
"files": [
"crc32.wasm32-wasi.wasm"
"crc32.wasm32-wasi.wasm",
"crc32.wasi.cjs",
"wasi-worker.mjs"
],
"description": "SIMD crc32",
"keywords": [
Expand All @@ -33,5 +35,9 @@
},
"bugs": {
"url": "https://github.com/napi-rs/node-rs/issues"
},
"dependencies": {
"@emnapi/core": "^0.45.0",
"@emnapi/runtime": "^0.45.0"
}
}
2 changes: 1 addition & 1 deletion packages/crc32/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"url": "https://github.com/napi-rs/node-rs/issues"
},
"devDependencies": {
"@napi-rs/cli": "^3.0.0-alpha.25",
"@napi-rs/cli": "^3.0.0-alpha.28",
"@types/crc": "^3.8.3",
"buffer": "^6.0.3",
"crc": "^4.3.2",
Expand Down
22 changes: 20 additions & 2 deletions packages/deno-lint/deno-lint.wasi.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,27 @@ const __sharedMemory = new WebAssembly.Memory({
shared: true,
})

const { instance: __napiInstance, module: __wasiModule, napiModule: __napiModule } = __emnapiInstantiateNapiModuleSync(__nodeFs.readFileSync(__nodePath.join(__dirname, 'deno-lint.wasm32-wasi.wasm')), {
let __wasmFilePath = __nodePath.join(__dirname, 'deno-lint.wasm32-wasi.wasm')

if (!__nodeFs.existsSync(__wasmFilePath)) {
try {
__wasmFilePath = __nodePath.resolve('@node-rs/deno-lint-wasm32-wasi')
} catch {
throw new Error('Cannot find deno-lint.wasm32-wasi.wasm file, and @node-rs/deno-lint-wasm32-wasi package is not installed.')
}
}

const { instance: __napiInstance, module: __wasiModule, napiModule: __napiModule } = __emnapiInstantiateNapiModuleSync(__nodeFs.readFileSync(__wasmFilePath), {
context: __emnapiContext,
asyncWorkPoolSize: 4,
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) {
return threadsSizeFromEnv
} else {
return 4
}
})(),
wasi: __wasi,
onCreateWorker() {
return new Worker(__nodePath.join(__dirname, 'wasi-worker.mjs'), {
Expand Down
9 changes: 1 addition & 8 deletions packages/deno-lint/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,14 +308,7 @@ switch (platform) {

if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
try {
localFileExisted = existsSync(
join(__dirname, 'deno-lint.wasm32-wasi.wasm')
) && existsSync(join(__dirname, 'deno-lint.wasi.cjs'))
if (localFileExisted) {
nativeBinding = require('./deno-lint.wasi.cjs')
} else {
nativeBinding = require('@node-rs/deno-lint-wasm32-wasi')
}
nativeBinding = require('./deno-lint.wasi.cjs')
} catch {
// ignore
}
Expand Down
Loading

0 comments on commit 874e336

Please sign in to comment.