2024-06-28 05:18:32 -05:00
|
|
|
// Ensure that rust-lld is used as the default linker on `x86_64-unknown-linux-gnu` on the nightly
|
|
|
|
// channel, and that it can also be turned off with a CLI flag.
|
2024-04-13 17:09:50 -05:00
|
|
|
|
|
|
|
//@ needs-rust-lld
|
2024-06-28 03:24:16 -05:00
|
|
|
//@ ignore-beta
|
|
|
|
//@ ignore-stable
|
2024-04-13 17:09:50 -05:00
|
|
|
//@ only-x86_64-unknown-linux-gnu
|
|
|
|
|
|
|
|
use run_make_support::regex::Regex;
|
|
|
|
use run_make_support::rustc;
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
// A regular compilation should use rust-lld by default. We'll check that by asking the linker
|
|
|
|
// to display its version number with a link-arg.
|
|
|
|
let output = rustc()
|
|
|
|
.env("RUSTC_LOG", "rustc_codegen_ssa::back::link=info")
|
|
|
|
.link_arg("-Wl,-v")
|
|
|
|
.input("main.rs")
|
|
|
|
.run();
|
|
|
|
assert!(
|
2024-06-07 08:23:10 -05:00
|
|
|
find_lld_version_in_logs(output.stderr_utf8()),
|
2024-05-24 10:46:42 -05:00
|
|
|
"the LLD version string should be present in the output logs:\n{}",
|
2024-06-07 08:23:10 -05:00
|
|
|
output.stderr_utf8()
|
2024-04-13 17:09:50 -05:00
|
|
|
);
|
|
|
|
|
|
|
|
// But it can still be disabled by turning the linker feature off.
|
|
|
|
let output = rustc()
|
|
|
|
.env("RUSTC_LOG", "rustc_codegen_ssa::back::link=info")
|
|
|
|
.link_arg("-Wl,-v")
|
|
|
|
.arg("-Zlinker-features=-lld")
|
|
|
|
.input("main.rs")
|
|
|
|
.run();
|
|
|
|
assert!(
|
2024-06-07 08:23:10 -05:00
|
|
|
!find_lld_version_in_logs(output.stderr_utf8()),
|
2024-05-24 10:46:42 -05:00
|
|
|
"the LLD version string should not be present in the output logs:\n{}",
|
2024-06-07 08:23:10 -05:00
|
|
|
output.stderr_utf8()
|
2024-04-13 17:09:50 -05:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-06-07 08:23:10 -05:00
|
|
|
fn find_lld_version_in_logs(stderr: String) -> bool {
|
2024-04-13 17:09:50 -05:00
|
|
|
let lld_version_re = Regex::new(r"^LLD [0-9]+\.[0-9]+\.[0-9]+").unwrap();
|
2024-05-24 10:50:20 -05:00
|
|
|
stderr.lines().any(|line| lld_version_re.is_match(line.trim()))
|
2024-04-13 17:09:50 -05:00
|
|
|
}
|