bazel: Transitive `cc_shared_library` doesn't work with inline functions
Description of the bug:
cc_shared_library and dynamic_deps deliberately link the shared libraries for only direct dependencies, while excluding the corresponding static libraries transitively. If any of the direct dependencies have inline functions which use transitive dependencies, this can result in linking failures. This is common with C++ code, it’s less common but I think it’s still possible with C.
Having to specify all the transitive dependencies in dynamic_deps is not good. It’s even worse because sometimes with some compilers and some optimization settings it’s necessary, and other times it’s not (it depends on what gets inlined where).
Linking all of the transitive shared libraries seems low-cost. They’re going to be needed at runtime anyways. Would that be an acceptable change?
Which category does this issue belong to?
C++ Rules
What’s the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
https://github.com/brians-neptune/bazel-cc_shared_library-transitive-deps has a main_dynamic target which fails to link, but I think it should. main_static is the same thing without dynamic_deps, which does link.
Which operating system are you running Bazel on?
Ubuntu 22.04
What is the output of bazel info release?
release 7.0.2
If bazel info release returns development version or (@non-git), tell us how you built Bazel.
No response
What’s the output of git remote get-url origin; git rev-parse HEAD ?
No response
Is this a regression? If yes, please try to identify the Bazel commit where the bug was introduced.
No response
Have you found anything relevant by searching the web?
No response
Any other information, logs, or outputs that you want to share?
No response
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 1
- Comments: 20 (9 by maintainers)
It seems to me that
implementation_depsis the solution to this issue. The headers from dependencies listed viadepsare accessible to the dependents of that target, so that means the symbols are also accessible and must be available to the linker.I think the proper solution when linking a binary with
dynamic_depsis to traverse the dependency tree and link in all of the transitivedeps. If a target has private dependencies that should not be available to its dependents, then those dependencies should be added toimplementation_depswhich will prevent them from being linked up the dependency tree.I agree with Thomas. One additional note to add: you need to traverse all the transitive
dynamic_depswhen linking each intermediate shared library too, unless you link with-z undefs.