Stream: wasmtime

Topic: Bindgen with component model


view this post on Zulip Div (May 15 2024 at 23:52):

Not sure if this is the right place or if the question makes sense, but would appreciate any help.

A project I'm working on previously used fp-bindgen and wasmer. But we are looking to adopt the component model with wasmtime. The project uses Rust for the host and the wasm plugin. The structures defined use #[derive] attribute for implementing some traits.

#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]

With my wit file, is it possible to generate bindings with the derive attribute trait implementations? Or am I going about this the wrong way?

view this post on Zulip Karel Hrkal (kajacx) (May 16 2024 at 10:06):

You can use with to specify custom types (as long as they have the correct fields), and then derive what you need. I have an example here but I don't know if there are any "official" examples/tutorials/explanations on how to use the with attribute.

A video game insipired by the Creeper World video games written in Bevy - kajacx/LiquiSlimeBevy

view this post on Zulip Lann Martin (May 16 2024 at 12:47):

Are you asking about host or guest bindings? For guest bindings, wit-bindgen has a additional_derives option that would cover Clone and PartialEq.

view this post on Zulip Lann Martin (May 16 2024 at 12:48):

It might also work for serde traits, but only if you don't need any other #[serde(...)] attributes

view this post on Zulip Lann Martin (May 16 2024 at 12:49):

https://serde.rs/remote-derive.html might be applicable here

view this post on Zulip Div (May 25 2024 at 07:10):

Karel Hrkal (kajacx) said:

You can use with to specify custom types (as long as they have the correct fields), and then derive what you need. I have an example here but I don't know if there are any "official" examples/tutorials/explanations on how to use the with attribute.

Sorry for the late reply, but thank you for this! I see your example uses it on the guest side.. could I do this on the host side too?

I seem to get several trait bounds for wasmtime::component::<x> not satisfied errors for my types referenced using the with attribute on the host side. Works fine on the guest side though.


Last updated: Nov 22 2024 at 16:03 UTC