Skip to content

ariadne_wasm: the WAMR backend, so arix's guests run where there is no wasmtime (G3) - #1592

Merged
transfix merged 6 commits into
masterfrom
feat/wamr-guest-runtime
Nov 28, 2026
Merged

transfix merged 6 commits into
masterfrom
feat/wamr-guest-runtime

Conversation

@transfix

@transfix transfix commented Nov 27, 2026 •

Copy link
Copy Markdown
Owner

Phase G3 of ARIADNE_SCRIPTING_HOSTS.md: a WAMR backend behind guest_runtime.h. With it, arix (and later ariglx) can run a document's wasm guests on FreeBSD, OpenBSD, NetBSD and Haiku, where cvcpkg has no wasmtime. Its packages came in cy-pca/cvcpkg#648 (merged, on cvcpkg.org): wamr cvc.4 with BSD and Haiku rows, and a new binaryen 129.

Selecting a runtime

  • cvc_find_ariadne_wasm takes WAMR where it finds no wasmtime.
  • -DCVC_ARIADNE_WASM_RUNTIME=wamr forces WAMR, =wasmtime requires wasmtime, and auto is the default.
  • wasmtime stays the runtime wherever it exists.

wamr_runtime.cpp, on WAMR's wasm-c-api:

  • Guests pause by Asyncify, as browser_runtime.cpp does. The imports call the guest's own asyncify_* exports from inside the import, which WAMR allows on the same execution environment.
  • A guest that wasn't transformed at install is transformed as it loads, as wasmtime meters one: WAT read as a binary, the gas pass, then Asyncify. That is binaryen in process (wasm_transform.cpp, its C++ API). Without binaryen the backend runs only transformed guests, like the browser.
  • No process-wide state. Each instance has its own store and its own imports. There is no native table, and WAMR's engine is reference-counted per Runtime.
  • WAMR quirks it covers:
    • A start function runs during instantiation, before the c-api wires the imports. So the start section becomes an export that runs right after.
    • The transform's -O1 drops an import nothing calls. So imports are judged as the guest was written, by imports_match, now shared with the browser in wasm_binary.cpp.
    • Host trap texts are cut at 107 bytes.
    • wasm_instance_new adds a heap page.
    • Uninitialized c-api vectors count no elements.
    • wasm_extern_as_func is an unchecked cast.
  • wamr_load.cpp: the native loader's validation text, and whether a binary is already metered and transformed. wasm_export.h and wasm_c_api.h can't share a file.

