wasmer-js
wasmer-js copied to clipboard
fail to read a file with deno
Steps to reproduce
- mkdir f; cd f
- cargo new a
- echo "hello">file
- echo 'fn main() {dbg!(std::fs::read_to_string("./file"));}'>a/src/main.rs
- cargo b --manifest-path a/Cargo.toml --target-dir target --target wasm32-wasi
- wasmer target/wasm32-wasi/debug/a.wasm --dir . # works, same for wasmtime
import { init, WASI } from "https://deno.land/x/[email protected]/wasi.ts";
await init();
const wasi = new WASI({});
const moduleBytes = await Deno.readFile(
"./target/wasm32-wasi/debug/a.wasm",
);
const module = await WebAssembly.compile(moduleBytes);
wasi.instantiate(module, {});
const exitCode = wasi.start();
const stdout = wasi.getStdoutString();
const stderr = wasi.getStderrString();
console.log(`${stdout}${stderr}(exit code: ${exitCode})`);
fails with
[src/main.rs:1] std::fs::read_to_string("./file") = Err(
Os {
code: 44,
kind: NotFound,
message: "No such file or directory",
},
)
(exit code: 0)
deno wasi implementation have its own issue https://github.com/denoland/deno_std/issues/3415
I guess I'm expecting wasi io to map to deno permissions which might not be the case, it might be that I have to pass relevant config here new WASI({})
So thats probably it I need to use
const wasi = new WASI({ preopens: { ".": "." } });
but this fails
error: Uncaught (in promise) Error: Failed to create the WasiState: wasi filesystem creation error: `Could not get metadata for fil
e ".": fd not a directory``
const ret = new Error(getStringFromWasm0(arg0, arg1));
^
at imports.wbg.__wbg_new_8d2af00bc1e329ee (https://deno.land/x/[email protected]/pkg/wasmer_wasi_js.js:1185:21)
at <anonymous> (https://deno.land/x/[email protected]/pkg/wasmer_wasi_js_bg.wasm:1:19665)
at new WASI (https://deno.land/x/[email protected]/pkg/wasmer_wasi_js.js:632:18)
at file:///home/mrcool/dev/deno/lab/tmp/xiU/b.ts:4:14
at eventLoopTick (ext:core/01_core.js:182:11)
using deno std implementation (https://deno.land/[email protected]/wasi/snapshot_preview1.ts) works so this maybe is a wasmerjs issue