Skip to content

Commit 80e8650

Browse files
committed
Node wrapper: support for using alternative Wasm engines
1 parent 96d73e9 commit 80e8650

File tree

2 files changed

+45
-8
lines changed

2 files changed

+45
-8
lines changed

tools/dune

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
(executable
22
(name node_wrapper)
3-
(modules node_wrapper node_wrapper_per_profile)
3+
(link_deps (env_var WASM_ENGINE))
4+
(modules node_wrapper node_wrapper_per_profile node_wrapper_per_engine)
45
(libraries unix))
56

67
(executable
@@ -14,6 +15,13 @@
1415
%{target}
1516
(run ./gen_node_wrapper_per_profile.exe %{profile}))))
1617

18+
(rule
19+
(target node_wrapper_per_engine.ml)
20+
(action
21+
(with-stdout-to
22+
%{target}
23+
(run echo "let engine = \"%{env:WASM_ENGINE=node}\""))))
24+
1725
(executable
1826
(name ci_setup)
1927
(modules ci_setup)

tools/node_wrapper.ml

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
1+
let wizard_args = [ "-ext:stack-switching"; "-stack-size=2M"; "--dir=."; "--dir=/tmp" ]
2+
3+
let wasmtime_args =
4+
[ (* "-C"; "collector=null"; *) "-W=all-proposals=y"; "--dir=."; "--dir=/tmp" ]
5+
6+
let wasmedge_args =
7+
[ "--enable-gc"
8+
; "--enable-exception-handling"
9+
; "--enable-tail-call"
10+
; "--dir=."
11+
; "--dir=/tmp"
12+
]
13+
114
let extra_args_for_wasoo =
215
[ "--experimental-wasm-imported-strings"
316
; "--experimental-wasm-stack-switching"
17+
; "--experimental-wasm-exnref"
418
; "--stack-size=10000"
519
]
620

@@ -23,16 +37,31 @@ let env =
2337
else e)
2438
env
2539

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

3867
let () =
@@ -45,4 +74,4 @@ let () =
4574
| _, WEXITED n -> exit n
4675
| _, WSIGNALED _ -> exit 9
4776
| _, WSTOPPED _ -> exit 9
48-
else Unix.execvpe "node" args env
77+
else Unix.execvpe exe args env

0 commit comments

Comments
 (0)