Split compiletest --codegen-backend into two options --default-codegen-backend and --override-codegen-backend

This commit is contained in:
Guillaume Gomez
2025-08-18 23:30:10 +02:00
parent 5a451b8c1c
commit e4cdc0f56e
5 changed files with 33 additions and 17 deletions
+7 -4
View File
@@ -1840,14 +1840,17 @@ fn run(self, builder: &Builder<'_>) {
);
crate::exit!(1);
}
// Tells compiletest that we want to use this codegen in particular and to override
// the default one.
cmd.arg("--override-codegen-backend").arg(codegen_backend.name());
// Tells compiletest which codegen backend to use.
// It is used to e.g. ignore tests that don't support that codegen backend.
cmd.arg("--codegen-backend").arg(codegen_backend.name());
} else if let Some(codegen_backend) = builder.config.default_codegen_backend(compiler.host)
{
cmd.arg("--default-codegen-backend").arg(codegen_backend.name());
} else {
// Tells compiletest which codegen backend to use.
// It is used to e.g. ignore tests that don't support that codegen backend.
cmd.arg("--codegen-backend").arg(codegen_backend.name());
cmd.arg("--default-codegen-backend")
.arg(builder.config.default_codegen_backend(compiler.host).unwrap().name());
}
if builder.build.config.llvm_enzyme {
+5 -2
View File
@@ -692,7 +692,9 @@ pub struct Config {
pub minicore_path: Utf8PathBuf,
/// Current codegen backend used.
pub codegen_backend: CodegenBackend,
pub default_codegen_backend: CodegenBackend,
/// Name/path of the backend to use instead of `default_codegen_backend`.
pub override_codegen_backend: Option<String>,
}
impl Config {
@@ -796,7 +798,8 @@ pub fn incomplete_for_rustdoc_gui_test() -> Config {
profiler_runtime: Default::default(),
diff_command: Default::default(),
minicore_path: Default::default(),
codegen_backend: CodegenBackend::Llvm,
default_codegen_backend: CodegenBackend::Llvm,
override_codegen_backend: None,
}
}
+3 -3
View File
@@ -1624,7 +1624,7 @@ fn ignore_backends(
}
}
}) {
if config.codegen_backend == backend {
if config.default_codegen_backend == backend {
return IgnoreDecision::Ignore {
reason: format!("{} backend is marked as ignore", backend.as_str()),
};
@@ -1651,12 +1651,12 @@ fn needs_backends(
panic!("Invalid needs-backends value `{backend}` in `{path}`: {error}")
}
})
.any(|backend| config.codegen_backend == backend)
.any(|backend| config.default_codegen_backend == backend)
{
return IgnoreDecision::Ignore {
reason: format!(
"{} backend is not part of required backends",
config.codegen_backend.as_str()
config.default_codegen_backend.as_str()
),
};
}
+16 -6
View File
@@ -212,9 +212,15 @@ pub fn parse_config(args: Vec<String>) -> Config {
)
.optopt(
"",
"codegen-backend",
"default-codegen-backend",
"the codegen backend currently used",
"CODEGEN BACKEND NAME",
)
.optopt(
"",
"override-codegen-backend",
"the codegen backend to use instead of the default one",
"CODEGEN BACKEND [NAME | PATH]",
);
let (argv0, args_) = args.split_first().unwrap();
@@ -276,14 +282,17 @@ fn opt_path(m: &getopts::Matches, nm: &str) -> Utf8PathBuf {
|| directives::extract_llvm_version_from_binary(&matches.opt_str("llvm-filecheck")?),
);
let codegen_backend = match matches.opt_str("codegen-backend").as_deref() {
let default_codegen_backend = match matches.opt_str("default-codegen-backend").as_deref() {
Some(backend) => match CodegenBackend::try_from(backend) {
Ok(backend) => backend,
Err(error) => panic!("invalid value `{backend}` for `--codegen-backend`: {error}"),
Err(error) => {
panic!("invalid value `{backend}` for `--defalt-codegen-backend`: {error}")
}
},
// By default, it's always llvm.
None => CodegenBackend::Llvm,
};
let override_codegen_backend = matches.opt_str("override-codegen-backend");
let run_ignored = matches.opt_present("ignored");
let with_rustc_debug_assertions = matches.opt_present("with-rustc-debug-assertions");
@@ -472,7 +481,8 @@ fn opt_path(m: &getopts::Matches, nm: &str) -> Utf8PathBuf {
minicore_path: opt_path(matches, "minicore-path"),
codegen_backend,
default_codegen_backend,
override_codegen_backend,
}
}
@@ -812,13 +822,13 @@ fn collect_tests_from_dir(
&& let Some(Utf8Component::Normal(parent)) = components.next()
&& parent == "tests"
&& let Ok(backend) = CodegenBackend::try_from(backend)
&& backend != cx.config.codegen_backend
&& backend != cx.config.default_codegen_backend
{
// We ignore asm tests which don't match the current codegen backend.
warning!(
"Ignoring tests in `{dir}` because they don't match the configured codegen \
backend (`{}`)",
cx.config.codegen_backend.as_str(),
cx.config.default_codegen_backend.as_str(),
);
return Ok(TestCollector::new());
}
+2 -2
View File
@@ -1559,8 +1559,8 @@ fn make_compile_args(
}
// If the provided codegen backend is not LLVM, we need to pass it.
if !matches!(self.config.codegen_backend, crate::CodegenBackend::Llvm) {
rustc.arg(format!("-Zcodegen-backend={}", self.config.codegen_backend.as_str()));
if let Some(ref backend) = self.config.override_codegen_backend {
rustc.arg(format!("-Zcodegen-backend={}", backend));
}
// Optionally prevent default --target if specified in test compile-flags.