Skip to content

Commit 559e5ab

Browse files
authored
Rollup merge of #69549 - mati865:mingw, r=kennytm
Improve MinGW detection when cross compiling Official mingw-w64 builds, MSYS2 and LLVM MinGW provide both `gcc.exe` and `$ARCH-w64-mingw32-gcc.exe` so they should not regress but I included CI changes to verify it though `@bors try` (I don't have permission). This change will come handy when cross compiling from Linux or Cygwin since they use `gcc` as native compiler and `$ARCH-w64-mingw32-gcc.exe` for MinGW. This means users will no longer have to override the linker.
2 parents 1e25878 + cdb6955 commit 559e5ab

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

src/bootstrap/dist.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,14 @@ fn make_win_dist(
234234
}
235235
}
236236

237-
let target_tools = ["gcc.exe", "ld.exe", "dlltool.exe", "libwinpthread-1.dll"];
237+
let compiler = if target_triple == "i686-pc-windows-gnu" {
238+
"i686-w64-mingw32-gcc.exe"
239+
} else if target_triple == "x86_64-pc-windows-gnu" {
240+
"x86_64-w64-mingw32-gcc.exe"
241+
} else {
242+
"gcc.exe"
243+
};
244+
let target_tools = [compiler, "ld.exe", "dlltool.exe", "libwinpthread-1.dll"];
238245
let mut rustc_dlls = vec!["libwinpthread-1.dll"];
239246
if target_triple.starts_with("i686-") {
240247
rustc_dlls.push("libgcc_s_dw2-1.dll");

src/librustc_target/spec/i686_pc_windows_gnu.rs

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ pub fn target() -> TargetResult {
55
base.cpu = "pentium4".to_string();
66
base.max_atomic_width = Some(64);
77
base.eliminate_frame_pointer = false; // Required for backtraces
8+
base.linker = Some("i686-w64-mingw32-gcc".to_string());
89

910
// Mark all dynamic libraries and executables as compatible with the larger 4GiB address
1011
// space available to x86 Windows binaries on x86_64.

src/librustc_target/spec/x86_64_pc_windows_gnu.rs

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ pub fn target() -> TargetResult {
55
base.cpu = "x86-64".to_string();
66
base.pre_link_args.get_mut(&LinkerFlavor::Gcc).unwrap().push("-m64".to_string());
77
base.max_atomic_width = Some(64);
8+
base.linker = Some("x86_64-w64-mingw32-gcc".to_string());
89

910
Ok(Target {
1011
llvm_target: "x86_64-pc-windows-gnu".to_string(),

0 commit comments

Comments
 (0)