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?
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.
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:
@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.
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.
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:
@Lann Martin Yes, it works!! Thanks a lot! You can see the change here: https://github.com/cardil/knative-serving-wasm/pull/4
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!):
Once again, thanks for your help, folks! I appreciate it very much!
Chris Suszynski said:
The
wasmtime_wasi_httpcrate, 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!):
file a repro if you have a moment against the docs! that should ALWAYS work. :-)
ill fix the docs rn
thank you for catching our error
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
otherwise cargo doc would have caught this bug
im not brave enough to fix the no_running-ness right now. we regret the error.
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...?
its just missing the add_to_linker for the wasmtime-wasi parts
which are required, even in proxy, for the io package, stdio from cli, and others
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
Either way it seems reasonable for the example to link the rest of wasi just to avoid this kind of confusion.
oh, you know what, you're right.
but, unfortunately, its very hard to actually target the proxy world, virtually all guests end up being proxy + cli imports
the wasmtime server -Scli set
Spin always links both so I'm not going to argue there. :slight_smile:
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
https://github.com/bytecodealliance/wasmtime/pull/11171
@Pat Hickey :heart:
Last updated: Dec 06 2025 at 06:05 UTC