Stream: wasmtime

Topic: wasmtime serve


view this post on Zulip Dan Gohman (Oct 25 2023 at 18:00):

Does anyone have an example repo showing how to write a component that works with wasmtime serve?

view this post on Zulip Trevor Elliott (Oct 25 2023 at 18:04):

there's the test programs that start with api_proxy in crates/test-programs/src/bin, but i'm not aware of any others

view this post on Zulip Till Schneidereit (Oct 25 2023 at 18:13):

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");
}

view this post on Zulip Dan Gohman (Oct 25 2023 at 18:15):

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.

view this post on Zulip Trevor Elliott (Oct 25 2023 at 18:25):

awesome! happy to help out with that if there's any work you'd like to hand off :)

view this post on Zulip Dan Gohman (Oct 25 2023 at 18:27):

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

view this post on Zulip Dan Gohman (Oct 25 2023 at 18:39):

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;
             |          ^----------
Contribute to sunfishcode/hello-wasi-http development by creating an account on GitHub.

view this post on Zulip Trevor Elliott (Oct 25 2023 at 18:46):

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

view this post on Zulip Dan Gohman (Oct 25 2023 at 18:46):

I was hoping to come up with something I could build outside of the Wasmtime tree.

view this post on Zulip Dan Gohman (Oct 25 2023 at 18:53):

I think the thing to do is to get cargo component to have an adapter that matches Wasmtime 14

view this post on Zulip Dan Gohman (Oct 25 2023 at 18:54):

ah, it looks like it already does

view this post on Zulip Trevor Elliott (Oct 25 2023 at 18:56):

the monotonic-clock interface in your repo is lacking a package decl, was that intentional?

view this post on Zulip Dan Gohman (Oct 25 2023 at 18:57):

no, it's copied verbatim from Wasmtime

view this post on Zulip Trevor Elliott (Oct 25 2023 at 19:09):

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

view this post on Zulip Trevor Elliott (Oct 25 2023 at 19:31):

i sent you a pr that resolves the wit issues, though build issues with the generate macro remain

view this post on Zulip Trevor Elliott (Oct 25 2023 at 19:32):

https://github.com/sunfishcode/hello-wasi-http/pull/1

Fix some issues with the build: The local deps need to be present in Cargo.toml The crate needs to produce a lib, as the main is non-functional There needs to be a single world present in the wit ...

view this post on Zulip Dan Gohman (Oct 25 2023 at 21:45):

Thanks for your help, and thanks also to @Peter Huene for help and a key cargo component fix, I have a working demo now!

view this post on Zulip Dan Gohman (Oct 25 2023 at 21:45):

https://github.com/sunfishcode/hello-wasi-http#hello-wasi-http

Contribute to sunfishcode/hello-wasi-http development by creating an account on GitHub.

view this post on Zulip Pat Hickey (Oct 26 2023 at 05:50):

Hooray! Thank you for writing this!


Last updated: Oct 23 2024 at 20:03 UTC