Skip to content

Commit b2459e8

Browse files
authored
Unrolled build for #144125
Rollup merge of #144125 - GuillaumeGomez:new-annotations, r=Kobzol Add new `ignore-backends` and `needs-backends` tests annotations Part of rust-lang/compiler-team#891. Next step will be to add these annotations in the files where either the output is different based on the codegen (like `asm` tests) or that are known to fail in the GCC backend. cc `@oli-obk` `@antoyo` r? `@Kobzol`
2 parents ca9eecd + 4a35a9f commit b2459e8

File tree

5 files changed

+106
-2
lines changed

5 files changed

+106
-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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,8 @@ settings:
205205
on `wasm32-unknown-unknown` target because the target does not support the
206206
`proc-macro` crate type.
207207
- `needs-target-std` — ignores if target platform does not have std support.
208+
- `ignore-backends` — ignores the listed backends, separated by whitespace characters.
209+
- `needs-backends` — only runs the test if current codegen backend is listed.
208210

209211
The following directives will check LLVM support:
210212

src/tools/compiletest/src/common.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,36 @@ pub enum Sanitizer {
175175
Hwaddress,
176176
}
177177

178+
#[derive(Clone, Copy, Debug, PartialEq)]
179+
pub enum CodegenBackend {
180+
Cranelift,
181+
Gcc,
182+
Llvm,
183+
}
184+
185+
impl<'a> TryFrom<&'a str> for CodegenBackend {
186+
type Error = &'static str;
187+
188+
fn try_from(value: &'a str) -> Result<Self, Self::Error> {
189+
match value.to_lowercase().as_str() {
190+
"cranelift" => Ok(Self::Cranelift),
191+
"gcc" => Ok(Self::Gcc),
192+
"llvm" => Ok(Self::Llvm),
193+
_ => Err("unknown backend"),
194+
}
195+
}
196+
}
197+
198+
impl CodegenBackend {
199+
pub fn as_str(self) -> &'static str {
200+
match self {
201+
Self::Cranelift => "cranelift",
202+
Self::Gcc => "gcc",
203+
Self::Llvm => "llvm",
204+
}
205+
}
206+
}
207+
178208
/// Configuration for `compiletest` *per invocation*.
179209
///
180210
/// In terms of `bootstrap`, this means that `./x test tests/ui tests/run-make` actually correspond
@@ -651,6 +681,9 @@ pub struct Config {
651681
/// need `core` stubs in cross-compilation scenarios that do not otherwise want/need to
652682
/// `-Zbuild-std`. Used in e.g. ABI tests.
653683
pub minicore_path: Utf8PathBuf,
684+
685+
/// Current codegen backend used.
686+
pub codegen_backend: CodegenBackend,
654687
}
655688

656689
impl Config {
@@ -753,6 +786,7 @@ impl Config {
753786
profiler_runtime: Default::default(),
754787
diff_command: Default::default(),
755788
minicore_path: Default::default(),
789+
codegen_backend: CodegenBackend::Llvm,
756790
}
757791
}
758792

src/tools/compiletest/src/directives.rs

Lines changed: 48 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, RunFailMode, TestMode};
12+
use crate::common::{CodegenBackend, Config, Debugger, FailMode, PassMode, RunFailMode, 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;
@@ -818,6 +818,7 @@ const KNOWN_DIRECTIVE_NAMES: &[&str] = &[
818818
"ignore-arm-unknown-linux-musleabihf",
819819
"ignore-auxiliary",
820820
"ignore-avr",
821+
"ignore-backends",
821822
"ignore-beta",
822823
"ignore-cdb",
823824
"ignore-compare-mode-next-solver",
@@ -907,6 +908,7 @@ const KNOWN_DIRECTIVE_NAMES: &[&str] = &[
907908
"min-llvm-version",
908909
"min-system-llvm-version",
909910
"needs-asm-support",
911+
"needs-backends",
910912
"needs-crate-type",
911913
"needs-deterministic-layouts",
912914
"needs-dlltool",
@@ -1669,6 +1671,8 @@ pub(crate) fn make_test_description<R: Read>(
16691671
decision!(cfg::handle_only(config, ln));
16701672
decision!(needs::handle_needs(&cache.needs, config, ln));
16711673
decision!(ignore_llvm(config, path, ln));
1674+
decision!(ignore_backends(config, path, ln));
1675+
decision!(needs_backends(config, path, ln));
16721676
decision!(ignore_cdb(config, ln));
16731677
decision!(ignore_gdb(config, ln));
16741678
decision!(ignore_lldb(config, ln));
@@ -1795,6 +1799,49 @@ fn ignore_lldb(config: &Config, line: &str) -> IgnoreDecision {
17951799
IgnoreDecision::Continue
17961800
}
17971801

1802+
fn ignore_backends(config: &Config, path: &Utf8Path, line: &str) -> IgnoreDecision {
1803+
if let Some(backends_to_ignore) = config.parse_name_value_directive(line, "ignore-backends") {
1804+
for backend in backends_to_ignore.split_whitespace().map(|backend| {
1805+
match CodegenBackend::try_from(backend) {
1806+
Ok(backend) => backend,
1807+
Err(error) => {
1808+
panic!("Invalid ignore-backends value `{backend}` in `{path}`: {error}")
1809+
}
1810+
}
1811+
}) {
1812+
if config.codegen_backend == backend {
1813+
return IgnoreDecision::Ignore {
1814+
reason: format!("{} backend is marked as ignore", backend.as_str()),
1815+
};
1816+
}
1817+
}
1818+
}
1819+
IgnoreDecision::Continue
1820+
}
1821+
1822+
fn needs_backends(config: &Config, path: &Utf8Path, line: &str) -> IgnoreDecision {
1823+
if let Some(needed_backends) = config.parse_name_value_directive(line, "needs-backends") {
1824+
if !needed_backends
1825+
.split_whitespace()
1826+
.map(|backend| match CodegenBackend::try_from(backend) {
1827+
Ok(backend) => backend,
1828+
Err(error) => {
1829+
panic!("Invalid needs-backends value `{backend}` in `{path}`: {error}")
1830+
}
1831+
})
1832+
.any(|backend| config.codegen_backend == backend)
1833+
{
1834+
return IgnoreDecision::Ignore {
1835+
reason: format!(
1836+
"{} backend is not part of required backends",
1837+
config.codegen_backend.as_str()
1838+
),
1839+
};
1840+
}
1841+
}
1842+
IgnoreDecision::Continue
1843+
}
1844+
17981845
fn ignore_llvm(config: &Config, path: &Utf8Path, line: &str) -> IgnoreDecision {
17991846
if let Some(needed_components) =
18001847
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)