Skip to content

Comments

fix(napi): wasi debug compile error#3081

Merged
Brooooooklyn merged 1 commit intomainfrom
12-30-fix_napi_wasi_debug_compile_error
Dec 30, 2025
Merged

fix(napi): wasi debug compile error#3081
Brooooooklyn merged 1 commit intomainfrom
12-30-fix_napi_wasi_debug_compile_error

Conversation

@Brooooooklyn
Copy link
Member

@Brooooooklyn Brooooooklyn commented Dec 30, 2025

Note

Addresses WASI debug build issues and strengthens WASI CI.

  • Excludes wasm from debug-only buffer tracking and GC cleanup paths (js_values/buffer.rs, bindgen_runtime/mod.rs) via #[cfg(all(debug_assertions, not(windows), not(target_family = "wasm")))]
  • Tightens WASM cleanup hook gating to #[cfg(all(target_family = "wasm", not(feature = "noop")))] in env.rs
  • CI: Adds conditional cargo check -p napi --all-features --target wasm32-wasip1-threads when RUSTFLAGS == '--cfg tokio_unstable' in test-node-wasi

Written by Cursor Bugbot for commit ffc8cb9. This will update automatically on new commits. Configure here.

Summary by CodeRabbit

  • Chores
    • Added build validation step for WebAssembly target with all features enabled.
    • Optimized WebAssembly builds by excluding debug-only assertions and code tracking, reducing binary size and overhead.
    • Refined WebAssembly feature flag handling for better configuration control.

✏️ Tip: You can customize this high-level summary in your review settings.

Copilot AI review requested due to automatic review settings December 30, 2025 15:56
@coderabbitai
Copy link

coderabbitai bot commented Dec 30, 2025

📝 Walkthrough

Walkthrough

The PR tightens conditional compilation gates to exclude WebAssembly targets from debug-assertion code paths in the NAPI bindgen runtime, and adds a cargo check step for WASM builds in the CI workflow. Additionally, the environment cleanup hook registration is gated to exclude the noop feature under WASM targets.

Changes

Cohort / File(s) Summary
CI Workflow
.github/workflows/test-release.yaml
Adds a "Check" step in the test-node-wasi workflow that runs cargo check for the napi crate with all features targeting wasm32-wasip1-threads, conditional on RUSTFLAGS environment variable.
Debug Buffer Tracking
crates/napi/src/bindgen_runtime/js_values/buffer.rs
Tightens cfg conditions on debug-only buffer tracking and assertions by adding not(target_family = "wasm") to exclude WASM targets. Affects imports (HashSet, Mutex) and BufferSlice/Buffer debug guard implementations.
Runtime Cleanup Guards
crates/napi/src/bindgen_runtime/mod.rs
Excludes WASM targets from debug-only code in drop_buffer and drop_buffer_slice by adding not(target_family = "wasm") to existing debug-assertion cfgs.
Environment Cleanup Hook
crates/napi/src/bindgen_runtime/env.rs
Tightens WASM-specific cfg for Env::add_env_cleanup_hook to exclude compilation when the noop feature is enabled, preventing hook registration under that feature flag.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

🐰 A WASM build checked and cleaned,
Debug guards now lean and green,
No Windows, no WASM in sight,
The runtime shines ever bright! ✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main purpose of the PR: fixing a WebAssembly debug compilation error by gating debug-only code and adjusting conditional compilation attributes.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings

📜 Recent review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 893e913 and ffc8cb9.

📒 Files selected for processing (4)
  • .github/workflows/test-release.yaml
  • crates/napi/src/bindgen_runtime/js_values/buffer.rs
  • crates/napi/src/bindgen_runtime/mod.rs
  • crates/napi/src/env.rs
🧰 Additional context used
🧠 Learnings (7)
📓 Common learnings
Learnt from: CR
Repo: napi-rs/napi-rs PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-25T09:31:23.877Z
Learning: Applies to /crates/**/*.rs : Use `#[napi]` attribute on impl blocks to define classes exported to JavaScript/TypeScript
Learnt from: CR
Repo: napi-rs/napi-rs PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-25T09:31:23.877Z
Learning: Run `yarn workspace examples/napi build` before testing to ensure code generation reflects current Rust changes
📚 Learning: 2025-11-25T09:31:23.877Z
Learnt from: CR
Repo: napi-rs/napi-rs PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-25T09:31:23.877Z
Learning: Applies to /crates/**/*.rs : Use `#[napi]` attribute on impl blocks to define classes exported to JavaScript/TypeScript

