Skip to content

Commit

Permalink
chore(*): upgrade NAPI-RS and bindings (#825)
Browse files Browse the repository at this point in the history
  • Loading branch information
Brooooooklyn authored Apr 19, 2024
1 parent c518732 commit 4fb4bcc
Show file tree
Hide file tree
Showing 55 changed files with 907 additions and 1,876 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ jobs:
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/deno-lint" run build --target wasm32-wasi-preview1-threads
target: 'wasm32-wasip1-threads'
build: yarn workspaces foreach -A --no-private -j 1 --exclude "@node-rs/deno-lint" run build --target wasm32-wasip1-threads

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

- name: Upload artifact
uses: actions/upload-artifact@v4
if: ${{ matrix.settings.target != 'wasm32-wasi-preview1-threads' }}
if: ${{ matrix.settings.target != 'wasm32-wasip1-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' }}
if: ${{ matrix.settings.target == 'wasm32-wasip1-threads' }}
with:
name: bindings-${{ matrix.settings.target }}
path: packages/*/*.wasm
if-no-files-found: error

build-freebsd:
runs-on: macos-12
runs-on: macos-13
name: Build FreeBSD
steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -583,7 +583,7 @@ jobs:
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: bindings-wasm32-wasi-preview1-threads
name: bindings-wasm32-wasip1-threads
path: artifacts
- name: Move artifacts
run: yarn artifacts
Expand Down
2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
cargo-features = ["strip"]

[workspace]
members = [
"./crates/alloc",
Expand Down
28 changes: 11 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"bench": "lerna run bench --concurrency 1 --stream --no-prefix",
"build": "yarn workspaces foreach -A --no-private -j 1 run build",
"build:ts": "tsc -b tsconfig.project.json -verbose",
"lint": "eslint . -c ./.eslintrc.yml \"packages/**/*.{ts,js}\"",
"lint": "oxlint .",
"test": "ava",
"format": "run-p format:prettier format:rs format:toml",
"format:prettier": "prettier --config ./package.json -w .",
Expand All @@ -24,37 +24,31 @@
"postinstall": "husky install"
},
"devDependencies": {
"@napi-rs/cli": "^3.0.0-alpha.43",
"@napi-rs/wasm-runtime": "^0.1.1",
"@swc-node/core": "^1.12.0",
"@swc-node/register": "^1.8.0",
"@swc/core": "^1.4.2",
"@napi-rs/cli": "^3.0.0-alpha.51",
"@napi-rs/wasm-runtime": "^0.2.0",
"@swc-node/core": "^1.13.0",
"@swc-node/register": "^1.9.0",
"@swc/core": "^1.4.16",
"@taplo/cli": "^0.7.0",
"@tybys/wasm-util": "^0.8.1",
"@types/node": "^20.11.21",
"@typescript-eslint/eslint-plugin": "^7.1.0",
"@typescript-eslint/parser": "^7.1.0",
"ava": "^6.1.1",
"@types/node": "^20.12.7",
"ava": "^6.1.2",
"benchmark": "^2.1.4",
"codecov": "^3.8.3",
"cross-env": "^7.0.3",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-prettier": "^5.1.3",
"husky": "^9.0.11",
"lerna": "^8.1.2",
"lint-staged": "^15.2.2",
"memfs-browser": "^4.6.0",
"npm-run-all2": "^6.1.2",
"oxlint": "^0.2.17",
"prettier": "^3.2.5",
"ts-node": "^10.9.2",
"tslib": "^2.6.2",
"typescript": "^5.3.3"
"typescript": "^5.4.5"
},
"lint-staged": {
"*.@(js|ts|tsx)": [
"eslint -c .eslintrc.yml --fix"
"oxlint --fix"
],
"*.@(js|ts|tsx|yml|yaml|json|md)": [
"prettier --write"
Expand Down
12 changes: 2 additions & 10 deletions packages/argon2/argon2.wasi-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,18 @@ import {
getDefaultContext as __emnapiGetDefaultContext,
WASI as __WASI,
} from '@napi-rs/wasm-runtime'
import { Volume as __Volume, createFsFromVolume as __createFsFromVolume } from '@napi-rs/wasm-runtime/fs'

import __wasmUrl from './argon2.wasm32-wasi.wasm?url'

const __fs = __createFsFromVolume(
__Volume.fromJSON({
'/': null,
}),
)

const __wasi = new __WASI({
version: 'preview1',
fs: __fs,
})

const __emnapiContext = __emnapiGetDefaultContext()

const __sharedMemory = new WebAssembly.Memory({
initial: 1024,
maximum: 10240,
initial: 4000,
maximum: 65536,
shared: true,
})

Expand Down
13 changes: 9 additions & 4 deletions packages/argon2/argon2.wasi.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,30 @@ const {
getDefaultContext: __emnapiGetDefaultContext,
} = require('@napi-rs/wasm-runtime')

const __rootDir = __nodePath.parse(process.cwd()).root

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

const __emnapiContext = __emnapiGetDefaultContext()

const __sharedMemory = new WebAssembly.Memory({
initial: 1024,
maximum: 10240,
initial: 4000,
maximum: 65536,
shared: true,
})

let __wasmFilePath = __nodePath.join(__dirname, 'argon2.wasm32-wasi.wasm')
const __wasmDebugFilePath = __nodePath.join(__dirname, 'argon2.wasm32-wasi.debug.wasm')

if (!__nodeFs.existsSync(__wasmFilePath)) {
if (__nodeFs.existsSync(__wasmDebugFilePath)) {
__wasmFilePath = __wasmDebugFilePath
} else if (!__nodeFs.existsSync(__wasmFilePath)) {
try {
__wasmFilePath = __nodePath.resolve('@node-rs/argon2-wasm32-wasi')
} catch {
Expand Down
1 change: 0 additions & 1 deletion packages/argon2/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* auto-generated by NAPI-RS */
/* eslint-disable */

export const enum Algorithm {
/**
* Optimizes against GPU cracking attacks but vulnerable to side-channels.
Expand Down
26 changes: 26 additions & 0 deletions packages/argon2/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,20 @@ function requireNative() {

}
} else if (process.arch === 'arm') {
if (isMusl()) {
try {
return require('./argon2.linux-arm-musleabihf.node')
} catch (e) {
loadErrors.push(e)
}
try {
return require('@node-rs/argon2-linux-arm-musleabihf')
} catch (e) {
loadErrors.push(e)
}

} else {
try {
return require('./argon2.linux-arm-gnueabihf.node')
} catch (e) {
loadErrors.push(e)
Expand All @@ -257,6 +270,7 @@ function requireNative() {
loadErrors.push(e)
}

}
} else if (process.arch === 'riscv64') {
if (isMusl()) {
try {
Expand All @@ -283,6 +297,18 @@ function requireNative() {
}

}
} else if (process.arch === 'ppc64') {
try {
return require('./argon2.linux-ppc64-gnu.node')
} catch (e) {
loadErrors.push(e)
}
try {
return require('@node-rs/argon2-linux-ppc64-gnu')
} catch (e) {
loadErrors.push(e)
}

} else if (process.arch === 's390x') {
try {
return require('./argon2.linux-s390x-gnu.node')
Expand Down
2 changes: 1 addition & 1 deletion packages/argon2/npm/wasm32-wasi/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# `@node-rs/argon2-wasm32-wasi`

This is the **wasm32-wasi-preview1-threads** binary for `@node-rs/argon2`
This is the **wasm32-wasip1-threads** binary for `@node-rs/argon2`
4 changes: 2 additions & 2 deletions packages/argon2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"x86_64-unknown-freebsd",
"i686-pc-windows-msvc",
"armv7-linux-androideabi",
"wasm32-wasi-preview1-threads"
"wasm32-wasip1-threads"
]
},
"files": [
Expand Down Expand Up @@ -62,7 +62,7 @@
"version": "napi version && git add npm"
},
"devDependencies": {
"@napi-rs/cli": "^3.0.0-alpha.43",
"@napi-rs/cli": "^3.0.0-alpha.51",
"argon2": "^0.40.1",
"cross-env": "^7.0.3"
}
Expand Down
16 changes: 13 additions & 3 deletions packages/argon2/wasi-worker.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import fs from "node:fs";
import { createRequire } from "node:module";
import { WASI } from "node:wasi";
import { parentPort, Worker } from "node:worker_threads";

import { instantiateNapiModuleSync, MessageHandler, WASI } from "@napi-rs/wasm-runtime";

const require = createRequire(import.meta.url);

const { instantiateNapiModuleSync, MessageHandler, getDefaultContext } = require("@napi-rs/wasm-runtime");

if (parentPort) {
parentPort.on("message", (data) => {
globalThis.onmessage({ data });
Expand All @@ -26,13 +27,22 @@ Object.assign(globalThis, {
},
});

const emnapiContext = getDefaultContext()

const handler = new MessageHandler({
onLoad({ wasmModule, wasmMemory }) {
const wasi = new WASI({ fs });
const wasi = new WASI({
version: 'preview1',
env: process.env,
preopens: {
'/': '/',
},
});

return instantiateNapiModuleSync(wasmModule, {
childThread: true,
wasi,
context: emnapiContext,
overwriteImports(importObject) {
importObject.env = {
...importObject.env,
Expand Down
12 changes: 2 additions & 10 deletions packages/bcrypt/bcrypt.wasi-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,18 @@ import {
getDefaultContext as __emnapiGetDefaultContext,
WASI as __WASI,
} from '@napi-rs/wasm-runtime'
import { Volume as __Volume, createFsFromVolume as __createFsFromVolume } from '@napi-rs/wasm-runtime/fs'

import __wasmUrl from './bcrypt.wasm32-wasi.wasm?url'

const __fs = __createFsFromVolume(
__Volume.fromJSON({
'/': null,
}),
)

const __wasi = new __WASI({
version: 'preview1',
fs: __fs,
})

const __emnapiContext = __emnapiGetDefaultContext()

const __sharedMemory = new WebAssembly.Memory({
initial: 1024,
maximum: 10240,
initial: 4000,
maximum: 65536,
shared: true,
})

Expand Down
13 changes: 9 additions & 4 deletions packages/bcrypt/bcrypt.wasi.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,30 @@ const {
getDefaultContext: __emnapiGetDefaultContext,
} = require('@napi-rs/wasm-runtime')

const __rootDir = __nodePath.parse(process.cwd()).root

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

const __emnapiContext = __emnapiGetDefaultContext()

const __sharedMemory = new WebAssembly.Memory({
initial: 1024,
maximum: 10240,
initial: 4000,
maximum: 65536,
shared: true,
})

let __wasmFilePath = __nodePath.join(__dirname, 'bcrypt.wasm32-wasi.wasm')
const __wasmDebugFilePath = __nodePath.join(__dirname, 'bcrypt.wasm32-wasi.debug.wasm')

if (!__nodeFs.existsSync(__wasmFilePath)) {
if (__nodeFs.existsSync(__wasmDebugFilePath)) {
__wasmFilePath = __wasmDebugFilePath
} else if (!__nodeFs.existsSync(__wasmFilePath)) {
try {
__wasmFilePath = __nodePath.resolve('@node-rs/bcrypt-wasm32-wasi')
} catch {
Expand Down
1 change: 0 additions & 1 deletion packages/bcrypt/binding.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* auto-generated by NAPI-RS */
/* eslint-disable */

export const DEFAULT_COST: number

export function genSalt(round: number, version?: '2a' | '2x' | '2y' | '2b', signal?: AbortSignal): Promise<string>
Expand Down
Loading

0 comments on commit 4fb4bcc

Please sign in to comment.