Skip to content

fix(vm): build openvm-circuit for wasm32-unknown-unknown - #3178

Open
pauldelucia wants to merge 1 commit into
openvm-org:mainfrom
willow-network:fix/wasm32-abi-stable
Open

pauldelucia wants to merge 1 commit into
openvm-org:mainfrom
willow-network:fix/wasm32-abi-stable

Conversation

@pauldelucia

@pauldelucia pauldelucia commented Oct 27, 2026 •

Copy link
Copy Markdown

We want to verify OpenVM STARK proofs in the browser, but openvm-verify-stark-host doesn't build for wasm32-unknown-unknown. openvm-circuit depends on abi_stable unconditionally, and abi_stable needs libloading::Library, which libloading only defines on unix and windows:

error[E0432]: unresolved imports `libloading::Library`, `libloading::Symbol`
error: could not compile `abi_stable` (lib) due to 1 previous error

The only use is the RVec<u32> field addr_space_access_count in arch/execution_mode/metered/memory_ctx.rs. This moves abi_stable into the existing cfg(any(unix, windows)) dependency section next to memmap2 and gives the field an alias that's RVec<u32> on unix and windows and Vec<u32> elsewhere, like the MemoryBackend split in online.rs. The field is now built with collect(), which works for both types (.into() would be a same-type conversion on wasm32 and trips clippy::useless_conversion).

Unix and windows keep RVec because the AOT assembly reads the field's first word as its buffer pointer (extensions/rv32im/circuit/src/common/mod.rs), which RVec's repr(C) layout guarantees. AOT is x86_64-only and needs libloading::Library itself, so it never runs on the targets that get Vec. If you'd rather drop abi_stable altogether, making the field a Box<[u32]> like page_indices_since_checkpoint would also work, since the assembly already reads that field's pointer the same way. This PR leaves native builds on RVec as they are.

Testing

  • cargo clippy -p openvm-circuit --all-targets --tests -- -D warnings and cargo +nightly fmt --all -- --check pass (aarch64-apple-darwin).
  • cargo clippy -p openvm-circuit --target wasm32-unknown-unknown -- -D warnings passes, with getrandom's JS backends enabled for the run (js for 0.2, wasm_js for 0.3).
  • A small wasm-bindgen crate that depends on openvm-verify-stark-host builds for wasm32-unknown-unknown on this branch and fails on main with the error above.

Building openvm-verify-stark-host for wasm32 also needs a clang with a wasm32 target, for zstd-sys. Neither that nor the getrandom backends needs a change here. We can add a wasm32 build to CI if that's useful.

abi_stable needs libloading::Library, which libloading only defines on
unix and windows, so openvm-circuit (and openvm-verify-stark-host with it)
failed to build for wasm32-unknown-unknown. Its only use is the RVec<u32>
field addr_space_access_count in the metered memory context. Move
abi_stable into the existing cfg(any(unix, windows)) dependency section
next to memmap2, and give the field a type alias that is RVec<u32> on unix
and windows and Vec<u32> elsewhere, like the MemoryBackend split in
online.rs. The field is now built with collect(), which works for both
(into() would be a same-type conversion on wasm32).

Unix and windows keep RVec because the AOT assembly relies on its repr(C)
layout for this field. AOT is x86_64-only and needs libloading::Library
too, so it never runs on the targets that get Vec.
@pauldelucia
pauldelucia force-pushed the fix/wasm32-abi-stable branch from ff070c8 to 3780984 Compare December 2, 2026 09:37

This branch has not been deployed

No deployments
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