Respect `#[global_allocator]` in `cc_common.link` builds (#1926)

`rustc` generates allocator symbols at link time. When we link via `cc_common.link` those symbols are missing because `rustc` is not driving the linking anymore. We compensate by providing the symbols via the `rust_toolchain.allocator_library`.
Rust also allows a global allocator to be specified (via `#[global_allocator]`). The symbols `rustc` generates at link time are different based on whether the system allocator is used, or a global allocator was specified.

Currently, when linking via `cc_common.link`, `#[global_allocator]` is completely ignored. This PR makes using a global allocator actually work:
1. Adding a `rust_toolchain.global_allocator_library` attribute that can point to a set of symbols needed when `#[global_allocator]` is used.
2. Adding a build flag `--@rules_rust//rust/settings:experimental_use_global_allocator` flag that is only observed when `--@rules_rust//rust/settings:experimental_use_cc_common_link==True`. At this point this flag only applies to the target configuration.

Unrelated to the goal of this PR, I also modified visibility of a `rust_toolchain` in `test/toolchain/toolchain_test.bzl` to address failures of Bazel rolling releases tasks (https://buildkite.com/bazel/rules-rust-rustlang/builds/8457#018799ff-5908-4b57-918b-a582ed12a248)
14 files changed
tree: 5cf7770793bdcc911b17838dce1c3773fc239945
  1. .bazelci/
  2. .github/
  3. bindgen/
  4. cargo/
  5. crate_universe/
  6. docs/
  7. examples/
  8. proto/
  9. rust/
  10. test/
  11. tools/
  12. util/
  13. wasm_bindgen/
  14. .bazelignore
  15. .bazelrc
  16. .clang-format
  17. .gitattributes
  18. .gitignore
  19. .rustfmt.toml
  20. ARCHITECTURE.md
  21. AUTHORS
  22. BUILD.bazel
  23. CODEOWNERS
  24. COMPATIBILITY.md
  25. CONTRIBUTING.md
  26. CONTRIBUTORS
  27. LICENSE.txt
  28. MODULE.bazel
  29. README.md
  30. version.bzl
  31. WORKSPACE.bazel
README.md

Rust Rules

  • Postsubmit Build status

Overview

This repository provides rules for building Rust projects with Bazel.

Community

General discussions and announcements take place in the GitHub Discussions, but there are additional places where community members gather to discuss rules_rust.

Documentation

Please refer to the full documentation.