From f6ea2ea55104038f27c5b22f52ac3239552c918e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mateusz=20Miku=C5=82a?= <mati865@gmail.com>
Date: Fri, 5 Aug 2022 21:08:53 +0200
Subject: [PATCH] Upgrade mingw-w64 on CI

---
 .github/workflows/ci.yml                      | 12 +++++-----
 src/ci/github-actions/ci.yml                  | 12 ++--------
 src/ci/scripts/install-mingw.sh               | 23 ++-----------------
 tests/debuginfo/embedded-visualizer.rs        |  1 +
 tests/debuginfo/numeric-types.rs              |  1 +
 tests/debuginfo/vec-slices.rs                 |  1 -
 .../native-link-modifier-bundle/Makefile      |  5 ++++
 .../raw-dylib-inline-cross-dylib/Makefile     | 10 +++++---
 .../Makefile                                  |  5 ++++
 .../rlib-format-packed-bundled-libs/Makefile  |  5 ++++
 10 files changed, 34 insertions(+), 41 deletions(-)

diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 5f77656e5c189..75302d917bbc6 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -418,14 +418,14 @@ jobs:
             os: windows-latest-xl
           - name: i686-mingw-1
             env:
-              RUST_CONFIGURE_ARGS: "--build=i686-pc-windows-gnu --set llvm.allow-old-toolchain"
+              RUST_CONFIGURE_ARGS: "--build=i686-pc-windows-gnu"
               SCRIPT: make ci-mingw-subset-1
               NO_DOWNLOAD_CI_LLVM: 1
               CUSTOM_MINGW: 1
             os: windows-latest-xl
           - name: i686-mingw-2
             env:
-              RUST_CONFIGURE_ARGS: "--build=i686-pc-windows-gnu --set llvm.allow-old-toolchain"
+              RUST_CONFIGURE_ARGS: "--build=i686-pc-windows-gnu"
               SCRIPT: make ci-mingw-subset-2
               NO_DOWNLOAD_CI_LLVM: 1
               CUSTOM_MINGW: 1
@@ -433,14 +433,14 @@ jobs:
           - name: x86_64-mingw-1
             env:
               SCRIPT: make ci-mingw-subset-1
-              RUST_CONFIGURE_ARGS: "--build=x86_64-pc-windows-gnu --enable-profiler --set llvm.allow-old-toolchain"
+              RUST_CONFIGURE_ARGS: "--build=x86_64-pc-windows-gnu --enable-profiler"
               NO_DOWNLOAD_CI_LLVM: 1
               CUSTOM_MINGW: 1
             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 --set llvm.allow-old-toolchain"
+              RUST_CONFIGURE_ARGS: "--build=x86_64-pc-windows-gnu --enable-profiler"
               NO_DOWNLOAD_CI_LLVM: 1
               CUSTOM_MINGW: 1
             os: windows-latest-xl
@@ -465,7 +465,7 @@ jobs:
             os: windows-latest-xl
           - name: dist-i686-mingw
             env:
-              RUST_CONFIGURE_ARGS: "--build=i686-pc-windows-gnu --enable-full-tools --enable-profiler --set llvm.allow-old-toolchain"
+              RUST_CONFIGURE_ARGS: "--build=i686-pc-windows-gnu --enable-full-tools --enable-profiler"
               NO_DOWNLOAD_CI_LLVM: 1
               SCRIPT: python x.py dist bootstrap --include-default-paths
               CUSTOM_MINGW: 1
@@ -474,7 +474,7 @@ jobs:
           - name: dist-x86_64-mingw
             env:
               SCRIPT: python x.py dist bootstrap --include-default-paths
-              RUST_CONFIGURE_ARGS: "--build=x86_64-pc-windows-gnu --enable-full-tools --enable-profiler --set llvm.allow-old-toolchain"
+              RUST_CONFIGURE_ARGS: "--build=x86_64-pc-windows-gnu --enable-full-tools --enable-profiler"
               NO_DOWNLOAD_CI_LLVM: 1
               CUSTOM_MINGW: 1
               DIST_REQUIRE_ALL_TOOLS: 1
