diff options
Diffstat (limited to 'tools/wasi_run.mjs')
| -rw-r--r-- | tools/wasi_run.mjs | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/tools/wasi_run.mjs b/tools/wasi_run.mjs new file mode 100644 index 0000000..ab5d95a --- /dev/null +++ b/tools/wasi_run.mjs @@ -0,0 +1,9 @@ +// Runs a wasm32-wasi program (a Zig test binary) under Node's WASI, with +// the rest of the arguments as its own; exits with its exit code. +// usage: node tools/wasi_run.mjs program.wasm [args...] +import {readFile} from 'node:fs/promises'; +import {WASI} from 'node:wasi'; + +const wasi = new WASI({version: 'preview1', args: process.argv.slice(2), env: {}, returnOnExit: true}); +const module = await WebAssembly.compile(await readFile(process.argv[2])); +process.exitCode = wasi.start(await WebAssembly.instantiate(module, wasi.getImportObject())); |
