Closed andrew-otiv closed 3 months ago
Have you tried using https://docs.rs/prost-build/latest/prost_build/struct.Config.html#method.type_attribute?
That looks very promising, thanks! We're trying to set this up from bazel rules_rust; hopefully we can drive this through keyword arguments to https://bazelbuild.github.io/rules_rust/rust_proto.html#rust_prost_library.
You can derive any trait you want using type_attribute
as commented earlier. For example to derive Arbirary on every protobuf type:
prost_build::Config::new()
.type_attribute(".", "#[derive(arbitrary::Arbitrary)]")
.compile_protos(&["src/types.proto"], &["src/"])?;
If this doesn't resolve your problem, please reopen the issue.
That indeed solved our need for derving traits on everything! Thanks!
Prost already can generate types supporting Clone and PartialEq, which is great. We'd like to also be able to derive other traits, like Default, or the various traits used by fuzzers like cargo fuzz. Rust's orphan rules make this hard in the context of code generation.
We currently only have ~50 code generated types, so we could write our own impls manually, but maybe it would possible to add trait derivations to the generated code via configuration? Theres already a mechanism for switching ~off the already supported traits; I am interested in going the other direction.
Related: https://github.com/tokio-rs/prost/pull/493