Skip to content

Commit c479671

Browse files
Add new ignore-backends tests annotations
1 parent f8f6997 commit c479671

File tree

5 files changed

+80
-2
lines changed

5 files changed

+80
-2
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1757,6 +1757,10 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
17571757
cmd.arg("--host").arg(&*compiler.host.triple);
17581758
cmd.arg("--llvm-filecheck").arg(builder.llvm_filecheck(builder.config.host_target));
17591759

1760+
if let Some(codegen_backend) = builder.config.default_codegen_backend(compiler.host) {
1761+
cmd.arg("--codegen-backend").arg(&codegen_backend);
1762+
}
1763+
17601764
if builder.build.config.llvm_enzyme {
17611765
cmd.arg("--has-enzyme");
17621766
}

src/doc/rustc-dev-guide/src/tests/directives.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ settings:
203203
on `wasm32-unknown-unknown` target because the target does not support the
204204
`proc-macro` crate type.
205205
- `needs-target-std` — ignores if target platform does not have std support.
206+
- `ignore-backends` — ignores the listed backends, separated by whitespace characters.
206207

207208
The following directives will check LLVM support:
208209

src/tools/compiletest/src/common.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,36 @@ pub enum Sanitizer {
149149
Hwaddress,
150150
}
151151

152+
#[derive(Clone, Copy, Debug, PartialEq)]
153+
pub enum CodegenBackend {
154+
Cranelift,
155+
Gcc,
156+
Llvm,
157+
}
158+
159+
impl<'a> TryFrom<&'a str> for CodegenBackend {
160+
type Error = &'static str;
161+
162+
fn try_from(value: &'a str) -> Result<Self, Self::Error> {
163+
match value.to_lowercase().as_str() {
164+
"cranelift" => Ok(Self::Cranelift),
165+
"gcc" => Ok(Self::Gcc),
166+
"llvm" => Ok(Self::Llvm),
167+
_ => Err("unknown backend"),
168+
}
169+
}
170+
}
171+
172+
impl CodegenBackend {
173+
pub fn as_str(self) -> &'static str {
174+
match self {
175+
Self::Cranelift => "cranelift",
176+
Self::Gcc => "gcc",
177+
Self::Llvm => "llvm",
178+
}
179+
}
180+
}
181+
152182
/// Configuration for `compiletest` *per invocation*.
153183
///
154184
/// In terms of `bootstrap`, this means that `./x test tests/ui tests/run-make` actually correspond
@@ -625,6 +655,9 @@ pub struct Config {
625655
/// need `core` stubs in cross-compilation scenarios that do not otherwise want/need to
626656
/// `-Zbuild-std`. Used in e.g. ABI tests.
627657
pub minicore_path: Utf8PathBuf,
658+
659+
/// Current codegen backend used.
660+
pub codegen_backend: CodegenBackend,
628661
}
629662

630663
impl Config {
@@ -727,6 +760,7 @@ impl Config {
727760
profiler_runtime: Default::default(),
728761
diff_command: Default::default(),
729762
minicore_path: Default::default(),
763+
codegen_backend: CodegenBackend::Llvm,
730764
}
731765
}
732766

src/tools/compiletest/src/directives.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use camino::{Utf8Path, Utf8PathBuf};
99
use semver::Version;
1010
use tracing::*;
1111

