Skip to content

feat: add wasm32-wasip1-threads support#51

Merged
richerfu merged 9 commits into
mainfrom
feat/wasm32-wasip1-threads-support
Jul 7, 2026
Merged

feat: add wasm32-wasip1-threads support#51
richerfu merged 9 commits into
mainfrom
feat/wasm32-wasip1-threads-support

Conversation

@richerfu

@richerfu richerfu commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

No description provided.

@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown

zig-napi ArkVM benchmark

  • Generated: 2026-07-07T07:35:41Z
  • Status: ZIG_NAPI_BENCHMARK_RESULT status=ok
module api content iterations native C N-API avg (us) zig-napi avg (us) diff (us) ratio
global function void(*)() 100000 0.104 0.108 0.004 1.037x
primitive i32(i32, i32) 100000 0.137 0.14 0.002 1.018x
primitive bool(bool) 100000 0.129 0.133 0.004 1.029x
string len(string) 100000 0.159 0.157 -0.002 0.985x
object read properties 100000 0.325 0.317 -0.007 0.977x
array sum(number[]) 100000 0.623 0.646 0.023 1.036x
function call callback 100000 0.271 0.277 0.005 1.02x
class constructor 20000 0.969 4.823 3.854 4.977x
class getter 100000 0.21 0.214 0.004 1.019x
class setter 100000 0.39 0.373 -0.016 0.958x
class method 100000 0.221 0.228 0.006 1.028x
ArrayBuffer constructor 20000 0.315 0.373 0.058 1.186x
ArrayBuffer byteLength 100000 0.158 0.163 0.005 1.032x
Buffer constructor 20000 0.903 0.779 -0.124 0.862x
Buffer length 100000 0.162 0.162 0 0.999x
TypedArray Uint8Array constructor 20000 0.706 0.87 0.164 1.233x
TypedArray Uint8Array sum 100000 0.191 0.215 0.024 1.126x
DataView constructor 20000 0.412 0.436 0.023 1.057x
DataView byteLength 100000 0.154 0.194 0.04 1.259x

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 .wasm artifacts, 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.

Comment thread src/sys/wasm.zig
Comment thread node-test/load-addon.js
Comment thread src/prelude/module.zig

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 72 out of 76 changed files in this pull request and generated 3 comments.

Files not reviewed (1)
  • pnpm-lock.yaml: Generated file

Comment thread src/sys/node.zig
Comment thread src/build/napi-build.zig Outdated
Comment thread packages/zig-napi/templates/node-addon/browser.js

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 73 out of 77 changed files in this pull request and generated 2 comments.

Files not reviewed (1)
  • pnpm-lock.yaml: Generated file

Comment thread packages/zig-napi/templates/node-addon/__ADDON_NAME__.wasi.cjs Outdated
Comment thread packages/zig-napi/templates/node-addon/__ADDON_NAME__.wasi.cjs Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 73 out of 77 changed files in this pull request and generated 5 comments.

Files not reviewed (1)
  • pnpm-lock.yaml: Generated file

Comment thread src/napi/wrapper/typedarray.zig
Comment thread src/napi/wrapper/dataview.zig
Comment thread src/sys/wasm.zig
Comment thread node-test/napi/src/threadsafe_function.zig
Comment thread node-test/napi-compat-mode/src/napi4/threadsafe_function.zig

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 74 out of 78 changed files in this pull request and generated 2 comments.

Files not reviewed (1)
  • pnpm-lock.yaml: Generated file

Comment thread website/src/content/api/declaration-generation.md Outdated
Comment thread src/sys/node.zig

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 74 out of 78 changed files in this pull request and generated 3 comments.

Files not reviewed (1)
  • pnpm-lock.yaml: Generated file

Comment thread website/src/content/api/declaration-generation.md Outdated
Comment thread src/sys/wasm.zig
Comment thread src/sys/wasm.zig

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 74 out of 78 changed files in this pull request and generated no new comments.

Files not reviewed (1)
  • pnpm-lock.yaml: Generated file

@richerfu
richerfu merged commit ad4baf0 into main Jul 7, 2026
25 checks passed
@richerfu
richerfu deleted the feat/wasm32-wasip1-threads-support branch July 7, 2026 08:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants