-
Notifications
You must be signed in to change notification settings - Fork 6
Open
Description
This works on Node.js with node:wasi
:
import { readFile } from 'node:fs/promises';
import { WASI } from 'node:wasi';
import { argv, env } from 'node:process';
const wasi = new WASI({
version: 'preview1',
args: [argv[1], '--help'],
features: [],
env,
});
const wasm = await WebAssembly.compile(
await readFile(new URL('./dist/bee.wasm', import.meta.url)),
);
const instance = await WebAssembly.instantiate(wasm, wasi.getImportObject());
wasi.start(instance);
This doesn't work on Deno, nor Bun:
import { readFile } from 'node:fs/promises'
import { useArgs, useEnviron, useStdio, WASI } from 'npm:uwasi'
import { argv, env } from 'node:process'
const wasi = new WASI({
version: 'preview1',
args: [argv[1], '--help'],
features: [useEnviron, useArgs, useStdio],
env,
})
const wasm = await WebAssembly.compile(
await readFile(new URL('./dist/bee.wasm', import.meta.url)),
)
const instance = await WebAssembly.instantiate(wasm, {
wasi_snapshot_preview1: wasi.wasiImport,
})
wasi.start(instance)
The error is this:
error: Uncaught (in promise) RangeError: Maximum call stack size exceeded
at WASI.wasiImport.<computed> (file:///Users/user/Library/Caches/deno/npm/registry.npmjs.org/uwasi/1.4.1/lib/esm/index.js:1:1)
at runtime.fd_write (wasm://wasm/12e425de:1:833563)
at runtime.write1 (wasm://wasm/12e425de:1:833910)
at runtime.write (wasm://wasm/12e425de:1:1479550)
at runtime.writeErrData (wasm://wasm/12e425de:1:1062994)
at runtime.badsystemstack (wasm://wasm/12e425de:1:1157894)
at runtime.systemstack (wasm://wasm/12e425de:1:1488639)
at runtime.throw (wasm://wasm/12e425de:1:1438248)
at runtime.write1 (wasm://wasm/12e425de:1:834025)
at runtime.write (wasm://wasm/12e425de:1:1479550)
if it's related to permissions (as I see fd_write
) - probably it's better to output a nicer error message that makes it clear on what's wrong
Metadata
Metadata
Assignees
Labels
No labels