Applied to files:

  • crates/napi/src/bindgen_runtime/js_values/buffer.rs
  • crates/napi/src/env.rs
  • crates/napi/src/bindgen_runtime/mod.rs
📚 Learning: 2025-11-25T09:31:23.877Z
Learnt from: CR
Repo: napi-rs/napi-rs PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-25T09:31:23.877Z
Learning: Applies to /crates/**/*.rs : Use `#[napi(js_name = "...")]` attribute to rename Rust items in JavaScript/TypeScript

Applied to files:

  • crates/napi/src/bindgen_runtime/js_values/buffer.rs
  • crates/napi/src/bindgen_runtime/mod.rs
📚 Learning: 2025-11-25T09:31:23.877Z
Learnt from: CR
Repo: napi-rs/napi-rs PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-25T09:31:23.877Z
Learning: Applies to /crates/**/*.rs : Use `#[napi(object)]` attribute for plain objects that should be mapped to TypeScript interfaces

Applied to files:

  • crates/napi/src/bindgen_runtime/js_values/buffer.rs
📚 Learning: 2025-11-25T09:31:23.877Z
Learnt from: CR
Repo: napi-rs/napi-rs PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-25T09:31:23.877Z
Learning: Run `yarn workspace examples/napi build` before testing to ensure code generation reflects current Rust changes

Applied to files:

  • .github/workflows/test-release.yaml
📚 Learning: 2025-11-25T09:31:23.877Z
Learnt from: CR
Repo: napi-rs/napi-rs PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-25T09:31:23.877Z
Learning: Run `cargo test` for Rust unit tests and `yarn workspace examples/napi test` for integration tests

Applied to files:

  • .github/workflows/test-release.yaml
📚 Learning: 2025-11-25T09:31:23.877Z
Learnt from: CR
Repo: napi-rs/napi-rs PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-25T09:31:23.877Z
Learning: Rebuild TypeScript definitions after making changes to Rust code using `yarn workspace examples/napi build`

Applied to files:

  • .github/workflows/test-release.yaml
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (28)
  • GitHub Check: i686-pc-windows-msvc - node@22 - toolchain@ stable
  • GitHub Check: x86_64-pc-windows-msvc - node@22 - toolchain@ stable
  • GitHub Check: i686-pc-windows-msvc - node@24 - toolchain@ stable
  • GitHub Check: aarch64-apple-darwin - node@22 - toolchain@ stable
  • GitHub Check: aarch64-pc-windows-msvc - node@22 - toolchain@ stable
  • GitHub Check: x86_64-pc-windows-msvc - node@24 - toolchain@ stable
  • GitHub Check: aarch64-apple-darwin - node@24 - toolchain@ stable
  • GitHub Check: x86_64-unknown-linux-gnu - node@24 - toolchain@ stable
  • GitHub Check: aarch64-pc-windows-msvc - node@24 - toolchain@ stable
  • GitHub Check: x86_64-unknown-linux-gnu - node@24 - toolchain@ 1.88.0
  • GitHub Check: x86_64-unknown-linux-gnu - node@22 - toolchain@ stable
  • GitHub Check: x86_64-unknown-linux-gnu - node@22 - toolchain@ 1.88.0
  • GitHub Check: x86_64-unknown-linux-gnu - node@20 - toolchain@ stable
  • GitHub Check: aarch64-apple-darwin - node@20 - toolchain@ stable
  • GitHub Check: x86_64-pc-windows-msvc - node@20 - toolchain@ stable
  • GitHub Check: Build only test - aarch64-unknown-linux-ohos
  • GitHub Check: Build only test - riscv64gc-unknown-linux-gnu
  • GitHub Check: build - aarch64-unknown-linux-gnu
  • GitHub Check: Build only test - armv7-linux-androideabi
  • GitHub Check: build-and-test-msys2 (CLANG64)
  • GitHub Check: stable - armv7-unknown-linux-gnueabihf - node@22
  • GitHub Check: Test freebsd target
  • GitHub Check: build-and-test-msys2 (UCRT64)
  • GitHub Check: build-and-test-msys2 (MINGW64)
  • GitHub Check: ASAN - ubuntu-24.04
  • GitHub Check: ASAN - windows-latest
  • GitHub Check: Memory leak detect job
  • GitHub Check: Cursor Bugbot
