sdl2-compat: ci: test msys2 mingw patforms

From f837432900f0163ead1e4f8a999aea06d4e34f7e Mon Sep 17 00:00:00 2001
From: Anonymous Maarten <[EMAIL REDACTED]>
Date: Sun, 6 Aug 2023 15:18:48 +0200
Subject: [PATCH] ci: test msys2 mingw patforms

---
 .github/workflows/main.yml | 44 +++++++++++++++++++++++++++++---------
 1 file changed, 34 insertions(+), 10 deletions(-)

diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index 2660f37..41cadda 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -10,17 +10,34 @@ jobs:
       fail-fast: false
       matrix:
         platform:
-        - { name: 'Windows (x64)',    os: windows-latest, msvc: true, msvc-arch: x64 }
-        - { name: 'Windows (x86)',    os: windows-latest, msvc: true, msvc-arch: x86 }
-        - { name: 'Windows (arm32)',  os: windows-latest, msvc: true, msvc-arch: amd64_arm, cross: true }
-        - { name: 'Windows (arm64)',  os: windows-latest, msvc: true, msvc-arch: amd64_arm64, cross: true }
-        - { name: 'Linux',            os: ubuntu-latest }
-        - { name: 'MacOS',            os: macos-latest }
+        - { name: 'Linux',                    os: ubuntu-latest,  shell: sh }
+        - { name: 'MacOS',                    os: macos-latest,   shell: sh }
+        - { name: 'Windows msys2 (mingw32)',  os: windows-latest, shell: 'msys2 {0}', msystem: mingw32, msys-env: mingw-w64-i686 }
+        - { name: 'Windows msys2 (mingw64)',  os: windows-latest, shell: 'msys2 {0}', msystem: mingw64, msys-env: mingw-w64-x86_64 }
+        - { name: 'Windows msys2 (clang32)',  os: windows-latest, shell: 'msys2 {0}', msystem: clang32, msys-env: mingw-w64-clang-i686 }
+        - { name: 'Windows msys2 (clang64)',  os: windows-latest, shell: 'msys2 {0}', msystem: clang64, msys-env: mingw-w64-clang-x86_64 }
+        - { name: 'Windows MSVC (x86)',       os: windows-latest, shell: sh, msvc: true, msvc-arch: x86 }
+        - { name: 'Windows MSVC (x64)',       os: windows-latest, shell: sh, msvc: true, msvc-arch: x64 }
+        - { name: 'Windows MSVC (arm32)',     os: windows-latest, shell: sh, msvc: true, msvc-arch: amd64_arm, cross: true }
+        - { name: 'Windows MSVC (arm64)',     os: windows-latest, shell: sh, msvc: true, msvc-arch: amd64_arm64, cross: true }
+    defaults:
+      run:
+        shell: ${{ matrix.platform.shell }}
     steps:
     - uses: ilammy/msvc-dev-cmd@v1
       if: ${{ matrix.platform.msvc }}
       with:
         arch: ${{ matrix.platform.msvc-arch }}
+    - name: Set up MSYS2
+      if: ${{ contains(matrix.platform.shell, 'msys2') }}
+      uses: msys2/setup-msys2@v2
+      with:
+        msystem: ${{ matrix.platform.msystem }}
+        install: >-
+          ${{ matrix.platform.msys-env }}-cc
+          ${{ matrix.platform.msys-env }}-cmake
+          ${{ matrix.platform.msys-env }}-crt
+          ${{ matrix.platform.msys-env }}-ninja
     - name: Get sdl2-compat sources
       uses: actions/checkout@v3
     - name: Install Ninja
@@ -28,6 +45,7 @@ jobs:
       uses: turtlesec-no/get-ninja@main
     - name: Set up SDL3
       uses: libsdl-org/setup-sdl@main
+      id: sdl
       with:
         cmake-generator: Ninja
         version: 3-head
@@ -40,22 +58,28 @@ jobs:
         sudo apt-get update -y
         sudo apt-get install -y libgl1-mesa-dev libglu1-mesa-dev
     - name: Configure (CMake)
-      shell: sh
       run: |
         cmake -B build -GNinja
     - name: Build (CMake)
       run: |
-        cmake --build build/
+        cmake --build build/ --verbose
     - name: Run build-time tests (CMake)
       if: ${{ false && !matrix.platform.cross }} # FIXME: enable build-time tests on CI
-      shell: sh
       run: |
+        #FIXME: do this in libsdl-org/setup-sdl (by adding it to .bashrc)? Or move to separate ci step?
+        sdl_binpath="${{ steps.sdl.outputs.prefix }}/bin"
+        if [ "x${{ runner.os }}" = "xWindows" ]; then
+          sdl_binpath="$( cygpath -u "$sdl_binpath" )"
+        fi
+        echo "sdl_binpath=$sdl_binpath"
+        export PATH="$sdl_binpath:$PATH"
+        export LD_LIBRARY_PATH="$PWD:$LD_LIBRARY_PATH"
+
         set -eu
         export SDL_TESTS_QUICK=1
         ctest -VV --test-dir build/
     - name: Check that versioning is consistent
       # We only need to run this once: arbitrarily use the Linux build
       if: ${{ runner.os == 'Linux' }}
-      shell: bash
       run: |
         ./build-scripts/test-versioning.sh