From b3b252b401ad133fac6d7ea2b452da921ff7f3b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Miku=C5=82a?= Date: Fri, 21 Feb 2020 15:35:31 +0100 Subject: [PATCH 1/2] Fix MinGW detection for Cygwin --- src/librustc_codegen_ssa/back/link.rs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/librustc_codegen_ssa/back/link.rs b/src/librustc_codegen_ssa/back/link.rs index aaa4448fc1933..33036d97dfafb 100644 --- a/src/librustc_codegen_ssa/back/link.rs +++ b/src/librustc_codegen_ssa/back/link.rs @@ -1008,14 +1008,13 @@ fn get_crt_libs_path(sess: &Session) -> Option { path.pop(); path.pop(); // Based on Clang MinGW driver - let probe_path = path.join(&mingw_dir).join("lib"); - if probe_path.exists() { - return Some(probe_path); - }; - let probe_path = path.join(&mingw_dir).join("sys-root/mingw/lib"); - if probe_path.exists() { - return Some(probe_path); - }; + let probe_paths = vec!["lib", "sys-root/mingw/lib"]; + for probe_path in probe_paths { + let probe_path = path.join(&mingw_dir).join(&probe_path); + if probe_path.join("crt2.o").exists() { + return Some(probe_path); + }; + } }; }; None From 4904b9c228317a9cba963afb87425754a586acf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Miku=C5=82a?= Date: Fri, 21 Feb 2020 16:47:04 +0100 Subject: [PATCH 2/2] Detect Chocolatey MinGW installation --- src/librustc_codegen_ssa/back/link.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/librustc_codegen_ssa/back/link.rs b/src/librustc_codegen_ssa/back/link.rs index 33036d97dfafb..78aacc56ea42e 100644 --- a/src/librustc_codegen_ssa/back/link.rs +++ b/src/librustc_codegen_ssa/back/link.rs @@ -1002,15 +1002,22 @@ fn get_crt_libs_path(sess: &Session) -> Option { x if x == "x86" => "i686", x => x, }; + let mingw_bits = &sess.target.target.target_pointer_width; let mingw_dir = format!("{}-w64-mingw32", mingw_arch); // Here we have path/bin/gcc but we need path/ let mut path = linker_path; path.pop(); path.pop(); - // Based on Clang MinGW driver - let probe_paths = vec!["lib", "sys-root/mingw/lib"]; + // Loosely based on Clang MinGW driver + let probe_paths = vec![ + path.join(&mingw_dir).join("lib"), // Typical path + path.join(&mingw_dir).join("sys-root/mingw/lib"), // Rare path + path.join(format!( + "lib/mingw/tools/install/mingw{}/{}/lib", + &mingw_bits, &mingw_dir + )), // Chocolatey is creative + ]; for probe_path in probe_paths { - let probe_path = path.join(&mingw_dir).join(&probe_path); if probe_path.join("crt2.o").exists() { return Some(probe_path); };