Make linking the same shared library twice a rule error#11721
Make linking the same shared library twice a rule error#11721agluszak wants to merge 9 commits intobazelbuild:masterfrom
Conversation
oquenchil
left a comment
There was a problem hiding this comment.
Can you add a description and also add "Fixes #11167" to it?
But before you add that it fixes, please verify that it indeed fixes it. In #11167 they have a link to a PR which reproduces the problem and they also have the necessary command.
Try the command with released bazel (should crash) and try with your custom built binary that has this change (should succeed)
With released Bazel it crashed with an NPE, with custom built binary it fails with ...but there's no such file indeed |
|
We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google. ℹ️ Googlers: Go here for more info. |
eb489f6 to
807a48b
Compare
|
CLAs look good, thanks! ℹ️ Googlers: Go here for more info. |
…ts linked in correctly. Add more details to the rule error.
…hared-lib-twice-after-transition # Conflicts: # src/main/java/com/google/devtools/build/lib/rules/cpp/LibrariesToLinkCollector.java
> As more and more people start using the power of Starlark transitions, we are seeing more people bumping into a precondition baked deep in the C++ rules implementation which checks that a shared library being linked is in the same configuration directory. The check is there to make sure that the same library built in different configurations is not linked more than once. > Aside from the fact that it should be a proper rule error and not a crash, people are hitting this check when writing cc_import targets that have a transition applied to them. There are other ways to guarantee that the same library is not linked more than once without completely restricting the ability to link a library built in a different configuration. @oquenchil This PR makes linking the same shared library twice a rule error instead of a crash and it makes it possible to link a library built in a different configuration. A map from library identifiers to library paths is introduced, making sure that each shared library is linked at most once. Only dynamic linking is taken into account, for static linking see bazelbuild#11727 Fixes bazelbuild#11167 (the check which was causing the NPE was not directly related to transitions, but because it was removed, that NPE should no longer happen) Closes bazelbuild#11721. PiperOrigin-RevId: 322563028
This PR makes linking the same shared library twice a rule error instead of a crash and it makes it possible to link a library built in a different configuration. A map from library identifiers to library paths is introduced, making sure that each shared library is linked at most once. Only dynamic linking is taken into account, for static linking see #11727
Fixes #11167 (the check which was causing the NPE was not directly related to transitions, but because it was removed, that NPE should no longer happen)