Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
328846c
Rename `is_like_osx` to `is_like_darwin`
madsmtm Aug 19, 2024
0d8c33f
Remove creation of duplicate AnonPipe
JakeWharton Apr 3, 2025
3e762b1
compiletest: Allow `--fail-fast` as a command-line option
Zalathar Apr 3, 2025
ecf9e20
compiletest: Encapsulate all of the code that touches libtest
Zalathar Apr 3, 2025
6af96f8
Add a helper function for checking if LLD was used to `run-make-support`
Kobzol Mar 18, 2025
9ec11c2
Move `link-self-contained-consistency` test to a more reasonable loca…
Kobzol Mar 24, 2025
6189594
Deduplicate some `rustc_middle` function bodies by calling the `rustc…
oli-obk Apr 3, 2025
64b58dd
Pass correct param-env to error_implies
compiler-errors Apr 3, 2025
ad1fb1e
Add a mailmap entry for myself
meithecatte Apr 3, 2025
a14e8f6
adt_destructor: sanity-check returned item
meithecatte Apr 4, 2025
66e61c7
Rollup merge of #138949 - madsmtm:rename-to-darwin, r=WaffleLapkin
matthiaskrgr Apr 4, 2025
f701a5c
Rollup merge of #139295 - JakeWharton:jw.duplicate-anon-pipe.2025-04-…
matthiaskrgr Apr 4, 2025
96ab10c
Rollup merge of #139313 - oli-obk:push-uzvmpxqyvrzp, r=compiler-errors
matthiaskrgr Apr 4, 2025
9d84676
Rollup merge of #139317 - Zalathar:hide-libtest, r=jieyouxu
matthiaskrgr Apr 4, 2025
2e8bd29
Rollup merge of #139322 - Kobzol:run-make-lld-refactor, r=jieyouxu
matthiaskrgr Apr 4, 2025
c264f3e
Rollup merge of #139335 - compiler-errors:error-implies, r=oli-obk
matthiaskrgr Apr 4, 2025
0c4ac89
Rollup merge of #139342 - meithecatte:mailmap, r=compiler-errors
matthiaskrgr Apr 4, 2025
0a9eae1
Rollup merge of #139349 - meithecatte:destructor-constness, r=compile…
matthiaskrgr Apr 4, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/tools/run-make-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub mod assertion_helpers;
pub mod diff;
pub mod env;
pub mod external_deps;
pub mod linker;
pub mod path_helpers;
pub mod run;
pub mod scoped_run;
Expand Down
36 changes: 36 additions & 0 deletions src/tools/run-make-support/src/linker.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
use regex::Regex;

use crate::{Rustc, is_msvc};

/// Asserts that `rustc` uses LLD for linking when executed.
pub fn assert_rustc_uses_lld(rustc: &mut Rustc) {
let stderr = get_stderr_with_linker_messages(rustc);
assert!(
has_lld_version_in_logs(&stderr),
"LLD version should be present in rustc stderr:\n{stderr}"
);
}

/// Asserts that `rustc` doesn't use LLD for linking when executed.
pub fn assert_rustc_doesnt_use_lld(rustc: &mut Rustc) {
let stderr = get_stderr_with_linker_messages(rustc);
assert!(
!has_lld_version_in_logs(&stderr),
"LLD version should NOT be present in rustc stderr:\n{stderr}"
);
}

fn get_stderr_with_linker_messages(rustc: &mut Rustc) -> String {
// lld-link is used if msvc, otherwise a gnu-compatible lld is used.
let linker_version_flag = if is_msvc() { "--version" } else { "-Wl,-v" };

let output = rustc.arg("-Wlinker-messages").link_arg(linker_version_flag).run();
output.stderr_utf8()
}

fn has_lld_version_in_logs(stderr: &str) -> bool {
// Strip the `-Wlinker-messages` wrappers prefixing the linker output.
let stderr = Regex::new(r"warning: linker std(out|err):").unwrap().replace_all(&stderr, "");
let lld_version_re = Regex::new(r"^LLD [0-9]+\.[0-9]+\.[0-9]+").unwrap();
stderr.lines().any(|line| lld_version_re.is_match(line.trim()))
}
17 changes: 2 additions & 15 deletions tests/run-make/rust-lld-by-default-beta-stable/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,11 @@
//@ ignore-nightly
//@ only-x86_64-unknown-linux-gnu

use std::process::Output;

use run_make_support::regex::Regex;
use run_make_support::linker::assert_rustc_doesnt_use_lld;
use run_make_support::rustc;

fn main() {
// A regular compilation should not 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().arg("-Wlinker-messages").link_arg("-Wl,-v").input("main.rs").run();
assert!(
!find_lld_version_in_logs(output.stderr_utf8()),
"the LLD version string should not be present in the output logs:\n{}",
output.stderr_utf8()
);
}

fn find_lld_version_in_logs(stderr: String) -> bool {
let lld_version_re =
Regex::new(r"^warning: linker stdout: LLD [0-9]+\.[0-9]+\.[0-9]+").unwrap();
stderr.lines().any(|line| lld_version_re.is_match(line.trim()))
assert_rustc_doesnt_use_lld(rustc().input("main.rs"));
}
27 changes: 3 additions & 24 deletions tests/run-make/rust-lld-by-default-nightly/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,14 @@
//@ ignore-stable
//@ only-x86_64-unknown-linux-gnu

use run_make_support::regex::Regex;
use run_make_support::linker::{assert_rustc_doesnt_use_lld, assert_rustc_uses_lld};
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().arg("-Wlinker-messages").link_arg("-Wl,-v").input("main.rs").run();
assert!(
find_lld_version_in_logs(output.stderr_utf8()),
"the LLD version string should be present in the output logs:\n{}",
output.stderr_utf8()
);
assert_rustc_uses_lld(rustc().input("main.rs"));

// But it can still be disabled by turning the linker feature off.
let output = rustc()
.arg("-Wlinker-messages")
.link_arg("-Wl,-v")
.arg("-Zlinker-features=-lld")
.input("main.rs")
.run();
assert!(
!find_lld_version_in_logs(output.stderr_utf8()),
"the LLD version string should not be present in the output logs:\n{}",
output.stderr_utf8()
);
}

fn find_lld_version_in_logs(stderr: String) -> bool {
let lld_version_re =
Regex::new(r"^warning: linker stdout: LLD [0-9]+\.[0-9]+\.[0-9]+").unwrap();
stderr.lines().any(|line| lld_version_re.is_match(line.trim()))
assert_rustc_doesnt_use_lld(rustc().arg("-Zlinker-features=-lld").input("main.rs"));
}
39 changes: 9 additions & 30 deletions tests/run-make/rust-lld-custom-target/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,43 +8,22 @@
//@ needs-rust-lld
//@ only-x86_64-unknown-linux-gnu

use run_make_support::regex::Regex;
use run_make_support::linker::{assert_rustc_doesnt_use_lld, assert_rustc_uses_lld};
use run_make_support::rustc;

fn main() {
// Compile to a custom target spec with rust-lld enabled by default. We'll check that by asking
// the linker to display its version number with a link-arg.
let output = rustc()
.crate_type("cdylib")
.arg("-Wlinker-messages")
.target("custom-target.json")
.link_arg("-Wl,-v")
.input("lib.rs")
.run();
assert!(
find_lld_version_in_logs(output.stderr_utf8()),
"the LLD version string should be present in the output logs:\n{}",
output.stderr_utf8()
assert_rustc_uses_lld(
rustc().crate_type("cdylib").target("custom-target.json").input("lib.rs"),
);

// But it can also be disabled via linker features.
let output = rustc()
.crate_type("cdylib")
.arg("-Wlinker-messages")
.target("custom-target.json")
.arg("-Zlinker-features=-lld")
.link_arg("-Wl,-v")
.input("lib.rs")
.run();
assert!(
!find_lld_version_in_logs(output.stderr_utf8()),
"the LLD version string should not be present in the output logs:\n{}",
output.stderr_utf8()
assert_rustc_doesnt_use_lld(
rustc()
.crate_type("cdylib")
.target("custom-target.json")
.arg("-Zlinker-features=-lld")
.input("lib.rs"),
);
}

fn find_lld_version_in_logs(stderr: String) -> bool {
let lld_version_re =
Regex::new(r"^warning: linker stdout: LLD [0-9]+\.[0-9]+\.[0-9]+").unwrap();
stderr.lines().any(|line| lld_version_re.is_match(line.trim()))
}
68 changes: 18 additions & 50 deletions tests/run-make/rust-lld/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,64 +4,32 @@
//@ needs-rust-lld
//@ ignore-s390x lld does not yet support s390x as target

use run_make_support::regex::Regex;
use run_make_support::{is_msvc, rustc};
use run_make_support::linker::{assert_rustc_doesnt_use_lld, assert_rustc_uses_lld};
use run_make_support::rustc;

fn main() {
// lld-link is used if msvc, otherwise a gnu-compatible lld is used.
let linker_version_flag = if is_msvc() { "--version" } else { "-Wl,-v" };

// Opt-in to lld and the self-contained linker, to link with rust-lld. We'll check that by
// asking the linker to display its version number with a link-arg.
let output = rustc()
.arg("-Zlinker-features=+lld")
.arg("-Clink-self-contained=+linker")
.arg("-Zunstable-options")
.arg("-Wlinker-messages")
.link_arg(linker_version_flag)
.input("main.rs")
.run();
assert!(
find_lld_version_in_logs(output.stderr_utf8()),
"the LLD version string should be present in the output logs:\n{}",
output.stderr_utf8()
assert_rustc_uses_lld(
rustc()
.arg("-Zlinker-features=+lld")
.arg("-Clink-self-contained=+linker")
.arg("-Zunstable-options")
.input("main.rs"),
);

// It should not be used when we explicitly opt-out of lld.
let output = rustc()
.link_arg(linker_version_flag)
.arg("-Zlinker-features=-lld")
.arg("-Wlinker-messages")
.input("main.rs")
.run();
assert!(
!find_lld_version_in_logs(output.stderr_utf8()),
"the LLD version string should not be present in the output logs:\n{}",
output.stderr_utf8()
);
// It should not be used when we explicitly opt out of lld.
assert_rustc_doesnt_use_lld(rustc().arg("-Zlinker-features=-lld").input("main.rs"));

// While we're here, also check that the last linker feature flag "wins" when passed multiple
// times to rustc.
let output = rustc()
.link_arg(linker_version_flag)
.arg("-Clink-self-contained=+linker")
.arg("-Zunstable-options")
.arg("-Zlinker-features=-lld")
.arg("-Zlinker-features=+lld")
.arg("-Zlinker-features=-lld,+lld")
.arg("-Wlinker-messages")
.input("main.rs")
.run();
assert!(
find_lld_version_in_logs(output.stderr_utf8()),
"the LLD version string should be present in the output logs:\n{}",
output.stderr_utf8()
assert_rustc_uses_lld(
rustc()
.arg("-Clink-self-contained=+linker")
.arg("-Zunstable-options")
.arg("-Zlinker-features=-lld")
.arg("-Zlinker-features=+lld")
.arg("-Zlinker-features=-lld,+lld")
.input("main.rs"),
);
}

fn find_lld_version_in_logs(stderr: String) -> bool {
// Strip the `-Wlinker-messages` wrappers prefixing the linker output.
let stderr = Regex::new(r"warning: linker std(out|err):").unwrap().replace_all(&stderr, "");
let lld_version_re = Regex::new(r"^LLD [0-9]+\.[0-9]+\.[0-9]+").unwrap();
stderr.lines().any(|line| lld_version_re.is_match(line.trim()))
}