Tests

  • Local run on Windows, MSVC, with CVC_ARIADNE_WASM_RUNTIME=wamr, wamr cvc.4 and binaryen 129 built from physics: draw a world in a scene graph between its last two states (P6a) #648's recipes:
    • ariadne_wasm_test: 48 of 48;
    • ariadne_wasm_transform_test: 21 of 21, including the browser's unwind-room cases and its import-type messages, which now also run on WAMR;
    • arix_wasm_block, arix_wasi_stubs and ari_wasm_needs_arix: 3 of 3.
  • The new wasm-wamr job runs the same set on Linux with WAMR forced on. It installs wamr==2.4.4+cvc.4 and binaryen from cvcpkg.org (wamr on the BSDs and Haiku, and binaryen 129, for libcvc's wasm guests there cy-pca/cvcpkg#648, merged and published). wamr is pinned because cvc.3 has WAMR's own WASI on.
  • Three test guests change on every backend:
    • The gas tests' loop gets the ABI's memory and ari_alloc, which an Asyncify backend takes its unwind room from.
    • The WASI guest's 1024 iovecs move to the top of its page, clear of a heap the room pushed up.
    • The GC type the gas pass refuses is written as bytes, because binaryen drops unused types.

Found on the way (not fixed here)

  • A ServerDocument's step doesn't advance the app's pump frame (starts_frame runs only when group 0 has live processes). So a client guest's 8 ms frame budget (wasm_frame_budget), once spent, stays spent.
  • With wasmtime the tests never spend it. On WAMR's interpreter, WasmClientGuestTest's last two guests never got a slice. The fixture now turns the budget off, with a comment, and the pump bug itself is a follow-up.

Recipes

  • arix gains freebsd, openbsd and netbsd rows, on wamr and binaryen instead of wasmtime.
  • ariglx gets no BSD rows yet: pycvc-gl-cp312 needs vtk-python-cp312, which has no BSD build.

Not to merge without Joe's OK.

…o wasmtime (G3)

arix and ariglx run a document's WebAssembly guests on wasmtime, which
cvcpkg publishes for Linux, macOS and Windows only. This adds the backend
the roadmap plans for the rest (ARIADNE_SCRIPTING_HOSTS.md, phase G3):
guest_runtime.h on WAMR's wasm-c-api, which cvcpkg builds for FreeBSD,
OpenBSD, NetBSD and Haiku (cy-pca/cvcpkg#648).

cvc_find_ariadne_wasm takes WAMR where it finds no wasmtime, and
-DCVC_ARIADNE_WASM_RUNTIME=wamr forces it where wasmtime is there too.
wasmtime stays the default wherever it exists.

WAMR can't pause a running call, so a guest pauses by Asyncify, as in the
browser. The host's imports start and stop the unwind and the rewind by
calling the guest's own Asyncify exports from inside the import. The
slices, the waits, the unwind room and its overrun follow browser_runtime.cpp.

A guest that wasn't transformed at install is transformed as it loads, as
wasmtime meters one. WAT text is read as a binary, the gas pass meters it,
then binaryen's Asyncify runs around its ari imports. That is binaryen in
process (wasm_transform.cpp, the cvcpkg binaryen package), on its C++ API,
because the C API exits the process on bad WAT and keeps its pass options
process-wide. Without binaryen the backend takes only transformed guests,
as the browser does.

Each instance has a store of its own and imports with environments, so no
table of natives is registered anywhere. A module is loaded once per memory
cap and shared into each instance's store. The memory cap is the module's
own maximum, lowered by cap_memory. wamr_load.cpp asks WAMR's native loader
whether a binary loads and what it holds; its header and the wasm-c-api's
can't share a file.

WAMR differs from wasmtime in places the backend has to cover:
- WAMR runs a start function while it instantiates, before the wasm-c-api
  has wired the host's imports. So the start section becomes an export
  (start_as_export, wasm_binary.h), which runs once the imports are there,
  on the start's own gas.
- The transform's -O1 drops an import nothing calls. So a guest's imports
  are checked as it was written, by the browser's imports_match, which moves
  to wasm_binary.cpp for both.
- A host callback's result vector arrives empty but for its size.
- A host trap's text is cut at 107 bytes, so the backend keeps the whole
  text.
- wasm_instance_new adds a host heap page to the guest's memory, so
  instances are made with no heap.
- The c-api's vectors made uninitialized count no elements.
- wasm_extern_as_func casts whatever it is given.

The engine's tests run on WAMR with binaryen: ariadne_wasm_test (WAT
guests), ariadne_wasm_transform_test (with the browser's unwind-room cases
and its import-type messages), and arix_wasm_block, arix_wasi_stubs and
ari_wasm_needs_arix. ci.yml's new wasm-wamr job runs them on Linux with WAMR
forced on. It installs wamr and binaryen from the catalog. Three test
guests change for every backend:
- The gas tests' loop gains the guest ABI's memory and ari_alloc. A backend
  that pauses by Asyncify takes its unwind room from them.
- The WASI guest's 1024 iovecs move to the top of its page. The room moves
  its heap, and its output then landed on them.
- The GC type the gas pass refuses is bytes. binaryen writes no type that
  nothing uses.
The client guests' cases turn the frame budget off. A ServerDocument's
step doesn't advance the app's pump frame, so a budget once spent stays
spent. On WAMR's interpreter it was spent before the last two guests ran.

The arix recipe gains freebsd, openbsd and netbsd rows, on wamr and binaryen
there instead of wasmtime. Haiku has no row because it has no python312.
ariglx gets no BSD rows yet: its pycvc-gl-cp312 needs vtk-python-cp312,
which has no BSD build.
cvcpkg's binaryen has no netbsd row (cy-pca/cvcpkg#648): NetBSD's base
libstdc++ is GCC 10's, older than binaryen 129 needs. arix there runs on
WAMR without it, taking guests transformed at install.
… recipes

The job installed wamr and binaryen from cvcpkg.org, which has wamr only at
cvc.3 (with WAMR's own WASI, which takes a guest's WASI imports from the
host) and no binaryen until cy-pca/cvcpkg#648 is published, so it failed at
its install step. It now checks out that PR's recipes at a pinned commit and
builds both with cvcpkg build, then installs python312 from the catalog.
Once #648 is published the step goes back to cvcpkg install.
transfix added a commit to cy-pca/cvcpkg that referenced this pull request Nov 28, 2026
…s there (#648)

wamr 2.4.4+cvc.4 gains freebsd, openbsd, netbsd and haiku rows (WAMR's freebsd
platform layer, software bounds checks, no SIMD; no MAP_32BIT off FreeBSD; on
NetBSD no mremap, renamed popcount32/64 and PROT_MPROTECT for PaX). On every
platform it builds without WAMR's own WASI and with reference types, bulk
memory, tail calls and extended constants on. The windows bundle now ships the
static libiwasm.lib, not iwasm.exe's import library. test.sh runs a wasm-c-api
check: host re-entry, memory grow, host trap.

binaryen 129 (new): static library, C++20 headers under include/binaryen, and
wasm-opt, wasm-as and wasm-dis, for linux, macos, freebsd, openbsd, haiku and
windows (no netbsd: base libstdc++ is too old).

Both are for libcvc's WAMR guest runtime (transfix/libcvc#1592).
cy-pca/cvcpkg#648 is merged and published, so the job no longer builds them from
that PR's recipes. wamr is pinned at 2.4.4+cvc.4: cvc.3 has WAMR's own WASI on.
arix's freebsd, openbsd and netbsd rows run its wasm guests on WAMR, so the tag's
fleet DAG submits it with the rest of the family's BSD columns.
@transfix
transfix merged commit 0f11e6e into master Nov 28, 2026
57 of 58 checks passed
@transfix
transfix deleted the feat/wamr-guest-runtime branch November 28, 2026 17:54
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