Skip to content

Commit 9545538

Browse files
authored
Unrolled build for #145887
Rollup merge of #145887 - GuillaumeGomez:bootstrap-codegen-backends, r=Kobzol bootstrap: Don't panic if codegen-backends is set to empty It fixes a bug we encountered in our last GCC backend sync: https://github.com/rust-lang/rustc_codegen_gcc/actions/runs/17214525469/job/48834700055?pr=753#step:18:595 In short, we used to have in `bootstrap.toml` an empty `rust.codegen-backends = []`, triggering the `unwrap`. We fixed it in rust-lang/rustc_codegen_gcc@ad99858. r? `@Kobzol`
2 parents 160e762 + 2261968 commit 9545538

File tree

5 files changed

+10
-12
lines changed

5 files changed

+10
-12
lines changed

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,9 +1332,7 @@ pub fn rustc_cargo_env(builder: &Builder<'_>, cargo: &mut Cargo, target: TargetS
13321332
cargo.env("CFG_OMIT_GIT_HASH", "1");
13331333
}
13341334

1335-
if let Some(backend) = builder.config.default_codegen_backend(target) {
1336-
cargo.env("CFG_DEFAULT_CODEGEN_BACKEND", backend.name());
1337-
}
1335+
cargo.env("CFG_DEFAULT_CODEGEN_BACKEND", builder.config.default_codegen_backend(target).name());
13381336

13391337
let libdir_relative = builder.config.libdir_relative().unwrap_or_else(|| Path::new("lib"));
13401338
let target_config = builder.config.target_config.get(&target);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1850,7 +1850,7 @@ HELP: You can add it into `bootstrap.toml` in `rust.codegen-backends = [{name:?}
18501850
// Tells compiletest which codegen backend to use.
18511851
// It is used to e.g. ignore tests that don't support that codegen backend.
18521852
cmd.arg("--default-codegen-backend")
1853-
.arg(builder.config.default_codegen_backend(compiler.host).unwrap().name());
1853+
.arg(builder.config.default_codegen_backend(compiler.host).name());
18541854
}
18551855

18561856
if builder.build.config.llvm_enzyme {

src/bootstrap/src/core/builder/cargo.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,12 +1323,7 @@ impl Builder<'_> {
13231323

13241324
if let Some(limit) = limit
13251325
&& (build_compiler_stage == 0
1326-
|| self
1327-
.config
1328-
.default_codegen_backend(target)
1329-
.cloned()
1330-
.unwrap_or_default()
1331-
.is_llvm())
1326+
|| self.config.default_codegen_backend(target).is_llvm())
13321327
{
13331328
rustflags.arg(&format!("-Cllvm-args=-import-instr-limit={limit}"));
13341329
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1663,8 +1663,9 @@ impl Config {
16631663

16641664
/// Returns the codegen backend that should be configured as the *default* codegen backend
16651665
/// for a rustc compiled by bootstrap.
1666-
pub fn default_codegen_backend(&self, target: TargetSelection) -> Option<&CodegenBackendKind> {
1667-
self.enabled_codegen_backends(target).first()
1666+
pub fn default_codegen_backend(&self, target: TargetSelection) -> &CodegenBackendKind {
1667+
// We're guaranteed to have always at least one codegen backend listed.
1668+
self.enabled_codegen_backends(target).first().unwrap()
16681669
}
16691670

16701671
pub fn jemalloc(&self, target: TargetSelection) -> bool {

src/bootstrap/src/core/config/toml/rust.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,10 @@ pub(crate) fn parse_codegen_backends(
415415
};
416416
found_backends.push(backend);
417417
}
418+
if found_backends.is_empty() {
419+
eprintln!("ERROR: `{section}.codegen-backends` should not be set to `[]`");
420+
exit!(1);
421+
}
418422
found_backends
419423
}
420424

0 commit comments

Comments
 (0)