rules_rust
rules_rust copied to clipboard
What's a good default for protoc-gen-{prost|tonic}'s compile_well_known_types?
The compile_well_known_types flag controls whether generated libraries use prost-types or types from generated google.protobuf.* protos.
This flag is currently always enabled here (and a bit further below for tonic): https://github.com/bazelbuild/rules_rust/blob/478213bb114b6c2649f1c2533589ac3962d3bf28/proto/prost/private/prost.bzl#L63
Being enabled by default means that we have to use e.g. timestamp_proto::google::protobuf::Timestamp instead of prost_types::Timestamp.
I'm not sure whether this is a good or a bad thing.
- It's more precise if users explicitly use the types that are actually written in the proto files.
- It seems the ergonomics of prost-types are nicer. E.g. a generated
timestamp_proto::google::protobuf::Timestampdoesn't implementFrom<SystemTime>, butprost_types::Timestampdoes. Intuitively I could also imagine the specializedprost-typesto be more performant.
There is also a protoc-wkt crate that adds more extensive chrono-timestamp interop and other goodies.
Adding configurability for compile_well_known_types seems straightforward, but I'm not sure what the better default would be.
cc @allada @UebelAndre @freeformstu @illicitonion
compile_well_known_types could probably be an attribute on the toolchain along with something similar to proto_lang_toolchain.blacklisted_protos so users can specify what should and should not be compiled.
probably related to this; I'm struggling to compile proto rust libraries with code that relies on prost types.
To illustrate what I'm doing, I have pushed very small modifications to the bzlmod/proto example , see: https://github.com/bazelbuild/rules_rust/compare/main...joune:rules_rust:wkt-wrappers https://github.com/bazelbuild/rules_rust/compare/main...joune:rules_rust:wkt-timestamp
I get these errors when compiling with bazel:
the trait `From<bool>` is not implemented for `wrappers_proto::google::protobuf::BoolValue`, which is required by `bool: Into<_>`
the trait `From<SystemTime>` is not implemented for `timestamp_proto::google::protobuf::Timestamp`, which is required by `SystemTime: Into<_>`
What would be the recommended way to make this work?
PS: I have even tried removing the compile_well_known_types option from the rule implementation, but that leads to another strange error:
--prost_out: duplicate extern Protobuf path: .google.protobuf.BoolValue
I'm also struggling with the default compile_well_known_types option. It was surprising to me that it was passed by default, when prost's actual default is not to set it. I would like the ability to override it from the toolchain definition.