Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
b250a95
Declare menhir lower bound in dune-project and opam files
vouillon May 6, 2026
a4c7596
gen-rules: pass source dir explicitly instead of probing getcwd
vouillon May 6, 2026
6169a7c
Pin ocaml-dune-lint dev
vouillon May 6, 2026
f68c48a
Tests: declare dependency on wasm assets directory
vouillon May 6, 2026
65cd5c2
Tests: declare cmi dependencies for --toplevel rules
vouillon May 6, 2026
6dece23
Tests: declare wc.ml as a dep of the basic-io test
vouillon May 6, 2026
a863559
Switch to dune 3.23
vouillon May 5, 2026
0442ff6
OCaml 4.13 no longer supported
vouillon May 6, 2026
5239153
Update nodejs options
vouillon Jan 16, 2026
8c2bf70
Update Wasm linker to support stack switching instructions
vouillon Feb 19, 2026
dcdade1
Effects based on Stack Switching proposal
vouillon Mar 24, 2024
f180f74
Add dune profile for native effects
vouillon Feb 20, 2026
b694719
Update CI
vouillon Feb 20, 2026
a45b0d2
Document update: native effects
vouillon Mar 24, 2024
f88da80
Changes
vouillon Feb 26, 2026
6cf9eb5
Flag to generate the new exception handling instructions
vouillon Jul 4, 2024
43ca317
WASI runtime
vouillon Dec 17, 2024
9c10e6f
WASI: support for separate compilation
vouillon Feb 19, 2025
330488c
Node wrapper: support for using alternative Wasm engines
vouillon Feb 14, 2025
9cae9b5
CI updates: test WASI runtime with node and wasmtime
vouillon Feb 14, 2025
e23d051
CI: use Wizard engine as well
vouillon Feb 6, 2025
03b1318
WASI: update documentation
vouillon Sep 22, 2025
07f85ca
Changes
vouillon Sep 22, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/js_of_ocaml.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ jobs:
ocaml-name:
- ""
ocaml-compiler:
- "4.13"
- "5.0"
- "5.1"
- "5.2"
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ jobs:
with:
token: ${{ github.token }}
- run: sh tools/make_opam_dune_lint_dir.sh
- run: opam pin -n opam-dune-lint --dev-repo
- uses: ocaml/setup-ocaml/lint-opam@v3

lint-fmt:
Expand Down
94 changes: 90 additions & 4 deletions .github/workflows/wasm_of_ocaml.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,16 @@ jobs:
- false
all_jane_street_tests:
- false
wasi:
- false
include:
- os: macos-latest
os-name: MacOS
ocaml-compiler: "5.3"
separate_compilation: true
jane_street_tests: false
all_jane_street_tests: false
wasi: false
- os: windows-latest
os-name: Windows
ocaml-compiler: "5.3"
Expand All @@ -54,23 +57,33 @@ jobs:
separate_compilation: true
jane_street_tests: true
all_jane_street_tests: true
wasi: false
- os: ubuntu-latest
os-name: Ubuntu
ocaml-compiler: "5.3"
separate_compilation: false
jane_street_tests: true
all_jane_street_tests: false
wasi: false
- os: ubuntu-latest
os-name: Ubuntu
ocaml-compiler: "ocaml-variants.5.2.0+ox"
separate_compilation: true
jane_street_tests: true
all_jane_street_tests: true
wasi: false
- os: ubuntu-latest
os-name: Ubuntu
ocaml-compiler: "5.3"
separate_compilation: true
jane_street_tests: false
all_jane_street_tests: false
wasi: true

runs-on: ${{ matrix.os }}

name:
${{ (! matrix.separate_compilation) && 'Whole program / ' || ''}}${{ matrix.ocaml-compiler }} / ${{ matrix.os-name }}${{ matrix.all_jane_street_tests && ' / Jane Street tests' || ''}}
${{ matrix.wasi && 'WASI / ' || '' }}${{ (! matrix.separate_compilation) && 'Whole program / ' || ''}}${{ matrix.ocaml-compiler }} / ${{ matrix.os-name }}${{ matrix.all_jane_street_tests && ' / Jane Street tests' || ''}}

steps:
- name: Update apt cache
Expand Down Expand Up @@ -101,7 +114,55 @@ jobs:
- name: Set-up Node.js
uses: actions/setup-node@v6
with:
node-version: latest
node-version: ${{ matrix.os == 'windows-latest' && 'latest' || 'v26.0.0-v8-canary20260216631fb6e5ef' }}

- name: Set-up Rust toolchain
if: matrix.wasi
uses: actions-rust-lang/setup-rust-toolchain@v1

- name: Checkout Wasmtime
if: matrix.wasi
uses: actions/checkout@v4
with:
repository: bytecodealliance/wasmtime
path: wasmtime
submodules: true

- name: Build Wasmtime
if: matrix.wasi
working-directory: ./wasmtime
run: |
cargo build
echo `pwd`/target/debug >> "$GITHUB_PATH"

