Skip to content
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

Cannot depend on two overlapping cpp_proto_library()'s #25

Closed
fahhem opened this issue Oct 28, 2019 · 4 comments · Fixed by #106
Closed

Cannot depend on two overlapping cpp_proto_library()'s #25

fahhem opened this issue Oct 28, 2019 · 4 comments · Fixed by #106
Labels
bug Something isn't working enhancement New feature or request lang-cpp C++ rules specific resolved-next-release Code to resolve issue is pending release

Comments

@fahhem
Copy link
Contributor

fahhem commented Oct 28, 2019

If you do this, then bazel will link in two separate (merged) directories. At best, this will cause ODR violations at link time; at worst, it gets caught at runtime (I found it when compiling with ASAN to debug a segfault caused by it).

Essentially, if I have a cc_binary that depends on a rule at //path:proto_one_cc, which is a cpp_proto_library(), and another rule at //path:proto_two_cc, and they both depend on a cpp_proto_library(name="common"), then I'll get two instances of every linked object from the common proto. Typically, this will include things harmless like the default instance of the protos, but also various static objects like descriptors that are compared by pointer (because why would you have two descriptors for the same proto in your binary?).

One way to avoid this is to make the cpp_proto_library() also an aspect, not just the cpp_proto_compile(), and switch to merge_directories=False. That aspect would be able to grab the includes from all its dependencies, transitively, and add those to itself. It would then return CcInfo to be part of a C++ compilation natively.

@aaliddell aaliddell added bug Something isn't working enhancement New feature or request labels Nov 3, 2019
@aaliddell
Copy link
Member

Would you be able to provide a failing test workspace for this? Also, does the cpp_proto_library in the protobuf repo correctly handle this?

Your proposed solution looks like it's the proper way of doing this, so I'll add it to the TODO list.

@aaliddell aaliddell added this to the 1.x.0 milestone Nov 3, 2019
toddlipcon added a commit to toddlipcon/rules_proto_grpc that referenced this issue Nov 21, 2019
@toddlipcon
Copy link
Contributor

I threw together a test repo here: https://github.com/toddlipcon/rules_proto_grpc/tree/overlapping-deps/test_workspaces/common_cpp_library

The test fails at runtime due to multiple definitions of a field extension (this is the issue I'm hitting in my project due to a more complex dependency graph including the file which has the extensions multiple times)

@aaliddell
Copy link
Member

Thanks, that's a great help!

@aaliddell
Copy link
Member

This should be fixed in 3.0.0 release, where there is a non-transitive compilation mode that will avoid the common ancestor's definitions appearing multuple times.

@aaliddell aaliddell added resolved-next-release Code to resolve issue is pending release lang-cpp C++ rules specific labels Feb 13, 2021
@aaliddell aaliddell removed this from the 3.0.0 milestone Feb 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request lang-cpp C++ rules specific resolved-next-release Code to resolve issue is pending release
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants