Skip to content

Commit 0b2f81b

Browse files
committed
Node wrapper: support for using alternative Wasm engines
1 parent 93ced73 commit 0b2f81b

File tree

3 files changed

+48
-8
lines changed

3 files changed

+48
-8
lines changed

tools/ci_setup.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ let node_wrapper =
6464
(name node_wrapper)
6565
(libraries unix))|} )
6666
; "node_wrapper/node_wrapper_per_profile.ml", {|let args = []|}
67+
; "node_wrapper/node_wrapper_per_engine.ml", {|let engine = "node"|}
6768
; "node_wrapper/dune-project", "(lang dune 3.17)"
6869
; "node_wrapper/node_wrapper.opam", ""
6970
]

tools/dune

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
(executable
22
(name node_wrapper)
3-
(modules node_wrapper)
3+
(link_deps
4+
(env_var WASM_ENGINE))
5+
(modules node_wrapper node_wrapper_per_engine)
46
(libraries unix))
57

8+
(rule
9+
(target node_wrapper_per_engine.ml)
10+
(action
11+
(with-stdout-to
12+
%{target}
13+
(run echo "let engine = \"%{env:WASM_ENGINE=node}\""))))
14+
615
(executable
716
(name ci_setup)
817
(modules ci_setup)

tools/node_wrapper.ml

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
1+
let wizard_args =
2+
[ "-ext:stack-switching"; "-ext:legacy-eh"; "-stack-size=2M"; "--dir=."; "--dir=/tmp" ]
3+
4+
let wasmtime_args =
5+
[ (* "-C"; "collector=null"; *) "-W=all-proposals=y"; "--dir=."; "--dir=/tmp" ]
6+
7+
let wasmedge_args =
8+
[ "--enable-gc"
9+
; "--enable-exception-handling"
10+
; "--enable-tail-call"
11+
; "--dir=."
12+
; "--dir=/tmp"
13+
]
14+
115
let extra_args_for_wasoo =
216
[ "--experimental-wasm-imported-strings"
317
; "--experimental-wasm-stack-switching"
18+
; "--experimental-wasm-exnref"
419
; "--stack-size=10000"
520
]
621

@@ -23,16 +38,31 @@ let env =
2338
else e)
2439
env
2540

26-
let args =
41+
let environment_args () =
42+
List.filter
43+
(fun e -> not (String.contains e ','))
44+
(Array.to_list (Array.map (fun e -> "--env=" ^ e) env))
45+
46+
let wasm_file file =
47+
Filename.concat (Filename.chop_extension file ^ ".assets") "code.wasm"
48+
49+
let common_args file argv = environment_args () @ (wasm_file file :: List.tl argv)
50+
51+
let exe, args =
2752
match Array.to_list Sys.argv with
2853
| exe :: argv ->
29-
let argv =
54+
let exe', argv =
3055
match argv with
31-
| file :: _ when Filename.check_suffix file ".wasm.js" ->
32-
extra_args_for_wasoo @ argv
33-
| _ -> extra_args_for_jsoo @ argv
56+
| file :: _ when Filename.check_suffix file ".wasm.js" -> (
57+
match Node_wrapper_per_engine.engine with
58+
| "wizard" -> "wizeng.x86-linux", wizard_args @ common_args file argv
59+
| "wizard-fast" -> "wizeng.x86-64-linux", wizard_args @ common_args file argv
60+
| "wasmtime" -> "wasmtime", wasmtime_args @ common_args file argv
61+
| "wasmedge" -> "wasmedge", wasmedge_args @ common_args file argv
62+
| _ -> "node", extra_args_for_wasoo @ argv)
63+
| _ -> "node", extra_args_for_jsoo @ argv
3464
in
35-
Array.of_list (exe :: argv)
65+
exe', Array.of_list (exe :: argv)
3666
| [] -> assert false
3767

3868
let () =
@@ -45,4 +75,4 @@ let () =
4575
| _, WEXITED n -> exit n
4676
| _, WSIGNALED _ -> exit 9
4777
| _, WSTOPPED _ -> exit 9
48-
else Unix.execvpe "node" args env
78+
else Unix.execvpe exe args env

0 commit comments

Comments
 (0)