- name: Checkout Virgil
if: matrix.wasi
uses: actions/checkout@v4
with:
repository: titzer/virgil
path: virgil

- name: Build Virgil
if: matrix.wasi
working-directory: ./virgil
run: |
export PATH=$PATH:`pwd`/bin
echo `pwd`/bin >> "$GITHUB_PATH"
make

- name: Checkout Wizard engine
if: matrix.wasi
uses: actions/checkout@v4
with:
repository: titzer/wizard-engine
path: wizard-engine

- name: Build Wizard engine
if: matrix.wasi
working-directory: ./wizard-engine
run: |
make -j 4
echo `pwd`/bin >> "$GITHUB_PATH"

- name: Set-up OCaml ${{ matrix.ocaml-compiler }}
uses: ocaml/setup-ocaml@v3
Expand Down Expand Up @@ -169,7 +230,7 @@ jobs:
opam install . -t

- name: Run tests
if: ${{ matrix.separate_compilation }}
if: ${{ matrix.separate_compilation && ! matrix.wasi }}
working-directory: ./wasm_of_ocaml
run: opam exec -- dune build @runtest-wasm

Expand All @@ -178,11 +239,36 @@ jobs:
# See https://github.com/libuv/libuv/issues/3622

- name: Run tests with CPS effects
if: ${{ matrix.ocaml-compiler >= '5.' && matrix.separate_compilation }}
if: ${{ matrix.ocaml-compiler >= '5.' && matrix.separate_compilation && ! matrix.wasi }}
continue-on-error: ${{ matrix.os == 'windows-latest' }}
working-directory: ./wasm_of_ocaml
run: opam exec -- dune build @runtest-wasm --profile with-effects

- name: Run tests with native effects
if: ${{ matrix.ocaml-compiler >= '5.' && matrix.separate_compilation && matrix.os != 'windows-latest' }}
working-directory: ./wasm_of_ocaml
run: opam exec -- dune build @runtest-wasm --profile with-native-effects

- name: Run tests (WASI runtime - node)
if: ${{ matrix.wasi }}
working-directory: ./wasm_of_ocaml
run: opam exec -- dune build @runtest-wasm --profile wasi

- name: Run tests (WASI runtime - Wizard engine)
if: ${{ matrix.wasi }}
working-directory: ./wasm_of_ocaml
env:
WASM_ENGINE: wizard-fast
run: opam exec -- dune build @runtest-wasm --profile wasi

- name: Run tests (WASI runtime - wasmtime)
if: ${{ matrix.wasi }}
working-directory: ./wasm_of_ocaml
env:
WASM_ENGINE: wasmtime
WASI_FLAGS: --enable exnref
run: opam exec -- dune build @runtest-wasm --profile wasi

