Skip to content

Commit 87b0d83

Browse files
committed
Auto merge of #69351 - mati865:mingw-ultimate-fix, r=cramertj
Improve external MinGW detection Fixes #68872
2 parents 9c230f3 + 4904b9c commit 87b0d83

File tree

1 file changed

+15
-9
lines changed
  • src/librustc_codegen_ssa/back

1 file changed

+15
-9
lines changed

src/librustc_codegen_ssa/back/link.rs

+15-9
Original file line numberDiff line numberDiff line change
@@ -1002,20 +1002,26 @@ fn get_crt_libs_path(sess: &Session) -> Option<PathBuf> {
10021002
x if x == "x86" => "i686",
10031003
x => x,
10041004
};
1005+
let mingw_bits = &sess.target.target.target_pointer_width;
10051006
let mingw_dir = format!("{}-w64-mingw32", mingw_arch);
10061007
// Here we have path/bin/gcc but we need path/
10071008
let mut path = linker_path;
10081009
path.pop();
10091010
path.pop();
1010-
// Based on Clang MinGW driver
1011-
let probe_path = path.join(&mingw_dir).join("lib");
1012-
if probe_path.exists() {
1013-
return Some(probe_path);
1014-
};
1015-
let probe_path = path.join(&mingw_dir).join("sys-root/mingw/lib");
1016-
if probe_path.exists() {
1017-
return Some(probe_path);
1018-
};
1011+
// Loosely based on Clang MinGW driver
1012+
let probe_paths = vec![
1013+
path.join(&mingw_dir).join("lib"), // Typical path
1014+
path.join(&mingw_dir).join("sys-root/mingw/lib"), // Rare path
1015+
path.join(format!(
1016+
"lib/mingw/tools/install/mingw{}/{}/lib",
1017+
&mingw_bits, &mingw_dir
1018+
)), // Chocolatey is creative
1019+
];
1020+
for probe_path in probe_paths {
1021+
if probe_path.join("crt2.o").exists() {
1022+
return Some(probe_path);
1023+
};
1024+
}
10191025
};
10201026
};
10211027
None

0 commit comments

Comments
 (0)