summaryrefslogtreecommitdiff
path: root/tools/wasi_run.mjs
blob: ab5d95a31dd7fe0201ae53cf221f04cbd330188a (plain) (blame)
1
2
3
4
5
6
7
8
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()));