Skip to content

Commit 915bee9

Browse files
committed
Add a run-make test for same-arch --print=target-cpus
1 parent b5f4883 commit 915bee9

File tree

1 file changed

+37
-0
lines changed
  • tests/run-make/print-target-cpus-native

1 file changed

+37
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//@ ignore-cross-compile
2+
3+
use run_make_support::{assert_contains_regex, rfs, rustc, target};
4+
5+
// Test that when querying `--print=target-cpus` for a target with the same
6+
// architecture as the host, the first CPU is "native" with a suitable remark.
7+
8+
fn main() {
9+
let expected = r"^Available CPUs for this target:
10+
native +- Select the CPU of the current host \(currently [^ )]+\)\.
11+
";
12+
13+
// Without an explicit target.
14+
rustc().print("target-cpus").run().assert_stdout_contains_regex(expected);
15+
16+
// With an explicit target that happens to be the host.
17+
let host = target(); // Because of ignore-cross-compile, assume host == target.
18+
rustc().print("target-cpus").target(host).run().assert_stdout_contains_regex(expected);
19+
20+
// With an explicit output path.
21+
rustc().print("target-cpus=./xyzzy.txt").run().assert_stdout_equals("");
22+
assert_contains_regex(rfs::read_to_string("./xyzzy.txt"), expected);
23+
24+
// Now try some cross-target queries with the same arch as the host.
25+
// (Specify multiple targets so that at least one of them is not the host.)
26+
let cross_targets: &[&str] = if cfg!(target_arch = "aarch64") {
27+
&["aarch64-unknown-linux-gnu", "aarch64-apple-darwin"]
28+
} else if cfg!(target_arch = "x86_64") {
29+
&["x86_64-unknown-linux-gnu", "x86_64-apple-darwin"]
30+
} else {
31+
&[]
32+
};
33+
for target in cross_targets {
34+
println!("Trying target: {target}");
35+
rustc().print("target-cpus").target(target).run().assert_stdout_contains_regex(expected);
36+
}
37+
}

0 commit comments

Comments
 (0)