Skip to content

Commit 51842da

Browse files
committed
Node wrapper: support for using alternative Wasm engines
1 parent c1c840e commit 51842da

File tree

3 files changed

+53
-8
lines changed

3 files changed

+53
-8
lines changed

tools/ci_setup.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ let node_wrapper =
4949
(name node_wrapper)
5050
(libraries unix))|} )
5151
; "node_wrapper/node_wrapper_per_profile.ml", {|let args = []|}
52+
; "node_wrapper/node_wrapper_per_engine.ml", {|let engine = "node"|}
5253
; "node_wrapper/dune-project", "(lang dune 3.17)"
5354
; "node_wrapper/node_wrapper.opam", ""
5455
]

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: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,26 @@
1+
let wizard_args =
2+
[ "--ext:stack-switching"
3+
; "--ext:legacy-eh"
4+
; "--stack-size=2M"
5+
; "--dir=."
6+
; "--dir=/tmp"
7+
]
8+
9+
let wasmtime_args =
10+
[ (* "-C"; "collector=null"; *) "-W=all-proposals=y"; "--dir=."; "--dir=/tmp" ]
11+
12+
let wasmedge_args =
13+
[ "--enable-gc"
14+
; "--enable-exception-handling"
15+
; "--enable-tail-call"
16+
; "--dir=."
17+
; "--dir=/tmp"
18+
]
19+
120
let extra_args_for_wasoo =
221
[ "--experimental-wasm-imported-strings"
322
; "--experimental-wasm-stack-switching"
23+
; "--experimental-wasm-exnref"
424
; "--stack-size=10000"
525
]
626

@@ -23,16 +43,31 @@ let env =
2343
else e)
2444
env
2545

26-
let args =
46+
let environment_args () =
47+
List.filter
48+
(fun e -> not (String.contains e ','))
49+
(Array.to_list (Array.map (fun e -> "--env=" ^ e) env))
50+
51+
let wasm_file file =
52+
Filename.concat (Filename.chop_extension file ^ ".assets") "code.wasm"
53+
54+
let common_args file argv = environment_args () @ (wasm_file file :: List.tl argv)
55+
56+
let exe, args =
2757
match Array.to_list Sys.argv with
2858
| exe :: argv ->
29-
let argv =
59+
let exe', argv =
3060
match argv with
31-
| file :: _ when Filename.check_suffix file ".wasm.js" ->
32-
extra_args_for_wasoo @ argv
33-
| _ -> extra_args_for_jsoo @ argv
61+
| file :: _ when Filename.check_suffix file ".wasm.js" -> (
62+
match Node_wrapper_per_engine.engine with
63+
| "wizard" -> "wizeng.x86-linux", wizard_args @ common_args file argv
64+
| "wizard-fast" -> "wizeng.x86-64-linux", wizard_args @ common_args file argv
65+
| "wasmtime" -> "wasmtime", wasmtime_args @ common_args file argv
66+
| "wasmedge" -> "wasmedge", wasmedge_args @ common_args file argv
67+
| _ -> "node", extra_args_for_wasoo @ argv)
68+
| _ -> "node", extra_args_for_jsoo @ argv
3469
in
35-
Array.of_list (exe :: argv)
70+
exe', Array.of_list (exe :: argv)
3671
| [] -> assert false
3772

3873
let () =
@@ -45,4 +80,4 @@ let () =
4580
| _, WEXITED n -> exit n
4681
| _, WSIGNALED _ -> exit 9
4782
| _, WSTOPPED _ -> exit 9
48-
else Unix.execvpe "node" args env
83+
else Unix.execvpe exe args env

0 commit comments

Comments
 (0)