diff --git a/src/ci/github-actions/ci.yml b/src/ci/github-actions/ci.yml
index a466777dd46f8..70b5a9d301b62 100644
--- a/src/ci/github-actions/ci.yml
+++ b/src/ci/github-actions/ci.yml
@@ -629,9 +629,7 @@ jobs:
 
           - name: i686-mingw-1
             env:
-              RUST_CONFIGURE_ARGS: >-
-                --build=i686-pc-windows-gnu
-                --set llvm.allow-old-toolchain
+              RUST_CONFIGURE_ARGS: --build=i686-pc-windows-gnu
               SCRIPT: make ci-mingw-subset-1
               # We are intentionally allowing an old toolchain on this builder (and that's
               # incompatible with LLVM downloads today).
@@ -641,9 +639,7 @@ jobs:
 
           - name: i686-mingw-2
             env:
-              RUST_CONFIGURE_ARGS: >-
-                --build=i686-pc-windows-gnu
-                --set llvm.allow-old-toolchain
+              RUST_CONFIGURE_ARGS: --build=i686-pc-windows-gnu
               SCRIPT: make ci-mingw-subset-2
               # We are intentionally allowing an old toolchain on this builder (and that's
               # incompatible with LLVM downloads today).
@@ -657,7 +653,6 @@ jobs:
               RUST_CONFIGURE_ARGS: >-
                 --build=x86_64-pc-windows-gnu
                 --enable-profiler
-                --set llvm.allow-old-toolchain
               # We are intentionally allowing an old toolchain on this builder (and that's
               # incompatible with LLVM downloads today).
               NO_DOWNLOAD_CI_LLVM: 1
@@ -670,7 +665,6 @@ jobs:
               RUST_CONFIGURE_ARGS: >-
                 --build=x86_64-pc-windows-gnu
                 --enable-profiler
-                --set llvm.allow-old-toolchain
               # We are intentionally allowing an old toolchain on this builder (and that's
               # incompatible with LLVM downloads today).
               NO_DOWNLOAD_CI_LLVM: 1
@@ -722,7 +716,6 @@ jobs:
                 --build=i686-pc-windows-gnu
                 --enable-full-tools
                 --enable-profiler
-                --set llvm.allow-old-toolchain
               # We are intentionally allowing an old toolchain on this builder (and that's
               # incompatible with LLVM downloads today).
               NO_DOWNLOAD_CI_LLVM: 1
@@ -738,7 +731,6 @@ jobs:
                 --build=x86_64-pc-windows-gnu
                 --enable-full-tools
                 --enable-profiler
-                --set llvm.allow-old-toolchain
               # We are intentionally allowing an old toolchain on this builder (and that's
               # incompatible with LLVM downloads today).
               NO_DOWNLOAD_CI_LLVM: 1
diff --git a/src/ci/scripts/install-mingw.sh b/src/ci/scripts/install-mingw.sh
index 1685fbbbbba15..7eccb9b86502c 100755
--- a/src/ci/scripts/install-mingw.sh
+++ b/src/ci/scripts/install-mingw.sh
@@ -2,24 +2,6 @@
 # If we need to download a custom MinGW, do so here and set the path
 # appropriately.
 #
-# Here we also do a pretty heinous thing which is to mangle the MinGW
-# installation we just downloaded. Currently, as of this writing, we're using
-# MinGW-w64 builds of gcc, and that's currently at 6.3.0. We use 6.3.0 as it
-# appears to be the first version which contains a fix for #40546, builds
-# randomly failing during LLVM due to ar.exe/ranlib.exe failures.
-#
-# Unfortunately, though, 6.3.0 *also* is the first version of MinGW-w64 builds
-# to contain a regression in gdb (#40184). As a result if we were to use the
-# gdb provided (7.11.1) then we would fail all debuginfo tests.
-#
-# In order to fix spurious failures (pretty high priority) we use 6.3.0. To
-# avoid disabling gdb tests we download an *old* version of gdb, specifically
-# that found inside the 6.2.0 distribution. We then overwrite the 6.3.0 gdb
-# with the 6.2.0 gdb to get tests passing.
-#
-# Note that we don't literally overwrite the gdb.exe binary because it appears
-# to just use gdborig.exe, so that's the binary we deal with instead.
-#
 # Otherwise install MinGW through `pacman`
 
 set -euo pipefail
