Skip to content

Commit 89fd59a

Browse files
authored
Rollup merge of rust-lang#145256 - GuillaumeGomez:bootstrap-test-codegen-backend, r=Kobzol,bjorn3
Add new `--test-codegen-backend` bootstrap option This new bootstrap command line flag allows to do: ```shell ./x.py test tests/ui/intrinsics/panic-uninitialized-zeroed.rs --stage 1 -j8 --test-codegen-backend gcc ``` This is the last step before running it into the CI. Supersedes rust-lang#144687. r? ````@Kobzol````
2 parents f1af532 + e4cdc0f commit 89fd59a

File tree

18 files changed

+103
-20
lines changed

18 files changed

+103
-20
lines changed

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

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1830,10 +1830,27 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
18301830
cmd.arg("--host").arg(&*compiler.host.triple);
18311831
cmd.arg("--llvm-filecheck").arg(builder.llvm_filecheck(builder.config.host_target));
18321832

1833-
if let Some(codegen_backend) = builder.config.default_codegen_backend(compiler.host) {
1834-
// Tells compiletest which codegen backend is used by default by the compiler.
1833+
if let Some(codegen_backend) = builder.config.cmd.test_codegen_backend() {
1834+
if !builder.config.enabled_codegen_backends(compiler.host).contains(codegen_backend) {
1835+
eprintln!(
1836+
"\
1837+
ERROR: No configured backend named `{name}`
1838+
HELP: You can add it into `bootstrap.toml` in `rust.codegen-backends = [{name:?}]`",
1839+
name = codegen_backend.name(),
1840+
);
1841+
crate::exit!(1);
1842+
}
1843+
// Tells compiletest that we want to use this codegen in particular and to override
1844+
// the default one.
1845+
cmd.arg("--override-codegen-backend").arg(codegen_backend.name());
1846+
// Tells compiletest which codegen backend to use.
1847+
// It is used to e.g. ignore tests that don't support that codegen backend.
1848+
cmd.arg("--default-codegen-backend").arg(codegen_backend.name());
1849+
} else {
1850+
// Tells compiletest which codegen backend to use.
18351851
// It is used to e.g. ignore tests that don't support that codegen backend.
1836-
cmd.arg("--codegen-backend").arg(codegen_backend.name());
1852+
cmd.arg("--default-codegen-backend")
1853+
.arg(builder.config.default_codegen_backend(compiler.host).unwrap().name());
18371854
}
18381855

18391856
if builder.build.config.llvm_enzyme {

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

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

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

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

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

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

17621762
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 {
@@ -419,6 +419,9 @@ pub enum Subcommand {
419419
#[arg(long)]
420420
/// don't capture stdout/stderr of tests
421421
no_capture: bool,
422+
#[arg(long)]
423+
/// Use a different codegen backend when running tests.
424+
test_codegen_backend: Option<CodegenBackendKind>,
422425
},
423426
/// Build and run some test suites *in Miri*
424427
Miri {
@@ -658,6 +661,13 @@ impl Subcommand {
658661
_ => vec![],
659662
}
660663
}
664+
665+
pub fn test_codegen_backend(&self) -> Option<&CodegenBackendKind> {
666+
match self {
667+
Subcommand::Test { test_codegen_backend, .. } => test_codegen_backend.as_ref(),
668+
_ => None,
669+
}
670+
}
661671
}
662672

663673
/// 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
@@ -165,6 +165,20 @@ impl CodegenBackendKind {
165165
}
166166
}
167167

168+
impl std::str::FromStr for CodegenBackendKind {
169+
type Err = &'static str;
170+
171+
fn from_str(s: &str) -> Result<Self, Self::Err> {
172+
match s.to_lowercase().as_str() {
173+
"" => Err("Invalid empty backend name"),
174+
"gcc" => Ok(Self::Gcc),
175+
"llvm" => Ok(Self::Llvm),
176+
"cranelift" => Ok(Self::Cranelift),
177+
_ => Ok(Self::Custom(s.to_string())),
178+
}
179+
}
180+
}
181+
168182
#[derive(PartialEq, Eq, Copy, Clone, Debug)]
169183
pub enum DocTests {
170184
/// 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
@@ -506,6 +506,11 @@ pub const CONFIG_CHANGE_HISTORY: &[ChangeInfo] = &[
506506
severity: ChangeSeverity::Warning,
507507
summary: "It is no longer possible to `x clippy` with stage 0. All clippy commands have to be on stage 1+.",
508508
},
509+
ChangeInfo {
510+
change_id: 145256,
511+
severity: ChangeSeverity::Info,
512+
summary: "Added `--test-codegen-backend` CLI option for tests",
513+
},
509514
ChangeInfo {
510515
change_id: 145379,
511516
severity: ChangeSeverity::Info,

src/etc/completions/x.fish

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ complete -c x -n "__fish_x_using_subcommand test" -l extra-checks -d 'comma-sepa
305305
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
306306
complete -c x -n "__fish_x_using_subcommand test" -l pass -d 'force {check,build,run}-pass tests to this mode' -r
307307
complete -c x -n "__fish_x_using_subcommand test" -l run -d 'whether to execute run-* tests' -r
308+
complete -c x -n "__fish_x_using_subcommand test" -l test-codegen-backend -d 'Use a different codegen backend when running tests' -r
308309
complete -c x -n "__fish_x_using_subcommand test" -l config -d 'TOML configuration file for build' -r -F
309310
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)"
310311
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
@@ -351,6 +351,7 @@ Register-ArgumentCompleter -Native -CommandName 'x' -ScriptBlock {
351351
[CompletionResult]::new('--compare-mode', '--compare-mode', [CompletionResultType]::ParameterName, 'mode describing what file the actual ui output will be compared to')
352352
[CompletionResult]::new('--pass', '--pass', [CompletionResultType]::ParameterName, 'force {check,build,run}-pass tests to this mode')
353353
[CompletionResult]::new('--run', '--run', [CompletionResultType]::ParameterName, 'whether to execute run-* tests')
354+
[CompletionResult]::new('--test-codegen-backend', '--test-codegen-backend', [CompletionResultType]::ParameterName, 'Use a different codegen backend when running tests')
354355
[CompletionResult]::new('--config', '--config', [CompletionResultType]::ParameterName, 'TOML configuration file for build')
355356
[CompletionResult]::new('--build-dir', '--build-dir', [CompletionResultType]::ParameterName, 'Build directory, overrides `build.build-dir` in `bootstrap.toml`')
356357
[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
@@ -305,6 +305,7 @@ complete -c x.py -n "__fish_x.py_using_subcommand test" -l extra-checks -d 'comm
305305
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
306306
complete -c x.py -n "__fish_x.py_using_subcommand test" -l pass -d 'force {check,build,run}-pass tests to this mode' -r
307307
complete -c x.py -n "__fish_x.py_using_subcommand test" -l run -d 'whether to execute run-* tests' -r
308+
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
308309
complete -c x.py -n "__fish_x.py_using_subcommand test" -l config -d 'TOML configuration file for build' -r -F
309310
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)"
310311
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
@@ -351,6 +351,7 @@ Register-ArgumentCompleter -Native -CommandName 'x.py' -ScriptBlock {
351351
[CompletionResult]::new('--compare-mode', '--compare-mode', [CompletionResultType]::ParameterName, 'mode describing what file the actual ui output will be compared to')
352352
[CompletionResult]::new('--pass', '--pass', [CompletionResultType]::ParameterName, 'force {check,build,run}-pass tests to this mode')
353353
[CompletionResult]::new('--run', '--run', [CompletionResultType]::ParameterName, 'whether to execute run-* tests')
354+
[CompletionResult]::new('--test-codegen-backend', '--test-codegen-backend', [CompletionResultType]::ParameterName, 'Use a different codegen backend when running tests')
354355
[CompletionResult]::new('--config', '--config', [CompletionResultType]::ParameterName, 'TOML configuration file for build')
355356
[CompletionResult]::new('--build-dir', '--build-dir', [CompletionResultType]::ParameterName, 'Build directory, overrides `build.build-dir` in `bootstrap.toml`')
356357
[CompletionResult]::new('--build', '--build', [CompletionResultType]::ParameterName, 'host target of the stage0 compiler')

0 commit comments

Comments
 (0)