Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fail to read a file with WASI #3415

Closed
sigmaSd opened this issue May 31, 2023 · 3 comments
Closed

fail to read a file with WASI #3415

sigmaSd opened this issue May 31, 2023 · 3 comments
Labels
bug Something isn't working needs triage

Comments

@sigmaSd
Copy link
Contributor

sigmaSd commented May 31, 2023

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 Context from "https://deno.land/[email protected]/wasi/snapshot_preview1.ts";

const context = new Context({});

const binary = await Deno.readFile(
  "./target/wasm32-wasi/debug/a.wasm",
);
const module = await WebAssembly.compile(binary);

const instance = await WebAssembly.instantiate(module, {
  "wasi_snapshot_preview1": context.exports,
});

context.start(instance);

fails with

[src/main.rs:1] std::fs::read_to_string("./file") = Err(
    Custom {
        kind: Uncategorized,
        error: "failed to find a pre-opened file descriptor through which \"./file\" could be opened",
    },
)

I follow the code a bit it seems it fails here https://github.com/denoland/deno_std/blob/main/wasi/snapshot_preview1.ts#L848

it doesn't find the file fd preloaded it seems

@sigmaSd sigmaSd added bug Something isn't working needs triage labels May 31, 2023
@sigmaSd
Copy link
Contributor Author

sigmaSd commented May 31, 2023

wasmer-js have its own issue wasmerio/wasmer-js#321

@sigmaSd
Copy link
Contributor Author

sigmaSd commented May 31, 2023

I guess I'm expecting wasi io to map to deno permissions which might not be the case

@sigmaSd
Copy link
Contributor Author

sigmaSd commented May 31, 2023

yes making this change makes it work

const context = new Context({ preopens: { ".": "." } });

so permissions are going to be asked on that line

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage
Projects
None yet
Development

No branches or pull requests

1 participant