Skip to content

Commit 358a1b9

Browse files
Auto merge of #145256 - GuillaumeGomez:bootstrap-test-codegen-backend, r=<try>
Add new `--test-codegen-backend` bootstrap option try-job: i686-gnu-1 try-job: i686-gnu-2
2 parents a153133 + 67a7a4d commit 358a1b9

File tree

16 files changed

+102
-8
lines changed

16 files changed

+102
-8
lines changed

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use tracing::{instrument, span};
2020

2121
use crate::core::build_steps::gcc::{Gcc, add_cg_gcc_cargo_flags};
2222
use crate::core::build_steps::tool::{RustcPrivateCompilers, SourceType, copy_lld_artifacts};
23-
use crate::core::build_steps::{dist, llvm};
23+
use crate::core::build_steps::{dist, gcc, llvm};
2424
use crate::core::builder;
2525
use crate::core::builder::{
2626
Builder, Cargo, Kind, RunConfig, ShouldRun, Step, StepMetadata, crate_description,
@@ -2358,6 +2358,19 @@ impl Step for Assemble {
23582358
dist::maybe_install_llvm_runtime(builder, target_compiler.host, &sysroot);
23592359
dist::maybe_install_llvm_target(builder, target_compiler.host, &sysroot);
23602360

2361+
if builder.config.gcc_enabled(target_compiler.host) {
2362+
let gcc::GccOutput { mut libgccjit } =
2363+
builder.ensure(gcc::Gcc { target: target_compiler.host });
2364+
let dst_libdir = sysroot.join("lib");
2365+
builder.install(&libgccjit, &dst_libdir, FileType::NativeLibrary);
2366+
if let Some(file_name) = libgccjit.file_name() {
2367+
let mut file_name = file_name.to_os_string();
2368+
file_name.push(".0");
2369+
libgccjit.set_file_name(file_name);
2370+
builder.install(&libgccjit, &dst_libdir, FileType::NativeLibrary);
2371+
}
2372+
}
2373+
23612374
// Link the compiler binary itself into place
23622375
let out_dir = builder.cargo_out(build_compiler, Mode::Rustc, host);
23632376
let rustc = out_dir.join(exe("rustc-main", host));

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: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,16 @@ impl Builder<'_> {
583583
rustflags.arg("--cfg=bootstrap");
584584
}
585585

586+
if self
587+
.config
588+
.default_codegen_backend(compiler.host)
589+
.is_some_and(|backend| backend.is_gcc())
590+
{
591+
let sysroot = sysroot.join("lib");
592+
let sysroot_str = sysroot.as_os_str().to_str().expect("sysroot should be UTF-8");
593+
cargo.env("LD_LIBRARY_PATH", sysroot_str);
594+
}
595+
586596
if cmd_kind == Kind::Clippy {
587597
// clippy overwrites sysroot if we pass it to cargo.
588598
// Pass it directly to clippy instead.
@@ -1292,7 +1302,12 @@ impl Builder<'_> {
12921302

12931303
if let Some(limit) = limit
12941304
&& (build_compiler_stage == 0
1295-
|| 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())
12961311
{
12971312
rustflags.arg(&format!("-Cllvm-args=-import-instr-limit={limit}"));
12981313
}

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

Lines changed: 6 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 {
@@ -1774,6 +1774,10 @@ impl Config {
17741774
self.enabled_codegen_backends(target).contains(&CodegenBackendKind::Llvm)
17751775
}
17761776

1777+
pub fn gcc_enabled(&self, target: TargetSelection) -> bool {
1778+
self.enabled_codegen_backends(target).contains(&CodegenBackendKind::Gcc)
1779+
}
1780+
17771781
pub fn llvm_libunwind(&self, target: TargetSelection) -> LlvmLibunwind {
17781782
self.target_config
17791783
.get(&target)

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

0 commit comments

Comments
 (0)