Skip to content

Improve Wasm64 support - #2959

Merged
chaliy merged 1 commit into
everruns:mainfrom
nobodywho-ooo:wasm64-support
Nov 20, 2026
Merged

chaliy merged 1 commit into
everruns:mainfrom
nobodywho-ooo:wasm64-support

Conversation

@madsmtm

@madsmtm madsmtm commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

What changed

Find/replace instances of target_os = "wasm32" with target_family = "wasm".

(Changed everywhere apart from the bundled monty fork, 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

$ cargo +nightly build -Zbuild-std -pbashkit --target wasm64-unknown-unknown --features wasm_js
   Compiling tokio v1.54.1
error: Only features sync,macros,io-util,rt,time are supported on wasm.
   --> /Users/madsmtm/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.54.1/src/lib.rs:516:1
    |
516 | compile_error!("Only features sync,macros,io-util,rt,time are supported on wasm.");
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: could not compile `tokio` (lib) due to 1 previous error
$ cargo +nightly build -Zbuild-std -pbashkit --target wasm64-unknown-emscripten
   Compiling tokio v1.54.1
error: The `rt-multi-thread` feature on wasm32-unknown-emscripten requires pthreads support (build with `-pthread`).
   --> /Users/madsmtm/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.54.1/src/lib.rs:529:1
    |
529 | / compile_error!(
530 | |     "The `rt-multi-thread` feature on wasm32-unknown-emscripten requires pthreads support (build with `-pthread`)."
531 | | );
    | |_

After

The above commands succeed.

Risk

  • Low.
  • This is strictly allowing more targets to compile.

Checklist

  • Tests added or updated
    • I considered adding to CI, but the current CI only uses tier 2 WASM targets, and there are no tier 2 WASM64 targets.
  • Backward compatibility considered
    • No such concerns.

Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

Copilot AI balanced review requested due to automatic review settings November 20, 2026 13:24

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.

🟡 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

Comment thread crates/bashkit-monty-types/Cargo.toml Resolved

@bashkit-pr-reviewer bashkit-pr-reviewer Bot 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.

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")]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[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")))]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[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.

@bashkit-pr-reviewer

bashkit-pr-reviewer Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Review summary — wasm64 support (af549cb)

Verdict: Clean, narrow revision. The PR is now a mechanical target_arch = \"wasm32\" → target_family = \"wasm\" widening across 14 files (core cfgs, bashkit-python Cargo/lib, wasi-gated tests, two knowledge pages). No sandbox, network, or resource-limit behavior change; wasm64-unknown-unknown now correctly takes the wasm paths (no-thread VM step, inline parse, wasm-safe tokio deps, skipped process-spawning tests) instead of falling through to native paths. No blocking issues.

Findings:

  • [P2, new] wasm-doc-stale-time-compat (time_compat/mod.rs:22): cfgs widened but module docs still say wasm32-unknown-unknown (lines 4, 14, 146, 176). Reword to wasm-unknown-unknown.
  • Prior findings resolved/superseded: wasm-spin-wasi-block-for, wasm-instant-emscripten-grouping (resource/execution-clock split), and the CI wasm64-check concern are gone — those files are no longer in the diff (14 files now vs 18 before; monty-types/resource*.rs, ci.yml, host_call.rs, sleep.rs, lib.rs, builtins/mod.rs untouched or reduced to the same mechanical rename).

Context read beyond the diff: time_compat/mod.rs:1-180 (wasm/unknown/wasm_js matrix), typescript.rs wasm cfg sites, bashkit-python/Cargo.toml + lib.rs gating notes, input_redirect_budget_tests.rs unix/non-wasm guards, knowledge/runtimes/emscripten-wheels.md:39-41 and markkit-fetchkit-builtins.md:96 (already say target_family = \"wasm\").

Could not review: full unified diff truncated by tooling; verified against the checked-out head at /workspace/bashkit. No build/test run per instructions.

@madsmtm

madsmtm commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

I agree with the bot that there are several places where all(target_family = "wasm", target_os = "unknown") should be used instead of just the family, but that should perhaps be done in a separate PR?

@bashkit-pr-reviewer bashkit-pr-reviewer Bot 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.

Narrowed revision is a clean mechanical widening; prior resource/CI concerns no longer apply.


#[cfg(all(
target_arch = "wasm32",
target_family = "wasm",

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[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 chaliy left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 to target_arch. I'll fix that when I squash-merge, so no need to touch it.
  • Docs nit: crates/bashkit/src/time_compat/mod.rs still says wasm32-unknown-unknown in 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:
    1. Narrow the browser-only paths to all(target_family = "wasm", target_os = "unknown"), so WASI keeps the real thread::sleep and std::time instead of spinning.
    2. 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.py will flag the Cargo.toml target key change. Please add a narrow exception for that one change, with a test.
  • CI: no need to add wasm64 to CI for now, since it needs nightly and -Zbuild-std.

Generated by Claude Code

@chaliy
chaliy merged commit 1e2a6a7 into everruns:main Nov 20, 2026
60 checks passed
@chaliy

chaliy commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

@madsmtm I am super sorry for my agent behaviour.

chaliy added a commit that referenced this pull request Nov 20, 2026
Follow-up to #2959: the time_compat, host_clock and grow_stack docs now name wasm{32,64} instead of wasm32 only.
@madsmtm

madsmtm commented Nov 21, 2026

Copy link
Copy Markdown
Contributor Author

Haha, no worries

@madsmtm
madsmtm deleted the wasm64-support branch November 21, 2026 16:37
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.

3 participants