Fix cc_shared_library to take into account indirect top level deps

The cc_shared_library implementation wraps its top level direct dependencies in
whole archive because otherwise since there aren't any symbols in the shared
library depending on them they would be dropped by the linker.

There are instances where the target placed in the direct dep of a
cc_shared_library doesn't have a linker_input or if it has it, the linker_input
may not have any code to be linked statically into the shared library.

When that happens, the actual code to be linked is depended on indirectly, e.g.
cc_shared_library -> cc_proto_library -> proto_library. Here it is the code
generated by the aspect applied on proto_library that should be linked
statically. Since this dependency was indirect, that code wasn't
whole-archived. Before this fix, we only tried to whole-archive
cc_proto_library but the cc_proto_library target itself did not produce any
linker_inputs, for this reason the code from the proto_library was dropped by
the linker.

This CL also adds more test coverage for the dynamic_only_roots failure
triggered explicitly by the cc_shared_library implementation.

RELNOTES:none
PiperOrigin-RevId: 515017649
Change-Id: I022e1cb4f70fa4584893d3c34172236fdf2e5f73
7 files changed
tree: 613a04c316be5ae0abbe9bc6d0cc07eb5821e971
  1. .bazelci/
  2. .github/
  3. examples/
  4. scripts/
  5. site/
  6. src/
  7. third_party/
  8. tools/
  9. .bazelrc
  10. .gitattributes
  11. .gitignore
  12. AUTHORS
  13. BUILD
  14. CHANGELOG.md
  15. CODE_OF_CONDUCT.md
  16. CODEOWNERS
  17. combine_distfiles.py
  18. combine_distfiles_to_tar.sh
  19. compile.sh
  20. CONTRIBUTING.md
  21. CONTRIBUTORS
  22. distdir.bzl
  23. distdir_deps.bzl
  24. LICENSE
  25. maven_install.json
  26. MODULE.bazel
  27. README.md
  28. SECURITY.md
  29. WORKSPACE
  30. WORKSPACE.bzlmod
README.md

Bazel

{Fast, Correct} - Choose two

Build and test software of any size, quickly and reliably.

  • Speed up your builds and tests: Bazel rebuilds only what is necessary. With advanced local and distributed caching, optimized dependency analysis and parallel execution, you get fast and incremental builds.

  • One tool, multiple languages: Build and test Java, C++, Android, iOS, Go, and a wide variety of other language platforms. Bazel runs on Windows, macOS, and Linux.

  • Scalable: Bazel helps you scale your organization, codebase, and continuous integration solution. It handles codebases of any size, in multiple repositories or a huge monorepo.

  • Extensible to your needs: Easily add support for new languages and platforms with Bazel's familiar extension language. Share and re-use language rules written by the growing Bazel community.

Getting Started

Documentation

Reporting a Vulnerability

To report a security issue, please email security@bazel.build with a description of the issue, the steps you took to create the issue, affected versions, and, if known, mitigations for the issue. Our vulnerability management team will respond within 3 working days of your email. If the issue is confirmed as a vulnerability, we will open a Security Advisory. This project follows a 90 day disclosure timeline.

Contributing to Bazel

See CONTRIBUTING.md

Build status