Skip to content

Commit 588f96f

Browse files
committed
Clarify the behavior of rust.codegen-backends
1 parent 669a9e0 commit 588f96f

File tree

5 files changed

+32
-15
lines changed

5 files changed

+32
-15
lines changed

bootstrap.example.toml

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -740,11 +740,19 @@
740740
# result (broken, compiling, testing) into this JSON file.
741741
#rust.save-toolstates = <none> (path)
742742

743-
# This is an array of the codegen backends that will be compiled for the rustc
744-
# that's being compiled. The default is to only build the LLVM codegen backend,
745-
# and currently the only standard options supported are `"llvm"`, `"cranelift"`
746-
# and `"gcc"`. The first backend in this list will be used as default by rustc
747-
# when no explicit backend is specified.
743+
# This array serves three distinct purposes:
744+
# - Backends in this list will be automatically compiled and included in the sysroot of each
745+
# rustc compiled by bootstrap.
746+
# - The first backend in this list will be configured as the **default codegen backend** by each
747+
# rustc compiled by bootstrap. In other words, if the first backend is e.g. cranelift, then when
748+
# we build a stage 1 rustc, it will by default compile Rust programs using the Cranelift backend.
749+
# This also means that stage 2 rustc would get built by the Cranelift backend.
750+
# - Running `x dist` (without additional arguments, or with `--include-default-paths`) will produce
751+
# a dist component/tarball for the Cranelift backend if it is included in this array.
752+
#
753+
# Note that the LLVM codegen backend is special and will always be built and distributed.
754+
#
755+
# Currently, the only standard options supported here are `"llvm"`, `"cranelift"` and `"gcc"`.
748756
#rust.codegen-backends = ["llvm"]
749757

750758
# Indicates whether LLD will be compiled and made available in the sysroot for rustc to execute, and

src/bootstrap/src/core/build_steps/compile.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2194,7 +2194,7 @@ impl Step for Assemble {
21942194
let _codegen_backend_span =
21952195
span!(tracing::Level::DEBUG, "building requested codegen backends").entered();
21962196

2197-
for backend in builder.config.codegen_backends(target_compiler.host) {
2197+
for backend in builder.config.enabled_codegen_backends(target_compiler.host) {
21982198
// FIXME: this is a horrible hack used to make `x check` work when other codegen
21992199
// backends are enabled.
22002200
// `x check` will check stage 1 rustc, which copies its rmetas to the stage0 sysroot.

src/bootstrap/src/core/build_steps/dist.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1384,7 +1384,7 @@ impl Step for CraneliftCodegenBackend {
13841384
let clif_enabled_by_default = run
13851385
.builder
13861386
.config
1387-
.codegen_backends(run.builder.host_target)
1387+
.enabled_codegen_backends(run.builder.host_target)
13881388
.contains(&CodegenBackendKind::Cranelift);
13891389
run.alias("rustc_codegen_cranelift").default_condition(clif_enabled_by_default)
13901390
}

src/bootstrap/src/core/build_steps/test.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3468,7 +3468,11 @@ impl Step for CodegenCranelift {
34683468
return;
34693469
}
34703470

3471-
if !builder.config.codegen_backends(run.target).contains(&CodegenBackendKind::Cranelift) {
3471+
if !builder
3472+
.config
3473+
.enabled_codegen_backends(run.target)
3474+
.contains(&CodegenBackendKind::Cranelift)
3475+
{
34723476
builder.info("cranelift not in rust.codegen-backends. skipping");
34733477
return;
34743478
}
@@ -3595,7 +3599,7 @@ impl Step for CodegenGCC {
35953599
return;
35963600
}
35973601

3598-
if !builder.config.codegen_backends(run.target).contains(&CodegenBackendKind::Gcc) {
3602+
if !builder.config.enabled_codegen_backends(run.target).contains(&CodegenBackendKind::Gcc) {
35993603
builder.info("gcc not in rust.codegen-backends. skipping");
36003604
return;
36013605
}

src/bootstrap/src/core/config/config.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1747,19 +1747,24 @@ impl Config {
17471747
.unwrap_or(self.profiler)
17481748
}
17491749

1750-
pub fn codegen_backends(&self, target: TargetSelection) -> &[CodegenBackendKind] {
1750+
/// Returns codegen backends that should be:
1751+
/// - Built and added to the sysroot when we build the compiler.
1752+
/// - Distributed when `x dist` is executed (if the codegen backend has a dist step).
1753+
pub fn enabled_codegen_backends(&self, target: TargetSelection) -> &[CodegenBackendKind] {
17511754
self.target_config
17521755
.get(&target)
17531756
.and_then(|cfg| cfg.codegen_backends.as_deref())
17541757
.unwrap_or(&self.rust_codegen_backends)
17551758
}
17561759

1757-
pub fn jemalloc(&self, target: TargetSelection) -> bool {
1758-
self.target_config.get(&target).and_then(|cfg| cfg.jemalloc).unwrap_or(self.jemalloc)
1760+
/// Returns the codegen backend that should be configured as the *default* codegen backend
1761+
/// for a rustc compiled by bootstrap.
1762+
pub fn default_codegen_backend(&self, target: TargetSelection) -> Option<CodegenBackendKind> {
1763+
self.enabled_codegen_backends(target).first().cloned()
17591764
}
17601765

1761-
pub fn default_codegen_backend(&self, target: TargetSelection) -> Option<CodegenBackendKind> {
1762-
self.codegen_backends(target).first().cloned()
1766+
pub fn jemalloc(&self, target: TargetSelection) -> bool {
1767+
self.target_config.get(&target).and_then(|cfg| cfg.jemalloc).unwrap_or(self.jemalloc)
17631768
}
17641769

17651770
pub fn rpath_enabled(&self, target: TargetSelection) -> bool {
@@ -1774,7 +1779,7 @@ impl Config {
17741779
}
17751780

17761781
pub fn llvm_enabled(&self, target: TargetSelection) -> bool {
1777-
self.codegen_backends(target).contains(&CodegenBackendKind::Llvm)
1782+
self.enabled_codegen_backends(target).contains(&CodegenBackendKind::Llvm)
17781783
}
17791784

17801785
pub fn llvm_libunwind(&self, target: TargetSelection) -> LlvmLibunwind {

0 commit comments

Comments
 (0)