Skip to content

Commit 3756602

Browse files
committed
Slightly refactor mingw detection
1 parent daa7862 commit 3756602

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
@@ -1762,7 +1762,13 @@ fn link_output_kind(sess: &Session, crate_type: CrateType) -> LinkOutputKind {
17621762
}
17631763

17641764
// Returns true if linker is located within sysroot
1765-
fn detect_self_contained_mingw(sess: &Session, linker: &Path) -> bool {
1765+
fn detect_self_contained_mingw(sess: &Session) -> bool {
1766+
let linker = if let Some(linker) = &sess.target.linker {
1767+
Path::new(linker.as_ref())
1768+
} else {
1769+
return false;
1770+
};
1771+
17661772
// Assume `-C linker=rust-lld` as self-contained mode
17671773
if linker == Path::new("rust-lld") {
17681774
return true;
@@ -1774,7 +1780,7 @@ fn detect_self_contained_mingw(sess: &Session, linker: &Path) -> bool {
17741780
};
17751781
for dir in env::split_paths(&env::var_os("PATH").unwrap_or_default()) {
17761782
let full_path = dir.join(&linker_with_extension);
1777-
// If linker comes from sysroot assume self-contained mode
1783+
// If linker doesn't come from sysroot assume non-self-contained mode
17781784
if full_path.is_file() && !full_path.starts_with(sess.opts.sysroot.path()) {
17791785
return false;
17801786
}
@@ -1785,11 +1791,7 @@ fn detect_self_contained_mingw(sess: &Session, linker: &Path) -> bool {
17851791
/// Various toolchain components used during linking are used from rustc distribution
17861792
/// instead of being found somewhere on the host system.
17871793
/// We only provide such support for a very limited number of targets.
1788-
fn self_contained_components(
1789-
sess: &Session,
1790-
crate_type: CrateType,
1791-
linker: &Path,
1792-
) -> LinkSelfContainedComponents {
1794+
fn self_contained_components(sess: &Session, crate_type: CrateType) -> LinkSelfContainedComponents {
17931795
// Turn the backwards compatible bool values for `self_contained` into fully inferred
17941796
// `LinkSelfContainedComponents`.
17951797
let self_contained =
@@ -1818,7 +1820,7 @@ fn self_contained_components(
18181820
LinkSelfContainedDefault::InferredForMingw => {
18191821
sess.host == sess.target
18201822
&& sess.target.abi != Abi::Uwp
1821-
&& detect_self_contained_mingw(sess, linker)
1823+
&& detect_self_contained_mingw(sess)
18221824
}
18231825
}
18241826
};

0 commit comments

Comments
 (0)