cargo-component icon indicating copy to clipboard operation
cargo-component copied to clipboard

Configuration for additional_derives_ignore

Open jeff1010322 opened this issue 8 months ago • 2 comments

wit-bindgen has a feature to disable certain variants and records from being included for the additional_derives: https://github.com/bytecodealliance/wit-bindgen/pull/1199

Looks like this is just empty currently: https://github.com/bytecodealliance/cargo-component/blob/40a41559a1cd938900823f727e7a9ab4f4ada910/src/bindings.rs#L112

I would like to be able to set the derives for serde, but the generated code has errors due to it adding these derives to imported types from wasi io:

[package.metadata.component.bindings] derives = ["serde::Serialize", "serde::Deserialize"]

 LastOperationFailed(Error),
                 ^^^^^ the trait `Deserialize<'_>` is not implemented for `bindings::wasi::io::error::Error`

Can this be implemented so that we can specify this value in the Cargo metadata?

jeff1010322 avatar Apr 21 '25 18:04 jeff1010322

My recommendation for the moment is that you should just use wit-bindgen directly instead of through cargo component. A lot of what cargo component does is just wrap that crate, and we aren’t finding that to be the best choice for users as the ecosystem evolves.

pchickey avatar Apr 21 '25 19:04 pchickey

Thanks for the suggestion! Just to confirm I was able to get the derives working by using the wit-bindgen macro directly. However, I think it would still be nice to have this feature in Cargo Component eventually. Its nice to be able to see and check in the generated bindings for guest components.

jeff1010322 avatar Apr 22 '25 13:04 jeff1010322