diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2025-07-18 12:05:08 +0200 |
|---|---|---|
| committer | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2025-07-20 14:44:01 +0200 |
| commit | 4a35a9f074f5df8ce0d1f14d8569da3b6badfc01 (patch) | |
| tree | 79792e61b140ed200810ee043bb501d2f1df9aad | |
| parent | 9944139f70f2423f572ce48675458ccb67bb8d46 (diff) | |
| download | rust-4a35a9f074f5df8ce0d1f14d8569da3b6badfc01.tar.gz rust-4a35a9f074f5df8ce0d1f14d8569da3b6badfc01.zip | |
Add new `needs-backends` tests annotations
| -rw-r--r-- | src/doc/rustc-dev-guide/src/tests/directives.md | 1 | ||||
| -rw-r--r-- | src/tools/compiletest/src/directives.rs | 25 |
2 files changed, 26 insertions, 0 deletions
diff --git a/src/doc/rustc-dev-guide/src/tests/directives.md b/src/doc/rustc-dev-guide/src/tests/directives.md index 15655d1bb2c..5c3ae359ba0 100644 --- a/src/doc/rustc-dev-guide/src/tests/directives.md +++ b/src/doc/rustc-dev-guide/src/tests/directives.md @@ -206,6 +206,7 @@ settings: `proc-macro` crate type. - `needs-target-std` — ignores if target platform does not have std support. - `ignore-backends` — ignores the listed backends, separated by whitespace characters. +- `needs-backends` — only runs the test if current codegen backend is listed. The following directives will check LLVM support: diff --git a/src/tools/compiletest/src/directives.rs b/src/tools/compiletest/src/directives.rs index b773956c69f..1397c87ab07 100644 --- a/src/tools/compiletest/src/directives.rs +++ b/src/tools/compiletest/src/directives.rs @@ -908,6 +908,7 @@ const KNOWN_DIRECTIVE_NAMES: &[&str] = &[ "min-llvm-version", "min-system-llvm-version", "needs-asm-support", + "needs-backends", "needs-crate-type", "needs-deterministic-layouts", "needs-dlltool", @@ -1671,6 +1672,7 @@ pub(crate) fn make_test_description<R: Read>( decision!(needs::handle_needs(&cache.needs, config, ln)); decision!(ignore_llvm(config, path, ln)); decision!(ignore_backends(config, path, ln)); + decision!(needs_backends(config, path, ln)); decision!(ignore_cdb(config, ln)); decision!(ignore_gdb(config, ln)); decision!(ignore_lldb(config, ln)); @@ -1817,6 +1819,29 @@ fn ignore_backends(config: &Config, path: &Utf8Path, line: &str) -> IgnoreDecisi IgnoreDecision::Continue } +fn needs_backends(config: &Config, path: &Utf8Path, line: &str) -> IgnoreDecision { + if let Some(needed_backends) = config.parse_name_value_directive(line, "needs-backends") { + if !needed_backends + .split_whitespace() + .map(|backend| match CodegenBackend::try_from(backend) { + Ok(backend) => backend, + Err(error) => { + panic!("Invalid needs-backends value `{backend}` in `{path}`: {error}") + } + }) + .any(|backend| config.codegen_backend == backend) + { + return IgnoreDecision::Ignore { + reason: format!( + "{} backend is not part of required backends", + config.codegen_backend.as_str() + ), + }; + } + } + IgnoreDecision::Continue +} + fn ignore_llvm(config: &Config, path: &Utf8Path, line: &str) -> IgnoreDecision { if let Some(needed_components) = config.parse_name_value_directive(line, "needs-llvm-components") |
