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