Hi! I'm trying to implement a world that imports both wasi types and wasi-http types and running into issues with satisfying wasmtime bindgen Host trait requirements. So if I use just wasi then I can implement all my interfaces for WasiImpl<MyState>
and it automatically satisfies all the wasi import traits because they are implemented for WasiImpl<T>
, but then I can't add wasi-http implementations since they are only implemented for WasiHttpImpl<T> newtype, and the wasmtime bindgen generated world requires the World::add_to_linker(linker, state)
to have state satisfy FnOnce(T) -> U
, where U
implements all my world interfaces, wasi interfaces, and wasi-http interfaces in one type, which seems impossible unless I create a new newtype and implement all wasi and wasi-http implementations for it?
I guess I can implement a custom add_to_linker
without the Host traits as they are satisfied via newtype conversions already
Are you implementing the wasi traits by hand? Or using the impls in the wasmtime-wasi*
crates? If you're only doing your own functionality by hand then you might also be interested in the *_get_host
variant of the add_to_linker functions that are generated
I'm using impls from wasmtime-wasi* crates
ah ok, in that case what led you to work with WasiImpl
? In theory that's just an implementation detail of those crates
The wasmtime-wasi* crates add_to_linker()
are fine because they require T to be WasiView/WasiHttpView and then wrap the T in newtype and add bindings for that. The problem is bindgen generated add_to_linker
for my world which generates a function that looks like this:
pub fn add_to_linker<T, U>(
linker: &mut wasmtime::component::Linker<T>,
get: impl Fn(&mut T) -> &mut U + Send + Sync + Copy + 'static,
) -> wasmtime::Result<()>
where
T: Send, U: host::app::init::Host + __with_name9::network::Host + __with_name5::wall_clock::Host ...
But the wasi traits are implemented only for WasiImpl<U>
and not U
.
Like ideally bindgen would generate U constraints like host::app::init::Host + WasiView
I ignored the generated add_to_linker
, and instead implemented add_to_linker
manually for my concrete MyState which seems like the best solution
Makes sense, I'd recommend avoiding the generated add_to_linker for wasi, you probably want the top-level handwritten one instead which avoids dealing with WasiImpl
Yeah makes sense thanks! I was thinking about this for a while but only after writing this it occurred to me that I can just write my own add_to_linker
:melting_face:
any recommended tutorials for using wasmtime with hot reloading? trying to figure it out for a game I am making
Last updated: Apr 09 2025 at 11:03 UTC