Stream: wasmtime

Topic: Writing & Using a custom WASI implementation with wasmtime


view this post on Zulip Melody Madeline Lyons (Aug 01 2024 at 07:46):

I'd like to use wasmtime (more specifically, wasm_bridge, which is built on top of wasmtime) to add plugin support to one of my projects. It's got a custom virtual filesystem, which I'd like to use to back a custom WASI implementation.
How would I go about doing this?

view this post on Zulip Notification Bot (Aug 01 2024 at 15:48):

This topic was moved here from #general > Writing & Using a custom WASI implementation with wasmtime by fitzgen (he/him).

view this post on Zulip Alex Crichton (Aug 01 2024 at 15:56):

The general answer is that this is not well supported. The implementation of wasmtime-wasi routes filesystem things to the host filesystem. Implementing your own custom virtual filesystem would require you to not use wasmtime-wasi and supply the host imports yourself, which is likely a larger undertaking than what you're looking to bite off

view this post on Zulip Melody Madeline Lyons (Aug 01 2024 at 23:14):

So, what should I do?

view this post on Zulip Victor Adossi (Aug 02 2024 at 05:28):

Have you seen https://github.com/bytecodealliance/WASI-Virt ? It htink the goals might be somewhat similar and it might spark some inspiration!

Virtual implementations of WASI APIs. Contribute to bytecodealliance/WASI-Virt development by creating an account on GitHub.

view this post on Zulip Melody Madeline Lyons (Aug 02 2024 at 06:12):

Hmm, this is definitely useful as a reference, I think!
One of my goals though is running plugins in the browser, as my project also currently supports running in the browser (hence why I'm using wasm_bridge, which uses wasmtime on native and browser APIs on wasm) and WASI-Virt doesn't seem to align with that goal.
This is also one of my motivating reasons for writing a custom WASI implementation- my project uses the FileSystem Access API, which directly modifies the user's filesystem- so I could get plugins that interact with files to work even on the web!

view this post on Zulip Victor Adossi (Aug 02 2024 at 11:54):

Ah so in that case, you're going to want to also glance at jco as well: https://github.com/bytecodealliance/jco , just in case you haven't seen it already!

JavaScript toolchain for working with WebAssembly Components - bytecodealliance/jco

view this post on Zulip Melody Madeline Lyons (Aug 03 2024 at 11:07):

Alex Crichton said:

Implementing your own custom virtual filesystem would require you to not use wasmtime-wasi and supply the host imports yourself, which is likely a larger undertaking than what you're looking to bite off

How large of an undertaking are we talking?

view this post on Zulip Pat Hickey (Aug 03 2024 at 21:13):

the implementation of the filesystem that uses cap-std to implement a bunch of the hard parts (sandboxing access underneath a directory via openat2(2)) is around 1500loc between https://github.com/bytecodealliance/wasmtime/blob/main/crates/wasi/src/host/filesystem.rs and https://github.com/bytecodealliance/wasmtime/blob/main/crates/wasi/src/filesystem.rs

A fast and secure runtime for WebAssembly. Contribute to bytecodealliance/wasmtime development by creating an account on GitHub.
A fast and secure runtime for WebAssembly. Contribute to bytecodealliance/wasmtime development by creating an account on GitHub.

view this post on Zulip Pat Hickey (Aug 03 2024 at 21:14):

implementing a custom filesystem that is read-only and lacks symlinks/hardlinks is probably a day or two of work. the rest of that is quite a bit of complexity


Last updated: Dec 23 2024 at 14:03 UTC