wasmerio / wasmer

🚀 The leading Wasm Runtime supporting WASIX, WASI and Emscripten
https://wasmer.io
MIT License
18.53k stars 793 forks source link

Wasix is unable to map the current directory using `WasiStateBuilder::map_dir()` #3472

Open Michael-F-Bryan opened 1 year ago

Michael-F-Bryan commented 1 year ago

Describe the bug

In the wasix branch (d34ce882e5e90ef500b51a2caacd5939e3397c82), the WasiStateBuilder::map_dir() function is unable to map the current directory on the host to the . directory on the guest.

Steps to reproduce

I am attempting to map directories like this:

    let current_dir = std::env::current_dir()?;

    let mut env = WasiState::new(program_name)
        .stdin(Box::new(stdin))
        .env("PATH_INFO", path)
        .env("REQUEST_METHOD", "GET")
        .env("QUERY_STRING", "")
        .env("SCRIPT_NAME", "asd")
        .env("SERVER_PROTOCOL", "HTTP/1.1")
        .map_dir(".", current_dir)?
        .finalize(&mut store)
        .context("Unable to instantiate the WASI state")?;

It looks like the finalize() call fails because we aren't able to get metadata for the current directory (which the error message refers to as a "file") because an "entry" wasn't found.

$ RUST_LOG=info,wasmer_wasi=debug,cgi_runner=debug cargo run -- ./no_socket_accept.wasm
   Compiling cgi-runner v0.1.0 (/Users/work/Documents/wasmer/happiness-for-success/crates/cgi-runner)
    Finished dev [unoptimized + debuginfo] target(s) in 1.94s
     Running `/Users/work/Documents/wasmer/happiness-for-success/target/debug/cgi-runner ./no_socket_accept.wasm`
2023-01-10T23:59:37.869626Z  INFO cgi_runner: Starting input=./no_socket_accept.wasm
2023-01-10T23:59:40.037270Z  INFO cgi_runner: Compiled
2023-01-10T23:59:40.039497Z DEBUG wasmer_wasi::fs: Initializing WASI filesystem
2023-01-10T23:59:40.039903Z DEBUG wasmer_wasi::fs: Attempting to preopen /Users/work/Documents/wasmer/happiness-for-success/crates/cgi-runner with alias Some(".")
Error: Unable to instantiate the WASI state

Caused by:
    wasi filesystem creation error: `Could not get metadata for file "/Users/work/Documents/wasmer/happiness-for-success/crates/cgi-runner": entry not found`

Where no_socket_accept.wasm comes from this archive: inputs.zip

Expected behavior

The directory should be mapped into the WASIX container.

Cactice commented 1 year ago

Is there any workaround for this issue? I want to read a file from wasm but I have no idea how to provide the file to wasm.

stale[bot] commented 1 month ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.