I've been looking into WASI Preview 2 and it seems like some important functionality has been lost: The ability to define my own virtual file system by implementing the Dir and File traits. The types are now fully concrete: https://docs.rs/wasmtime-wasi/18.0.2/wasmtime_wasi/preview2/struct.WasiCtxBuilder.html#method.preopened_dir
Is there a plan to fix this or is there maybe some other way that I haven't discovered yet?
In particular I'm mostly interested in implementing the Dir trait to prevent write access to the files. This was my workaround until now to the permissions systrem also having disappeared in recent wasmtime versions.
prevent write access to the files
This particular feature is still available via the file_perms
argument of preopened_dir
(see also perms
if you need the directory to be read-only as well)
Oh wow, I must be blind. I didn't even look at the parameters properly, assuming the permissions would be gone there as well like in preview 1.
mmh, I do however indeed have one folder that's entirely implemented via a trait. Is there no way to do this now?
I believe there is no direct equivalent to the old WasiFile
/WasiDir
traits for WASI 0.2. It should still be possible to implement a virtual filesystem but I don't know of any friendly wrappers so it would require digging pretty deeply into the wasi filesystem details.
Depending on your exact requirements wasi-virt might be of interest too: https://github.com/bytecodealliance/WASI-Virt/?tab=readme-ov-file#filesystem
that's what I was thinking....
Yes it's intentional that the Wasi{File,Dir}
traits did not survive the transition to preview2. No fundamental issues with p2 vs p1, just a decision we made when writing the wasmtime-wasi
crate's support. It was concluded that supporting the traits-of-old was too much of a maintenance burden on us for not enough benefit.
It's always possible to implement the bindgen-generated traits in a custom fashion and add those to a linker instead of adding the wasmtime-wasi
implementations to the linker. That's of course much of a larger lift than just implementing the file/dir traits, however. Some of the tricky parts around polling and streams, however, are still taken care of automatically with the I/O interface.
Last updated: Dec 23 2024 at 13:07 UTC