Skip to content

Commit

Permalink
fix(*): update wasi bindings (#831)
Browse files Browse the repository at this point in the history
* fix(*): update wasi bindings

* Add architecture
  • Loading branch information
Brooooooklyn committed Apr 23, 2024
1 parent 69e7f80 commit 83037ac
Show file tree
Hide file tree
Showing 44 changed files with 187 additions and 116 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ jobs:
with:
node-version: ${{ matrix.node }}
cache: yarn
architecture: x64

- name: Install dependencies
run: yarn install --immutable --mode=skip-build
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
"postinstall": "husky install"
},
"devDependencies": {
"@napi-rs/cli": "^3.0.0-alpha.52",
"@napi-rs/wasm-runtime": "^0.2.0",
"@napi-rs/cli": "^3.0.0-alpha.53",
"@napi-rs/wasm-runtime": "^0.2.3",
"@swc-node/core": "^1.13.0",
"@swc-node/register": "^1.9.0",
"@swc/core": "^1.4.16",
Expand Down
5 changes: 4 additions & 1 deletion packages/argon2/argon2.wasi-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
instantiateNapiModuleSync as __emnapiInstantiateNapiModuleSync,
getDefaultContext as __emnapiGetDefaultContext,
WASI as __WASI,
createOnMessage as __wasmCreateOnMessageForFsProxy,
} from '@napi-rs/wasm-runtime'