12-
use crate::common::{Config, Debugger, FailMode, PassMode, TestMode};
12+
use crate::common::{CodegenBackend, Config, Debugger, FailMode, PassMode, TestMode};
1313
use crate::debuggers::{extract_cdb_version, extract_gdb_version};
1414
use crate::directives::auxiliary::{AuxProps, parse_and_update_aux};
1515
use crate::directives::needs::CachedNeedsConditions;
@@ -812,6 +812,7 @@ const KNOWN_DIRECTIVE_NAMES: &[&str] = &[
812812
"ignore-arm-unknown-linux-musleabihf",
813813
"ignore-auxiliary",
814814
"ignore-avr",
815+
"ignore-backends",
815816
"ignore-beta",
816817
"ignore-cdb",
817818
"ignore-compare-mode-next-solver",
@@ -1661,6 +1662,7 @@ pub(crate) fn make_test_description<R: Read>(
16611662
decision!(cfg::handle_only(config, ln));
16621663
decision!(needs::handle_needs(&cache.needs, config, ln));
16631664
decision!(ignore_llvm(config, path, ln));
1665+
decision!(ignore_backends(config, path, ln));
16641666
decision!(ignore_cdb(config, ln));
16651667
decision!(ignore_gdb(config, ln));
16661668
decision!(ignore_lldb(config, ln));
@@ -1787,6 +1789,26 @@ fn ignore_lldb(config: &Config, line: &str) -> IgnoreDecision {
17871789
IgnoreDecision::Continue
17881790
}
17891791

1792+
fn ignore_backends(config: &Config, path: &Utf8Path, line: &str) -> IgnoreDecision {
1793+
if let Some(backends_to_ignore) = config.parse_name_value_directive(line, "ignore-backends") {
1794+
for backend in backends_to_ignore.split_whitespace().map(|backend| {
1795+
match CodegenBackend::try_from(backend) {
1796+
Ok(backend) => backend,
1797+
Err(error) => {
1798+
panic!("Invalid ignore-backends value `{backend}` in `{path}`: {error}")
1799+
}
1800+
}
1801+
}) {
1802+
if config.codegen_backend == backend {
1803+
return IgnoreDecision::Ignore {
1804+
reason: format!("{} backend is marked as ignore", backend.as_str()),
1805+
};
1806+
}
1807+
}
1808+
}
1809+
IgnoreDecision::Continue
1810+
}
1811+
17901812
fn ignore_llvm(config: &Config, path: &Utf8Path, line: &str) -> IgnoreDecision {
17911813
if let Some(needed_components) =
17921814
config.parse_name_value_directive(line, "needs-llvm-components")

src/tools/compiletest/src/lib.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use walkdir::WalkDir;
3939

4040
use self::directives::{EarlyProps, make_test_description};
4141
use crate::common::{
42-
CompareMode, Config, Debugger, PassMode, TestMode, TestPaths, UI_EXTENSIONS,
42+
CodegenBackend, CompareMode, Config, Debugger, PassMode, TestMode, TestPaths, UI_EXTENSIONS,
4343
expected_output_path, output_base_dir, output_relative_path,
4444
};
4545
use crate::directives::DirectivesCache;
@@ -203,6 +203,12 @@ pub fn parse_config(args: Vec<String>) -> Config {
203203
"debugger",
204204
"only test a specific debugger in debuginfo tests",
205205
"gdb | lldb | cdb",
206+
)
207+
.optopt(
208+
"",
209+
"codegen-backend",
210+
"the codegen backend currently used",
211+
"CODEGEN BACKEND NAME",
206212
);
207213

208214
let (argv0, args_) = args.split_first().unwrap();
@@ -264,6 +270,15 @@ pub fn parse_config(args: Vec<String>) -> Config {
264270
|| directives::extract_llvm_version_from_binary(&matches.opt_str("llvm-filecheck")?),
265271
);
266272

273+
let codegen_backend = match matches.opt_str("codegen-backend").as_deref() {
274+
Some(backend) => match CodegenBackend::try_from(backend) {
275+
Ok(backend) => backend,
276+
Err(error) => panic!("invalid value `{backend}` for `--codegen-backend`: {error}"),
277+
},
278+
// By default, it's always llvm.
279+
None => CodegenBackend::Llvm,
280+
};
281+
267282
let run_ignored = matches.opt_present("ignored");
268283
let with_rustc_debug_assertions = matches.opt_present("with-rustc-debug-assertions");
269284
let with_std_debug_assertions = matches.opt_present("with-std-debug-assertions");
@@ -449,6 +464,8 @@ pub fn parse_config(args: Vec<String>) -> Config {
449464
diff_command: matches.opt_str("compiletest-diff-tool"),
450465

451466
minicore_path: opt_path(matches, "minicore-path"),
467+
468+
codegen_backend,
452469
}
453470
}
454471

0 commit comments

Comments
 (0)