Stream: beginners

Topic: WASI preview 2 http proxy integration for Roc


view this post on Zulip Vladimir Zotov (Nov 22 2024 at 15:28):

Hi peeps,
I've been looking at https://github.com/lukewilliamboswell/roc-platform-template-wasi/
I was trying to understand how to glue WASI APIs (e.g. https://github.com/WebAssembly/wasi-http/blob/main/proxy.md) to access from Roc side just as a PoC.
Any hints, references, examples?

view this post on Zulip Luke Boswell (Nov 22 2024 at 22:16):

It depends on a few things, like what host toolchain you prefer (rust/zig/c etc). I would suggest Rust is probably possible using wit bindgen -- I've seen a blog post that went this direction, though the preview 2 stuff is more experimental.

I would definitely recommend just letting the native cargo toolchain drive linking and everything for now.

So build roc stuff into an object file like roc build --no-link --target wasm32 app.roc and then link that when you build your .wasm module.

view this post on Zulip Vladimir Zotov (Nov 27 2024 at 14:27):

Maybe you could help me a bit more here. Roc will need a platform import, so I assume I need to provide the mapping to Roc. Are you saying I could just use a Rust platform, map existing wadi types from rust to Roc and then have both compiled to wasm? It might be gibberish what I just wrote, as my understanding is quite fuzzy here

view this post on Zulip Luke Boswell (Nov 27 2024 at 17:09):

The demo js dom thing I've just shared in another thread is a good end to end example of doing WASI with roc.

I made a WASI cli binary to help me debug things without the complications of the broswer. You could copy that as a starting point. Here is the main.rs for that.

https://github.com/lukewilliamboswell/roc-experiment-js-dom/blob/main/crates/cli/src/main.rs

This is just using Preview 1 stuff though which is included in Rust stdlib. There is a Preview 2 target but it is new and I dont think you can use it yet, so if you want to use the experimental APIs you need to generate the lowlevel bindings from WIT files manually I think.


Last updated: Jul 06 2025 at 12:14 UTC