Skip to content

Commit 9902add

Browse files
committed
rustc_back: change default GNU linkers for Windows
In particular, specify the target triple when specifying the name of the linker executable. This makes it possible to cross compile to Windows: rustc --target=x86_64-pc-windows-gnu without having to pass rustc the "-C linker=" parameter. This fixes cross compilation to 64-bit Windows. However, due to unwinding issues (rust-lang#12859) this does not fix cross compilation to 32-bit Windows. Additionally, update make-win-dist.py. This allows (non-cross) compilation on Windows to continue to work.
1 parent 8b7c17d commit 9902add

File tree

3 files changed

+6
-0
lines changed

3 files changed

+6
-0
lines changed

src/etc/make-win-dist.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ def make_win_dist(rust_root, gcc_root, target_triple):
4646
lib_path.extend(val.lstrip(' =').split(';'))
4747

4848
target_tools = ["gcc.exe", "ld.exe", "ar.exe", "dlltool.exe", "windres.exe"]
49+
if target_triple.startswith("i686-"):
50+
target_tools.append("i686-w64-mingw32-gcc.exe")
51+
else:
52+
target_tools.append("x86_64-w64-mingw32-gcc.exe")
4953

5054
rustc_dlls = ["libstdc++-6.dll"]
5155
if target_triple.startswith("i686-"):

src/librustc_back/target/i686_pc_windows_gnu.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use target::Target;
1313
pub fn target() -> Target {
1414
let mut options = super::windows_base::opts();
1515
options.cpu = "pentium4".to_string();
16+
options.linker = "i686-w64-mingw32-gcc".to_string();
1617

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

src/librustc_back/target/x86_64_pc_windows_gnu.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use target::Target;
1313
pub fn target() -> Target {
1414
let mut base = super::windows_base::opts();
1515
base.cpu = "x86-64".to_string();
16+
base.linker = "x86_64-w64-mingw32-gcc".to_string();
1617
// On Win64 unwinding is handled by the OS, so we can link libgcc statically.
1718
base.pre_link_args.push("-static-libgcc".to_string());
1819
base.pre_link_args.push("-m64".to_string());

0 commit comments

Comments
 (0)