Skip to content

Commit 2261968

Browse files
bootstrap: Make default_codegen_backend return &CodegenBackendKind instead of an Option
1 parent 5ce678a commit 2261968

File tree

4 files changed

+6
-12
lines changed

4 files changed

+6
-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
@@ -1326,12 +1326,7 @@ impl Builder<'_> {
13261326

13271327
if let Some(limit) = limit
13281328
&& (build_compiler_stage == 0
1329-
|| self
1330-
.config
1331-
.default_codegen_backend(target)
1332-
.cloned()
1333-
.unwrap_or_default()
1334-
.is_llvm())
1329+
|| self.config.default_codegen_backend(target).is_llvm())
13351330
{
13361331
rustflags.arg(&format!("-Cllvm-args=-import-instr-limit={limit}"));
13371332
}

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 {

0 commit comments

Comments
 (0)