commit | c6ad23abadf2c26f354db515ad2378f1bf21d414 | [log] [tgz] |
---|---|---|
author | scentini <rosica@google.com> | Thu Apr 20 14:25:20 2023 +0200 |
committer | GitHub <noreply@github.com> | Thu Apr 20 12:25:20 2023 +0000 |
tree | 5cf7770793bdcc911b17838dce1c3773fc239945 | |
parent | d787525049e4cbaadabb2f531fe86c871a6cf505 [diff] |
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)
This repository provides rules for building Rust projects with Bazel.
General discussions and announcements take place in the GitHub Discussions, but there are additional places where community members gather to discuss rules_rust
.
Please refer to the full documentation.