Skip to content

WASI runtime#1831

Open
vouillon wants to merge 23 commits intomasterfrom
wasi
Open

WASI runtime#1831
vouillon wants to merge 23 commits intomasterfrom
wasi

Conversation

@vouillon
Copy link
Copy Markdown
Member

@vouillon vouillon commented Feb 6, 2025

You can produce a WASI binary by running wasm_of_ocaml with the --enable wasi flag:

wasm_of_ocaml --enable wasi foo.byte -o foo.js

This produces some Wasm code that can be directly executed by the Wizard engine:

wizeng.x86-64-linux -ext:stack-switching -ext:legacy-eh foo.assets/code.wasm

wasmtime does not support the legacy exception handling instructions. You can produce a binary that will work with wasmtime as well by adding the --enable exnref flag:

wasm_of_ocaml --enable wasi --enable exnref foo.byte -o foo.js

You can then execute it with the following command:

wasmtime -W=all-proposals=y foo.assets/code.wasm

Note that we keep the same output convention, at least for now: a JavaScript file foo.js and a directory foo.assets containing the Wasm code. The JavaScript file can be use to run the WASI binary with node.

Blocked by:

@vouillon vouillon force-pushed the wasi branch 5 times, most recently from 28a41a0 to 7a4d3ff Compare February 13, 2025 16:42
@vouillon vouillon added the wasm label Feb 14, 2025
@vouillon vouillon force-pushed the wasi branch 12 times, most recently from c1fc50d to c9f7566 Compare February 20, 2025 12:55
@vouillon vouillon force-pushed the wasi branch 3 times, most recently from 85a9891 to 25a5e68 Compare February 26, 2025 17:14
@vouillon vouillon force-pushed the wasi branch 2 times, most recently from 391b19a to f3efbd6 Compare February 28, 2025 13:18
@vouillon vouillon force-pushed the wasi branch 7 times, most recently from 31610af to 2356554 Compare April 10, 2025 17:04
Comment thread compiler/bin-wasm_of_ocaml/link_wasm.ml Outdated
with
| Some "native" -> `Native
| Some "cps" -> `Cps
| _ -> `Jspi);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Waybe we should not silently ignore unknown values

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There is similar diff in #2189, is there a lot of intersection between the two ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The PR is on top of #2189.

vouillon added 23 commits May 6, 2026 17:47
Dune 3.23 derives the >= 20180523 menhir constraint from
(using menhir 3.0). Older dune versions don't, so they would
regenerate the opam files without it. State the bound explicitly
in each (depends ...) of dune-project so opam files stay stable
across dune versions, and update the opam files accordingly.
Dune 3.23 forces sandboxing on user rules, so gen.exe runs from
_build/.sandbox/<hash>/default/<dir> instead of the project tree.
The previous prefix walker (stop when parent ends with _build) then
yielded <hash>/default/<dir>/, which both shows up in the generated
;; comment and shifts the Hashtbl.hash-based name suffix, making the
runtest diff against the checked-in dune.inc fail.

Take the project-relative directory as argv.(1) (replacing the
previously unused library-name argument) so the prefix is stable
regardless of where dune runs the action.
The current release of ocaml-dune-lint is not compatible with dune 3.23.
Under dune 3.23 sandboxing, rules that run a *.bc.wasm.js file also
need to depend on the companion *.bc.wasm.assets/ directory so that
the .wasm files are copied into the sandbox.
Under dune 3.23 sandboxing, rules invoking js_of_ocaml or wasm_of_ocaml
with --toplevel need their .cmi files brought into the sandbox.

For locally built cmis, declare them as deps. For library cmis, add
a cmi_include_dirs.txt rule (mirroring the existing one for toplevel.bc)
that uses ocamlfind to produce -I flags, and pass the result via
read-strings.
Under dune 3.23 sandboxing, the test runs `node %{test} wc.ml` but
wc.ml is only referenced positionally on the command line, not as a
dune dep, so it isn't copied into the sandbox. Adding it under
(deps ...) makes the rule sandbox-clean.
It uses `js_of_ocaml --build-config` to manage config details.

Dune 3.23 sandboxes user rules by default; the necessary test
adjustments are in the following commits.
Drop CI matrix entries, opam constraints, and conditional code for
4.13. Minimum supported version is now 4.14.
Wasmtime only supports these instructions. We should eventually use
instead of the legacy instructions, but they are not allowed by default
in node.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants