Skip to content

Commit e10b2f6

Browse files
committed
Implement //@ needs-target-std directive in compiletest
To support tests to condition their (potentially cross-compile) execution based on whether the target supports std.
1 parent 8ef8062 commit e10b2f6

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

src/tools/compiletest/src/directive-list.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ const KNOWN_DIRECTIVE_NAMES: &[&str] = &[
166166
"needs-subprocess",
167167
"needs-symlink",
168168
"needs-target-has-atomic",
169+
"needs-target-std",
169170
"needs-threads",
170171
"needs-unwind",
171172
"needs-wasmtime",

src/tools/compiletest/src/header/needs.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,11 @@ pub(super) fn handle_needs(
174174
condition: config.with_std_debug_assertions,
175175
ignore_reason: "ignored if std wasn't built with debug assertions",
176176
},
177+
Need {
178+
name: "needs-target-std",
179+
condition: build_helper::targets::target_supports_std(&config.target),
180+
ignore_reason: "ignored if target does not support std",
181+
},
177182
];
178183

179184
let (name, rest) = match ln.split_once([':', ' ']) {

src/tools/compiletest/src/header/tests.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -945,3 +945,14 @@ fn test_ignore_auxiliary() {
945945
let config = cfg().build();
946946
assert!(check_ignore(&config, "//@ ignore-auxiliary"));
947947
}
948+
949+
#[test]
950+
fn test_needs_target_std() {
951+
// Cherry-picks two targets:
952+
// 1. `x86_64-unknown-none`: Tier 2, intentionally never supports std.
953+
// 2. `x86_64-unknown-linux-gnu`: Tier 1, always supports std.
954+
let config = cfg().target("x86_64-unknown-none").build();
955+
assert!(check_ignore(&config, "//@ needs-target-std"));
956+
let config = cfg().target("x86_64-unknown-linux-gnu").build();
957+
assert!(!check_ignore(&config, "//@ needs-target-std"));
958+
}

0 commit comments

Comments
 (0)