Auto merge of #69351 - mati865:mingw-ultimate-fix, r=cramertj

Improve external MinGW detection

Fixes #68872
This commit is contained in:
bors 2020-02-23 12:52:48 +00:00
commit 87b0d83745

View File

@ -1002,20 +1002,26 @@ fn get_crt_libs_path(sess: &Session) -> Option<PathBuf> {
x if x == "x86" => "i686", x if x == "x86" => "i686",
x => x, x => x,
}; };
let mingw_bits = &sess.target.target.target_pointer_width;
let mingw_dir = format!("{}-w64-mingw32", mingw_arch); let mingw_dir = format!("{}-w64-mingw32", mingw_arch);
// Here we have path/bin/gcc but we need path/ // Here we have path/bin/gcc but we need path/
let mut path = linker_path; let mut path = linker_path;
path.pop(); path.pop();
path.pop(); path.pop();
// Based on Clang MinGW driver // Loosely based on Clang MinGW driver
let probe_path = path.join(&mingw_dir).join("lib"); let probe_paths = vec![
if probe_path.exists() { path.join(&mingw_dir).join("lib"), // Typical path
return Some(probe_path); path.join(&mingw_dir).join("sys-root/mingw/lib"), // Rare path
}; path.join(format!(
let probe_path = path.join(&mingw_dir).join("sys-root/mingw/lib"); "lib/mingw/tools/install/mingw{}/{}/lib",
if probe_path.exists() { &mingw_bits, &mingw_dir
)), // Chocolatey is creative
];
for probe_path in probe_paths {
if probe_path.join("crt2.o").exists() {
return Some(probe_path); return Some(probe_path);
}; };
}
}; };
}; };
None None