Skip to content

Commit 73167b7

Browse files
committed
Switch pc-windows-gnu targets from GCC to Clang
1 parent 03360be commit 73167b7

File tree

9 files changed

+55
-62
lines changed

9 files changed

+55
-62
lines changed

.github/workflows/ci.yml

+6-6
Original file line numberDiff line numberDiff line change
@@ -366,25 +366,25 @@ jobs:
366366
env:
367367
RUST_CONFIGURE_ARGS: "--build=i686-pc-windows-gnu"
368368
SCRIPT: make ci-mingw-subset-1
369-
CUSTOM_MINGW: 1
369+
CUSTOM_MINGW: 0
370370
os: windows-latest-xl
371371
- name: i686-mingw-2
372372
env:
373373
RUST_CONFIGURE_ARGS: "--build=i686-pc-windows-gnu"
374374
SCRIPT: make ci-mingw-subset-2
375-
CUSTOM_MINGW: 1
375+
CUSTOM_MINGW: 0
376376
os: windows-latest-xl
377377
- name: x86_64-mingw-1
378378
env:
379379
SCRIPT: make ci-mingw-subset-1
380380
RUST_CONFIGURE_ARGS: "--build=x86_64-pc-windows-gnu --enable-profiler"
381-
CUSTOM_MINGW: 1
381+
CUSTOM_MINGW: 0
382382
os: windows-latest-xl
383383
- name: x86_64-mingw-2
384384
env:
385385
SCRIPT: make ci-mingw-subset-2
386386
RUST_CONFIGURE_ARGS: "--build=x86_64-pc-windows-gnu --enable-profiler"
387-
CUSTOM_MINGW: 1
387+
CUSTOM_MINGW: 0
388388
os: windows-latest-xl
389389
- name: dist-x86_64-msvc
390390
env:
@@ -409,14 +409,14 @@ jobs:
409409
env:
410410
RUST_CONFIGURE_ARGS: "--build=i686-pc-windows-gnu --enable-full-tools --enable-profiler"
411411
SCRIPT: python x.py dist
412-
CUSTOM_MINGW: 1
412+
CUSTOM_MINGW: 0
413413
DIST_REQUIRE_ALL_TOOLS: 1
414414
os: windows-latest-xl
415415
- name: dist-x86_64-mingw
416416
env:
417417
SCRIPT: python x.py dist
418418
RUST_CONFIGURE_ARGS: "--build=x86_64-pc-windows-gnu --enable-full-tools --enable-profiler"
419-
CUSTOM_MINGW: 1
419+
CUSTOM_MINGW: 0
420420
DIST_REQUIRE_ALL_TOOLS: 1
421421
os: windows-latest-xl
422422
- name: dist-x86_64-msvc-alt

compiler/rustc_target/src/spec/i686_pc_windows_gnu.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub fn target() -> Target {
77
.insert(LinkerFlavor::Lld(LldFlavor::Ld), vec!["-m".to_string(), "i386pe".to_string()]);
88
base.max_atomic_width = Some(64);
99
base.frame_pointer = FramePointer::Always; // Required for backtraces
10-
base.linker = Some("i686-w64-mingw32-gcc".to_string());
10+
base.linker = Some("i686-w64-mingw32-clang".to_string());
1111

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

compiler/rustc_target/src/spec/windows_gnu_base.rs

+4-26
Original file line numberDiff line numberDiff line change
@@ -16,34 +16,13 @@ pub fn opts() -> TargetOptions {
1616
],
1717
);
1818

