feat: add wasm32-wasip1-threads support#51
Merged
Conversation
zig-napi ArkVM benchmark
|
There was a problem hiding this comment.
Pull request overview
Adds first-class support for building and packaging Zig-based Node-API addons for wasm32-wasip1-threads, integrating emnapi/@napi-rs/wasm-runtime compatibility across the build system, runtime glue, templates, and CI.
Changes:
- Extend the Zig runtime layer to support emnapi/WASI behavior (async work, cleanup hooks, module registration, and explicit memory syncing for ArrayBuffer/Buffer/TypedArray/DataView mutations).
- Update build and packaging tooling to emit
.wasmartifacts, generate.wasi.cjs/ browser bindings and worker files, and normalize WASI threads target names. - Expand documentation and CI to cover the WASI threads build and test path.
Reviewed changes
Copilot reviewed 45 out of 49 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| website/src/content/api/build-node.md | Documents .wasm outputs and how to target WASI threads via the CLI. |
| src/sys/wasm.zig | Adds emnapi/WASI-specific Node-API shims and worker glue for wasm builds. |
| src/sys/node.zig | Routes selected Node-API calls to WASI/emnapi implementations when enabled. |
| src/prelude/module.zig | Switches exported module init symbol name for wasm builds. |
| src/napi/wrapper/typedarray.zig | Adds flush() and uses it after copying into typed arrays under WASI/emnapi. |
| src/napi/wrapper/dataview.zig | Adds flush() and uses it after creating DataViews under WASI/emnapi. |
| src/napi/wrapper/buffer.zig | Adds flush() for syncing Buffer mutations back to JS under WASI/emnapi. |
| src/napi/wrapper/arraybuffer.zig | Adds flush() and calls it after ArrayBuffer creation under WASI/emnapi. |
| src/napi/options.zig | Introduces isWasmNodeAddon() feature detection helper. |
| src/napi/async.zig | Adds a WASI path that uses napi_async_work instead of spawning OS threads. |
| src/build/napi-build.zig | Adds WASI target handling, .wasm naming, and links emnapi for wasm builds. |
| README.md | Documents WASI threads usage, naming, and CI coverage expectations. |
| pnpm-lock.yaml | Updates lockfile to include/require emnapi and wasm runtime dependencies. |
| packages/zig-napi/templates/node-addon/wasi-worker.mjs | Adds Node worker script template for wasm runtime threading. |
| packages/zig-napi/templates/node-addon/wasi-worker-browser.mjs | Adds browser worker script template for wasm runtime threading. |
| packages/zig-napi/templates/node-addon/src/lib.zig | Removes requestedNapiVersion() from the template addon source. |
| packages/zig-napi/templates/node-addon/package.json | Adds browser entry and WASI-related files/dependencies to templates. |
| packages/zig-napi/templates/node-addon/index.js | Updates loader to support native + WASI fallback/forcing behavior. |
| packages/zig-napi/templates/node-addon/index.d.ts | Adds template TypeScript declarations output. |
| packages/zig-napi/templates/node-addon/browser.js | Adds browser entrypoint re-exporting the wasm32-wasi package. |
| packages/zig-napi/templates/node-addon/test/index.spec.js | Updates template tests to match the new exported surface. |
| packages/zig-napi/templates/node-addon/ADDON_NAME.wasi.cjs | Adds generated WASI CJS loader template for wasm runtime. |
| packages/zig-napi/templates/node-addon/ADDON_NAME.wasi-browser.js | Adds generated WASI browser loader template for wasm runtime. |
| packages/zig-napi/bin/zig-napi.js | Normalizes WASI target names and generates WASI bindings/worker files. |
| node-test/wasi-worker.mjs | Adds worker used by wasm runtime during node-test runs. |
| node-test/wasi-worker-browser.mjs | Adds browser worker used by wasm runtime during node-test runs. |
| node-test/package.json | Adds wasm runtime deps and configures napi targets for WASI threads. |
| node-test/napi/src/values.zig | Ensures WASI-visible buffer/typedarray/dataview mutations are flushed. |
| node-test/napi/src/threadsafe_function.zig | Uses async work queueing under WASI instead of OS threads. |
| node-test/napi-compat-mode/src/napi6/bigint.zig | Flushes BigInt typed array mutation for WASI/emnapi correctness. |
| node-test/napi-compat-mode/src/napi4/threadsafe_function.zig | Uses async work queueing under WASI instead of OS threads. |
| node-test/napi-compat-mode/src/buffer.zig | Flushes Buffer mutation for WASI/emnapi correctness. |
| node-test/napi-compat-mode/src/arraybuffer.zig | Flushes typed array mutations for WASI/emnapi correctness. |
| node-test/load-addon.js | Updates test loader to support WASI bindings and forcing behavior. |
| node-test/example.wasi.cjs | Adds generated WASI CJS loader for node-test example addon. |
| node-test/example.wasi-browser.js | Adds generated WASI browser loader for node-test example addon. |
| node-test/compat_mode.wasi.cjs | Adds generated WASI CJS loader for compat_mode addon. |
| node-test/compat_mode.wasi-browser.js | Adds generated WASI browser loader for compat_mode addon. |
| examples/node/wasi-worker.mjs | Adds example worker used by wasm runtime threading. |
| examples/node/wasi-worker-browser.mjs | Adds example browser worker used by wasm runtime threading. |
| examples/node/test.js | Extends example test coverage to async APIs and progress events. |
| examples/node/src/hello.zig | Adds async + event-emitting APIs to validate the WASI runtime path. |
| examples/node/package.json | Adds browser entry, WASI files, deps, and WASI target to example. |
| examples/node/index.js | Updates example loader to support native + WASI fallback/forcing behavior. |
| examples/node/index.d.ts | Updates example TS declarations for new APIs and event payload shape. |
| examples/node/hello.wasi.cjs | Adds generated WASI CJS loader for the example addon. |
| examples/node/hello.wasi-browser.js | Adds generated WASI browser loader for the example addon. |
| examples/node/browser.js | Adds example browser entrypoint re-exporting the wasm32-wasi package. |
| .github/workflows/node-addon.yml | Adds a WASI threads build+test job to CI. |
Files not reviewed (1)
- pnpm-lock.yaml: Generated file
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.