# MinGW-w64 GCC for Windows x86_64 (UCRT) on Arch Linux, plus Wine.
#
# mingw-w64 14 made UCRT the default (mingw-w64-crt/configure.ac:
# --with-default-msvcrt defaults to ucrt), so x86_64-w64-mingw32-g++ here
# produces UCRT binaries. Arch packages mingw-w64-gcc 16.2, the same GCC major
# the Void projects use natively.
#
# Wine runs the resulting tests. Vulkan under Wine maps to the host Vulkan
# driver, so the Mesa/RADV/lavapipe packages are installed too.
#
# Arch ships only the core MinGW toolchain. Extra Windows libraries belong to
# the project (CMake FetchContent, vcpkg or conan); the Vulkan headers are
# copied into the MinGW sysroot because they are platform-independent.
#
# The install is split into several RUN layers so no single image layer gets
# large enough to upset the container registry.
FROM archlinux:base-devel

LABEL org.opencontainers.image.title="Void CI Windows GCC" \
      org.opencontainers.image.description="MinGW-w64 GCC 16 (UCRT) cross toolchain, CMake, Ninja and Wine" \
      org.opencontainers.image.source="https://git.faumaray.com/Void/CI-Images"

ENV LANG=C.UTF-8 \
    LC_ALL=C.UTF-8 \
    CMAKE_GENERATOR=Ninja \
    MINGW_TRIPLET=x86_64-w64-mingw32 \
    WINEPREFIX=/home/builder/.wine \
    WINEARCH=win64 \
    WINEDEBUG=-all \
    WINEDLLOVERRIDES=mscoree,mshtml= \
    WINEPATH=Z:/usr/x86_64-w64-mingw32/bin

RUN pacman -Syu --noconfirm \
    && pacman -S --noconfirm --needed \
        base-devel gcc cmake ninja git pkgconf python zip unzip \
    && pacman -Scc --noconfirm

RUN pacman -S --noconfirm --needed \
        mingw-w64-toolchain \
    && pacman -Scc --noconfirm

RUN pacman -S --noconfirm --needed \
        vulkan-headers vulkan-icd-loader vulkan-tools \
        mesa vulkan-radeon vulkan-swrast \
    && pacman -Scc --noconfirm

RUN pacman -S --noconfirm --needed \
        wine xorg-server-xvfb jq curl ca-certificates \
    && pacman -Scc --noconfirm

RUN pacman -S --noconfirm --needed \
        nodejs npm \
    && pacman -Scc --noconfirm

# The Vulkan headers are OS-independent; make them visible to the MinGW compiler.
RUN cp -a /usr/include/vulkan /usr/x86_64-w64-mingw32/include/ \
    && git config --system --add safe.directory '*' \
    && useradd --create-home --shell /bin/bash builder

USER builder
WORKDIR /home/builder

# Initialise the Wine prefix once, at build time, not in every job.
RUN wineboot --init >/dev/null 2>&1 || true; wineserver -w || true

CMD ["/bin/bash"]
