Hi everyone,
I'm an experienced developer, but pretty new to Rust, so I'm looking to contribute how I can for now.
I got started with wasmtime_wasi:sync really quickly thanks to the docs and example here: https://github.com/bytecodealliance/wasmtime/blob/main/examples/wasi/main.rs
But for my use case I needed to switch the async version and it took me a long time to get it to work. I was wondering if I could contribute some preview2 async example code and related docs page.
I've been using wasmtime to run WASI-based programs using the wasmtime and wasmtime-wasi Rust APIs. Project is basically a toy project - it's a Rock-Paper-Scissors tournament web server where people can upload wasi based bots as .wasm files to compete in the tournament. https://github.com/katharosada/wasm-snippy My plan would be to take some of the code I wrote there to get async WASI invocation to work with the preview2 API and trim it down to the minimum possible example, add plenty of comments and write corresponding documentation.
I also note this comment on an issue where someone faced a similar problem to me, that the docs for WASI usage in particular could be improved: https://github.com/bytecodealliance/wasmtime/issues/7579#issuecomment-1827104741
I would need some help to make sure that my example is showing good/correct use of the APIs, but if this is something that'd be helpful, I'm happy to put together an issue describing the above, and see how far I get with a PR.
Hmm I realise that I wasn't super clear on what I was proposing.
I want to add example code for running a preview1 WASI module - but using the wasmtime_wasi::preview2
API using the adapter logic.
For my own use case, I didn't actually have a preview2 wasm module to run, but the preview2 API supported an async implementation of the WASI API - even when accessed through the preview1 adapter. I wanted to have an async timeout for a wasm program that used sleep, and the preview2 implementation let me do that. On top of that the preview2 context builder had more APIs available to me to conveniently implement limitations on the wasm module (like making a preopen directory readonly).
Maybe this is a little too niche to be in a tutorial in the docs, but here's a first pass on the example code I had in mind: https://github.com/katharosada/wasmtime/commit/f10ca304d98b4dabcf370f859f5a5bc38ef1e241
It could be useful for anyone wanted to use the new preview2 API features but with a preview1 wasm module.
I think it'd be great to have more docs/examples around WASI, please feel free to send a PR!
agreed, just got back from winter break and this is really nice to see. the docs for wasmtime-wasi are close to the top of my list to improve this month, so i'm grateful that you are kicking the tires, finding spots where it is lacking, and especially for creating examples or any other improvements to our docs!
Great! I'll put together a PR. :)
Last updated: Dec 23 2024 at 14:03 UTC