19-
let mut late_link_args = LinkArgs::new();
2019
let mut late_link_args_dynamic = LinkArgs::new();
2120
let mut late_link_args_static = LinkArgs::new();
22-
// Order of `late_link_args*` was found through trial and error to work with various
23-
// mingw-w64 versions (not tested on the CI). It's expected to change from time to time.
24-
let mingw_libs = vec![
25-
"-lmsvcrt".to_string(),
26-
"-lmingwex".to_string(),
27-
"-lmingw32".to_string(),
28-
"-lgcc".to_string(), // alas, mingw* libraries above depend on libgcc
29-
// mingw's msvcrt is a weird hybrid import library and static library.
30-
// And it seems that the linker fails to use import symbols from msvcrt
31-
// that are required from functions in msvcrt in certain cases. For example
32-
// `_fmode` that is used by an implementation of `__p__fmode` in x86_64.
33-
// The library is purposely listed twice to fix that.
34-
//
35-
// See https://github.com/rust-lang/rust/pull/47483 for some more details.
36-
"-lmsvcrt".to_string(),
37-
"-luser32".to_string(),
38-
"-lkernel32".to_string(),
39-
];
40-
late_link_args.insert(LinkerFlavor::Gcc, mingw_libs.clone());
41-
late_link_args.insert(LinkerFlavor::Lld(LldFlavor::Ld), mingw_libs);
4221
let dynamic_unwind_libs = vec![
4322
// If any of our crates are dynamically linked then we need to use
4423
// the shared libgcc_s-dw2-1.dll. This is required to support
4524
// unwinding across DLL boundaries.
46-
"-lgcc_s".to_string(),
25+
"-l:libunwind.dll.a".to_string(),
4726
];
4827
late_link_args_dynamic.insert(LinkerFlavor::Gcc, dynamic_unwind_libs.clone());
4928
late_link_args_dynamic.insert(LinkerFlavor::Lld(LldFlavor::Ld), dynamic_unwind_libs);
@@ -53,8 +32,7 @@ pub fn opts() -> TargetOptions {
5332
// binaries to be redistributed without the libgcc_s-dw2-1.dll
5433
// dependency, but unfortunately break unwinding across DLL
5534
// boundaries when unwinding across FFI boundaries.
56-
"-lgcc_eh".to_string(),
57-
"-l:libpthread.a".to_string(),
35+
"-l:libunwind.a".to_string(),
5836
];
5937
late_link_args_static.insert(LinkerFlavor::Gcc, static_unwind_libs.clone());
6038
late_link_args_static.insert(LinkerFlavor::Lld(LldFlavor::Ld), static_unwind_libs);
@@ -64,7 +42,8 @@ pub fn opts() -> TargetOptions {
6442
env: "gnu".to_string(),
6543
vendor: "pc".to_string(),
6644
// FIXME(#13846) this should be enabled for windows
67-
function_sections: false,
45+
function_sections: true,
46+
no_default_libraries: false,
6847
linker: Some("gcc".to_string()),
6948
dynamic_linking: true,
7049
executables: true,
@@ -80,7 +59,6 @@ pub fn opts() -> TargetOptions {
8059
pre_link_objects_fallback: crt_objects::pre_mingw_fallback(),
8160
post_link_objects_fallback: crt_objects::post_mingw_fallback(),
8261
crt_objects_fallback: Some(CrtObjectsFallback::Mingw),
83-
late_link_args,
8462
late_link_args_dynamic,
8563
late_link_args_static,
8664
abi_return_struct_as_int: true,

compiler/rustc_target/src/spec/x86_64_pc_windows_gnu.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub fn target() -> Target {
1010
base.pre_link_args
1111
.insert(LinkerFlavor::Lld(LldFlavor::Ld), vec!["-m".to_string(), "i386pep".to_string()]);
1212
base.max_atomic_width = Some(64);
13-
base.linker = Some("x86_64-w64-mingw32-gcc".to_string());
13+
base.linker = Some("x86_64-w64-mingw32-clang".to_string());
1414

1515
Target {
1616
llvm_target: "x86_64-pc-windows-gnu".to_string(),

src/bootstrap/bootstrap.py

+9
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,15 @@ def download_toolchain(self, stage0=True, rustc_channel=None):
470470
with output(self.rustc_stamp(stage0)) as rust_stamp:
471471
rust_stamp.write(key)
472472

473+
# FIXME remove this when the Clang Windows GNU toolchain has been published
474+
if (os.environ.get('GCC_LIBS_HACK')):
475+
gcc_libs_hack = os.environ.get('GCC_LIBS_HACK')
476+
gcc_libs_hack_dest = '{}/rustlib/{}/lib'.format(lib_dir, self.build)
477+
shutil.copy(gcc_libs_hack + '/libgcc.a', gcc_libs_hack_dest)
478+
shutil.copy(gcc_libs_hack + '/libgcc_eh.a', gcc_libs_hack_dest)
479+
shutil.copy(gcc_libs_hack + '/libgcc_s.a', gcc_libs_hack_dest)
480+
shutil.copy(gcc_libs_hack + '/libstdc++.a', gcc_libs_hack_dest)
481+
473482
if self.rustfmt() and self.rustfmt().startswith(bin_root) and (
474483
not os.path.exists(self.rustfmt())
475484
or self.program_out_of_date(

src/bootstrap/dist.rs

+11-13
Original file line numberDiff line numberDiff line change
@@ -160,31 +160,29 @@ fn make_win_dist(
160160
}
161161

162162
let compiler = if target == "i686-pc-windows-gnu" {
163-
"i686-w64-mingw32-gcc.exe"
163+
"i686-w64-mingw32-clang.exe"
164164
} else if target == "x86_64-pc-windows-gnu" {
165-
"x86_64-w64-mingw32-gcc.exe"
165+
"x86_64-w64-mingw32-clang.exe"
166+
} else if target == "aarch64-pc-windows-gnu" {
167+
"aarch64-w64-mingw32-clang.exe"
166168
} else {
167-
"gcc.exe"
169+
"clang.exe"
168170
};
169171
let target_tools = [compiler, "ld.exe", "dlltool.exe", "libwinpthread-1.dll"];
170172
let mut rustc_dlls = vec!["libwinpthread-1.dll"];
171-
if target.starts_with("i686-") {
172-
rustc_dlls.push("libgcc_s_dw2-1.dll");
173-
} else {
174-
rustc_dlls.push("libgcc_s_seh-1.dll");
175-
}
173+
174+
rustc_dlls.push("libunwind.dll");
175+
rustc_dlls.push("libc++.dll");
176176

177177
let target_libs = [
178178
//MinGW libs
179-
"libgcc.a",
180-
"libgcc_eh.a",
181-
"libgcc_s.a",
179+
"libunwind.a",
180+
"libunwind.dll.a",
182181
"libm.a",
183182
"libmingw32.a",
184183
"libmingwex.a",
185-
"libstdc++.a",
184+
"libc++.a",
186185
"libiconv.a",
187-
"libmoldname.a",
188186
"libpthread.a",
189187
//Windows import libs
190188
"libadvapi32.a",

src/bootstrap/native.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,10 @@ impl Step for Llvm {
163163
}
164164
};
165165

166-
let llvm_exp_targets = match builder.config.llvm_experimental_targets {
167-
Some(ref s) => s,
168-
None => "AVR;M68k",
169-
};
166+
//let llvm_exp_targets = match builder.config.llvm_experimental_targets {
167+
// Some(ref s) => s,
168+
// None => "AVR;M68k",
169+
//};
170170

171171
let assertions = if builder.config.llvm_assertions { "ON" } else { "OFF" };
172172
let plugins = if builder.config.llvm_plugins { "ON" } else { "OFF" };
@@ -177,7 +177,7 @@ impl Step for Llvm {
177177
.define("LLVM_ENABLE_ASSERTIONS", assertions)
178178
.define("LLVM_ENABLE_PLUGINS", plugins)
179179
.define("LLVM_TARGETS_TO_BUILD", llvm_targets)
180-
.define("LLVM_EXPERIMENTAL_TARGETS_TO_BUILD", llvm_exp_targets)
180+
// .define("LLVM_EXPERIMENTAL_TARGETS_TO_BUILD", llvm_exp_targets)
181181
.define("LLVM_INCLUDE_EXAMPLES", "OFF")
182182
.define("LLVM_INCLUDE_DOCS", "OFF")
183183
.define("LLVM_INCLUDE_BENCHMARKS", "OFF")

src/ci/github-actions/ci.yml

+6-6
Original file line numberDiff line numberDiff line change
@@ -577,28 +577,28 @@ jobs:
577577
env:
578578
RUST_CONFIGURE_ARGS: --build=i686-pc-windows-gnu
579579
SCRIPT: make ci-mingw-subset-1
580-
CUSTOM_MINGW: 1
580+
CUSTOM_MINGW: 0
581581
<<: *job-windows-xl
582582

583583
- name: i686-mingw-2
584584
env:
585585
RUST_CONFIGURE_ARGS: --build=i686-pc-windows-gnu
586586
SCRIPT: make ci-mingw-subset-2
587-
CUSTOM_MINGW: 1
587+
CUSTOM_MINGW: 0
588588
<<: *job-windows-xl
589589

590590
- name: x86_64-mingw-1
591591
env:
592592
SCRIPT: make ci-mingw-subset-1
593593
RUST_CONFIGURE_ARGS: --build=x86_64-pc-windows-gnu --enable-profiler
594-
CUSTOM_MINGW: 1
594+
CUSTOM_MINGW: 0
595595
<<: *job-windows-xl
596596

597597
- name: x86_64-mingw-2
598598
env:
599599
SCRIPT: make ci-mingw-subset-2
600600
RUST_CONFIGURE_ARGS: --build=x86_64-pc-windows-gnu --enable-profiler
601-
CUSTOM_MINGW: 1
601+
CUSTOM_MINGW: 0
602602
<<: *job-windows-xl
603603

604604
- name: dist-x86_64-msvc
@@ -644,15 +644,15 @@ jobs:
644644
env:
645645
RUST_CONFIGURE_ARGS: --build=i686-pc-windows-gnu --enable-full-tools --enable-profiler
646646
SCRIPT: python x.py dist
647-
CUSTOM_MINGW: 1
647+
CUSTOM_MINGW: 0
648648
DIST_REQUIRE_ALL_TOOLS: 1
649649
<<: *job-windows-xl
650650

651651
- name: dist-x86_64-mingw
652652
env:
653653
SCRIPT: python x.py dist
654654
RUST_CONFIGURE_ARGS: --build=x86_64-pc-windows-gnu --enable-full-tools --enable-profiler
655-
CUSTOM_MINGW: 1
655+
CUSTOM_MINGW: 0
656656
DIST_REQUIRE_ALL_TOOLS: 1
657657
<<: *job-windows-xl
658658

src/ci/scripts/install-mingw.sh

+12-4
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,18 @@ if isWindows; then
5757
esac
5858

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

0 commit comments

Comments
 (0)