diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 67deb3d977942..9d3902828918e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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: @@ -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 diff --git a/compiler/rustc_target/src/spec/i686_pc_windows_gnu.rs b/compiler/rustc_target/src/spec/i686_pc_windows_gnu.rs index 92c3a1554ac54..f477778de6464 100644 --- a/compiler/rustc_target/src/spec/i686_pc_windows_gnu.rs +++ b/compiler/rustc_target/src/spec/i686_pc_windows_gnu.rs @@ -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. diff --git a/compiler/rustc_target/src/spec/windows_gnu_base.rs b/compiler/rustc_target/src/spec/windows_gnu_base.rs index 35a52896f6fa6..b01a17fb80eba 100644 --- a/compiler/rustc_target/src/spec/windows_gnu_base.rs +++ b/compiler/rustc_target/src/spec/windows_gnu_base.rs @@ -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); @@ -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); @@ -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, @@ -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, diff --git a/compiler/rustc_target/src/spec/x86_64_pc_windows_gnu.rs b/compiler/rustc_target/src/spec/x86_64_pc_windows_gnu.rs index 26a81a484b900..60b72018097d2 100644 --- a/compiler/rustc_target/src/spec/x86_64_pc_windows_gnu.rs +++ b/compiler/rustc_target/src/spec/x86_64_pc_windows_gnu.rs @@ -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(), diff --git a/src/bootstrap/bootstrap.py b/src/bootstrap/bootstrap.py index 5a33073e6b022..ee1e8a4af2375 100644 --- a/src/bootstrap/bootstrap.py +++ b/src/bootstrap/bootstrap.py @@ -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( diff --git a/src/bootstrap/dist.rs b/src/bootstrap/dist.rs index dd179df394889..0de39a1432746 100644 --- a/src/bootstrap/dist.rs +++ b/src/bootstrap/dist.rs @@ -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", diff --git a/src/bootstrap/native.rs b/src/bootstrap/native.rs index 4a754e6da1209..93fbc0738bdb6 100644 --- a/src/bootstrap/native.rs +++ b/src/bootstrap/native.rs @@ -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" }; @@ -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") diff --git a/src/ci/github-actions/ci.yml b/src/ci/github-actions/ci.yml index ac5d5822bfbd5..bf87944ac2887 100644 --- a/src/ci/github-actions/ci.yml +++ b/src/ci/github-actions/ci.yml @@ -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 @@ -644,7 +644,7 @@ 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 @@ -652,7 +652,7 @@ jobs: 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 diff --git a/src/ci/scripts/install-mingw.sh b/src/ci/scripts/install-mingw.sh index 1685fbbbbba15..49b7c9dd44d32 100755 --- a/src/ci/scripts/install-mingw.sh +++ b/src/ci/scripts/install-mingw.sh @@ -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}"