Skip to content

Commit 77ed54a

Browse files
authored
Rollup merge of rust-lang#137074 - jieyouxu:rustc_abi, r=onur-ozkan
compiletest: add `{ignore,only}-rustc_abi-x86-sse2` directives As requested in https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/compiletest.20target.20selection.20is.20way.20too.20rigid, cc `@RalfJung` r? bootstrap (or compiler)
2 parents 6a7bff2 + d419da1 commit 77ed54a

File tree

5 files changed

+37
-1
lines changed

5 files changed

+37
-1
lines changed

Diff for: src/doc/rustc-dev-guide/src/tests/directives.md

+1
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ Some examples of `X` in `ignore-X` or `only-X`:
154154
`ignore-coverage-map`, `ignore-coverage-run`
155155
- When testing a dist toolchain: `dist`
156156
- This needs to be enabled with `COMPILETEST_ENABLE_DIST_TESTS=1`
157+
- The `rustc_abi` of the target: e.g. `rustc_abi-x86_64-sse2`
157158

158159
The following directives will check rustc build settings and target
159160
settings:

Diff for: src/tools/compiletest/src/common.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,7 @@ pub struct TargetCfgs {
517517
pub all_abis: HashSet<String>,
518518
pub all_families: HashSet<String>,
519519
pub all_pointer_widths: HashSet<String>,
520+
pub all_rustc_abis: HashSet<String>,
520521
}
521522

522523
impl TargetCfgs {
@@ -536,6 +537,9 @@ impl TargetCfgs {
536537
let mut all_abis = HashSet::new();
537538
let mut all_families = HashSet::new();
538539
let mut all_pointer_widths = HashSet::new();
540+
// NOTE: for distinction between `abi` and `rustc_abi`, see comment on
541+
// `TargetCfg::rustc_abi`.
542+
let mut all_rustc_abis = HashSet::new();
539543

540544
// If current target is not included in the `--print=all-target-specs-json` output,
541545
// we check whether it is a custom target from the user or a synthetic target from bootstrap.
@@ -576,7 +580,9 @@ impl TargetCfgs {
576580
all_families.insert(family.clone());
577581
}
578582
all_pointer_widths.insert(format!("{}bit", cfg.pointer_width));
579-
583+
if let Some(rustc_abi) = &cfg.rustc_abi {
584+
all_rustc_abis.insert(rustc_abi.clone());
585+
}
580586
all_targets.insert(target.clone());
581587
}
582588

@@ -590,6 +596,7 @@ impl TargetCfgs {
590596
all_abis,
591597
all_families,
592598
all_pointer_widths,
599+
all_rustc_abis,
593600
}
594601
}
595602

@@ -676,6 +683,10 @@ pub struct TargetCfg {
676683
pub(crate) xray: bool,
677684
#[serde(default = "default_reloc_model")]
678685
pub(crate) relocation_model: String,
686+
// NOTE: `rustc_abi` should not be confused with `abi`. `rustc_abi` was introduced in #137037 to
687+
// make SSE2 *required* by the ABI (kind of a hack to make a target feature *required* via the
688+
// target spec).
689+
pub(crate) rustc_abi: Option<String>,
679690

680691
// Not present in target cfg json output, additional derived information.
681692
#[serde(skip)]

Diff for: src/tools/compiletest/src/directive-list.rs

+2
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ const KNOWN_DIRECTIVE_NAMES: &[&str] = &[
8787
"ignore-remote",
8888
"ignore-riscv64",
8989
"ignore-rustc-debug-assertions",
90+
"ignore-rustc_abi-x86-sse2",
9091
"ignore-s390x",
9192
"ignore-sgx",
9293
"ignore-sparc64",
@@ -198,6 +199,7 @@ const KNOWN_DIRECTIVE_NAMES: &[&str] = &[
198199
"only-nvptx64",
199200
"only-powerpc",
200201
"only-riscv64",
202+
"only-rustc_abi-x86-sse2",
201203
"only-s390x",
202204
"only-sparc",
203205
"only-sparc64",

Diff for: src/tools/compiletest/src/header/cfg.rs

+8
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,14 @@ fn parse_cfg_name_directive<'a>(
234234
allowed_names: ["coverage-map", "coverage-run"],
235235
message: "when the test mode is {name}",
236236
}
237+
condition! {
238+
name: target_cfg.rustc_abi.as_ref().map(|abi| format!("rustc_abi-{abi}")).unwrap_or_default(),
239+
allowed_names: ContainsPrefixed {
240+
prefix: "rustc_abi-",
241+
inner: target_cfgs.all_rustc_abis.clone(),
242+
},
243+
message: "when the target `rustc_abi` is {name}",
244+
}
237245

238246
condition! {
239247
name: "dist",

Diff for: src/tools/compiletest/src/header/tests.rs

+14
Original file line numberDiff line numberDiff line change
@@ -889,3 +889,17 @@ fn test_needs_target_has_atomic() {
889889
assert!(!check_ignore(&config, "//@ needs-target-has-atomic: 8, ptr"));
890890
assert!(check_ignore(&config, "//@ needs-target-has-atomic: 8, ptr, 128"));
891891
}
892+
893+
#[test]
894+
// FIXME: this test will fail against stage 0 until #137037 changes reach beta.
895+
#[cfg_attr(bootstrap, ignore)]
896+
fn test_rustc_abi() {
897+
let config = cfg().target("i686-unknown-linux-gnu").build();
898+
assert_eq!(config.target_cfg().rustc_abi, Some("x86-sse2".to_string()));
899+
assert!(check_ignore(&config, "//@ ignore-rustc_abi-x86-sse2"));
900+
assert!(!check_ignore(&config, "//@ only-rustc_abi-x86-sse2"));
901+
let config = cfg().target("x86_64-unknown-linux-gnu").build();
902+
assert_eq!(config.target_cfg().rustc_abi, None);
903+
assert!(!check_ignore(&config, "//@ ignore-rustc_abi-x86-sse2"));
904+
assert!(check_ignore(&config, "//@ only-rustc_abi-x86-sse2"));
905+
}

0 commit comments

Comments
 (0)