cstruct: ship a Wasm runtime (cstruct.wat), the analog of cstruct.js#320
Draft
samoht wants to merge 2 commits into
Draft
cstruct: ship a Wasm runtime (cstruct.wat), the analog of cstruct.js#320samoht wants to merge 2 commits into
samoht wants to merge 2 commits into
Conversation
Member
Author
|
/cc @vouillon - is this the right way to support wasm_of_ocaml ? |
|
Looks good. The functions already exist under another name. So you can also just reexport them. |
samoht
force-pushed
the
wasm-runtime
branch
4 times, most recently
from
July 10, 2026 05:46
941ef74 to
a530cf9
Compare
The wasm_of_ocaml (wasm_files ...) stanza needs dune language 3.17, so bump dune-project and the dune lower bound in every package -- otherwise opam may resolve an older dune (e.g. 2.3) that cannot parse the project. Lang 3.17 also makes the dev profile treat warning 32 (unused value) as an error, so drop the unused pp_cstruct in the fuzzer and use the compile-test binding in the lwt ppx test.
wasm_of_ocaml already provides the bigstring blit, memset and memcmp operations, so cstruct.wat re-exports them under cstruct's stub names; only caml_check_alignment_bigstring is cstruct-specific.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
wasm_of_ocaml resolves a library's C primitives from Wasm modules registered with (wasm_of_ocaml (wasm_files ...)), importing runtime helpers from the env namespace. cstruct.wat mirrors cstruct.js one to one: the three bigstring blits alias the runtime's caml_bigstring_blit_* exports, fill and compare loop over caml_ba_set_1 / caml_ba_get_1 + caml_int_compare, and check_alignment is always true. Without it a program that links cstruct cannot run as wasm (the blit primitives get dummy stubs that throw).