@@ -27,8 +9,8 @@ IFS=$'\n\t'
 
 source "$(cd "$(dirname "$0")" && pwd)/../shared.sh"
 
-MINGW_ARCHIVE_32="i686-6.3.0-release-posix-dwarf-rt_v5-rev2.7z"
-MINGW_ARCHIVE_64="x86_64-6.3.0-release-posix-seh-rt_v5-rev2.7z"
+MINGW_ARCHIVE_32="i686-12.2.0-release-posix-dwarf-rt_v10-rev0.7z"
+MINGW_ARCHIVE_64="x86_64-12.2.0-release-posix-seh-rt_v10-rev0.7z"
 
 if isWindows; then
     case "${CI_JOB_NAME}" in
@@ -66,7 +48,6 @@ if isWindows; then
 
         curl -o mingw.7z "${MIRRORS_BASE}/${mingw_archive}"
         7z x -y mingw.7z > /dev/null
-        curl -o "${mingw_dir}/bin/gdborig.exe" "${MIRRORS_BASE}/2017-04-20-${bits}bit-gdborig.exe"
         ciCommandAddPath "$(pwd)/${mingw_dir}/bin"
     fi
 fi
diff --git a/tests/debuginfo/embedded-visualizer.rs b/tests/debuginfo/embedded-visualizer.rs
index 0269015b46617..2898e75e0ee36 100644
--- a/tests/debuginfo/embedded-visualizer.rs
+++ b/tests/debuginfo/embedded-visualizer.rs
@@ -1,6 +1,7 @@
 // compile-flags:-g
 // min-gdb-version: 8.1
 // ignore-lldb
+// ignore-windows-gnu // emit_debug_gdb_scripts is disabled on Windows
 
 // === CDB TESTS ==================================================================================
 
diff --git a/tests/debuginfo/numeric-types.rs b/tests/debuginfo/numeric-types.rs
index c41c9ee21df89..c122112e6c77a 100644
--- a/tests/debuginfo/numeric-types.rs
+++ b/tests/debuginfo/numeric-types.rs
@@ -1,6 +1,7 @@
 // compile-flags:-g
 
 // min-gdb-version: 8.1
+// ignore-windows-gnu // emit_debug_gdb_scripts is disabled on Windows
 
 // Tests the visualizations for `NonZero{I,U}{8,16,32,64,128,size}`, `Wrapping<T>` and
 // `Atomic{Bool,I8,I16,I32,I64,Isize,U8,U16,U32,U64,Usize}` located in `libcore.natvis`.
diff --git a/tests/debuginfo/vec-slices.rs b/tests/debuginfo/vec-slices.rs
index 7d88e45caf257..de4099a7f50cb 100644
--- a/tests/debuginfo/vec-slices.rs
+++ b/tests/debuginfo/vec-slices.rs
@@ -1,4 +1,3 @@
-// ignore-windows
 // min-lldb-version: 310
 
 // compile-flags:-g
diff --git a/tests/run-make/native-link-modifier-bundle/Makefile b/tests/run-make/native-link-modifier-bundle/Makefile
index 7c78d7783e0b6..e8a1121bfcd97 100644
--- a/tests/run-make/native-link-modifier-bundle/Makefile
+++ b/tests/run-make/native-link-modifier-bundle/Makefile
@@ -5,7 +5,12 @@ include ../../run-make-fulldeps/tools.mk
 
 # We're using the llvm-nm instead of the system nm to ensure it is compatible
 # with the LLVM bitcode generated by rustc.
+# Except on Windows where piping/IO redirection under MSYS2 is wonky with llvm-nm.
+ifndef IS_WINDOWS
 NM = "$(LLVM_BIN_DIR)"/llvm-nm
+else
+NM = nm
+endif
 
 all: $(call NATIVE_STATICLIB,native-staticlib)
 	# Build a staticlib and a rlib, the `native_func` symbol will be bundled into them
