Skip to content

feat(bb): migrate WASM toolchain from wasi-sdk to Emscripten#22815

Open
AztecBot wants to merge 16 commits into
nextfrom
claudebox/a62d1521c38e34c3-3
Open

feat(bb): migrate WASM toolchain from wasi-sdk to Emscripten#22815
AztecBot wants to merge 16 commits into
nextfrom
claudebox/a62d1521c38e34c3-3

Conversation

@AztecBot
Copy link
Copy Markdown
Collaborator

Applies the diff from AztecProtocol/barretenberg-claude#2921 (wasi-sdk → Emscripten migration) on top of next. Source patch (mirror): https://gist.githubusercontent.com/zac-williamson/8eb9ee8a7b0b384b245456dfe34b88bb/raw/fd8eaeeb1f3d66fcfa8127e4d07d257d0171e79b/gistfile1.txt

Branch is opened on Zac's behalf — he authored / proxied the original PR. I just transcribed the patch onto next and resolved a handful of context drifts; I have not built or tested it.

What this changes

  • Switches the bb WASM toolchain from wasi-sdk (wasmtime runtime) to Emscripten / emsdk + Node runtime.
  • New .emsdk-version (4.0.7) is the single source of truth, consumed by bootstrap.sh, build-images, and container setup.
  • New barretenberg/cpp/scripts/wasm-run Node-based runner replaces barretenberg/cpp/scripts/wasmtime.sh (deleted).
  • New cmake toolchain barretenberg/cpp/cmake/toolchains/wasm-emscripten.cmake; wasm32-wasi.cmake deleted.
  • Replaces barretenberg/cpp/src/barretenberg/wasi/* glue (wasi_stubs.cpp, wasm_init.cpp) with the new wasm_threads_tests/ harness (memory growth + thread-pool exhaustion tests).
  • Reshapes barretenberg/ts/src/barretenberg_wasm/** — drops the factory/browser/, barretenberg_wasm_thread/, fetch_code/, helpers/browser/ shims that were specific to the old wasi flow; adds clean_shutdown + reentry test harnesses.
  • New bb_backends/ reorganisation (browser / node split, wasm.ts).
  • Build-image and scripts/setup-container.sh updated; node version floor lowered to 22 (Emscripten worker_threads requirement).

Manual fixups vs the upstream patch

3 hunks rejected against next due to context drift, all resolved by hand:

  1. barretenberg/cpp/cmake/arch.cmake — drops -fno-exceptions from the WASM add_compile_options line; exception handling is now owned by the new wasm-emscripten toolchain.
  2. barretenberg/cpp/scripts/ci_benchmark_ivc_flows.shWASMTIME_ALLOWED_DIRSBB_WASM_ALLOWED_DIRS, scripts/wasmtime.shscripts/wasm-run.
  3. bootstrap.sh — first hunk's context line expected_abs_yarn_version=4.13.0 doesn't exist on next (we have 4.5.2). Applied the actual changes (expected_min_node_version → 22.0.0, expected_abs_wasi_versionexpected_abs_emsdk_version) by hand and left the yarn version untouched.

Hunks intentionally not applied

  • barretenberg/.claude/skills/{benchmark-chonk,profile-chonk,remote-bench}/SKILL.md — these are modifications (not new files) but the skills don't exist on next (only stdlib-point-at-infinity and sumcheck do). The diff is delta-only, so I can't reconstruct them. If those skills should land here, push the full SKILL.md content separately.
  • docs/network_versioned_docs/version-v4.2.0/operators/setup/building-from-source.mdversion-v4.2.0 doesn't exist under docs/network_versioned_docs/ on next (only version-v2.1.11-ignition and version-v4.1.0-rc.2). The matching change to the live docs/docs-operate/operators/setup/building-from-source.md did apply.

Container-policy adjustment — please move before merging

.github/workflows/wasm-emscripten.yml (320 lines, the new wasm-grep-gate / wasm-threaded-tests / wasm-perf-gate / legacy-toolchain-compat workflow) was relocated to .github-new/workflows/wasm-emscripten.yml because this session was not started with ci-allow. Move it back before this merges:

git mv .github-new/workflows/wasm-emscripten.yml .github/workflows/wasm-emscripten.yml
rmdir .github-new/workflows .github-new

The file content is unchanged.

Suspected scratch files at the repo root — please review

These were in the source diff and look like Claude's own iterative review notes. They were applied as-is (they're not obviously CLAUDE.md-style files Claude would skip), but they don't seem like intended PR content:

  • Finalise.md
  • REVIEW_ITER_1.md
  • REVIEW_ITER_2.md
  • REVIEW_ITER_3.md

Strip them on the branch if they shouldn't ship.

Not built / not tested

This is a large multi-toolchain migration; the build container has no Docker, no preinstalled emsdk, and the new tests need the new wasm-threads Emscripten preset. Verification belongs in CI.

Sanity / application notes

Full notes (including totals, every skipped hunk, and what the diff does per area) are in:
https://gist.github.com/AztecBot/5f8c2c2c87f0580383b9ba341bec8ef8

ClaudeBox log: https://claudebox.work/s/a62d1521c38e34c3?run=3

@AztecBot AztecBot added ci-draft Run CI on draft PRs. claudebox Owned by claudebox. it can push to this PR. labels Apr 28, 2026
@zac-williamson zac-williamson added ci-full Run all master checks. ci-draft Run CI on draft PRs. and removed ci-draft Run CI on draft PRs. ci-full Run all master checks. labels Apr 28, 2026
@zac-williamson zac-williamson marked this pull request as ready for review April 28, 2026 15:55
zac-williamson and others added 7 commits April 28, 2026 18:12
….sh $USER

# Conflicts:
#	barretenberg/cpp/src/barretenberg/polynomials/backing_memory.cpp
…asm_bin exec

`bb` (built by the wasm-threads preset) links against the `barretenberg`
target. Previously under WASM, `barretenberg` was an `add_executable` and
the link line emits `-lbarretenberg`, which wasm-ld fails to resolve.

Split the target: `barretenberg` is always a static library (so `bb` and
other consumers can link it), and the WASM bundle is produced by a new
`barretenberg_wasm_bin` executable target with `OUTPUT_NAME barretenberg`
(so artifacts on disk remain `barretenberg.js` / `barretenberg.wasm`).

Also pin bb / bb-avm WASM link options: -sNODERAWFS=1, -sPROXY_TO_PTHREAD=0,
-sALLOW_BLOCKING_ON_MAIN_THREAD=1 — bb has main() and reads CRS from disk;
the toolchain default proxies main onto a worker which silently zeros file
ops under NODERAWFS (Emscripten #19330).
…meta.url

`run_test.sh` runs jest with `--rootDir ./dest/node` from `barretenberg/ts/`,
so the test file at runtime lives at `dest/node/barretenberg/clean_shutdown.test.js`
and `path.resolve(import.meta.url, '..', '..')` lands in `dest/`, where the
harness source does not exist (it stays in `src/`). The test would silently
time out at 30s. Use `process.cwd()` (set by run_test.sh to the package
root) and join from there.
…m targets

preset_cache_paths only matched targets by name + native sibling extensions
(.exe, .node, lib*.a). Emscripten emits a .js loader and .worker.mjs pthread
worker alongside every .wasm exec target as a unit, so cache_upload missed
them and a wasm-threads cache hit restored barretenberg.wasm without the
matching barretenberg.js.

bb-ts/scripts/copy_wasm.sh then unconditionally copies cpp/build-wasm-threads/
bin/barretenberg.js into dest/<flavor>/barretenberg_wasm/, which fast-mode CI
hits before any cache miss can rebuild the cpp side, producing:
  cp: cannot stat '../cpp/build-wasm-threads/bin/barretenberg.js': No such file or directory

Extend preset_cache_paths so any target ending in .wasm also picks up the
$stem.js and $stem.worker.mjs siblings from the same bin/ directory.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-draft Run CI on draft PRs. claudebox Owned by claudebox. it can push to this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants