Skip to content

Commit 65df661

Browse files
Add new --test-codegen-backend bootstrap option
1 parent eefa83e commit 65df661

File tree

6 files changed

+53
-5
lines changed

6 files changed

+53
-5
lines changed

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1845,7 +1845,21 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
18451845
cmd.arg("--host").arg(&*compiler.host.triple);
18461846
cmd.arg("--llvm-filecheck").arg(builder.llvm_filecheck(builder.config.host_target));
18471847

1848-
if let Some(codegen_backend) = builder.config.default_codegen_backend(compiler.host) {
1848+
if let Some(codegen_backend) = builder.config.cmd.test_codegen_backend() {
1849+
if !builder.config.enabled_codegen_backends(compiler.host).contains(codegen_backend) {
1850+
eprintln!(
1851+
"\
1852+
ERROR: No configured backend named `{name}`
1853+
HELP: You can add it into `bootstrap.toml` in `rust.codegen-backends = [{name:?}]`",
1854+
name = codegen_backend.name(),
1855+
);
1856+
crate::exit!(1);
1857+
}
1858+
// Tells compiletest which codegen backend is used by default by the compiler.
1859+
// It is used to e.g. ignore tests that don't support that codegen backend.
1860+
cmd.arg("--codegen-backend").arg(codegen_backend.name());
1861+
} else if let Some(codegen_backend) = builder.config.default_codegen_backend(compiler.host)
1862+
{
18491863
// Tells compiletest which codegen backend is used by default by the compiler.
18501864
// It is used to e.g. ignore tests that don't support that codegen backend.
18511865
cmd.arg("--codegen-backend").arg(codegen_backend.name());

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1302,7 +1302,12 @@ impl Builder<'_> {
13021302

13031303
if let Some(limit) = limit
13041304
&& (build_compiler_stage == 0
1305-
|| self.config.default_codegen_backend(target).unwrap_or_default().is_llvm())
1305+
|| self
1306+
.config
1307+
.default_codegen_backend(target)
1308+
.cloned()
1309+
.unwrap_or_default()
1310+
.is_llvm())
13061311
{
13071312
rustflags.arg(&format!("-Cllvm-args=-import-instr-limit={limit}"));
13081313
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1751,8 +1751,8 @@ impl Config {
17511751

17521752
/// Returns the codegen backend that should be configured as the *default* codegen backend
17531753
/// for a rustc compiled by bootstrap.
1754-
pub fn default_codegen_backend(&self, target: TargetSelection) -> Option<CodegenBackendKind> {
1755-
self.enabled_codegen_backends(target).first().cloned()
1754+
pub fn default_codegen_backend(&self, target: TargetSelection) -> Option<&CodegenBackendKind> {
1755+
self.enabled_codegen_backends(target).first()
17561756
}
17571757

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

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::core::build_steps::setup::Profile;
1515
use crate::core::builder::{Builder, Kind};
1616
use crate::core::config::Config;
1717
use crate::core::config::target_selection::{TargetSelectionList, target_selection_list};
18-
use crate::{Build, DocTests};
18+
use crate::{Build, CodegenBackendKind, DocTests};
1919

2020
#[derive(Copy, Clone, Default, Debug, ValueEnum)]
2121
pub enum Color {
@@ -413,6 +413,9 @@ pub enum Subcommand {
413413
#[arg(long)]
414414
/// don't capture stdout/stderr of tests
415415
no_capture: bool,
416+
#[arg(long)]
417+
/// Use a different codegen backend when running tests.
418+
test_codegen_backend: Option<CodegenBackendKind>,
416419
},
417420
/// Build and run some test suites *in Miri*
418421
Miri {
@@ -639,6 +642,13 @@ impl Subcommand {
639642
_ => vec![],
640643
}
641644
}
645+
646+
pub fn test_codegen_backend(&self) -> Option<&CodegenBackendKind> {
647+
match self {
648+
Subcommand::Test { test_codegen_backend, .. } => test_codegen_backend.as_ref(),
649+
_ => None,
650+
}
651+
}
642652
}
643653

644654
/// Returns the shell completion for a given shell, if the result differs from the current

src/bootstrap/src/lib.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,20 @@ impl CodegenBackendKind {
163163
}
164164
}
165165

166+
impl std::str::FromStr for CodegenBackendKind {
167+
type Err = &'static str;
168+
169+
fn from_str(s: &str) -> Result<Self, Self::Err> {
170+
match s.to_lowercase().as_str() {
171+
"" => Err("Invalid empty backend name"),
172+
"gcc" => Ok(Self::Gcc),
173+
"llvm" => Ok(Self::Llvm),
174+
"cranelift" => Ok(Self::Cranelift),
175+
_ => Ok(Self::Custom(s.to_string())),
176+
}
177+
}
178+
}
179+
166180
#[derive(PartialEq, Eq, Copy, Clone, Debug)]
167181
pub enum DocTests {
168182
/// Run normal tests and doc tests (default).

src/bootstrap/src/utils/change_tracker.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,4 +496,9 @@ pub const CONFIG_CHANGE_HISTORY: &[ChangeInfo] = &[
496496
severity: ChangeSeverity::Warning,
497497
summary: "It is no longer possible to `x doc` with stage 0. All doc commands have to be on stage 1+.",
498498
},
499+
ChangeInfo {
500+
change_id: 145256,
501+
severity: ChangeSeverity::Info,
502+
summary: "Added `--test-codegen-backend` CLI option for tests",
503+
},
499504
];

0 commit comments

Comments
 (0)