Skip to content

compiletest: add {ignore,only}-rustc_abi-x86-sse2 directives #137074

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/doc/rustc-dev-guide/src/tests/directives.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
13 changes: 12 additions & 1 deletion src/tools/compiletest/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,7 @@ pub struct TargetCfgs {
pub all_abis: HashSet<String>,
pub all_families: HashSet<String>,
pub all_pointer_widths: HashSet<String>,
pub all_rustc_abis: HashSet<String>,
}

impl TargetCfgs {
Expand All @@ -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.
Expand Down Expand Up @@ -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());
}

Expand All @@ -590,6 +596,7 @@ impl TargetCfgs {
all_abis,
all_families,
all_pointer_widths,
all_rustc_abis,
}
}

Expand Down Expand Up @@ -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<String>,

// Not present in target cfg json output, additional derived information.
#[serde(skip)]
Expand Down
2 changes: 2 additions & 0 deletions src/tools/compiletest/src/directive-list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
8 changes: 8 additions & 0 deletions src/tools/compiletest/src/header/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
14 changes: 14 additions & 0 deletions src/tools/compiletest/src/header/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}
Comment on lines +894 to +905
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that #137037 changes is in master but hasn't reached beta yet, so the rustc_abi field isn't present for i686=unknown-linux-gnu yet.

Loading