Skip to content

Commit 9c62bae

Browse files
committed
Slightly refactor mingw detection
1 parent 928f025 commit 9c62bae

File tree

1 file changed

+11
-9
lines changed
  • compiler/rustc_codegen_ssa/src/back

1 file changed

+11
-9
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -685,8 +685,8 @@ fn link_natively(
685685
codegen_backend: &'static str,
686686
) {
687687
info!("preparing {:?} to {:?}", crate_type, out_filename);
688+
let self_contained_components = self_contained_components(sess, crate_type);
688689
let (linker_path, flavor) = linker_and_flavor(sess);
689-
let self_contained_components = self_contained_components(sess, crate_type, &linker_path);
690690

691691
// On AIX, we ship all libraries as .a big_af archive
692692
// the expected format is lib<name>.a(libname.so) for the actual
@@ -1764,7 +1764,13 @@ fn link_output_kind(sess: &Session, crate_type: CrateType) -> LinkOutputKind {
17641764
}
17651765

17661766
// Returns true if linker is located within sysroot
1767-
fn detect_self_contained_mingw(sess: &Session, linker: &Path) -> bool {
1767+
fn detect_self_contained_mingw(sess: &Session) -> bool {
1768+
let linker = if let Some(linker) = &sess.target.linker {
1769+
Path::new(linker.as_ref())
1770+
} else {
1771+
return false;
1772+
};
1773+
17681774
// Assume `-C linker=rust-lld` as self-contained mode
17691775
if linker == Path::new("rust-lld") {
17701776
return true;
@@ -1776,7 +1782,7 @@ fn detect_self_contained_mingw(sess: &Session, linker: &Path) -> bool {
17761782
};
17771783
for dir in env::split_paths(&env::var_os("PATH").unwrap_or_default()) {
17781784
let full_path = dir.join(&linker_with_extension);
1779-
// If linker comes from sysroot assume self-contained mode
1785+
// If linker doesn't come from sysroot assume non-self-contained mode
17801786
if full_path.is_file() && !full_path.starts_with(sess.opts.sysroot.path()) {
17811787
return false;
17821788
}
@@ -1787,11 +1793,7 @@ fn detect_self_contained_mingw(sess: &Session, linker: &Path) -> bool {
17871793
/// Various toolchain components used during linking are used from rustc distribution
17881794
/// instead of being found somewhere on the host system.
17891795
/// We only provide such support for a very limited number of targets.
1790-
fn self_contained_components(
1791-
sess: &Session,
1792-
crate_type: CrateType,
1793-
linker: &Path,
1794-
) -> LinkSelfContainedComponents {
1796+
fn self_contained_components(sess: &Session, crate_type: CrateType) -> LinkSelfContainedComponents {
17951797
// Turn the backwards compatible bool values for `self_contained` into fully inferred
17961798
// `LinkSelfContainedComponents`.
17971799
let self_contained =
@@ -1820,7 +1822,7 @@ fn self_contained_components(
18201822
LinkSelfContainedDefault::InferredForMingw => {
18211823
sess.host == sess.target
18221824
&& sess.target.vendor != "uwp"
1823-
&& detect_self_contained_mingw(sess, linker)
1825+
&& detect_self_contained_mingw(sess)
18241826
}
18251827
}
18261828
};

0 commit comments

Comments
 (0)