Stream: git-wasmtime

Topic: wasmtime / issue #4925 Example of using `WasiFile` and `W...


view this post on Zulip Wasmtime GitHub notifications bot (Sep 19 2022 at 16:16):

xpepermint opened issue #4925:

I'd kindly ask the community to provide an example of how to pass files and folders to WasiCtx based on the scaffold below:

fn main() -> Result<()> {
    let engine = Engine::default();

    let mut linker = Linker::new(&engine);
    wasmtime_wasi::add_to_linker(&mut linker, |s| s)?;

    let mut wasi = WasiCtxBuilder::new()
        .inherit_stdio()
        .inherit_stdout()
        .build();

    wasi.insert_file(1, ...); // ???
    wasi.insert_dir(2, ...); // ???
    ...
}

view this post on Zulip Wasmtime GitHub notifications bot (Sep 19 2022 at 19:37):

lann commented on issue #4925:

If you don't want to dig deep into the internals of how WASI works, the only "friendly-ish" interface is to attach an entire directory with https://docs.rs/wasmtime-wasi/0.39.1/wasmtime_wasi/sync/struct.WasiCtxBuilder.html#method.preopened_dir

This is adapted from working code but otherwise untested:

let host_dir = "/host/directory";
let guest_dir = "/guest/directory";

let dir = wasmtime_wasi::Dir::open_ambient_dir(host_dir, wasi_cap_std_sync::ambient_authority())?;

let mut wasi = WasiCtxBuilder::new()
    // ...
    .preopened_dir(dir, guest_dir)
    .build();

view this post on Zulip Wasmtime GitHub notifications bot (Sep 20 2022 at 07:45):

xpepermint commented on issue #4925:

@lann this should work for now. Thank you.

view this post on Zulip Wasmtime GitHub notifications bot (Sep 20 2022 at 07:45):

xpepermint closed issue #4925:

I'd kindly ask the community to provide an example of how to pass files and folders to WasiCtx based on the scaffold below:

fn main() -> Result<()> {
    let engine = Engine::default();

    let mut linker = Linker::new(&engine);
    wasmtime_wasi::add_to_linker(&mut linker, |s| s)?;

    let mut wasi = WasiCtxBuilder::new()
        .inherit_stdio()
        .inherit_stdout()
        .build();

    wasi.insert_file(1, ...); // ???
    wasi.insert_dir(2, ...); // ???
    ...
}


Last updated: Nov 22 2024 at 17:03 UTC