create_library_to_link: add mangle_name and unique_name arguments

Closes #8180

- Adds `mangle_name` and `unique_name` arguments to `create_library_to_link`
    - `mangle_name` allows users replicate the behavior of `cc_library` in their custom rules. The link placed under the solib directory will be mangled and no intermediate directory will be generated.
    - `unique_name` allows users to specify that the given library name is unique and no intermediate directory is required.
- Adds the `prefixLibraryPath` argument to the internal `CcCommon` API to facilitate the above changes to `create_library_to_link`.
- Adds shell tests for the `mangle_name` and `unique_name` arguments to `create_library_to_link`.

### Motivation

See https://github.com/bazelbuild/bazel/issues/8180 https://github.com/tweag/rules_haskell/issues/958

Before this PR the new Starlark Cc API's `create_library_to_link` would always preserve the given library name and link it into the solib directory underneath an intermediate directory based on the library label and consumer label. These intermediate directories can grow very long, in particular if external workspaces are involved. In rules_haskell this causes issues on Windows and MacOS. On Windows the linker cannot look for libraries underneath search paths which exceed a certain path length. On MacOS the header size of a MACH-O binary/library is limited and the required runpaths/load commands would quickly exceed this limit due to the long paths generated by Bazel. In rules_haskell in particular these intermediate directories are unnecessary, as rules_haskell already mangles the library names itself to ensure their uniqueness. Furthermore, the Haskell compiler GHC expects library names of a particular shape, such that Bazel's builtin mangling cannot be used. This motivates the combination `mangle_name = False`, `unique_name = True` enabled by this PR.

cc @oquenchil @mboes @cocreature

Closes #8888.

PiperOrigin-RevId: 285993823
5 files changed
tree: a0d28b2d1fe51f0a47e08b61f76b97a216996666
  1. .bazelci/
  2. examples/
  3. scripts/
  4. site/
  5. src/
  6. third_party/
  7. tools/
  8. .bazelrc
  9. .gitattributes
  10. .gitignore
  11. AUTHORS
  12. BUILD
  13. CHANGELOG.md
  14. CODEOWNERS
  15. combine_distfiles.py
  16. combine_distfiles_to_tar.sh
  17. compile.sh
  18. CONTRIBUTING.md
  19. CONTRIBUTORS
  20. distdir.bzl
  21. ISSUE_TEMPLATE.md
  22. LICENSE
  23. README.md
  24. WORKSPACE
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

Contributing to Bazel

See CONTRIBUTING.md

Build status