Skip to content

Commit ca6e367

Browse files
committed
Clarify the behavior of rust.codegen-backends
1 parent 929b3bb commit ca6e367

File tree

5 files changed

+33
-16
lines changed

5 files changed

+33
-16
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
@@ -2190,7 +2190,7 @@ impl Step for Assemble {
21902190
let _codegen_backend_span =
21912191
span!(tracing::Level::DEBUG, "building requested codegen backends").entered();
21922192

2193-
for backend in builder.config.codegen_backends(target_compiler.host) {
2193+
for backend in builder.config.enabled_codegen_backends(target_compiler.host) {
21942194
// FIXME: this is a horrible hack used to make `x check` work when other codegen
21952195
// backends are enabled.
21962196
// `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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,7 +1406,7 @@ impl Step for CraneliftCodegenBackend {
14061406
let clif_enabled_by_default = run
14071407
.builder
14081408
.config
1409-
.codegen_backends(run.builder.host_target)
1409+
.enabled_codegen_backends(run.builder.host_target)
14101410
.contains(&CodegenBackendKind::Cranelift);
14111411
run.alias("rustc_codegen_cranelift").default_condition(clif_enabled_by_default)
14121412
}
@@ -1437,7 +1437,7 @@ impl Step for CraneliftCodegenBackend {
14371437
return None;
14381438
}
14391439

1440-
let mut tarball = Tarball::new(builder, &"rustc-codegen-cranelift", &target.triple);
1440+
let mut tarball = Tarball::new(builder, "rustc-codegen-cranelift", &target.triple);
14411441
tarball.set_overlay(OverlayKind::RustcCodegenCranelift);
14421442
tarball.is_preview(true);
14431443
tarball.add_legal_and_readme_to("share/doc/rustc_codegen_cranelift");

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3478,7 +3478,11 @@ impl Step for CodegenCranelift {
34783478
return;
34793479
}
34803480

3481-
if !builder.config.codegen_backends(run.target).contains(&CodegenBackendKind::Cranelift) {
3481+
if !builder
3482+
.config
3483+
.enabled_codegen_backends(run.target)
3484+
.contains(&CodegenBackendKind::Cranelift)
3485+
{
34823486
builder.info("cranelift not in rust.codegen-backends. skipping");
34833487
return;
34843488
}
@@ -3605,7 +3609,7 @@ impl Step for CodegenGCC {
36053609
return;
36063610
}
36073611

3608-
if !builder.config.codegen_backends(run.target).contains(&CodegenBackendKind::Gcc) {
3612+
if !builder.config.enabled_codegen_backends(run.target).contains(&CodegenBackendKind::Gcc) {
36093613
builder.info("gcc not in rust.codegen-backends. skipping");
36103614
return;
36113615
}

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1977,19 +1977,24 @@ impl Config {
19771977
.unwrap_or(self.profiler)
19781978
}
19791979

1980-
pub fn codegen_backends(&self, target: TargetSelection) -> &[CodegenBackendKind] {
1980+
/// Returns codegen backends that should be:
1981+
/// - Built and added to the sysroot when we build the compiler.
1982+
/// - Distributed when `x dist` is executed (if the codegen backend has a dist step).
1983+
pub fn enabled_codegen_backends(&self, target: TargetSelection) -> &[CodegenBackendKind] {
19811984
self.target_config
19821985
.get(&target)
19831986
.and_then(|cfg| cfg.codegen_backends.as_deref())
19841987
.unwrap_or(&self.rust_codegen_backends)
19851988
}
19861989

1987-
pub fn jemalloc(&self, target: TargetSelection) -> bool {
1988-
self.target_config.get(&target).and_then(|cfg| cfg.jemalloc).unwrap_or(self.jemalloc)
1990+
/// Returns the codegen backend that should be configured as the *default* codegen backend
1991+
/// for a rustc compiled by bootstrap.
1992+
pub fn default_codegen_backend(&self, target: TargetSelection) -> Option<CodegenBackendKind> {
1993+
self.enabled_codegen_backends(target).first().cloned()
19891994
}
19901995

1991-
pub fn default_codegen_backend(&self, target: TargetSelection) -> Option<CodegenBackendKind> {
1992-
self.codegen_backends(target).first().cloned()
1996+
pub fn jemalloc(&self, target: TargetSelection) -> bool {
1997+
self.target_config.get(&target).and_then(|cfg| cfg.jemalloc).unwrap_or(self.jemalloc)
19931998
}
19941999

19952000
pub fn rpath_enabled(&self, target: TargetSelection) -> bool {
@@ -2004,7 +2009,7 @@ impl Config {
20042009
}
20052010

20062011
pub fn llvm_enabled(&self, target: TargetSelection) -> bool {
2007-
self.codegen_backends(target).contains(&CodegenBackendKind::Llvm)
2012+
self.enabled_codegen_backends(target).contains(&CodegenBackendKind::Llvm)
20082013
}
20092014

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

0 commit comments

Comments
 (0)