Repository navigation
feat(cli): support non-threaded WASI targets - #3353
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughThe PR adds canonical WASI target handling, transactional CLI filesystem workflows, generated loader disposal and rollback, richer TypeScript declaration generation, emnapi v2 integration, a custom async runtime example, and CI coverage across native, WASI, browser, and Workerd environments. ChangesWASI runtime, packaging, and type generation
Estimated code review effort: 5 (Critical) | ~120 minutes Possibly related issues
Possibly related PRs
Sequence Diagram(s)sequenceDiagram
participant CI
participant NapiCli
participant WasmBuilder
participant GeneratedLoader
participant Runtime
CI->>NapiCli: build WASI artifacts
NapiCli->>WasmBuilder: configure target and emnapi archive
WasmBuilder->>GeneratedLoader: emit loader and declarations
GeneratedLoader->>Runtime: instantiate with plugins and memory
Runtime-->>GeneratedLoader: expose N-API binding
CI->>GeneratedLoader: run lifecycle tests
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Caution Review failedAn error occurred during the review process. Please try again later. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
85c3211 to
a38e9d9
Compare
adae24d to
b6ec867
Compare
d187a6d to
6c13247
Compare
7cc8af8 to
5cb591f
Compare
42d51a1 to
af4fa14
Compare
34f3722 to
e2bc651
Compare
8cba580 to
13e8b55
Compare
e5f9e6f to
d182579
Compare
…them The failed-snapshot cleanup guard verified ownership with an lstat of the destination pathname and then unlinked the same pathname — a TOCTOU window the code itself documented as a known limitation: a successor swapped onto the pathname between the two syscalls was deleted even though the transaction never owned it. Close the window with the subsystem's existing retire idiom (retireExactFileSystemTransactionPath / restoreUnexpectedFileSystemTransactionRetirement): atomically rename the leftover to a unique process-private sibling, revalidate the retired entry against the recorded 64-bit decimal-string identity, and unlink only a revalidated match — the retired name is unreachable to other writers, so the unlink deletes exactly the revalidated inode. A mismatched entry is hard-linked back to the destination, or preserved at the retired name when an even newer successor already reoccupied the pathname. The race window is covered deterministically in tests through the onBeforeRetire seam, which swaps a distinct inode onto the pathname between the ownership pre-check and the retirement rename. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01T34fMrYCf2V13Mg8BKmnda
emnapi v1 @emnapi/core and @emnapi/runtime do not list ./package.json in their export maps, so the package.json subpath require threw a bare ERR_PACKAGE_PATH_NOT_EXPORTED before the descriptive version-mismatch error could fire for stale installs. Try the package.json subpath first (works on the pinned 2.0.0-alpha.3) and fall back to the module's own version export (works on v1). Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01T34fMrYCf2V13Mg8BKmnda
…asi job The job only builds and tests; it never pushes, so the checkout token does not need to persist in the local git config (zizmor artipacked). Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01T34fMrYCf2V13Mg8BKmnda
…rebase onto main Main added the type-tag surface (#3405); the rebase text-merged its export lines into the threaded WASI loaders but could not update the embedded artifact-metadata export lists, the wasip1 flavor loaders, or the binary AVA snapshot. Regenerated via yarn regenerate and a native values.spec.ts snapshot update so every flavor exports TypeTagA, TypeTagB and makeTypeTagA consistently. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01T34fMrYCf2V13Mg8BKmnda
…loor restrictWasiNodeEngine fell back to the entire WASI-supported range when the declared engines.node was valid but disjoint from it (e.g. ">=21 <22" or "<20"), so create-npm-dirs and pre-publish published metadata claiming support for Node.js versions the package explicitly excluded. Fail with an error naming both ranges instead. Malformed ranges still fall back to the WASI floor. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01T34fMrYCf2V13Mg8BKmnda
…I_BINDING The d\.[ct]s branch only matched literal d.ts/d.cs, so the generated binary.wasi.d.cts / binary.wasip1.d.cts loader typings (already listed in WASI_CI_ARTIFACT_PATTERNS and written to .gitattributes by this file) were neither skipped by copyDirectory nor stripped by updateGeneratedWasiAttributes. Use the d\.[cm]?ts idiom shared with TYPE_DEF_FILE. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01T34fMrYCf2V13Mg8BKmnda
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: serverGenReqId_0adddda9-8712-4806-917b-3567152b1d1b) |
Note
Restacked (2026-07-13). The base PR #3352 was rebuilt from scratch as a minimal additive SPI (see its description). This branch was rebased onto the new base: the 13 feature commits replayed with zero
crates/napichanges, plus three adaptation commits —examples/custom-async-runtimeis now carried in this PR (the new base no longer ships it) and drives its own executor; tests asserting removed old-base machinery were dropped with notes; explicit-shutdown assertions follow the new self-healing lifecycle (a napi dispatch after shutdown restarts the backend; the drained Tokio runtime refills on the next environment registration).Napi-side capabilities the old base provided that tests no longer assert (candidates for follow-up PRs): env-cleanup preparation hook (dispose-time promise settlement on threadless WASI), TSFN exception-identity hardening, graceful rejection of built-in tokio async exports on threadless WASI, wasm wrap-slot sharing.
crates/buildnow uses--export-if-definedfornapi_prepare_wasm_env_cleanupuntil the hook lands.Summary
Add first-class non-threaded
wasm32-wasip1support to napi-build and thenapi-rs CLI, including production-hardened Node, browser, and deferred workerd
loaders.
This PR is stacked on #3352 so async addons can register a cooperative backend
instead of relying on Tokio/Rust threads.
Stack status
feat/custom-async-runtime-backendc1f70451d6ba957f09166fdd4fd345e31589e2f8ae5196b5c1be97363834e29582ca4aadd4a3ab0fBuild behavior
For
wasm32-wasip1:libemnapi-basic.a;-pthreadflags;wasm32-wasip1WASI SDK sysroot;The existing threaded WASI path continues to use
libemnapi-basic-mt.aand its worker exports.Deferred lifecycle API
The workerd loader exposes:
instantiate(module)for a module-local singleton;createInstance(module)for independently owned instances;dispose(): Promise<void>for deterministic singleton and retained rollbackcleanup;
WasiInstance.dispose(): Promise<void>for deterministic independent cleanup.Lifecycle ownership is explicit and failure-safe:
exports;
registered while a cleanup batch is pending;
beforeExitcleanup reports only failures from cleanup it starts,not a public batch it merely joins;
suppressDestroy()failure still establishes rollback ownership;thengetters cannot strand lifecycle state;ERR_NAPI_WASI_LIFECYCLE_REENTRYinstead of forming promise cycles;beforeExitcycles andreceive best-effort terminal cleanup.
The adversarial lifecycle coverage is in
examples/napi; noMODULE_COUNT_TEST_LOCKor synthetic scheduler lock is used.Packaging and DX
identities.
/workerd,/wasm, and/wasm.wasmfacades work with npm, isolatedpnpm installs, Yarn PnP, Vite SSR, and Wrangler's extension-sensitive Wasm
handling.
assignments.
constraints, and dual-flavor regeneration are deterministic.
Validation
Passed locally across the current #3352/#3353 stack:
async-runtime,tokio_rtsuite: 94 unit tests plus feature-selection testsMODULE_COUNT_TEST_LOCKis usedCI=1 YARN_ENABLE_HARDENED_MODE=1 yarn test:cli(365 passed)examples/napiWASI lifecycle and regeneration tests (10 passed)cargo test -p napi-build --locked(3 passed)cargo fmt --all -- --checkyarn lintgit diff --check--unhandled-rejections=strictTwo adversarial review passes were completed after the lifecycle changes; the
last pass found no new actionable issue.
Dependencies
@emnapi/coreand@emnapi/runtimeto1.11.2.1.11.2contains fix: bind captured setImmediate to the global receiver toyobayashi/emnapi#221.released.
Tracking
Note
High Risk
Large changes to WASM/WASI loader generation, lifecycle/disposal semantics, and packaging touch every consumer path; emnapi v2 alpha and raised Node engine floors are breaking for older environments.
Overview
Introduces first-class threadless
wasm32-wasip1alongside existing threaded WASI, with flavor-specific loaders, npm identities, and build/link flags (non-pthread emnapi archives, deferred workerd entry, no worker scripts for threadless).CLI build and packaging now emit richer WASI artifacts: metadata-prefixed bindings,
.d.ctsloader typings,browser.js/ root facades,NAPI_RS_WASI_FLAVOR-aware index chains, andSymbol.for('napi.rs.wasi.dispose')plus deferredinstantiate/createInstance/disposelifecycle in generated loaders (init rollback, worker termination, re-entry guards).artifactsandcreate-npm-dirswere reworked for transactional reconciliation, duplicate/missing artifact checks, stale flavor cleanup, and WASI packages without misleadingcpu/osfields.Dependencies and requirements: bumps
@napi-rs/clito emnapi 2.0.0-alpha.3, raises supported Node to^20.17.0 || ^22.13.0 || >=23.5.0, and documents WASI targets incli/docs/wasi.md.cli.mjsloads TypeScript directly in source checkouts.CI: new
test-custom-async-runtime-wasijob (native + WASI + browser + workerd + public-surface tests); unit-test timeout increased to 20 minutes on Windows.Reviewed by Cursor Bugbot for commit b487f53. Bugbot is set up for automated code reviews on this repo. Configure here.
Summary by CodeRabbit
wasm32-wasip1, with broader WASI/WASM browser/Workerd runs.