Skip to content

Commit

Permalink
rustc_back: change default GNU linkers for Windows
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
iainnicol committed May 17, 2015
1 parent 8b7c17d commit 9902add
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/etc/make-win-dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ def make_win_dist(rust_root, gcc_root, target_triple):
lib_path.extend(val.lstrip(' =').split(';'))

target_tools = ["gcc.exe", "ld.exe", "ar.exe", "dlltool.exe", "windres.exe"]
if target_triple.startswith("i686-"):
target_tools.append("i686-w64-mingw32-gcc.exe")
else:
target_tools.append("x86_64-w64-mingw32-gcc.exe")

rustc_dlls = ["libstdc++-6.dll"]
if target_triple.startswith("i686-"):
Expand Down
1 change: 1 addition & 0 deletions src/librustc_back/target/i686_pc_windows_gnu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use target::Target;
pub fn target() -> Target {
let mut options = super::windows_base::opts();
options.cpu = "pentium4".to_string();
options.linker = "i686-w64-mingw32-gcc".to_string();

// Mark all dynamic libraries and executables as compatible with the larger 4GiB address
// space available to x86 Windows binaries on x86_64.
Expand Down
1 change: 1 addition & 0 deletions src/librustc_back/target/x86_64_pc_windows_gnu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use target::Target;
pub fn target() -> Target {
let mut base = super::windows_base::opts();
base.cpu = "x86-64".to_string();
base.linker = "x86_64-w64-mingw32-gcc".to_string();
// On Win64 unwinding is handled by the OS, so we can link libgcc statically.
base.pre_link_args.push("-static-libgcc".to_string());
base.pre_link_args.push("-m64".to_string());
Expand Down

0 comments on commit 9902add

Please sign in to comment.