Does anyone have an example repo showing how to write a component that works with wasmtime serve
?
there's the test programs that start with api_proxy
in crates/test-programs/src/bin, but i'm not aware of any others
a minimal C example is just
#include "bindings.h"
void exports_wasi_http_incoming_handler_handle(
bindings_own_incoming_request_t request,
bindings_own_response_outparam_t response_out) {
printf("hello world");
}
I'm working on an example repo, using that api_proxy.rs
as a starting point, as I'm talking with folks interested in seeing a step-by-step for setting the whole thing up. It takes some care to get the right wits etc.
awesome! happy to help out with that if there's any work you'd like to hand off :)
I checked out the release-14.0.0 branch to match the wasmtime serve
in the 14.0 release, but that doesn't have the api_proxy.rs example in it. I'll try copying the example from trunk and let's see what happens
Ok, I got to this repo: https://github.com/sunfishcode/hello-wasi-http and cargo component build
says
error: failed to create a target world for package `hello-wasi-http` (/home/dev/wasm/hello-wasi-http/Cargo.toml)
Caused by:
0: failed to merge local target `/home/dev/wasm/hello-wasi-http/wit`
1: package not found
--> /home/dev/wasm/hello-wasi-http/wit/command-extended.wit:4:10
|
4 | import wasi:clocks/wall-clock@0.2.0-rc-2023-10-18;
| ^----------
you might run into issues with the adapter version... you can build the wasi-http-proxy-tests crate in the 14.x branch for an example program that's pretty much the same as api_proxy.rs
I was hoping to come up with something I could build outside of the Wasmtime tree.
I think the thing to do is to get cargo component to have an adapter that matches Wasmtime 14
ah, it looks like it already does
the monotonic-clock interface in your repo is lacking a package decl, was that intentional?
no, it's copied verbatim from Wasmtime
ah, you need to manually tell cargo component about the deps. you can resolve the first error with:
cargo component add --target --path wit/deps/clocks wasi:clocks
i sent you a pr that resolves the wit issues, though build issues with the generate macro remain
https://github.com/sunfishcode/hello-wasi-http/pull/1
Thanks for your help, and thanks also to @Peter Huene for help and a key cargo component fix, I have a working demo now!
https://github.com/sunfishcode/hello-wasi-http#hello-wasi-http
Hooray! Thank you for writing this!
Last updated: Nov 22 2024 at 16:03 UTC