import __wasmUrl from './argon2.wasm32-wasi.wasm?url'
Expand Down Expand Up @@ -29,9 +30,11 @@ const {
asyncWorkPoolSize: 4,
wasi: __wasi,
onCreateWorker() {
return new Worker(new URL('./wasi-worker-browser.mjs', import.meta.url), {
const worker = new Worker(new URL('./wasi-worker-browser.mjs', import.meta.url), {
type: 'module',
})

return worker
},
overwriteImports(importObject) {
importObject.env = {
Expand Down
9 changes: 7 additions & 2 deletions packages/argon2/argon2.wasi.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@

/* auto-generated by NAPI-RS */

const __nodeFs= require('node:fs')
const __nodeFs = require('node:fs')
const __nodePath = require('node:path')
const { WASI: __nodeWASI } = require('node:wasi')
const { Worker } = require('node:worker_threads')

const {
instantiateNapiModuleSync: __emnapiInstantiateNapiModuleSync,
getDefaultContext: __emnapiGetDefaultContext,
createOnMessage: __wasmCreateOnMessageForFsProxy,
} = require('@napi-rs/wasm-runtime')

const __rootDir = __nodePath.parse(process.cwd()).root
Expand Down Expand Up @@ -57,10 +58,14 @@ const { instance: __napiInstance, module: __wasiModule, napiModule: __napiModule
})(),
wasi: __wasi,
onCreateWorker() {
return new Worker(__nodePath.join(__dirname, 'wasi-worker.mjs'), {
const worker = new Worker(__nodePath.join(__dirname, 'wasi-worker.mjs'), {
env: process.env,
execArgv: ['--experimental-wasi-unstable-preview1'],
})
worker.onmessage = ({ data }) => {
__wasmCreateOnMessageForFsProxy(__nodeFs)(data)
}
return worker
},
overwriteImports(importObject) {
importObject.env = {
Expand Down
2 changes: 1 addition & 1 deletion packages/argon2/npm/wasm32-wasi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@
},
"browser": "argon2.wasi-browser.js",
"dependencies": {
"@napi-rs/wasm-runtime": "^0.2.0"
"@napi-rs/wasm-runtime": "^0.2.3"
}
}
2 changes: 1 addition & 1 deletion packages/argon2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"version": "napi version && git add npm"
},
"devDependencies": {
"@napi-rs/cli": "^3.0.0-alpha.52",
"@napi-rs/cli": "^3.0.0-alpha.53",
"argon2": "^0.40.1",
"cross-env": "^7.0.3"
}
Expand Down
5 changes: 4 additions & 1 deletion packages/argon2/wasi-worker-browser.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { instantiateNapiModuleSync, MessageHandler, WASI } from '@napi-rs/wasm-runtime'
import { instantiateNapiModuleSync, MessageHandler, WASI, createFsProxy } from '@napi-rs/wasm-runtime'

const fs = null

const handler = new MessageHandler({
onLoad({ wasmModule, wasmMemory }) {
const wasi = new WASI({
fs,
preopens: {
'/': '/',
},
print: function () {
// eslint-disable-next-line no-console
console.log.apply(console, arguments)
Expand Down
7 changes: 5 additions & 2 deletions packages/argon2/wasi-worker.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import fs from "node:fs";
import { createRequire } from "node:module";
import { parse } from "node:path";
import { WASI } from "node:wasi";
import { parentPort, Worker } from "node:worker_threads";

Expand Down Expand Up @@ -27,15 +28,17 @@ Object.assign(globalThis, {
},
});

const emnapiContext = getDefaultContext()
const emnapiContext = getDefaultContext();

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

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

Expand Down
5 changes: 4 additions & 1 deletion packages/bcrypt/bcrypt.wasi-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
instantiateNapiModuleSync as __emnapiInstantiateNapiModuleSync,
getDefaultContext as __emnapiGetDefaultContext,
WASI as __WASI,
createOnMessage as __wasmCreateOnMessageForFsProxy,
} from '@napi-rs/wasm-runtime'

import __wasmUrl from './bcrypt.wasm32-wasi.wasm?url'
Expand Down Expand Up @@ -29,9 +30,11 @@ const {
asyncWorkPoolSize: 4,
wasi: __wasi,
onCreateWorker() {
return new Worker(new URL('./wasi-worker-browser.mjs', import.meta.url), {
const worker = new Worker(new URL('./wasi-worker-browser.mjs', import.meta.url), {
type: 'module',
})

return worker
},
overwriteImports(importObject) {
importObject.env = {
Expand Down
9 changes: 7 additions & 2 deletions packages/bcrypt/bcrypt.wasi.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@

/* auto-generated by NAPI-RS */

const __nodeFs= require('node:fs')
const __nodeFs = require('node:fs')
const __nodePath = require('node:path')
const { WASI: __nodeWASI } = require('node:wasi')
const { Worker } = require('node:worker_threads')

const {
instantiateNapiModuleSync: __emnapiInstantiateNapiModuleSync,
getDefaultContext: __emnapiGetDefaultContext,
createOnMessage: __wasmCreateOnMessageForFsProxy,
} = require('@napi-rs/wasm-runtime')

const __rootDir = __nodePath.parse(process.cwd()).root
Expand Down Expand Up @@ -57,10 +58,14 @@ const { instance: __napiInstance, module: __wasiModule, napiModule: __napiModule
})(),
wasi: __wasi,
onCreateWorker() {
return new Worker(__nodePath.join(__dirname, 'wasi-worker.mjs'), {
const worker = new Worker(__nodePath.join(__dirname, 'wasi-worker.mjs'), {
env: process.env,
execArgv: ['--experimental-wasi-unstable-preview1'],
})
worker.onmessage = ({ data }) => {
__wasmCreateOnMessageForFsProxy(__nodeFs)(data)
}
return worker
},
overwriteImports(importObject) {
importObject.env = {
Expand Down
2 changes: 1 addition & 1 deletion packages/bcrypt/npm/wasm32-wasi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@
},
"browser": "bcrypt.wasi-browser.js",
"dependencies": {
"@napi-rs/wasm-runtime": "^0.2.0"
"@napi-rs/wasm-runtime": "^0.2.3"
}
}
2 changes: 1 addition & 1 deletion packages/bcrypt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"url": "https://github.com/napi-rs/node-rs/issues"
},
"devDependencies": {
"@napi-rs/cli": "^3.0.0-alpha.52",
"@napi-rs/cli": "^3.0.0-alpha.53",
"@types/bcrypt": "^5.0.2",
"bcrypt": "^5.1.1",
"bcryptjs": "^2.4.3",
Expand Down
5 changes: 4 additions & 1 deletion packages/bcrypt/wasi-worker-browser.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { instantiateNapiModuleSync, MessageHandler, WASI } from '@napi-rs/wasm-runtime'
import { instantiateNapiModuleSync, MessageHandler, WASI, createFsProxy } from '@napi-rs/wasm-runtime'

const fs = null

const handler = new MessageHandler({
onLoad({ wasmModule, wasmMemory }) {
const wasi = new WASI({
fs,
preopens: {
'/': '/',
},
print: function () {
// eslint-disable-next-line no-console
console.log.apply(console, arguments)
Expand Down
7 changes: 5 additions & 2 deletions packages/bcrypt/wasi-worker.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import fs from "node:fs";
import { createRequire } from "node:module";
import { parse } from "node:path";
import { WASI } from "node:wasi";
import { parentPort, Worker } from "node:worker_threads";

Expand Down Expand Up @@ -27,15 +28,17 @@ Object.assign(globalThis, {
},
});

const emnapiContext = getDefaultContext()
const emnapiContext = getDefaultContext();

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

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

Expand Down
5 changes: 4 additions & 1 deletion packages/crc32/crc32.wasi-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
instantiateNapiModuleSync as __emnapiInstantiateNapiModuleSync,
getDefaultContext as __emnapiGetDefaultContext,
WASI as __WASI,
createOnMessage as __wasmCreateOnMessageForFsProxy,
} from '@napi-rs/wasm-runtime'

import __wasmUrl from './crc32.wasm32-wasi.wasm?url'
Expand Down Expand Up @@ -29,9 +30,11 @@ const {
asyncWorkPoolSize: 4,
wasi: __wasi,
onCreateWorker() {
return new Worker(new URL('./wasi-worker-browser.mjs', import.meta.url), {
const worker = new Worker(new URL('./wasi-worker-browser.mjs', import.meta.url), {
type: 'module',
})

return worker
},
overwriteImports(importObject) {
importObject.env = {
Expand Down
9 changes: 7 additions & 2 deletions packages/crc32/crc32.wasi.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@

/* auto-generated by NAPI-RS */

const __nodeFs= require('node:fs')
const __nodeFs = require('node:fs')
const __nodePath = require('node:path')
const { WASI: __nodeWASI } = require('node:wasi')
const { Worker } = require('node:worker_threads')

const {
instantiateNapiModuleSync: __emnapiInstantiateNapiModuleSync,
getDefaultContext: __emnapiGetDefaultContext,
createOnMessage: __wasmCreateOnMessageForFsProxy,
} = require('@napi-rs/wasm-runtime')

const __rootDir = __nodePath.parse(process.cwd()).root
Expand Down Expand Up @@ -57,10 +58,14 @@ const { instance: __napiInstance, module: __wasiModule, napiModule: __napiModule
})(),
wasi: __wasi,
onCreateWorker() {
return new Worker(__nodePath.join(__dirname, 'wasi-worker.mjs'), {
const worker = new Worker(__nodePath.join(__dirname, 'wasi-worker.mjs'), {
env: process.env,
execArgv: ['--experimental-wasi-unstable-preview1'],
})
worker.onmessage = ({ data }) => {
__wasmCreateOnMessageForFsProxy(__nodeFs)(data)
}
return worker
},
overwriteImports(importObject) {
importObject.env = {
Expand Down
2 changes: 1 addition & 1 deletion packages/crc32/npm/wasm32-wasi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@
},
"browser": "crc32.wasi-browser.js",
"dependencies": {
"@napi-rs/wasm-runtime": "^0.2.0"
"@napi-rs/wasm-runtime": "^0.2.3"
}
}
2 changes: 1 addition & 1 deletion packages/crc32/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"url": "https://github.com/napi-rs/node-rs/issues"
},
"devDependencies": {
"@napi-rs/cli": "^3.0.0-alpha.52",
"@napi-rs/cli": "^3.0.0-alpha.53",
"@types/crc": "^3.8.3",
"buffer": "^6.0.3",
"crc": "^4.3.2",
Expand Down
5 changes: 4 additions & 1 deletion packages/crc32/wasi-worker-browser.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { instantiateNapiModuleSync, MessageHandler, WASI } from '@napi-rs/wasm-runtime'
import { instantiateNapiModuleSync, MessageHandler, WASI, createFsProxy } from '@napi-rs/wasm-runtime'

const fs = null

const handler = new MessageHandler({
onLoad({ wasmModule, wasmMemory }) {
const wasi = new WASI({
fs,
preopens: {
'/': '/',
},
print: function () {
// eslint-disable-next-line no-console
console.log.apply(console, arguments)
Expand Down
7 changes: 5 additions & 2 deletions packages/crc32/wasi-worker.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import fs from "node:fs";
import { createRequire } from "node:module";
import { parse } from "node:path";
import { WASI } from "node:wasi";
import { parentPort, Worker } from "node:worker_threads";

Expand Down Expand Up @@ -27,15 +28,17 @@ Object.assign(globalThis, {
},
});

const emnapiContext = getDefaultContext()
const emnapiContext = getDefaultContext();

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

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

Expand Down
2 changes: 1 addition & 1 deletion packages/deno-lint/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"typanion": "^3.14.0"
},
"devDependencies": {
"@napi-rs/cli": "^3.0.0-alpha.52",
"@napi-rs/cli": "^3.0.0-alpha.53",
"@types/webpack": "^5.28.5"
},
"funding": {
Expand Down
5 changes: 4 additions & 1 deletion packages/jieba/jieba.wasi-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
instantiateNapiModuleSync as __emnapiInstantiateNapiModuleSync,
getDefaultContext as __emnapiGetDefaultContext,
WASI as __WASI,
createOnMessage as __wasmCreateOnMessageForFsProxy,
} from '@napi-rs/wasm-runtime'

import __wasmUrl from './jieba.wasm32-wasi.wasm?url'
Expand Down Expand Up @@ -29,9 +30,11 @@ const {
asyncWorkPoolSize: 4,
wasi: __wasi,
onCreateWorker() {
return new Worker(new URL('./wasi-worker-browser.mjs', import.meta.url), {
const worker = new Worker(new URL('./wasi-worker-browser.mjs', import.meta.url), {
type: 'module',
})

return worker
},
overwriteImports(importObject) {
importObject.env = {
Expand Down

0 comments on commit 83037ac

Please sign in to comment.