Repository navigation
Improve Wasm64 support - #2959
Conversation
8d6ed90 to
7a4f4bb
Compare
There was a problem hiding this comment.
🟡 Changes recommended
CI is blocked because the wasm64 target request fails toolchain installation and the dependency target-table change causes the Monty fork drift check to fail.
1 open issue
What changed in this PR
Broadens Bashkit’s WebAssembly target gating so Memory64 targets use the existing Wasm-compatible dependency and runtime paths.
Changes:
- Replaces wasm32-specific predicates with Wasm-family predicates across the core, Python bindings, and Monty runtime.
- Adds wasm64 compile-check configuration to CI.
- Updates runtime documentation to match the broader target gates.
| File | Description |
|---|---|
knowledge/runtimes/markkit-fetchkit-builtins.md |
Updates the documented native-only gate. |
knowledge/runtimes/emscripten-wheels.md |
Documents Wasm-family dependency and API gates. |
crates/bashkit/tests/integration/input_redirect_budget_tests.rs |
Excludes native process helpers from all Wasm targets. |
crates/bashkit/src/time_compat/mod.rs |
Extends portable clock and timer selection to wasm64. |
crates/bashkit/src/lib.rs |
Broadens the native-only documentation gate. |
crates/bashkit/src/interpreter/mod.rs |
Keeps native-only builtins off all Wasm targets. |
crates/bashkit/src/interpreter/grow_stack.rs |
Uses direct polling without stack growth on Wasm. |
crates/bashkit/src/host_call.rs |
Extends Wasm execution-spawner selection. |
crates/bashkit/src/builtins/typescript.rs |
Extends Wasm-specific VM execution gates. |
crates/bashkit/src/builtins/sleep.rs |
Broadens non-JavaScript Wasm sleep handling. |
crates/bashkit/src/builtins/mod.rs |
Gates native-only builtin modules and exports. |
crates/bashkit/Cargo.toml |
Applies native/Wasm dependency splits to wasm64. |
crates/bashkit-python/src/lib.rs |
Extends Wasm API restrictions and callback paths. |
crates/bashkit-python/Cargo.toml |
Broadens the Python crate’s Wasm dependency selection. |
crates/bashkit-monty-types/src/resource/execution_clock.rs |
Extends Wasm clock selection. |
crates/bashkit-monty-types/src/resource.rs |
Broadens Wasm resource-wait and clock gates. |
crates/bashkit-monty-types/Cargo.toml |
Enables the clock dependency for wasm64. |
.github/workflows/ci.yml |
Adds wasm64 target setup and compilation checking. |
Review effort: Balanced
There was a problem hiding this comment.
Wasm64 generalization looks correct overall: cfg widening is consistent, CI now checks wasm64-unknown-unknown, and wasi/emscripten splits preserve prior behavior except as noted below.
Comments outside the diff
crates/bashkit/src/interpreter/grow_stack.rs line 15: [P2] Stale wasm32-only comments now cover wasm64 too and will mislead the next reader: crates/bashkit/src/interpreter/grow_stack.rs:15 ("On wasm32 stacker cannot switch stacks"), crates/bashkit/src/builtins/typescript.rs:100 ("wasm32 has no native VM threads") and :1185 ("wasm32 has no threads"), crates/bashkit-python/src/lib.rs:22 ("wasm32-unknown-emscripten"). Fix: reword to wasm / wasm unknown-unknown as appropriate in this PR since you already touch those lines' cfgs.
| /// only asynchronously. Only standard execution waits here; the wasm worker | ||
| /// suspends its sleeps to the JavaScript host instead. | ||
| #[cfg(target_arch = "wasm32")] | ||
| #[cfg(target_family = "wasm")] |
There was a problem hiding this comment.
[P1] block_for now spins on all target_family = "wasm", including wasm32-wasip2 (WASI). The comment just above justifies spinning because std::thread::sleep needs wasi:io/poll, which only a browser host serves asynchronously — on WASI the poll import is served synchronously and thread::sleep works. Spinning on WASI burns host CPU for the full duration (a sleep 10 becomes 10s of spin_loop) and skews CPU-clock accounting. Evidence: crates/bashkit-monty-types/src/resource.rs:890-899 (#[cfg(target_family = "wasm")] fn block_for spins). Fix: scope the spin to browser-only (#[cfg(all(target_family = "wasm", target_os = "unknown"))]) and let the thread::sleep branch cover WASI (#[cfg(not(all(target_family = "wasm", target_os = "unknown")))]), matching the Instant split used in execution_clock.rs:6-12.
| #[cfg(not(target_family = "wasm"))] | ||
| use std::thread; | ||
| #[cfg(all(target_arch = "wasm32", not(target_os = "unknown")))] | ||
| #[cfg(all(target_family = "wasm", not(target_os = "unknown")))] |
There was a problem hiding this comment.
[P2] The new Instant split groups Emscripten with WASI (#[cfg(all(target_family = "wasm", not(target_os = "unknown")))] use std::time::Instant, resource.rs:8-9; same shape in execution_clock.rs:6-7). Emscripten (target_os = "emscripten") also runs in the browser event loop where the old wasm32 cfg used web_time::Instant. std::time::Instant may work there, but the PR gives no evidence it was verified, and the grouping looks driven by "not unknown = WASI" rather than "WASI-only". Consider web_time for unknown + emscripten and std for WASI-only (e.g. target_os = "wasi" / cfg(target_env)), or document why std is correct on Emscripten.
Review summary — wasm64 support (af549cb)Verdict: Clean, narrow revision. The PR is now a mechanical Findings:
Context read beyond the diff: Could not review: full unified diff truncated by tooling; verified against the checked-out head at |
|
I agree with the bot that there are several places where |
7a4f4bb to
af549cb
Compare
|
|
||
| #[cfg(all( | ||
| target_arch = "wasm32", | ||
| target_family = "wasm", |
There was a problem hiding this comment.
[P2] The cfg widening here is correct (wasm32 → wasm picks up wasm64-unknown-unknown), but the module docs directly above still say wasm32-unknown-unknown (lines 4, 14) and lines 146/176 repeat it. std's unsupported.rs time path applies to wasm unknown generally, so a reader may wrongly conclude wasm64-unknown-unknown has a working std::time. Evidence: crates/bashkit/src/time_compat/mod.rs:4,14,146,176 vs the widened #[cfg(all(target_family = "wasm", ...))] below. Fix: reword to wasm-unknown-unknown (or wasm32/64-unknown-unknown).
chaliy
left a comment
There was a problem hiding this comment.
Thanks, this looks good. target_family = "wasm" covers exactly what target_arch = "wasm32" did, plus wasm64, so nothing changes for the wasm32 targets we ship today. I checked wasm32-unknown-unknown locally and it builds fine. I've approved the CI runs and will squash-merge once they're green.
A few notes:
- Squash message: the commit message says
target_os = "wasm32", but the change is totarget_arch. I'll fix that when I squash-merge, so no need to touch it. - Docs nit:
crates/bashkit/src/time_compat/mod.rsstill sayswasm32-unknown-unknownin its docs (around lines 4, 14, 146 and 176). Feel free to fix it here or in the follow-up. - Follow-up PR: yes please, a separate PR is the right place for it. Two things to include:
- Narrow the browser-only paths to
all(target_family = "wasm", target_os = "unknown"), so WASI keeps the realthread::sleepandstd::timeinstead of spinning. - Apply the same change to
crates/bashkit-monty-types. That's our own fork, so the upstream Monty PR won't reach it, and without this change Python on wasm64 stays broken. As Copilot noted,scripts/check_monty_fork.pywill flag theCargo.tomltarget key change. Please add a narrow exception for that one change, with a test.
- Narrow the browser-only paths to
- CI: no need to add wasm64 to CI for now, since it needs nightly and
-Zbuild-std.
Generated by Claude Code
|
@madsmtm I am super sorry for my agent behaviour. |
Follow-up to #2959: the time_compat, host_clock and grow_stack docs now name wasm{32,64} instead of wasm32 only.
|
Haha, no worries |

What changed
Find/replace instances of
target_os = "wasm32"withtarget_family = "wasm".(Changed everywhere apart from the bundled
montyfork, I filed a PR upstream instead, see pydantic/monty#1399).Why
To improve support for the Memory64 WASM targets (
wasm64-unknown-unknown,wasm64-unknown-emscripten).Before
After
The above commands succeed.
Risk
Checklist
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.