- name: Run Base tests
if: matrix.all_jane_street_tests
continue-on-error: ${{ matrix.os == 'windows-latest' }}
Expand Down
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
* Compiler: improved shape computation (#2198)
* Add the --build-config and --apply-build-config flags (#2177)
* Runtime/wasm: optimized some bigstring primitives (#2144)
* Wasm_of_ocaml: alternative effect implementation based on the Stack Switching proposal (#2189)
* Compiler/wasm: WASI 0.1 support (#1831)

## Bug fixes
* Compiler: fix reference unboxing (#2210)
Expand Down
2 changes: 1 addition & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ opam install odoc lwt_log yojson ocp-indent graphics higlo
```

**Requirements:**
- OCaml 4.13 to 5.4
- OCaml 4.14 to 5.4
- Dune 3.19+
- For wasm_of_ocaml: Binaryen 119+

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.3.2
6.4.0~alpha~dev
22 changes: 16 additions & 6 deletions compiler/bin-wasm_of_ocaml/cmd_arg.ml
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,18 @@ let trim_trailing_dir_sep s =

let normalize_include_dirs dirs = List.map dirs ~f:trim_trailing_dir_sep

let normalize_effects (effects : [ `Disabled | `Cps | `Jspi ] option) common :
let normalize_effects (effects : [ `Disabled | `Cps | `Jspi | `Native ] option) common :
Config.effects_backend =
match effects with
| None ->
(* For backward compatibility, consider that [--enable effects] alone means
[--effects cps] *)
if List.mem ~eq:String.equal "effects" common.Jsoo_cmdline.Arg.optim.enable
then `Cps
else if List.mem ~eq:String.equal "wasi" common.Jsoo_cmdline.Arg.optim.enable
then `Disabled
else `Jspi
| Some ((`Disabled | `Cps | `Jspi) as e) -> e
| Some ((`Disabled | `Cps | `Jspi | `Native) as e) -> e

type t =
{ common : Jsoo_cmdline.Arg.t
Expand Down Expand Up @@ -182,11 +184,15 @@ let options () =
let effects =
let doc =
"Select an implementation of effect handlers. [$(docv)] should be one of $(b,jspi) \
(the default), $(b,cps), or $(b,disabled)."
(the default), $(b,cps), $(b,native) or $(b,disabled)."
in
Arg.(
value
& opt (some (enum [ "jspi", `Jspi; "cps", `Cps; "disabled", `Disabled ])) None
& opt
(some
(enum
[ "jspi", `Jspi; "cps", `Cps; "native", `Native; "disabled", `Disabled ]))
None
& info [ "effects" ] ~docv:"KIND" ~doc)
in
let build_t
Expand Down Expand Up @@ -330,11 +336,15 @@ let options_runtime_only () =
let effects =
let doc =
"Select an implementation of effect handlers. [$(docv)] should be one of $(b,jspi) \
(the default), $(b,cps), or $(b,disabled)."
(the default), $(b,cps), $(b,native) or $(b,disabled)."
in
Arg.(
value
& opt (some (enum [ "jspi", `Jspi; "cps", `Cps; "disabled", `Disabled ])) None
& opt
(some
(enum
[ "jspi", `Jspi; "cps", `Cps; "native", `Native; "disabled", `Disabled ]))
None
& info [ "effects" ] ~docv:"KIND" ~doc)
in
let build_config = Jsoo_cmdline.Arg.build_config in
Expand Down
50 changes: 36 additions & 14 deletions compiler/bin-wasm_of_ocaml/compile.ml
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,13 @@ let preprocessor_variables () =
[ ( "effects"
, Wat_preprocess.String
(match Config.effects () with
| `Disabled | `Jspi -> "jspi"
| `Disabled -> "disabled"
| `Jspi -> "jspi"
| `Cps -> "cps"
| `Native -> "native"
| `Double_translation -> assert false) )
; "wasi", Wat_preprocess.Bool (Config.Flag.wasi ())
; "exnref", Wat_preprocess.Bool (Config.Flag.exnref ())
]

let with_runtime_files ~runtime_wasm_files f =
Expand Down Expand Up @@ -115,21 +119,26 @@ let build_runtime ~runtime_file =
; file = module_name ^ ".wat"
; source = Contents contents
})
Runtime_files.wat_files
(if Config.Flag.wasi ()
then ("libc", Runtime_files.wasi_libc) :: Runtime_files.wat_files
else Runtime_files.wat_files)
in
Runtime.build
~link_options:[ "-g" ]
~opt_options:[ "-g"; "-O2" ]
~variables
~allowed_imports:
(Some
[ "bindings"
; "Math"
; "js"
; "wasm:js-string"
; "wasm:text-encoder"
; "wasm:text-decoder"
])
(if Config.Flag.wasi ()
then [ "wasi_snapshot_preview1"; "OCaml" ]
else
[ "bindings"
; "Math"
; "js"
; "wasm:js-string"
; "wasm:text-encoder"
; "wasm:text-decoder"
]))
~inputs
~output_file:runtime_file

Expand Down Expand Up @@ -210,7 +219,10 @@ let link_and_optimize
let t = Timer.make ~get_time:Unix.time () in
let primitives =
Binaryen.dead_code_elimination
~dependencies:Runtime_files.dependencies
~dependencies:
(if Config.Flag.wasi ()
then Runtime_files.wasi_dependencies
else Runtime_files.dependencies)
~opt_input_sourcemap:opt_temp_sourcemap
~opt_output_sourcemap:opt_temp_sourcemap'
~input_file:temp_file
Expand Down Expand Up @@ -318,7 +330,14 @@ let build_js_runtime ~primitives ?runtime_arguments () =
| _ -> assert false
in
let init_fun =
match Parse_js.parse `Script (Parse_js.Lexer.of_string Runtime_files.js_runtime) with
match
Parse_js.parse
`Script
(Parse_js.Lexer.of_string
(if Config.Flag.wasi ()
then Runtime_files.js_wasi_launcher
else Runtime_files.js_launcher))
with
| [ (Expression_statement f, _) ] -> f
| _ -> assert false
in
Expand Down Expand Up @@ -682,9 +701,12 @@ let run
if binaryen_times ()
then Format.eprintf " link_and_optimize: %a@." Timer.print t2;
let wasm_name =
Printf.sprintf
"code-%s"
(String.sub (Digest.to_hex (Digest.file tmp_wasm_file)) ~pos:0 ~len:20)
if Config.Flag.wasi ()
then "code"
else
Printf.sprintf
"code-%s"
(String.sub (Digest.to_hex (Digest.file tmp_wasm_file)) ~pos:0 ~len:20)
in
let tmp_wasm_file' = Filename.concat tmp_dir (wasm_name ^ ".wasm") in
Sys.rename tmp_wasm_file tmp_wasm_file';
Expand Down
3 changes: 3 additions & 0 deletions compiler/bin-wasm_of_ocaml/dune
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
gen/gen.exe
../../runtime/wasm/runtime.js
../../runtime/wasm/deps.json
../../runtime/wasm/runtime-wasi.js
../../runtime/wasm/deps-wasi.json
../../runtime/wasm/libc.wasm
(glob_files ../../runtime/wasm/*.wat)
(glob_files ../../runtime/wasm/runtime-*.wasm))
(action
Expand Down
Loading
Loading