diff --git a/tests/run-make/raw-dylib-inline-cross-dylib/Makefile b/tests/run-make/raw-dylib-inline-cross-dylib/Makefile
index 9e603f9583598..722a49b02cb3b 100644
--- a/tests/run-make/raw-dylib-inline-cross-dylib/Makefile
+++ b/tests/run-make/raw-dylib-inline-cross-dylib/Makefile
@@ -4,15 +4,19 @@
 
 include ../../run-make-fulldeps/tools.mk
 
+# We'd be using the llvm-objdump instead of the system objdump to ensure compatibility
+# with the LLVM bitcode generated by rustc but on Windows  piping/IO redirection under MSYS2 is wonky with llvm-objdump.
+OBJDUMP = objdump
+
 all:
 	$(RUSTC) --crate-type dylib --crate-name raw_dylib_test lib.rs -C prefer-dynamic
 	$(RUSTC) --crate-type dylib --crate-name raw_dylib_test_wrapper lib_wrapper.rs -C prefer-dynamic
 	$(RUSTC) --crate-type bin driver.rs -L "$(TMPDIR)" -C prefer-dynamic
 	# Make sure we don't find an import to the functions we expect to be inlined.
-	"$(LLVM_BIN_DIR)"/llvm-objdump -p $(TMPDIR)/driver.exe | $(CGREP) -v -e "inline_library_function"
-	"$(LLVM_BIN_DIR)"/llvm-objdump -p $(TMPDIR)/driver.exe | $(CGREP) -v -e "inline_library_function_calls_inline"
+	$(OBJDUMP) -p $(TMPDIR)/driver.exe | $(CGREP) -v -e "inline_library_function"
+	$(OBJDUMP) -p $(TMPDIR)/driver.exe | $(CGREP) -v -e "inline_library_function_calls_inline"
 	# Make sure we do find an import to the functions we expect to be imported.
-	"$(LLVM_BIN_DIR)"/llvm-objdump -p $(TMPDIR)/driver.exe | $(CGREP) -e "library_function"
+	$(OBJDUMP) -p $(TMPDIR)/driver.exe | $(CGREP) -e "library_function"
 	$(call COMPILE_OBJ,"$(TMPDIR)"/extern_1.obj,extern_1.c)
 	$(call COMPILE_OBJ,"$(TMPDIR)"/extern_2.obj,extern_2.c)
 ifdef IS_MSVC
diff --git a/tests/run-make/rlib-format-packed-bundled-libs-2/Makefile b/tests/run-make/rlib-format-packed-bundled-libs-2/Makefile
index 4574cf17f0ef0..37b8d809a2742 100644
--- a/tests/run-make/rlib-format-packed-bundled-libs-2/Makefile
+++ b/tests/run-make/rlib-format-packed-bundled-libs-2/Makefile
@@ -6,7 +6,12 @@
 
 # We're using the llvm-nm instead of the system nm to ensure it is compatible
 # with the LLVM bitcode generated by rustc.
+# Except on Windows where piping/IO redirection under MSYS2 is wonky with llvm-nm.
+ifndef IS_WINDOWS
 NM = "$(LLVM_BIN_DIR)"/llvm-nm
+else
+NM = nm
+endif
 
 all:
 	# Build strange-named dep.
diff --git a/tests/run-make/rlib-format-packed-bundled-libs/Makefile b/tests/run-make/rlib-format-packed-bundled-libs/Makefile
index 0b991ac42e3dc..7fb6ce8d1e411 100644
--- a/tests/run-make/rlib-format-packed-bundled-libs/Makefile
+++ b/tests/run-make/rlib-format-packed-bundled-libs/Makefile
@@ -6,7 +6,12 @@
 
 # We're using the llvm-nm instead of the system nm to ensure it is compatible
 # with the LLVM bitcode generated by rustc.
+# Except on Windows where piping/IO redirection under MSYS2 is wonky with llvm-nm.
+ifndef IS_WINDOWS
 NM = "$(LLVM_BIN_DIR)"/llvm-nm
+else
+NM = nm
+endif
 
 all: $(call NATIVE_STATICLIB,native_dep_1) $(call NATIVE_STATICLIB,native_dep_2) $(call NATIVE_STATICLIB,native_dep_3)
 	$(RUSTC) rust_dep_up.rs --crate-type=rlib -Zpacked_bundled_libs