Skip to content

Commit 09c014a

Browse files
Add new --test-codegen-backend bootstrap option
1 parent eefa83e commit 09c014a

File tree

14 files changed

+69
-7
lines changed

14 files changed

+69
-7
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
];

src/etc/completions/x.fish

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ complete -c x -n "__fish_x_using_subcommand test" -l extra-checks -d 'comma-sepa
303303
complete -c x -n "__fish_x_using_subcommand test" -l compare-mode -d 'mode describing what file the actual ui output will be compared to' -r
304304
complete -c x -n "__fish_x_using_subcommand test" -l pass -d 'force {check,build,run}-pass tests to this mode' -r
305305
complete -c x -n "__fish_x_using_subcommand test" -l run -d 'whether to execute run-* tests' -r
306+
complete -c x -n "__fish_x_using_subcommand test" -l test-codegen-backend -d 'Use a different codegen backend when running tests' -r
306307
complete -c x -n "__fish_x_using_subcommand test" -l config -d 'TOML configuration file for build' -r -F
307308
complete -c x -n "__fish_x_using_subcommand test" -l build-dir -d 'Build directory, overrides `build.build-dir` in `bootstrap.toml`' -r -f -a "(__fish_complete_directories)"
308309
complete -c x -n "__fish_x_using_subcommand test" -l build -d 'host target of the stage0 compiler' -r -f

src/etc/completions/x.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ Register-ArgumentCompleter -Native -CommandName 'x' -ScriptBlock {
349349
[CompletionResult]::new('--compare-mode', '--compare-mode', [CompletionResultType]::ParameterName, 'mode describing what file the actual ui output will be compared to')
350350
[CompletionResult]::new('--pass', '--pass', [CompletionResultType]::ParameterName, 'force {check,build,run}-pass tests to this mode')
351351
[CompletionResult]::new('--run', '--run', [CompletionResultType]::ParameterName, 'whether to execute run-* tests')
352+
[CompletionResult]::new('--test-codegen-backend', '--test-codegen-backend', [CompletionResultType]::ParameterName, 'Use a different codegen backend when running tests')
352353
[CompletionResult]::new('--config', '--config', [CompletionResultType]::ParameterName, 'TOML configuration file for build')
353354
[CompletionResult]::new('--build-dir', '--build-dir', [CompletionResultType]::ParameterName, 'Build directory, overrides `build.build-dir` in `bootstrap.toml`')
354355
[CompletionResult]::new('--build', '--build', [CompletionResultType]::ParameterName, 'host target of the stage0 compiler')

src/etc/completions/x.py.fish

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ complete -c x.py -n "__fish_x.py_using_subcommand test" -l extra-checks -d 'comm
303303
complete -c x.py -n "__fish_x.py_using_subcommand test" -l compare-mode -d 'mode describing what file the actual ui output will be compared to' -r
304304
complete -c x.py -n "__fish_x.py_using_subcommand test" -l pass -d 'force {check,build,run}-pass tests to this mode' -r
305305
complete -c x.py -n "__fish_x.py_using_subcommand test" -l run -d 'whether to execute run-* tests' -r
306+
complete -c x.py -n "__fish_x.py_using_subcommand test" -l test-codegen-backend -d 'Use a different codegen backend when running tests' -r
306307
complete -c x.py -n "__fish_x.py_using_subcommand test" -l config -d 'TOML configuration file for build' -r -F
307308
complete -c x.py -n "__fish_x.py_using_subcommand test" -l build-dir -d 'Build directory, overrides `build.build-dir` in `bootstrap.toml`' -r -f -a "(__fish_complete_directories)"
308309
complete -c x.py -n "__fish_x.py_using_subcommand test" -l build -d 'host target of the stage0 compiler' -r -f

src/etc/completions/x.py.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ Register-ArgumentCompleter -Native -CommandName 'x.py' -ScriptBlock {
349349
[CompletionResult]::new('--compare-mode', '--compare-mode', [CompletionResultType]::ParameterName, 'mode describing what file the actual ui output will be compared to')
350350
[CompletionResult]::new('--pass', '--pass', [CompletionResultType]::ParameterName, 'force {check,build,run}-pass tests to this mode')
351351
[CompletionResult]::new('--run', '--run', [CompletionResultType]::ParameterName, 'whether to execute run-* tests')
352+
[CompletionResult]::new('--test-codegen-backend', '--test-codegen-backend', [CompletionResultType]::ParameterName, 'Use a different codegen backend when running tests')
352353
[CompletionResult]::new('--config', '--config', [CompletionResultType]::ParameterName, 'TOML configuration file for build')
353354
[CompletionResult]::new('--build-dir', '--build-dir', [CompletionResultType]::ParameterName, 'Build directory, overrides `build.build-dir` in `bootstrap.toml`')
354355
[CompletionResult]::new('--build', '--build', [CompletionResultType]::ParameterName, 'host target of the stage0 compiler')

0 commit comments

Comments
 (0)