WASM WASI Core Extension
This VS Code library extension provides API to run WASM binaries in VS Code's extension host both in the desktop and the Web. The WASM file needs to be created with a WASI Preview 1 compliant tool chain like the WASI-SDK or Rust using the wasm32-wasip1
target.
The library extension supports the following WASI specifications:
Please note that WASI is work in progress. As a result, newer versions of this extension might not be backwards compatible with older WASI standards.
There is also an additional npm module @vscode/wasm-wasi
that eases the API access to the extension.
Example
The source code of the example can be found here
First we need to define a package.json
for the extension that wants to execute a WASM process:
{
"name": "...",
...
// depend on the wasm-wasi-core extension
"extensionDependencies": [
"ms-vscode.wasm-wasi-core"
],
// Depend on the wasm-wasi facade npm module to get easier API access to the
// core extension.
"dependencies": {
"@vscode/wasm-wasi": "..."
},
}
The actual source code to execute a WASM process looks like this
// Load the WASM API
const wasm: Wasm = await Wasm.load();
const pty = wasm.createPseudoterminal();
const terminal = window.createTerminal({ name: 'My Example', pty, isTransient: true });
terminal.show(true);
const module = await WebAssembly.compile(await fs.readFile(...);
const process = await wasm.createProcess('hello', module, { stdio: pty.stdio });
await process.run();