Skip to content

Commit 32b97d0

Browse files
authored
utils/wasm: Add Node.js WASI runner (#83524)
This runner can be utilized as an alternative to WasmKit when running tests or executables from Swift packages compiled to Wasm, when better performance or improved coverage of WASI 0.1 ABI is needed. This script is meant to be running only locally at this time and doesn't assume presence of Node.js on CI, since no CI scripts were changed.
1 parent b982f16 commit 32b97d0

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

utils/wasm/node-wasi-runner

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env node --disable-warning=ExperimentalWarning
2+
3+
//===----------------------------------------------------------------------===//
4+
//
5+
// This source file is part of the Swift open source project
6+
//
7+
// Copyright (c) 2025 Apple Inc. and the Swift project authors
8+
// Licensed under Apache License v2.0 with Runtime Library Exception
9+
//
10+
// See https://swift.org/LICENSE.txt for license information
11+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
12+
//
13+
//===----------------------------------------------------------------------===//
14+
15+
const { readFile } = require('node:fs/promises');
16+
const { WASI } = require('node:wasi');
17+
const { argv, env } = require('node:process');
18+
19+
const wasmFile = argv[2];
20+
21+
const wasi = new WASI({
22+
version: 'preview1',
23+
args: argv.splice(2),
24+
env,
25+
preopens: {
26+
},
27+
});
28+
29+
(async () => {
30+
const wasm = await WebAssembly.compile(
31+
await readFile(wasmFile)
32+
);
33+
const instance = await WebAssembly.instantiate(wasm, wasi.getImportObject());
34+
35+
wasi.start(instance);
36+
})();

0 commit comments

Comments
 (0)