File: rmake.rs

package info (click to toggle)
rustc 1.89.0%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 906,624 kB
  • sloc: xml: 158,148; python: 34,888; javascript: 19,595; sh: 19,221; ansic: 13,046; cpp: 7,144; asm: 4,376; makefile: 692; lisp: 174; sql: 15
file content (39 lines) | stat: -rw-r--r-- 1,656 bytes parent folder | download | duplicates (15)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//@ ignore-cross-compile
//@ needs-llvm-components: aarch64 x86
// FIXME(#132514): Is needs-llvm-components actually necessary for this test?

use run_make_support::{assert_contains_regex, rfs, rustc, target};

// Test that when querying `--print=target-cpus` for a target with the same
// architecture as the host, the first CPU is "native" with a suitable remark.

fn main() {
    let expected = r"^Available CPUs for this target:
    native +- Select the CPU of the current host \(currently [^ )]+\)\.
";

    // Without an explicit target.
    rustc().print("target-cpus").run().assert_stdout_contains_regex(expected);

    // With an explicit target that happens to be the host.
    let host = target(); // Because of ignore-cross-compile, assume host == target.
    rustc().print("target-cpus").target(host).run().assert_stdout_contains_regex(expected);

    // With an explicit output path.
    rustc().print("target-cpus=./xyzzy.txt").run().assert_stdout_equals("");
    assert_contains_regex(rfs::read_to_string("./xyzzy.txt"), expected);

    // Now try some cross-target queries with the same arch as the host.
    // (Specify multiple targets so that at least one of them is not the host.)
    let cross_targets: &[&str] = if cfg!(target_arch = "aarch64") {
        &["aarch64-unknown-linux-gnu", "aarch64-apple-darwin"]
    } else if cfg!(target_arch = "x86_64") {
        &["x86_64-unknown-linux-gnu", "x86_64-apple-darwin"]
    } else {
        &[]
    };
    for target in cross_targets {
        println!("Trying target: {target}");
        rustc().print("target-cpus").target(target).run().assert_stdout_contains_regex(expected);
    }
}