File: rmake.rs

package info (click to toggle)
rustc 1.88.0%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental, forky, sid
  • size: 934,168 kB
  • sloc: xml: 158,127; python: 36,062; javascript: 19,855; sh: 19,700; cpp: 18,947; ansic: 12,993; asm: 4,792; makefile: 690; perl: 29; lisp: 29; ruby: 19; sql: 11
file content (97 lines) | stat: -rw-r--r-- 3,775 bytes parent folder | download | duplicates (3)
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
use run_make_support::{Rustc, diff, regex, rustc};

fn run_rustc() -> Rustc {
    let mut rustc = rustc();
    rustc
        .arg("main.rs")
        // NOTE: `link-self-contained` can vary depending on bootstrap.toml.
        // Make sure we use a consistent value.
        .arg("-Clink-self-contained=-linker")
        .arg("-Zunstable-options")
        .arg("-Wlinker-messages")
        .output("main")
        .linker("./fake-linker");
    if run_make_support::target() == "x86_64-unknown-linux-gnu" {
        // The value of `rust.lld` is different between CI and locally. Override it explicitly.
        rustc.arg("-Clinker-flavor=gnu-cc");
    }
    rustc
}

fn main() {
    // first, compile our linker
    rustc().arg("fake-linker.rs").output("fake-linker").run();

    // Run rustc with our fake linker, and make sure it shows warnings
    let warnings = run_rustc().link_arg("run_make_warn").run();
    warnings.assert_stderr_contains("warning: linker stderr: bar");

    // Make sure it shows stdout
    run_rustc()
        .link_arg("run_make_info")
        .run()
        .assert_stderr_contains("warning: linker stdout: foo");

    // Make sure we short-circuit this new path if the linker exits with an error
    // (so the diagnostic is less verbose)
    run_rustc().link_arg("run_make_error").run_fail().assert_stderr_contains("note: error: baz");

    // Make sure we don't show the linker args unless `--verbose` is passed
    let out = run_rustc().link_arg("run_make_error").verbose().run_fail();
    out.assert_stderr_contains_regex("fake-linker.*run_make_error")
        .assert_stderr_not_contains("object files omitted")
        .assert_stderr_contains(r".rcgu.o")
        .assert_stderr_contains_regex(r"lib(/|\\\\)libstd");

    let out = run_rustc().link_arg("run_make_error").run_fail();
    out.assert_stderr_contains("fake-linker")
        .assert_stderr_contains("object files omitted")
        .assert_stderr_contains_regex(r"\{")
        .assert_stderr_not_contains(r".rcgu.o")
        .assert_stderr_not_contains_regex(r"lib(/|\\\\)libstd");

    // FIXME: we should have a version of this for mac and windows
    if run_make_support::target() == "x86_64-unknown-linux-gnu" {
        diff()
            .expected_file("short-error.txt")
            .actual_text("(linker error)", out.stderr())
            .normalize(r#"/rustc[^/_-]*/"#, "/rustc/")
            .normalize("libpanic_abort", "libpanic_unwind")
            .normalize(
                regex::escape(run_make_support::build_root().to_str().unwrap()),
                "/build-root",
            )
            .normalize(r#""[^"]*\/symbols.o""#, "\"/symbols.o\"")
            .normalize(r#""[^"]*\/raw-dylibs""#, "\"/raw-dylibs\"")
            .run();
    }

    // Make sure we show linker warnings even across `-Z no-link`
    rustc()
        .arg("-Zno-link")
        .input("-")
        .stdin_buf("#![deny(linker_messages)] \n fn main() {}")
        .run()
        .assert_stderr_equals("");
    rustc()
        .arg("-Zlink-only")
        .arg("rust_out.rlink")
        .linker("./fake-linker")
        .link_arg("run_make_warn")
        .run_fail()
        // NOTE: the error message here is quite bad (we don't have a source
        // span, but still try to print the lint source). But `-Z link-only` is
        // unstable and this still shows the linker warning itself so this is
        // probably good enough.
        .assert_stderr_contains("linker stderr: bar");

    // Same thing, but with json output.
    rustc()
        .error_format("json")
        .arg("-Zlink-only")
        .arg("rust_out.rlink")
        .linker("./fake-linker")
        .link_arg("run_make_warn")
        .run_fail()
        .assert_stderr_contains(r#""$message_type":"diagnostic""#);
}