🔇 Additional comments (8)
.github/workflows/test-release.yaml (1)

756-760: LGTM! The CI check validates wasm compilation.

This new step ensures the napi crate compiles for wasm32-wasip1-threads with all features when tokio_unstable is enabled, which directly validates the conditional compilation changes made in this PR.

crates/napi/src/env.rs (1)

1117-1117: LGTM! Correctly narrows the wasm cleanup hook path.

The additional not(feature = "noop") condition appropriately excludes cleanup hook registration when the noop feature is enabled under wasm targets, which aligns with the PR's goal of preventing wasm builds from pulling in unnecessary code paths.

crates/napi/src/bindgen_runtime/mod.rs (2)

82-82: LGTM! Correctly excludes wasm from debug buffer tracking.

The additional not(target_family = "wasm") condition prevents wasm builds from accessing the debug-only BUFFER_DATA tracking, which aligns with the corresponding changes in buffer.rs where BUFFER_DATA is conditionally compiled.


104-104: LGTM! Consistent wasm exclusion for buffer slice tracking.

The additional not(target_family = "wasm") condition maintains consistency with the drop_buffer function above and prevents wasm builds from accessing debug-only buffer tracking code.

crates/napi/src/bindgen_runtime/js_values/buffer.rs (4)

1-9: LGTM! Correctly gates debug-only imports for non-wasm targets.

The additional not(target_family = "wasm") conditions on the HashSet and Mutex imports are appropriate, as these types are only needed for debug buffer tracking that is now excluded from wasm builds.


42-51: LGTM! Consistent wasm exclusion for debug buffer tracking.

The additional not(target_family = "wasm") condition in BufferSlice::from_data correctly excludes wasm targets from the debug assertion that prevents sharing buffer data between multiple buffers.


124-133: LGTM! Consistent wasm exclusion for external buffer tracking.

The additional not(target_family = "wasm") condition in BufferSlice::from_external maintains consistency with the from_data method above and correctly excludes wasm targets from debug buffer tracking.


373-382: LGTM! Consistent wasm exclusion in Buffer::From implementation.

The additional not(target_family = "wasm") condition in the From<Vec<u8>> implementation correctly excludes wasm targets from debug buffer tracking, maintaining consistency across all buffer creation paths.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Member Author


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • ready-to-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a compilation error that occurs when building the napi crate for WASI (WebAssembly System Interface) targets in debug mode. The issue stems from the use of thread-local storage and mutexes, which are not available in WebAssembly environments.

  • Adds not(target_family = "wasm") guards to debug assertion code that uses thread-local storage
  • Ensures the BUFFER_DATA thread-local variable and its usage are excluded from WASM builds
  • Adds a CI check to catch similar issues early in the WASI build pipeline

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
crates/napi/src/env.rs Adds not(feature = "noop") guard to WASM-specific cleanup hook implementation
crates/napi/src/bindgen_runtime/mod.rs Excludes WASM from debug buffer tracking in drop_buffer and drop_buffer_slice functions
crates/napi/src/bindgen_runtime/js_values/buffer.rs Excludes WASM from all debug buffer tracking code including imports, thread-local declaration, and usage sites
.github/workflows/test-release.yaml Adds cargo check step for WASI target with all features enabled to catch compile errors earlier

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Brooooooklyn Brooooooklyn force-pushed the 12-30-fix_napi_wasi_debug_compile_error branch from 96511ee to ffc8cb9 Compare December 30, 2025 15:58
@Brooooooklyn Brooooooklyn merged commit 42cb47a into main Dec 30, 2025
76 checks passed
@Brooooooklyn Brooooooklyn deleted the 12-30-fix_napi_wasi_debug_compile_error branch December 30, 2025 16:18
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.

1 participant