From 7bdece0680fa35fd86bad0d89c4dab455ca17c3a Mon Sep 17 00:00:00 2001 From: "Aleksei (Faumaray) Selikhov" Date: Sun, 6 Dec 2026 06:41:58 +0300 Subject: [PATCH] ci: install a C++26-capable MinGW-w64 for the Windows cross build The Wine build compiles VBS itself, so MinGW GCC >= 16 is required. install-mingw.sh keeps the toolchain already on PATH when compatible, otherwise takes it from the project dev environment (dev cpp-gcc -p pkgsCross.mingwW64.stdenv.cc), then falls back to the distribution package, and fails with a clear message when none provides GCC 16. --- .gitea/scripts/install-mingw.sh | 67 +++++++++++++++++++++++++++++++++ .gitea/workflows/ci.yml | 20 +--------- 2 files changed, 68 insertions(+), 19 deletions(-) create mode 100644 .gitea/scripts/install-mingw.sh diff --git a/.gitea/scripts/install-mingw.sh b/.gitea/scripts/install-mingw.sh new file mode 100644 index 0000000..bc543aa --- /dev/null +++ b/.gitea/scripts/install-mingw.sh @@ -0,0 +1,67 @@ +#!/usr/bin/env bash +# Ensures a C++26-capable MinGW-w64 cross compiler (GCC >= 16). +# +# Tries, in order: the toolchain already on PATH, the project's Nix +# environment (`dev cpp-gcc -p pkgsCross.mingwW64.stdenv.cc`), and the +# distribution package. Fails explicitly when none provides GCC 16. +set -euo pipefail + +minimum=16 + +compiler_major() { + local compiler="${1:-x86_64-w64-mingw32-g++}" + command -v "${compiler}" >/dev/null 2>&1 || { + echo 0 + return + } + "${compiler}" -dumpversion 2>/dev/null | cut -d. -f1 || echo 0 +} + +compatible() { + [ "${1:-0}" -ge "${minimum}" ] +} + +report() { + local major + major="$(compiler_major)" + if compatible "${major}"; then + echo "using MinGW-w64 $(x86_64-w64-mingw32-g++ --version | head -n1)" + return 0 + fi + return 1 +} + +if report; then + exit 0 +fi + +# The project environment provides the cross toolchain through its dev shell. +if command -v dev >/dev/null 2>&1; then + echo "trying the project dev environment for MinGW-w64 GCC ${minimum}+" + nix_path="$(dev cpp-gcc -p pkgsCross.mingwW64.stdenv.cc -c sh -c 'printf %s "$PATH"' \ + 2>/dev/null | tr -d '\r' | tail -n1 || true)" + if [ -n "${nix_path:-}" ]; then + export PATH="${nix_path}:${PATH}" + hash -r + fi + if report; then + exit 0 + fi +fi + +# Distribution package (may be older than GCC 16). +if command -v apt-get >/dev/null 2>&1; then + sudo="" + if [ "$(id -u)" -ne 0 ]; then sudo="sudo"; fi + ${sudo} apt-get update || true + ${sudo} apt-get install -y mingw-w64 || true + hash -r + if report; then + exit 0 + fi +fi + +echo "MinGW-w64 GCC ${minimum} or newer is required to build VBS for Windows" >&2 +echo "(C++26 reflection); found $(compiler_major). Install it on the runner image" >&2 +echo "or provide it through the project's dev environment." >&2 +exit 1 diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 99b0b05..154a1d8 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -255,25 +255,7 @@ jobs: steps: - uses: actions/checkout@v4 - name: Install the MinGW-w64 cross toolchain - run: | - sudo="" - if [ "$(id -u)" -ne 0 ]; then sudo="sudo"; fi - if ! command -v x86_64-w64-mingw32-g++ >/dev/null 2>&1; then - if command -v apt-get >/dev/null 2>&1; then - ${sudo} apt-get update - ${sudo} apt-get install -y mingw-w64 - fi - fi - if ! command -v x86_64-w64-mingw32-g++ >/dev/null 2>&1; then - echo "x86_64-w64-mingw32-g++ is required for the Windows build" >&2 - exit 1 - fi - x86_64-w64-mingw32-g++ --version | head -1 - major="$(x86_64-w64-mingw32-g++ -dumpversion | cut -d. -f1)" - if [ "${major:-0}" -lt 16 ]; then - echo "MinGW-w64 GCC 16 or newer is required for C++26 (found ${major:-unknown}); install it on the runner image" >&2 - exit 1 - fi + run: bash .gitea/scripts/install-mingw.sh - name: Configure run: | cmake -S . -B "build/wine-${{ matrix.variant }}" -G Ninja \