@Joel Dice I've updated to the latest naot and witbind gen packages. Everything is compiling properly but I am not able to run the http example with wasmtime, I am getting.
wasmtime serve .\bin\Debug\net8.0\wasi-wasm\native\MyApp.wasm --addr 127.0.0.1:3000
Error: component imports instance `wasi:cli/environment@0.2.0`, 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
Any ideas on what I am missing? I thought it might be the wit for cli imports in the linker but got a different error when that ran
looking at the proxy component_type.wit generated by wit-bindgen it seems to have a package wasi:cli@0.2.0 but I don't see the get-environment import. but the final binary has it:
wasm-tools.exe component wit .\bin\Debug\net8.0\wasi-wasm\native\MyApp.wasm
package root:component;
world root {
import wasi:cli/environment@0.2.0;
import wasi:cli/exit@0.2.0;
try wasmtime serve -S cli ...
I don't think there's currently a way to tell the ILC/runtime to stub out and omit wasi:cli stuff, so we have to tell wasmtime to provide it.
that work! what's adding the adding import wasi:cli/environment@0.2.0;? is that the dotnet compiler?
https://github.com/jsturtevant/wasi-http-oci
Yeah, presumably either the .NET runtime or wasi-libc are pulling those in such that they can't be trimmed away. I'll bet you could stub them out by passing -Wl,--wasi-adapter,proxy as a linker flag.
It would be better to have those not generated right? I guess I should create an issue in dotnet repo to start to track?
Well, they should be generated if the application uses environment variables and/or calls exit. Ideally they wouldn't be generated if the application doesn't use such features, I suppose, but I don't know how easy it is to detect that, nor if either the .NET runtime or wasi-libc proactively grabs environment variables just in case the application might need them.
Feel free to open an issue, but we should be careful not to veer to the other extreme and omit imports when the app actually needs them.
ah, ok that make sense. I was discussing that the other day with some folks, how it is detected if something like an env is needed in the runtime and what would happen
good issue to add to that repo -- they either have an answer, or are on default as it's being built (which, understandable)
It tells me that wasi-http/proxy probably needs to import wasi:cli/environment
I don't think wasi-http should import, it isn't needed for the functionality. It would be perferable to have smaller independent functionality and then let the user bring it toget as needed. Ideally the lanaguage compiler could dectect if ENVs/exit are in use and either bring them in or leave them out but maybe that's pretty hard to do and is why its there be default
created an issue https://github.com/dotnet/runtime/issues/107405
Joel Dice said:
by passing
-Wl,--wasi-adapter,proxyas a linker flag.
This works for cli, but then you can get
called `Result::unwrap()` on an `Err` value: component imports instance `wasi:io/error@0.2.0`, but a matching implementation was not found in the linker
Caused by:
0: instance export `error` has the wrong type
1: resource implementation is missing
Is there an equivalent for -S cli etc but when linking or instantiating components in rust ?
Adding these was what I wanted
fn type_annotate_wasi<T, F>(val: F) -> F
where
F: Fn(&mut T) -> &mut T,
{
val
}
let wasi_closure = type_annotate_wasi::<HostState, _>(|t| t);
stdin::add_to_linker_get_host(&mut linker, wasi_closure)?;
stdout::add_to_linker_get_host(&mut linker, wasi_closure)?;
stderr::add_to_linker_get_host(&mut linker, wasi_closure)?;
error::add_to_linker_get_host(&mut linker, wasi_closure)?;
monotonic_clock::add_to_linker_get_host(&mut linker, wasi_closure)?;
wall_clock::add_to_linker_get_host(&mut linker, wasi_closure)?;
tcp::add_to_linker_get_host(&mut linker, wasi_closure)?;
udp::add_to_linker_get_host(&mut linker, wasi_closure)?;
random::add_to_linker_get_host(&mut linker, wasi_closure)?;
I now have an unaligned pointer but that's a different problem.
Last updated: Dec 13 2025 at 20:04 UTC