| 
4 | 4 | //@ needs-rust-lld  | 
5 | 5 | //@ ignore-s390x lld does not yet support s390x as target  | 
6 | 6 | 
 
  | 
7 |  | -use run_make_support::regex::Regex;  | 
8 |  | -use run_make_support::{is_msvc, rustc};  | 
 | 7 | +use run_make_support::linker::{assert_rustc_doesnt_use_lld, assert_rustc_uses_lld};  | 
 | 8 | +use run_make_support::rustc;  | 
9 | 9 | 
 
  | 
10 | 10 | fn main() {  | 
11 |  | -    // lld-link is used if msvc, otherwise a gnu-compatible lld is used.  | 
12 |  | -    let linker_version_flag = if is_msvc() { "--version" } else { "-Wl,-v" };  | 
13 |  | - | 
14 | 11 |     // Opt-in to lld and the self-contained linker, to link with rust-lld. We'll check that by  | 
15 | 12 |     // asking the linker to display its version number with a link-arg.  | 
16 |  | -    let output = rustc()  | 
17 |  | -        .arg("-Zlinker-features=+lld")  | 
18 |  | -        .arg("-Clink-self-contained=+linker")  | 
19 |  | -        .arg("-Zunstable-options")  | 
20 |  | -        .arg("-Wlinker-messages")  | 
21 |  | -        .link_arg(linker_version_flag)  | 
22 |  | -        .input("main.rs")  | 
23 |  | -        .run();  | 
24 |  | -    assert!(  | 
25 |  | -        find_lld_version_in_logs(output.stderr_utf8()),  | 
26 |  | -        "the LLD version string should be present in the output logs:\n{}",  | 
27 |  | -        output.stderr_utf8()  | 
 | 13 | +    assert_rustc_uses_lld(  | 
 | 14 | +        rustc()  | 
 | 15 | +            .arg("-Zlinker-features=+lld")  | 
 | 16 | +            .arg("-Clink-self-contained=+linker")  | 
 | 17 | +            .arg("-Zunstable-options")  | 
 | 18 | +            .input("main.rs"),  | 
28 | 19 |     );  | 
29 | 20 | 
 
  | 
30 |  | -    // It should not be used when we explicitly opt-out of lld.  | 
31 |  | -    let output = rustc()  | 
32 |  | -        .link_arg(linker_version_flag)  | 
33 |  | -        .arg("-Zlinker-features=-lld")  | 
34 |  | -        .arg("-Wlinker-messages")  | 
35 |  | -        .input("main.rs")  | 
36 |  | -        .run();  | 
37 |  | -    assert!(  | 
38 |  | -        !find_lld_version_in_logs(output.stderr_utf8()),  | 
39 |  | -        "the LLD version string should not be present in the output logs:\n{}",  | 
40 |  | -        output.stderr_utf8()  | 
41 |  | -    );  | 
 | 21 | +    // It should not be used when we explicitly opt out of lld.  | 
 | 22 | +    assert_rustc_doesnt_use_lld(rustc().arg("-Zlinker-features=-lld").input("main.rs"));  | 
42 | 23 | 
 
  | 
43 | 24 |     // While we're here, also check that the last linker feature flag "wins" when passed multiple  | 
44 | 25 |     // times to rustc.  | 
45 |  | -    let output = rustc()  | 
46 |  | -        .link_arg(linker_version_flag)  | 
47 |  | -        .arg("-Clink-self-contained=+linker")  | 
48 |  | -        .arg("-Zunstable-options")  | 
49 |  | -        .arg("-Zlinker-features=-lld")  | 
50 |  | -        .arg("-Zlinker-features=+lld")  | 
51 |  | -        .arg("-Zlinker-features=-lld,+lld")  | 
52 |  | -        .arg("-Wlinker-messages")  | 
53 |  | -        .input("main.rs")  | 
54 |  | -        .run();  | 
55 |  | -    assert!(  | 
56 |  | -        find_lld_version_in_logs(output.stderr_utf8()),  | 
57 |  | -        "the LLD version string should be present in the output logs:\n{}",  | 
58 |  | -        output.stderr_utf8()  | 
 | 26 | +    assert_rustc_uses_lld(  | 
 | 27 | +        rustc()  | 
 | 28 | +            .arg("-Clink-self-contained=+linker")  | 
 | 29 | +            .arg("-Zunstable-options")  | 
 | 30 | +            .arg("-Zlinker-features=-lld")  | 
 | 31 | +            .arg("-Zlinker-features=+lld")  | 
 | 32 | +            .arg("-Zlinker-features=-lld,+lld")  | 
 | 33 | +            .input("main.rs"),  | 
59 | 34 |     );  | 
60 | 35 | }  | 
61 |  | - | 
62 |  | -fn find_lld_version_in_logs(stderr: String) -> bool {  | 
63 |  | -    // Strip the `-Wlinker-messages` wrappers prefixing the linker output.  | 
64 |  | -    let stderr = Regex::new(r"warning: linker std(out|err):").unwrap().replace_all(&stderr, "");  | 
65 |  | -    let lld_version_re = Regex::new(r"^LLD [0-9]+\.[0-9]+\.[0-9]+").unwrap();  | 
66 |  | -    stderr.lines().any(|line| lld_version_re.is_match(line.trim()))  | 
67 |  | -}  | 
0 commit comments