-
Notifications
You must be signed in to change notification settings - Fork 15.7k
Add cc_proto_aspect_hint to allow copts on cc_proto_library #19706
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
base: main
Are you sure you want to change the base?
Add cc_proto_aspect_hint to allow copts on cc_proto_library #19706
Conversation
This new `cc_proto_aspect_hint` allows users to specify `copts` that are then used when compiling the generated C++ code. This is a potential solution to bazelbuild/bazel#4446 In that discussion the primary concern was that if you have multiple `cc_proto_library` targets that depend on the same `proto_library` targets, if the `copts` was part of `cc_proto_library` you'd have to be sure to duplicate that to all `cc_proto_library` targets in the dependency tree. Using the relatively new `aspect_hints` functionality in bazel we can instead attach that info to the `proto_library` target itself, without adding C++ specific attributes to the `proto_library` rule.
cc_proto_aspect_hint = rule( | ||
implementation = _aspect_hint_impl, | ||
attrs = { | ||
"copts": attr.string_list(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can add any other attributes we want here, i imagine linkopts
would be the next most sensible one, happy to add other useful ones in this PR, or just as use cases come up
@comius Could you help take a look? |
What is the motivation to set different flags for C++ on one specific proto_library? Let me expand on bazelbuild/bazel#4446 (comment) a bit more. Controlling C++ compilation and linking flags on generated C++ proto code is a pain at Google. We had a bunch of flags, on Generated C++ code should always be "compilable/linkable" with the same set of flags. Let's say it's possible to set flags on a specific library. What happens when the generated code changes and because of it that library is broken? |
I might be misunderstanding, but that wasn't my goal, it was just to be able to set custom flags on it at all, while also solving the concern of those flags not propagating to dependent cc_proto_library targets.
If I'm understanding you correctly I don't disagree, but the problem today is the only "same set of flags" is the default flags, and those aren't customizable. I imagine in many cases users would want all protos to use the same set of flags, just that differ from the defaults. For example in the upstream issue there is a windows specific flag a user wanted to apply to their protos, that couldn't be applied to all compiles
I think the same could be said for the opposite direction? As in my default flags contain |
It's true that flags for compiling protos aren't customizable. Do you have examples of systems where that's needed? I'm asking because protobuf repo is already tested on wide variety of platforms and compilers. I guess there must be something missing. Setting them somewhere on Since protobuf team is the owner, any such design decisions need to be run through them.
Yes the argument works in reverse. protobuf should be controlling what |
It seems like the first case users normally hit is differing warning flags. I imagine centralizing that in protobuf itself is a tough since those vary depending on project and compiler. Based on the thread linked above it seems like there's a second category of flags that are actually required, such as:
|
I would desperately need it for one specific case (which of itself needed to upgrade protobuf depencency for Google's ML stack, including TensorFlow, JAX and XLA): need to support Window's windows dymaic linking (
to get but those whoe depnd on those cc_proto_library targets (and include generated
to get Need to have different __declspec directive dependin on which side compiled code is (provider or a consumer of a dynamic library) is at the very core design of windows dynamic linking model, the |
This new
cc_proto_aspect_hint
allows users to specifycopts
that arethen used when compiling the generated C++ code.
This is a potential solution to bazelbuild/bazel#4446
In that discussion the primary concern was that if you have multiple
cc_proto_library
targets that depend on the sameproto_library
targets, if the
copts
was part ofcc_proto_library
you'd have to besure to duplicate that to all
cc_proto_library
targets in thedependency tree. Using the relatively new
aspect_hints
functionalityin bazel we can instead attach that info to the
proto_library
targetitself, without adding C++ specific attributes to the
proto_library
rule.