Skip to content

Commit 908e720

Browse files
committed
Slightly refactor mingw detection
1 parent fe42c5e commit 908e720

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

17621762
// Returns true if linker is located within sysroot
1763-
fn detect_self_contained_mingw(sess: &Session, linker: &Path) -> bool {
1763+
fn detect_self_contained_mingw(sess: &Session) -> bool {
1764+
let linker = if let Some(linker) = &sess.target.linker {
1765+
Path::new(linker.as_ref())
1766+
} else {
1767+
return false;
1768+
};
1769+
17641770
// Assume `-C linker=rust-lld` as self-contained mode
17651771
if linker == Path::new("rust-lld") {
17661772
return true;
@@ -1772,7 +1778,7 @@ fn detect_self_contained_mingw(sess: &Session, linker: &Path) -> bool {
17721778
};
17731779
for dir in env::split_paths(&env::var_os("PATH").unwrap_or_default()) {
17741780
let full_path = dir.join(&linker_with_extension);
1775-
// If linker comes from sysroot assume self-contained mode
1781+
// If linker doesn't come from sysroot assume non-self-contained mode
17761782
if full_path.is_file() && !full_path.starts_with(sess.opts.sysroot.path()) {
17771783
return false;
17781784
}
@@ -1783,11 +1789,7 @@ fn detect_self_contained_mingw(sess: &Session, linker: &Path) -> bool {
17831789
/// Various toolchain components used during linking are used from rustc distribution
17841790
/// instead of being found somewhere on the host system.
17851791
/// We only provide such support for a very limited number of targets.
1786-
fn self_contained_components(
1787-
sess: &Session,
1788-
crate_type: CrateType,
1789-
linker: &Path,
1790-
) -> LinkSelfContainedComponents {
1792+
fn self_contained_components(sess: &Session, crate_type: CrateType) -> LinkSelfContainedComponents {
17911793
// Turn the backwards compatible bool values for `self_contained` into fully inferred
17921794
// `LinkSelfContainedComponents`.
17931795
let self_contained =
@@ -1816,7 +1818,7 @@ fn self_contained_components(
18161818
LinkSelfContainedDefault::InferredForMingw => {
18171819
sess.host == sess.target
18181820
&& sess.target.vendor != "uwp"
1819-
&& detect_self_contained_mingw(sess, linker)
1821+
&& detect_self_contained_mingw(sess)
18201822
}
18211823
}
18221824
};

0 commit comments

Comments
 (0)