Stream: wasmtime

Topic: ✔ WASI preopened_dir


view this post on Zulip bachrc (Feb 22 2023 at 19:35):

Hello, using a WasiCtx in which my wasi runs, I wonder how it could parse a directory?
I saw that wasi_filesystem is being integrated to wasmtime, but I saw a preopened_dir method. But I didn’t see any documentation on it.
There is two arguments: fd, and dir
I must get the file descriptor of the host folder? Ane how can I generate a Dir object?

view this post on Zulip bjorn3 (Feb 22 2023 at 19:54):

You can use push_preopened_dir on WasiCtx (not WasiCtxBuilder) to add a preopened dir to the WasiCtx. This method only needs a dir and path, no fd. WasiDir is implemented by the wasmtime_wasi::sync::dir::Dir type which has the from_cap_std function. This function takes a wasmtime_wasi::sync::Dir as argument, which you can construct using the from_ambient_dir function. The AmbientAuthority argument can be constructed using wasmtime_wasi::sync::ambient_authority().

view this post on Zulip bachrc (Feb 22 2023 at 21:32):

Oh wow, I wouldn't have find this myself, thanks a lot xD I'm gonna try this right now

view this post on Zulip bachrc (Feb 23 2023 at 21:58):

Well I struggled to make this work, because there is wasmtime_wasi::sync::Dir and wasmtime_wasi::sync::dir::Dir.. so I struggled for an hour lol

view this post on Zulip Notification Bot (Feb 23 2023 at 21:58):

bachrc has marked this topic as resolved.


Last updated: Dec 23 2024 at 13:07 UTC