Add Windows cross-compilation via MinGW, and fix Docker build permission
build / build (push) Successful in 3m5s

issues on vboxsf-mounted checkouts

New `make dist-win`/`package-win` targets (folded into `dist`/`package`
alongside the renamed `dist-linux`/`package-linux`) cross-compile
systemshock.exe via MinGW, using prebuilt SDL2/SDL2_mixer/GLEW/
fluidsynth-lite baked into the build-image - no Windows machine or Wine
needed to build it, confirmed working and playable on a real Windows
machine. dist-win/ ships DLLs flat alongside the exe plus a new
res/run.bat launcher, packaged into a .zip the same way dist/ becomes a
.tar.gz.

Also fixes three build-image bugs hit while testing on a VirtualBox
vboxsf-mounted checkout: build-engine.sh/docker-entrypoint.sh losing
their execute bit (chmod +x on restrictive source perms), the container
user missing access to /workspace's supplementary vboxsf group, and
cp -a failing on symlink/hard-link creation (vboxsf doesn't support
either) - now falls back to dereferencing copies when detected. Also
adds Docker/zip/etc. prerequisites to the README for both the desktop
and Quest builds.
This commit is contained in:
2026-08-11 05:14:13 +02:00
parent 581af95e7b
commit a2fb95e57b
11 changed files with 457 additions and 47 deletions
+113 -3
View File
@@ -18,6 +18,13 @@ ARG FLUIDSYNTH_LITE_REF=c539a8d9270ba5a3f7d6e460606483fc2ab1eb61
# Soundfont used for MIDI music, matching what engine/build_deps.sh itself
# fetches (a free substitute for the Windows default GM soundfont).
ARG SOUNDFONT_URL=http://rancid.kapsi.fi/windows.sf2
# GLEW, for the Windows/MinGW cross-build only (engine/CMakeLists.txt's
# WIN32 branch - Windows' own opengl32.dll only exposes OpenGL 1.1, so
# anything newer needs GLEW's runtime extension loading; Linux instead
# gets modern prototypes straight from Mesa's headers, no loader needed -
# see engine/src/MacSrc/OpenGL.cc). Matches the version engine/'s own
# upstream Windows build script (build_win64.sh) used.
ARG GLEW_VERSION=2.1.0
# Gitea/GitHub Actions' JS-based actions (actions/checkout,
# actions/upload-artifact, ...) need a node binary in the container job's
# PATH - this image is otherwise pure C toolchain, so it isn't pulled in
@@ -99,6 +106,15 @@ ENV DEBIAN_FRONTEND=noninteractive
# openssh-client: the CI workflow's `sftp` publish step.
# openjdk-17-jdk-headless: Gradle/AGP's own minimum JDK for the APK build.
# unzip: extracts the Android cmdline-tools zip below.
# mingw-w64: the x86_64-w64-mingw32-{gcc,g++,windres,ar,...} cross
# toolchain for the Windows desktop build (see the "Windows cross-compile"
# section below). Ubuntu ships both a win32-thread-model and a
# posix-thread-model variant behind update-alternatives; the default
# (win32) is fine here since nothing in engine/ uses std::thread.
# zip: `make package-win`'s Windows release archive - a CI job's own
# `make package` runs inside this image as its container (see
# .gitea/workflows/build.yml), so it needs to be baked in here, not just
# available on a local dev machine's own host (see README).
#
# All apt installs deliberately live in this one RUN, first, so editing
# anything below it (in particular the Android cross-compile steps, the
@@ -111,7 +127,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
libgl1-mesa-dev libglx-dev libxext-dev libx11-dev libxrandr-dev \
libxi-dev libxfixes-dev libxss-dev libxinerama-dev libxcursor-dev \
libogg-dev libvorbis-dev libasound2-dev openssh-client \
openjdk-17-jdk-headless unzip \
openjdk-17-jdk-headless unzip mingw-w64 zip \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /opt/prebuilt
@@ -150,10 +166,96 @@ RUN git clone https://github.com/EtherTyper/fluidsynth-lite.git \
&& rm -rf .git
# General MIDI soundfont for fluidsynth playback - engine/build_deps.sh
# fetches the same file and drops it into engine/res/.
# fetches the same file and drops it into engine/res/. Shared by both the
# Linux and Windows builds below.
RUN mkdir -p soundfont \
&& curl -sSL -o soundfont/default.sf2 "${SOUNDFONT_URL}"
# CMake toolchain file for the Windows/MinGW cross-build below, reused at
# container-run time by build-image/build-engine-win.sh (see
# MINGW_TOOLCHAIN_FILE) to cross-compile engine/ itself the same way. GCC's
# runtime (libgcc/libstdc++) is linked statically so only the SDL2/
# SDL2_mixer/GLEW/fluidsynth-lite DLLs (plus libwinpthread, which isn't
# safe to static-link the same way) need shipping alongside systemshock.exe.
ENV MINGW_TOOLCHAIN_FILE=/opt/mingw-toolchain.cmake
RUN printf '%s\n' \
'set(CMAKE_SYSTEM_NAME Windows)' \
'set(CMAKE_SYSTEM_PROCESSOR x86_64)' \
'set(CMAKE_C_COMPILER x86_64-w64-mingw32-gcc)' \
'set(CMAKE_CXX_COMPILER x86_64-w64-mingw32-g++)' \
'set(CMAKE_RC_COMPILER x86_64-w64-mingw32-windres)' \
'set(CMAKE_FIND_ROOT_PATH /usr/x86_64-w64-mingw32)' \
'# LIBRARY/INCLUDE/PACKAGE deliberately left at CMake'"'"'s own' \
'# cross-compiling default (BOTH) - engine/CMakeLists.txt'"'"'s' \
'# BUNDLED SDL2/SDL2_mixer/FluidSynth find_library() calls point at' \
'# build_ext/ (outside this sysroot entirely), which ONLY would' \
'# refuse to search.' \
'set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)' \
'set(CMAKE_EXE_LINKER_FLAGS_INIT "-static-libgcc -static-libstdc++")' \
> "${MINGW_TOOLCHAIN_FILE}"
# SDL2 and SDL2_mixer for Windows: unlike the desktop build above, these
# are libsdl.org's own official prebuilt MinGW devel packages (headers +
# import libs + DLLs for x86_64-w64-mingw32), not built from source here -
# SDL2's autotools setup targets *nix; upstream ships MinGW builds
# pre-made instead, same as engine/'s own upstream Windows build script
# (build_win64.sh) uses. Same version pins as the Linux build above, so
# both desktop builds ship the same SDL2/SDL2_mixer release.
RUN curl -sSLO "https://www.libsdl.org/release/SDL2-devel-${SDL2_VERSION}-mingw.tar.gz" \
&& tar xf "SDL2-devel-${SDL2_VERSION}-mingw.tar.gz" \
&& mkdir -p /opt/prebuilt/win \
&& mv "SDL2-${SDL2_VERSION}/x86_64-w64-mingw32" /opt/prebuilt/win/sdl2 \
&& rm -rf "SDL2-${SDL2_VERSION}" "SDL2-devel-${SDL2_VERSION}-mingw.tar.gz"
RUN curl -sSLO "https://www.libsdl.org/projects/SDL_mixer/release/SDL2_mixer-devel-${SDL2_MIXER_VERSION}-mingw.tar.gz" \
&& tar xf "SDL2_mixer-devel-${SDL2_MIXER_VERSION}-mingw.tar.gz" --exclude=Xcode \
&& mv "SDL2_mixer-${SDL2_MIXER_VERSION}/x86_64-w64-mingw32" /opt/prebuilt/win/sdl2_mixer \
&& rm -rf "SDL2_mixer-${SDL2_MIXER_VERSION}" "SDL2_mixer-devel-${SDL2_MIXER_VERSION}-mingw.tar.gz"
# GLEW for Windows: compiled directly instead of via GLEW's own bundled
# cross-compile Makefile configs (config/Makefile.linux-mingw64 et al) -
# those pass raw `-soname`/`--out-implib` straight to whatever $(LD) is
# set to, which only works if LD is the real `ld` binary, not gcc-as-
# linker-driver (and that config also hardcodes a 32-bit `i686-w64-
# mingw32` host despite the "64" in its name) - simpler and more robust
# to just compile+link GLEW's one source file ourselves. Produces
# glew32.dll (to ship alongside systemshock.exe) and libglew32.dll.a (the
# MinGW import library engine/CMakeLists.txt's WIN32 branch links
# against).
RUN curl -sSL -o "glew-${GLEW_VERSION}.tgz" \
"https://sourceforge.net/projects/glew/files/glew/${GLEW_VERSION}/glew-${GLEW_VERSION}.tgz/download" \
&& tar xf "glew-${GLEW_VERSION}.tgz" \
&& cd "glew-${GLEW_VERSION}" \
&& mkdir -p /opt/prebuilt/win/glew/include/GL /opt/prebuilt/win/glew/lib \
&& x86_64-w64-mingw32-gcc -DGLEW_NO_GLU -O2 -Iinclude -c src/glew.c -o glew.o \
&& x86_64-w64-mingw32-gcc -shared \
-Wl,--out-implib,/opt/prebuilt/win/glew/lib/libglew32.dll.a \
-o /opt/prebuilt/win/glew/lib/glew32.dll \
glew.o -lopengl32 -lgdi32 -luser32 -lkernel32 \
&& cp include/GL/glew.h include/GL/wglew.h /opt/prebuilt/win/glew/include/GL/ \
&& cd .. && rm -rf "glew-${GLEW_VERSION}" "glew-${GLEW_VERSION}.tgz"
# fluidsynth-lite for Windows: same source/ref/DLL-mode patch as the
# desktop build above, cross-compiled via the MinGW toolchain file. WIN32
# skips fluidsynth-lite's own pthread dependency (see its CMakeLists.txt),
# so no libwinpthread linkage to worry about here.
RUN git clone https://github.com/EtherTyper/fluidsynth-lite.git fluidsynth-lite-win \
&& cd fluidsynth-lite-win \
&& git checkout "${FLUIDSYNTH_LITE_REF}" \
&& sed -i 's/DLL"\ off/DLL"\ on/' CMakeLists.txt \
&& rm -rf .git \
&& cd .. \
&& cmake -S fluidsynth-lite-win -B build-fluidsynth-win \
-DCMAKE_TOOLCHAIN_FILE="${MINGW_TOOLCHAIN_FILE}" \
&& cmake --build build-fluidsynth-win -j"$(nproc)" \
&& mkdir -p /opt/prebuilt/win/fluidsynth-lite/lib /opt/prebuilt/win/fluidsynth-lite/include \
&& cp build-fluidsynth-win/src/*.dll build-fluidsynth-win/src/*.dll.a \
/opt/prebuilt/win/fluidsynth-lite/lib/ \
&& cp -a fluidsynth-lite-win/include/. /opt/prebuilt/win/fluidsynth-lite/include/ \
&& cp build-fluidsynth-win/include/fluidsynth/version.h \
/opt/prebuilt/win/fluidsynth-lite/include/fluidsynth/version.h \
&& rm -rf fluidsynth-lite-win build-fluidsynth-win
# Node.js: needed only so Gitea/GitHub Actions' JS-based actions can run
# when this image is used as a CI job's container - see NODE_VERSION above.
RUN curl -sSL -o /tmp/node.tar.xz \
@@ -283,7 +385,15 @@ RUN git clone --branch "release-${ANDROID_OPENXR_VERSION}" --depth 1 \
COPY build-image/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
COPY build-image/build-engine.sh /usr/local/bin/build-engine.sh
RUN chmod +x /usr/local/bin/docker-entrypoint.sh /usr/local/bin/build-engine.sh
# 755, not +x: the entrypoint drops to a `builder` user matching the
# *host's* UID/GID (see docker-entrypoint.sh), which is never in these
# root-owned files' group, so it needs the image's own explicit
# world-read+execute here - `chmod +x` alone only adds execute bits on
# top of whatever "other" permissions the source file happened to have
# (which depends on the host's umask at checkout, e.g. a restrictive
# 0007 umask yields unreadable-by-other files, which then round-trip
# into the image and cause a Permission denied at container run time).
RUN chmod 755 /usr/local/bin/docker-entrypoint.sh /usr/local/bin/build-engine.sh
# Marks a shell as already running inside this image (with every engine
# build dependency prebuilt above) - lets the Makefile's `engine` target