Skip to content

Commit

Permalink
Switch pc-windows-gnu targets from GCC to Clang
Browse files Browse the repository at this point in the history
  • Loading branch information
dennisameling committed Jan 2, 2022
1 parent 03360be commit 73167b7
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 62 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -366,25 +366,25 @@ jobs:
env:
RUST_CONFIGURE_ARGS: "--build=i686-pc-windows-gnu"
SCRIPT: make ci-mingw-subset-1
CUSTOM_MINGW: 1
CUSTOM_MINGW: 0
os: windows-latest-xl
- name: i686-mingw-2
env:
RUST_CONFIGURE_ARGS: "--build=i686-pc-windows-gnu"
SCRIPT: make ci-mingw-subset-2
CUSTOM_MINGW: 1
CUSTOM_MINGW: 0
os: windows-latest-xl
- name: x86_64-mingw-1
env:
SCRIPT: make ci-mingw-subset-1
RUST_CONFIGURE_ARGS: "--build=x86_64-pc-windows-gnu --enable-profiler"
CUSTOM_MINGW: 1
CUSTOM_MINGW: 0
os: windows-latest-xl
- name: x86_64-mingw-2
env:
SCRIPT: make ci-mingw-subset-2
RUST_CONFIGURE_ARGS: "--build=x86_64-pc-windows-gnu --enable-profiler"
CUSTOM_MINGW: 1
CUSTOM_MINGW: 0
os: windows-latest-xl
- name: dist-x86_64-msvc
env:
Expand All @@ -409,14 +409,14 @@ jobs:
env:
RUST_CONFIGURE_ARGS: "--build=i686-pc-windows-gnu --enable-full-tools --enable-profiler"
SCRIPT: python x.py dist
CUSTOM_MINGW: 1
CUSTOM_MINGW: 0
DIST_REQUIRE_ALL_TOOLS: 1
os: windows-latest-xl
- name: dist-x86_64-mingw
env:
SCRIPT: python x.py dist
RUST_CONFIGURE_ARGS: "--build=x86_64-pc-windows-gnu --enable-full-tools --enable-profiler"
CUSTOM_MINGW: 1
CUSTOM_MINGW: 0
DIST_REQUIRE_ALL_TOOLS: 1
os: windows-latest-xl
- name: dist-x86_64-msvc-alt
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_target/src/spec/i686_pc_windows_gnu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub fn target() -> Target {
.insert(LinkerFlavor::Lld(LldFlavor::Ld), vec!["-m".to_string(), "i386pe".to_string()]);
base.max_atomic_width = Some(64);
base.frame_pointer = FramePointer::Always; // Required for backtraces
base.linker = Some("i686-w64-mingw32-gcc".to_string());
base.linker = Some("i686-w64-mingw32-clang".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
30 changes: 4 additions & 26 deletions compiler/rustc_target/src/spec/windows_gnu_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,13 @@ pub fn opts() -> TargetOptions {
],
);

let mut late_link_args = LinkArgs::new();
let mut late_link_args_dynamic = LinkArgs::new();
let mut late_link_args_static = LinkArgs::new();
// Order of `late_link_args*` was found through trial and error to work with various
// mingw-w64 versions (not tested on the CI). It's expected to change from time to time.
let mingw_libs = vec![
"-lmsvcrt".to_string(),
"-lmingwex".to_string(),
"-lmingw32".to_string(),
"-lgcc".to_string(), // alas, mingw* libraries above depend on libgcc
// mingw's msvcrt is a weird hybrid import library and static library.
// And it seems that the linker fails to use import symbols from msvcrt
// that are required from functions in msvcrt in certain cases. For example
// `_fmode` that is used by an implementation of `__p__fmode` in x86_64.
// The library is purposely listed twice to fix that.
//
// See https://github.com/rust-lang/rust/pull/47483 for some more details.
"-lmsvcrt".to_string(),
"-luser32".to_string(),
"-lkernel32".to_string(),
];
late_link_args.insert(LinkerFlavor::Gcc, mingw_libs.clone());
late_link_args.insert(LinkerFlavor::Lld(LldFlavor::Ld), mingw_libs);
let dynamic_unwind_libs = vec![
// If any of our crates are dynamically linked then we need to use
// the shared libgcc_s-dw2-1.dll. This is required to support
// unwinding across DLL boundaries.
"-lgcc_s".to_string(),
"-l:libunwind.dll.a".to_string(),
];
late_link_args_dynamic.insert(LinkerFlavor::Gcc, dynamic_unwind_libs.clone());
late_link_args_dynamic.insert(LinkerFlavor::Lld(LldFlavor::Ld), dynamic_unwind_libs);
Expand All @@ -53,8 +32,7 @@ pub fn opts() -> TargetOptions {
// binaries to be redistributed without the libgcc_s-dw2-1.dll
// dependency, but unfortunately break unwinding across DLL
// boundaries when unwinding across FFI boundaries.
"-lgcc_eh".to_string(),
"-l:libpthread.a".to_string(),
"-l:libunwind.a".to_string(),
];
late_link_args_static.insert(LinkerFlavor::Gcc, static_unwind_libs.clone());
late_link_args_static.insert(LinkerFlavor::Lld(LldFlavor::Ld), static_unwind_libs);
Expand All @@ -64,7 +42,8 @@ pub fn opts() -> TargetOptions {
env: "gnu".to_string(),
vendor: "pc".to_string(),
// FIXME(#13846) this should be enabled for windows
function_sections: false,
function_sections: true,
no_default_libraries: false,
linker: Some("gcc".to_string()),
dynamic_linking: true,
executables: true,
Expand All @@ -80,7 +59,6 @@ pub fn opts() -> TargetOptions {
pre_link_objects_fallback: crt_objects::pre_mingw_fallback(),
post_link_objects_fallback: crt_objects::post_mingw_fallback(),
crt_objects_fallback: Some(CrtObjectsFallback::Mingw),
late_link_args,
late_link_args_dynamic,
late_link_args_static,
abi_return_struct_as_int: true,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_target/src/spec/x86_64_pc_windows_gnu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub fn target() -> Target {
base.pre_link_args
.insert(LinkerFlavor::Lld(LldFlavor::Ld), vec!["-m".to_string(), "i386pep".to_string()]);
base.max_atomic_width = Some(64);
base.linker = Some("x86_64-w64-mingw32-gcc".to_string());
base.linker = Some("x86_64-w64-mingw32-clang".to_string());

Target {
llvm_target: "x86_64-pc-windows-gnu".to_string(),
Expand Down
9 changes: 9 additions & 0 deletions src/bootstrap/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,15 @@ def download_toolchain(self, stage0=True, rustc_channel=None):
with output(self.rustc_stamp(stage0)) as rust_stamp:
rust_stamp.write(key)

# FIXME remove this when the Clang Windows GNU toolchain has been published
if (os.environ.get('GCC_LIBS_HACK')):
gcc_libs_hack = os.environ.get('GCC_LIBS_HACK')
gcc_libs_hack_dest = '{}/rustlib/{}/lib'.format(lib_dir, self.build)
shutil.copy(gcc_libs_hack + '/libgcc.a', gcc_libs_hack_dest)
shutil.copy(gcc_libs_hack + '/libgcc_eh.a', gcc_libs_hack_dest)
shutil.copy(gcc_libs_hack + '/libgcc_s.a', gcc_libs_hack_dest)
shutil.copy(gcc_libs_hack + '/libstdc++.a', gcc_libs_hack_dest)

if self.rustfmt() and self.rustfmt().startswith(bin_root) and (
not os.path.exists(self.rustfmt())
or self.program_out_of_date(
Expand Down
24 changes: 11 additions & 13 deletions src/bootstrap/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,31 +160,29 @@ fn make_win_dist(
}

let compiler = if target == "i686-pc-windows-gnu" {
"i686-w64-mingw32-gcc.exe"
"i686-w64-mingw32-clang.exe"
} else if target == "x86_64-pc-windows-gnu" {
"x86_64-w64-mingw32-gcc.exe"
"x86_64-w64-mingw32-clang.exe"
} else if target == "aarch64-pc-windows-gnu" {
"aarch64-w64-mingw32-clang.exe"
} else {
"gcc.exe"
"clang.exe"
};
let target_tools = [compiler, "ld.exe", "dlltool.exe", "libwinpthread-1.dll"];
let mut rustc_dlls = vec!["libwinpthread-1.dll"];
if target.starts_with("i686-") {
rustc_dlls.push("libgcc_s_dw2-1.dll");
} else {
rustc_dlls.push("libgcc_s_seh-1.dll");
}

rustc_dlls.push("libunwind.dll");
rustc_dlls.push("libc++.dll");

let target_libs = [
//MinGW libs
"libgcc.a",
"libgcc_eh.a",
"libgcc_s.a",
"libunwind.a",
"libunwind.dll.a",
"libm.a",
"libmingw32.a",
"libmingwex.a",
"libstdc++.a",
"libc++.a",
"libiconv.a",
"libmoldname.a",
"libpthread.a",
//Windows import libs
"libadvapi32.a",
Expand Down
10 changes: 5 additions & 5 deletions src/bootstrap/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,10 @@ impl Step for Llvm {
}
};

let llvm_exp_targets = match builder.config.llvm_experimental_targets {
Some(ref s) => s,
None => "AVR;M68k",
};
//let llvm_exp_targets = match builder.config.llvm_experimental_targets {
// Some(ref s) => s,
// None => "AVR;M68k",
//};

let assertions = if builder.config.llvm_assertions { "ON" } else { "OFF" };
let plugins = if builder.config.llvm_plugins { "ON" } else { "OFF" };
Expand All @@ -177,7 +177,7 @@ impl Step for Llvm {
.define("LLVM_ENABLE_ASSERTIONS", assertions)
.define("LLVM_ENABLE_PLUGINS", plugins)
.define("LLVM_TARGETS_TO_BUILD", llvm_targets)
.define("LLVM_EXPERIMENTAL_TARGETS_TO_BUILD", llvm_exp_targets)
// .define("LLVM_EXPERIMENTAL_TARGETS_TO_BUILD", llvm_exp_targets)
.define("LLVM_INCLUDE_EXAMPLES", "OFF")
.define("LLVM_INCLUDE_DOCS", "OFF")
.define("LLVM_INCLUDE_BENCHMARKS", "OFF")
Expand Down
12 changes: 6 additions & 6 deletions src/ci/github-actions/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -577,28 +577,28 @@ jobs:
env:
RUST_CONFIGURE_ARGS: --build=i686-pc-windows-gnu
SCRIPT: make ci-mingw-subset-1
CUSTOM_MINGW: 1
CUSTOM_MINGW: 0
<<: *job-windows-xl

- name: i686-mingw-2
env:
RUST_CONFIGURE_ARGS: --build=i686-pc-windows-gnu
SCRIPT: make ci-mingw-subset-2
CUSTOM_MINGW: 1
CUSTOM_MINGW: 0
<<: *job-windows-xl

- name: x86_64-mingw-1
env:
SCRIPT: make ci-mingw-subset-1
RUST_CONFIGURE_ARGS: --build=x86_64-pc-windows-gnu --enable-profiler
CUSTOM_MINGW: 1
CUSTOM_MINGW: 0
<<: *job-windows-xl

- name: x86_64-mingw-2
env:
SCRIPT: make ci-mingw-subset-2
RUST_CONFIGURE_ARGS: --build=x86_64-pc-windows-gnu --enable-profiler
CUSTOM_MINGW: 1
CUSTOM_MINGW: 0
<<: *job-windows-xl

- name: dist-x86_64-msvc
Expand Down Expand Up @@ -644,15 +644,15 @@ jobs:
env:
RUST_CONFIGURE_ARGS: --build=i686-pc-windows-gnu --enable-full-tools --enable-profiler
SCRIPT: python x.py dist
CUSTOM_MINGW: 1
CUSTOM_MINGW: 0
DIST_REQUIRE_ALL_TOOLS: 1
<<: *job-windows-xl

- name: dist-x86_64-mingw
env:
SCRIPT: python x.py dist
RUST_CONFIGURE_ARGS: --build=x86_64-pc-windows-gnu --enable-full-tools --enable-profiler
CUSTOM_MINGW: 1
CUSTOM_MINGW: 0
DIST_REQUIRE_ALL_TOOLS: 1
<<: *job-windows-xl

Expand Down
16 changes: 12 additions & 4 deletions src/ci/scripts/install-mingw.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,18 @@ if isWindows; then
esac

if [[ "${CUSTOM_MINGW-0}" -ne 1 ]]; then
pacman -S --noconfirm --needed mingw-w64-$arch-toolchain mingw-w64-$arch-cmake \
mingw-w64-$arch-gcc \
mingw-w64-$arch-python # the python package is actually for python3
ciCommandAddPath "$(ciCheckoutPath)/msys2/mingw${bits}/bin"
# FIXME remove the GCC_LIBS_HACK when the Clang Windows GNU toolchain has been published
export GCC_LIBS_HACK="$(cygpath -am missing-libs-hack)"
echo "GCC_LIBS_HACK path is ${GCC_LIBS_HACK}"
mkdir -p "${GCC_LIBS_HACK}"
cp "$(cygpath -u $(clang -print-libgcc-file-name))" "${GCC_LIBS_HACK}/libgcc.a"
cp "/clang64/lib/libunwind.a" "${GCC_LIBS_HACK}/libgcc_eh.a"
cp "/clang64/lib/libunwind.dll.a" "${GCC_LIBS_HACK}/libgcc_s.a"
export RUSTFLAGS_BOOTSTRAP="-C link-arg=-L$(cygpath -am missing-libs-hack)"
pacman -S --noconfirm --needed mingw-w64-clang-$arch-toolchain mingw-w64-clang-$arch-cmake \
mingw-w64-clang-$arch-ninja \
mingw-w64-clang-$arch-python # the python package is actually for python3
ciCommandAddPath "$(ciCheckoutPath)/msys2/clang${bits}/bin"
else
mingw_dir="mingw${bits}"

Expand Down

0 comments on commit 73167b7

Please sign in to comment.