commit | fae114ca2f4da560b6c85da47227d6b4769be8d6 | [log] [tgz] |
---|---|---|
author | Parker Timmerman <parker@parkertimmerman.com> | Mon Dec 16 11:54:53 2024 -0500 |
committer | GitHub <noreply@github.com> | Mon Dec 16 16:54:53 2024 +0000 |
tree | a72e786fb493e02c26c18003fe4f19455a5b2920 | |
parent | 4652fb58ddf8d310aca62b1f83a9fa867ab11a40 [diff] |
feat: Add `//rust/settings:lto` (#3104) Fixes https://github.com/bazelbuild/rules_rust/issues/3045 This PR adds a new build setting `//rust/settings:lto=(off|thin|fat)` which changes how we specify the following flags: * [`lto`](https://doc.rust-lang.org/rustc/codegen-options/index.html#lto) * [`embed-bitcode`](https://doc.rust-lang.org/rustc/codegen-options/index.html#embed-bitcode) * [`linker-plugin-lto`](https://doc.rust-lang.org/rustc/codegen-options/index.html#linker-plugin-lto) The way we invoke the flags was based on how Cargo does it today ([code](https://github.com/rust-lang/cargo/blob/769f622e12db0001431d8ae36d1093fb8727c5d9/src/cargo/core/compiler/lto.rs#L4)) and based on suggestions from the [Rust docs](https://doc.rust-lang.org/rustc/codegen-options/index.html#embed-bitcode). When LTO is not enabled, we will specify `-Cembed-bitcode=no` which tells `rustc` to skip embedding LLVM bitcode and should speed up builds. Similarly when LTO is enabled we specify `-Clinker-plugin-lto` which will cause `rustc` to skip generating objects files entirely, and instead replace them with LLVM bitcode*. *only when building an `rlib`, when building other crate types we continue generating object files. I added unit tests to make sure we pass the flags correctly, as well as some docs describing the new setting. Please let me know if I should add more!
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.