Stream: wasi

Topic: Help: Wasmtime's runner for WASI-HTTP p2 guest


view this post on Zulip Chris Suszynski (Jul 01 2025 at 13:33):

Hi there. I'm trying to develop a PoC of having the Wasmtime-based runner to execute wasi-http p2 guest. For the guest, I tried doing a similar thing that Dan did here: https://github.com/sunfishcode/hello-wasi-http, but instead of generating all the bindings from WIT files, I tried using wasi 0.14 crate.

Here you could see my code:

While trying to execute the runner, I get:

Error: component imports instance `wasi:cli/environment@0.2.4`, but a matching implementation was not found in the linker

Caused by:
    0: instance export `get-environment` has the wrong type
    1: function implementation is missing

Does this could be done, in a way I'm trying? Can someone help with this?

Contribute to sunfishcode/hello-wasi-http development by creating an account on GitHub.
A WASM (wasi) runner for Knative. Contribute to cardil/knative-serving-wasm development by creating an account on GitHub.
A WASM (wasi) runner for Knative. Contribute to cardil/knative-serving-wasm development by creating an account on GitHub.

view this post on Zulip bjorn3 (Jul 01 2025 at 13:59):

You will likely need to call wasmtime_wasi::p2::add_to_linker_async on the linker too. Your wasm component depends on the wasi-cli interfaces like all components compiled for the wasm32-wasip2 rustc target.

view this post on Zulip Lann Martin (Jul 01 2025 at 14:00):

You are linking wasmtime_wasi_http into your host but that doesn't include all of the interfaces needed by Rust wasi targets. You would either need your guest to target wasm32-unknown-unknown or ... do what bjorn3 just said :slight_smile:

view this post on Zulip Chris Suszynski (Jul 01 2025 at 15:07):

@Lann Martin I'm building the guest like this: build/tasks/build.go#L24-L25, so using the wasm32-wasip2 target. So, I thought it would have those interfaces.

A WASM (wasi) runner for Knative. Contribute to cardil/knative-serving-wasm development by creating an account on GitHub.

view this post on Zulip Lann Martin (Jul 01 2025 at 16:13):

Yes, by targetting wasm32-wasip2 your guest is implicitly importing a bunch of wasi interfaces that aren't currently provided by your host, which currently only implements the wasi:http/proxy world by linking with wasmtime_wasi_http.

A WASM (wasi) runner for Knative. Contribute to cardil/knative-serving-wasm development by creating an account on GitHub.

view this post on Zulip Lann Martin (Jul 01 2025 at 16:16):

I haven't worked on this for the latest versions of wasmtime but I think you would need to switch to instead use these two functions:

view this post on Zulip Chris Suszynski (Jul 01 2025 at 17:57):

@Lann Martin Yes, it works!! Thanks a lot! You can see the change here: https://github.com/cardil/knative-serving-wasm/pull/4

🥳 🍾 The runner works as expected: $ http :8000 text=='Hola!' HTTP/1.1 200 OK date: Tue, 01 Jul 2025 17:44:50 GMT transfer-encoding: chunked !aloH Runner process: $ cargo run --color=alway...

view this post on Zulip Chris Suszynski (Jul 01 2025 at 18:09):

The wasmtime_wasi_http crate, shows in the usage example - https://docs.rs/wasmtime-wasi-http/34.0.1/wasmtime_wasi_http/index.html to just use:

wasmtime_wasi_http::add_to_linker_async(&mut linker)?;

But that does not work either. I wonder if the doc is wrong on this? Probably yes, as the tests are using this working tandem (I should have been looking at the tests, they never lie!):

https://github.com/bytecodealliance/wasmtime/blob/c953cc8fd16df3ff73853101402f343436ab4cef/crates/wasi-http/tests/all/p2/async_.rs#L15-L16

A lightweight WebAssembly runtime that is fast, secure, and standards-compliant - bytecodealliance/wasmtime

view this post on Zulip Chris Suszynski (Jul 01 2025 at 18:10):

Once again, thanks for your help, folks! I appreciate it very much!

view this post on Zulip Ralph (Jul 01 2025 at 18:15):

Chris Suszynski said:

The wasmtime_wasi_http crate, shows in the usage example - https://docs.rs/wasmtime-wasi-http/34.0.1/wasmtime_wasi_http/index.html to just use:

wasmtime_wasi_http::add_to_linker_async(&mut linker)?;

But that does not work either. I wonder if the doc is wrong on this? Probably yes, as the tests are using this working tandem (I should have been looking at the tests, they never lie!):

https://github.com/bytecodealliance/wasmtime/blob/c953cc8fd16df3ff73853101402f343436ab4cef/crates/wasi-http/tests/all/p2/async_.rs#L15-L16

file a repro if you have a moment against the docs! that should ALWAYS work. :-)

view this post on Zulip Pat Hickey (Jul 01 2025 at 18:24):

ill fix the docs rn

view this post on Zulip Pat Hickey (Jul 01 2025 at 18:24):

thank you for catching our error

view this post on Zulip Pat Hickey (Jul 01 2025 at 18:27):

unfortunately that doc is no_run, because it starts a server that never gets any requests and never dies, so it would just spin forever

view this post on Zulip Pat Hickey (Jul 01 2025 at 18:27):

otherwise cargo doc would have caught this bug

view this post on Zulip Pat Hickey (Jul 01 2025 at 18:27):

im not brave enough to fix the no_running-ness right now. we regret the error.

view this post on Zulip Lann Martin (Jul 01 2025 at 18:29):

Is the example actually wrong? It might be confusing that your guest can't target wasm32-wasip2 but it would work fine for a guest that just uses proxy right? Or am I missing something...?

view this post on Zulip Pat Hickey (Jul 01 2025 at 18:35):

its just missing the add_to_linker for the wasmtime-wasi parts

view this post on Zulip Pat Hickey (Jul 01 2025 at 18:35):

which are required, even in proxy, for the io package, stdio from cli, and others

view this post on Zulip Lann Martin (Jul 01 2025 at 18:37):

I'm pretty sure wasmtime_wasi_http::add_to_linker_async does add those, which is what differentiates it from add_only_http_to_linker_async

view this post on Zulip Lann Martin (Jul 01 2025 at 18:38):

Either way it seems reasonable for the example to link the rest of wasi just to avoid this kind of confusion.

view this post on Zulip Pat Hickey (Jul 01 2025 at 18:39):

oh, you know what, you're right.

view this post on Zulip Pat Hickey (Jul 01 2025 at 18:39):

but, unfortunately, its very hard to actually target the proxy world, virtually all guests end up being proxy + cli imports

view this post on Zulip Pat Hickey (Jul 01 2025 at 18:39):

the wasmtime server -Scli set

view this post on Zulip Lann Martin (Jul 01 2025 at 18:40):

Spin always links both so I'm not going to argue there. :slight_smile:

view this post on Zulip Pat Hickey (Jul 01 2025 at 18:40):

once we have 0.3 we can finally solve that problem in wasm with wasi-virt, but we gave up on it in 0.2 because too much pain for too little gain

view this post on Zulip Pat Hickey (Jul 01 2025 at 18:42):

https://github.com/bytecodealliance/wasmtime/pull/11171

wasmtime-wasi-http: fix docs missing wasmtime_wasi::p2::add_to_linker. This creates the equivelant of wasmtime serve -Scli, which is what most guests end up needing. reported in https://bytecodeall...

view this post on Zulip Chris Suszynski (Jul 01 2025 at 18:58):

@Pat Hickey :heart:


Last updated: Dec 06 2025 at 06:05 UTC