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.
This commit is contained in:
Max Desiatov
2025-08-04 23:02:35 +01:00
committed by GitHub
parent b982f164cd
commit 32b97d0e85

36
utils/wasm/node-wasi-runner Executable file
View File

@@ -0,0 +1,36 @@
#!/usr/bin/env node --disable-warning=ExperimentalWarning
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift open source project
//
// Copyright (c) 2025 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
const { readFile } = require('node:fs/promises');
const { WASI } = require('node:wasi');
const { argv, env } = require('node:process');
const wasmFile = argv[2];
const wasi = new WASI({
version: 'preview1',
args: argv.splice(2),
env,
preopens: {
},
});
(async () => {
const wasm = await WebAssembly.compile(
await readFile(wasmFile)
);
const instance = await WebAssembly.instantiate(wasm, wasi.getImportObject());
wasi.start(instance);
})();