-
Notifications
You must be signed in to change notification settings - Fork 504
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support specifying the exact type path #371
Comments
Hi @danburkert, I work with @Veetaha and am having this same problem. I tried your proposed solution in the example project which @Veetaha posted. Something like this: fn main() {
let mut cfg = prost_build::Config::new();
cfg.type_attribute(".issue.Foo", "#[derive(Copy)]");
// Don't apply the `derive(Copy)` attribute to the enum `NestedEnum`
cfg.type_attribute(".issue.Foo.NestedEnum", "");
cfg.compile_protos(&["issue.proto"], &[env!("CARGO_MANIFEST_DIR")]).unwrap();
} This doesn't work. I looked at the This is a really difficult limitation to overcome. We have some tooling which lets us annotate messages in our (pretty complex) Protobuf files with tags, and then for everything with that tag set a custom derive attribute. This completely breaks when a message contains an enum or We'd be happy to try to fix this in |
+1 this also came up when I was trying to add unique derives to a nested enum: message Key {
// Enum is only used here so it doesn't make sense to extract
enum Namespace {
DEFAULT = 0;
NAMESPACE_1 = 1;
}
Namespace namespace = 1; Where my build.rs is: let mut prost_config = prost_build::Config::default();
prost_config.type_attribute(
"issue.key.Namespace",
"#[derive(strum::IntoStaticStr)]",
); This works if I extract |
As for now,
prost
supports adding attributes to types and fields by matching the prefix of the proto path. This works fine in most cases but this breaks when we have nested types that should not have the same attributes as their parent messages.E.g.:
To reproduce the problem clone and
cargo build
this repo here:https://github.com/Veetaha/prost-prefix-proto-path-match-problem
The text was updated successfully, but these errors were encountered: