-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
cc_proto_library should support cc_library parameters (like copts, linkopts, etc) #4446
Comments
Hey @jin (sorry to rope you into this directly): is there some progress or a known workaround? I'm on bazel 0.14.0 and protobuf 3.4.0, my CROSSTOOL compiles with I tried to wrap
Error:
See related protobuf ticket: protocolbuffers/protobuf#4628 |
I got something hacky to work, maybe this helps someone with the same problem.
def _cc_proto_lib_impl(ctx):
p = ctx.attr.cc_proto_libraries[0].cc
print("=" * 50)
print("compile_flags", p.compile_flags) # <---- these flags.
print("=" * 50)
print("defines", p.defines)
print("=" * 50)
print("include_directories", p.include_directories)
print("=" * 50)
print("libs", p.libs)
print("=" * 50)
print("link_flags", p.link_flags)
print("=" * 50)
print("quote_include_directories", p.quote_include_directories)
print("=" * 50)
print("system_include_directories", p.system_include_directories)
print("=" * 50)
print("transitive_headers", p.transitive_headers)
print("=" * 50)
wrapped_cc_proto_library = rule(
implementation = _cc_proto_lib_impl,
attrs = {
"cc_proto_libraries": attr.label_list(mandatory = True, allow_empty = False),
},
) This rule is then imported and used within a BUILD file like so: wrapped_cc_proto_library(name = "whatever", cc_proto_libraries = [":your_cc_proto_library_target"]) which will print the contents of all fields in the cc provider of the
cc_library(
name = "some_general_cc_target",
srcs = [
":some_cc_proto_library", # The main cc_proto_library library you're compiling. Yes, passed to srcs. Ugh.
":transitive_dep_cc_proto_library", # You need to include all transitive dependencies' cc_proto_libraries.
],
copts = [
# Compile flags extracted using the custom rule here.
"-isystem external/com_google_protobuf/src", etc. etc.
# Custom copts.
"-w",
]
) |
@mhlopko Nice, thanks for the heads up. Is there a rough timeline? |
The roadmap says it will be done in July, which will be a challenge but it's possible. So it will be in released Bazel in August or in September. If all goes well. |
@oquenchil what's the current state? |
No plans to work on this in the short term. I updated priorities. |
Any further update on this? This would be a pretty useful feature for us. |
Sadly, cc_common does not seem to contain a cc_proto_library rule, requiring that the user build their own by reverse-engineering the old cc_proto_library rule. |
Ping, any word on updating cc_proto_library with this support? |
No plans in the immediate future. |
Thank you for contributing to the Bazel repository! This issue has been marked as stale since it has not had any activity in the last 1+ years. It will be closed in the next 90 days unless any other activity occurs or one of the following labels is added: "not stale", "awaiting-bazeler". Please reach out to the triage team ( |
This issue has been automatically closed due to inactivity. If you're still interested in pursuing this, please reach out to the triage team ( |
I'd really like this to not just be a "feature request" if my issue is going to be de-duped to it, only being un-staled in 2023. Without this, it is not possible to build protobufs in many configurations. Sadly, |
@chandlerc As a workaround, you could probably define a toolchain feature with the required flags and then use the |
Adding |
note one bad workaround you can use today is |
Most of these are places where we failed to include a header file and simply never got an error about this. The fix is to include the header file. Most other cases are functions that should have been marked `static` but were not. Finding all of these was a main motivation for me enabling the warning despite how much work it is. One complicating factor was that we weren't including the `handle.h` for all the state-based handler functions. While this isn't a tiny amount of code, it is just declarations and doesn't add any extra dependencies. It also lets us have the checking for which functions need to be `static` and which don't. For the `parse` library I had to add the `handle.h` header as well, I tried to match the design of it in `check`. I have also had to work around a bug in the warning, but given the value it seems to be providing, that seems reasonable. I've filed the bug upstream: llvm/llvm-project#94138 I also had to use some hacks to work around limitations of Bazel rules that wrap `cc_library` rules and don't expose `copts`. I filed a bug for `cc_proto_library` specifically: ~bazelbuild/bazel#22610 bazelbuild/bazel#4446
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.
I submitted an option for this to protobuf which uses aspect_hints to avoid the issue @comius mentioned above, PTAL protocolbuffers/protobuf#19706 |
Description of the problem / feature request:
The cc_proto_library is, in essence a cc_library rule and should thus honor the cc_library parameters, such as copts.
Feature requests: what underlying problem are you trying to solve with this feature?
Large protos may require the
-Wa,-mbig-obj
copt on Windows, but it is not always possible to use that flag globally (e.g. if also compiling go code).There are other reason why people may want to control the underlaying cc_library rule, of course.
What operating system are you running Bazel on?
Linux, OSX, Windows
What's the output of
bazel info release
?0.9.0
The text was updated successfully, but these errors were encountered: