diff --git a/src/doc/rustc-dev-guide/src/tests/directives.md b/src/doc/rustc-dev-guide/src/tests/directives.md index b6209bcb2d806..00bb2bc4dbb1e 100644 --- a/src/doc/rustc-dev-guide/src/tests/directives.md +++ b/src/doc/rustc-dev-guide/src/tests/directives.md @@ -154,6 +154,7 @@ Some examples of `X` in `ignore-X` or `only-X`: `ignore-coverage-map`, `ignore-coverage-run` - When testing a dist toolchain: `dist` - This needs to be enabled with `COMPILETEST_ENABLE_DIST_TESTS=1` +- The `rustc_abi` of the target: e.g. `rustc_abi-x86_64-sse2` The following directives will check rustc build settings and target settings: diff --git a/src/tools/compiletest/src/common.rs b/src/tools/compiletest/src/common.rs index cde4f7a665cbf..1614c35cb1ce4 100644 --- a/src/tools/compiletest/src/common.rs +++ b/src/tools/compiletest/src/common.rs @@ -517,6 +517,7 @@ pub struct TargetCfgs { pub all_abis: HashSet, pub all_families: HashSet, pub all_pointer_widths: HashSet, + pub all_rustc_abis: HashSet, } impl TargetCfgs { @@ -536,6 +537,9 @@ impl TargetCfgs { let mut all_abis = HashSet::new(); let mut all_families = HashSet::new(); let mut all_pointer_widths = HashSet::new(); + // NOTE: for distinction between `abi` and `rustc_abi`, see comment on + // `TargetCfg::rustc_abi`. + let mut all_rustc_abis = HashSet::new(); // If current target is not included in the `--print=all-target-specs-json` output, // we check whether it is a custom target from the user or a synthetic target from bootstrap. @@ -576,7 +580,9 @@ impl TargetCfgs { all_families.insert(family.clone()); } all_pointer_widths.insert(format!("{}bit", cfg.pointer_width)); - + if let Some(rustc_abi) = &cfg.rustc_abi { + all_rustc_abis.insert(rustc_abi.clone()); + } all_targets.insert(target.clone()); } @@ -590,6 +596,7 @@ impl TargetCfgs { all_abis, all_families, all_pointer_widths, + all_rustc_abis, } } @@ -676,6 +683,10 @@ pub struct TargetCfg { pub(crate) xray: bool, #[serde(default = "default_reloc_model")] pub(crate) relocation_model: String, + // NOTE: `rustc_abi` should not be confused with `abi`. `rustc_abi` was introduced in #137037 to + // make SSE2 *required* by the ABI (kind of a hack to make a target feature *required* via the + // target spec). + pub(crate) rustc_abi: Option, // Not present in target cfg json output, additional derived information. #[serde(skip)] diff --git a/src/tools/compiletest/src/directive-list.rs b/src/tools/compiletest/src/directive-list.rs index a7ac875d0a36c..8c909bcb19527 100644 --- a/src/tools/compiletest/src/directive-list.rs +++ b/src/tools/compiletest/src/directive-list.rs @@ -87,6 +87,7 @@ const KNOWN_DIRECTIVE_NAMES: &[&str] = &[ "ignore-remote", "ignore-riscv64", "ignore-rustc-debug-assertions", + "ignore-rustc_abi-x86-sse2", "ignore-s390x", "ignore-sgx", "ignore-sparc64", @@ -198,6 +199,7 @@ const KNOWN_DIRECTIVE_NAMES: &[&str] = &[ "only-nvptx64", "only-powerpc", "only-riscv64", + "only-rustc_abi-x86-sse2", "only-s390x", "only-sparc", "only-sparc64", diff --git a/src/tools/compiletest/src/header/cfg.rs b/src/tools/compiletest/src/header/cfg.rs index cfe51b5655f82..72a3b9d85c8cf 100644 --- a/src/tools/compiletest/src/header/cfg.rs +++ b/src/tools/compiletest/src/header/cfg.rs @@ -234,6 +234,14 @@ fn parse_cfg_name_directive<'a>( allowed_names: ["coverage-map", "coverage-run"], message: "when the test mode is {name}", } + condition! { + name: target_cfg.rustc_abi.as_ref().map(|abi| format!("rustc_abi-{abi}")).unwrap_or_default(), + allowed_names: ContainsPrefixed { + prefix: "rustc_abi-", + inner: target_cfgs.all_rustc_abis.clone(), + }, + message: "when the target `rustc_abi` is {name}", + } condition! { name: "dist", diff --git a/src/tools/compiletest/src/header/tests.rs b/src/tools/compiletest/src/header/tests.rs index 522d340b678f9..55292c46bba9c 100644 --- a/src/tools/compiletest/src/header/tests.rs +++ b/src/tools/compiletest/src/header/tests.rs @@ -889,3 +889,17 @@ fn test_needs_target_has_atomic() { assert!(!check_ignore(&config, "//@ needs-target-has-atomic: 8, ptr")); assert!(check_ignore(&config, "//@ needs-target-has-atomic: 8, ptr, 128")); } + +#[test] +// FIXME: this test will fail against stage 0 until #137037 changes reach beta. +#[cfg_attr(bootstrap, ignore)] +fn test_rustc_abi() { + let config = cfg().target("i686-unknown-linux-gnu").build(); + assert_eq!(config.target_cfg().rustc_abi, Some("x86-sse2".to_string())); + assert!(check_ignore(&config, "//@ ignore-rustc_abi-x86-sse2")); + assert!(!check_ignore(&config, "//@ only-rustc_abi-x86-sse2")); + let config = cfg().target("x86_64-unknown-linux-gnu").build(); + assert_eq!(config.target_cfg().rustc_abi, None); + assert!(!check_ignore(&config, "//@ ignore-rustc_abi-x86-sse2")); + assert!(check_ignore(&config, "//@ only-rustc_abi-x86-sse2")); +}