Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
134 changes: 134 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,57 @@ jobs:
retention-days: 1
if-no-files-found: error

# The x86-64 program cross-built on a Mac as well (runtime/win/build-x64-cross.sh: llvm-mingw's compiler and
# the MSYS2 LLVM packages runtime/win/x64/cross/msys2-sysroot.txt pins, no Windows). The release ships the
# MSYS2 build; smoke-x64-cross starts this one in that zip's place, so a break here shows in the run
# without holding a release back.
windows-x64-cross:
name: Windows x64 cross-build
needs: check
if: github.event.inputs.platforms == 'All' || github.event.inputs.platforms == 'Windows'
runs-on: macos-15
timeout-minutes: 60
env:
PROFILE: altverz
TL_WIN_TOOLCHAIN: ${{ github.workspace }}/out/win-toolchain
steps:
- uses: actions/checkout@v7

- name: Toolchain cache
uses: actions/cache@v6
with:
path: out/win-toolchain
key: win-arm64-toolchain-${{ hashFiles('runtime/win/setup-toolchain.sh', 'runtime/win/fetch-zlib.sh') }}

- name: Toolchain
run: runtime/win/setup-toolchain.sh

- name: Build tools
run: |
set -euo pipefail
for tool in cmake ninja zstd; do command -v "$tool" >/dev/null || brew install "$tool"; done

- name: Sysroot and ScarletNX cache
uses: actions/cache@v6
with:
path: out/win-x64-cross-work
key: win-x64-cross-${{ hashFiles('runtime/win/x64/cross/*', 'runtime/win/x64/scarletnx/*', 'runtime/win/fetch-zlib.sh') }}

- name: Build
run: |
set -euo pipefail
runtime/win/build-x64-cross.sh game-portable
ls -l "out/win-altverz-x64-portable/PvZ2 AltVerZ x64.exe" out/win-altverz-x64-runtime

- uses: actions/upload-artifact@v7
with:
name: windows-x64-cross-programs
path: |
out/win-altverz-x64-portable/PvZ2 AltVerZ x64.exe
out/win-altverz-x64-runtime/*.dll
retention-days: 1
if-no-files-found: error

windows:
name: Windows setup and zips
needs: windows-arm64
Expand Down Expand Up @@ -497,6 +548,89 @@ jobs:
retention-days: 14
if-no-files-found: ignore

# The cross-built x64 program, started twice as the smoke test does, in the MSYS2-built zip with its
# program and DLLs replaced. Its result does not gate the release (publish does not wait for it).
smoke-x64-cross:
name: Windows smoke test (x64, cross-built)
needs: [windows, windows-x64-cross]
if: github.event.inputs.skip_smoke != 'true'
runs-on: windows-2025
timeout-minutes: 60
defaults:
run:
shell: pwsh
steps:
- uses: actions/checkout@v7

# A single-file artifact that is a .zip arrives unpacked: the portable copy itself
- uses: actions/download-artifact@v8
with:
pattern: "*-Windows-x64.zip"
path: game
merge-multiple: true

- uses: actions/download-artifact@v8
with:
name: windows-x64-cross-programs
path: cross

- name: The cross-built program in the zip's place
run: |
Copy-Item "cross/win-altverz-x64-portable/PvZ2 AltVerZ x64.exe" game/ -Force
Copy-Item cross/win-altverz-x64-runtime/*.dll game/ -Force
Get-ChildItem game -File | Where-Object { $_.Extension -in '.exe', '.dll' } | Format-Table Name, Length

- name: The OBB's name
id: obb
run: |
$p = Get-Content data/profiles/altverz.json | ConvertFrom-Json
$j = Get-Content $p.game_data | ConvertFrom-Json
"package=$($p.package_name)" >> $env:GITHUB_OUTPUT
"exe=$($p.app_name)*.exe" >> $env:GITHUB_OUTPUT
"game=$($j.version)" >> $env:GITHUB_OUTPUT
"name=$($j.obb_name)" >> $env:GITHUB_OUTPUT
"sha=$($j.obb_sha256)" >> $env:GITHUB_OUTPUT
"url=$($j.obb_urls[0])" >> $env:GITHUB_OUTPUT

- name: OBB cache
id: obb-cache
uses: actions/cache@v6
with:
path: obb
key: obb-${{ steps.obb.outputs.sha }}

- name: The OBB
if: steps.obb-cache.outputs.cache-hit != 'true'
env:
NAME: ${{ steps.obb.outputs.name }}
SHA: ${{ steps.obb.outputs.sha }}
URL: ${{ steps.obb.outputs.url }}
run: |
New-Item -ItemType Directory -Force -Path obb | Out-Null
curl.exe -fL --retry 3 -o "obb/$env:NAME" $env:URL
if ($LASTEXITCODE) { throw "the OBB download failed" }
$sum = (Get-FileHash "obb/$env:NAME" -Algorithm SHA256).Hash.ToLower()
if ($sum -ne $env:SHA) { throw "the OBB has sha256 $sum, not $env:SHA" }

- name: Start the game twice
env:
NAME: ${{ steps.obb.outputs.name }}
GAME: ${{ steps.obb.outputs.game }}
PACKAGE: ${{ steps.obb.outputs.package }}
EXE: ${{ steps.obb.outputs.exe }}
run: ./runtime/win/smoke-test.ps1 -Game game -Obb "obb/$env:NAME" -Out smoke -Baseline "runtime/win/smoke/first-$env:GAME.png" -ExeFilter $env:EXE -Package $env:PACKAGE

- name: Keep the logs and screenshots
if: always()
# A failed upload (GitHub's storage) must not fail a test that passed
continue-on-error: true
uses: actions/upload-artifact@v7
with:
name: smoke-x64-cross
path: smoke
retention-days: 14
if-no-files-found: ignore

# One job publishes everything, once every build the run asked for has passed: the release
# (made as a draft, filled, then made public), its text, the AltStore source and both update
# feeds. A failed or cancelled build publishes nothing, and nor does a Windows build whose
Expand Down
33 changes: 33 additions & 0 deletions runtime/win/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,39 @@ the APK is the slim one).
The x64 program (`runtime/win/x64/build-x64.sh`) takes the same `game`/`game-portable` targets
and links `prebuilt/winsparkle/x64` for the installed one.

### The x64 program from a Mac or Linux

The release workflow builds the x64 program in MSYS2's CLANG64 shell on Windows. The same program can be
cross-built on a Mac or Linux, with no Windows and no MSYS2:

```sh
TL_WIN_TOOLCHAIN=<toolchain folder> runtime/win/build-x64-cross.sh game-portable
```

It needs what the ARM64 build needs (`runtime/win/setup-toolchain.sh` unpacks llvm-mingw; `LLVM_MINGW` names
another copy, a Linux host's own release) and `cmake`, `ninja`, `git`, `curl`, `zstd`, `python3` and a `clang`
for the one helper ScarletNX runs while it builds. The script then:

1. unpacks the MSYS2 CLANG64 packages pinned in `runtime/win/x64/cross/msys2-sysroot.txt` (versions and SHA-256
hashes, the same versions as `msys2-clang64.txt`): LLVM 23's headers, CMake package and import library for
Windows, and the DLLs the program ships with (`runtime/win/x64/cross/setup-sysroot.sh`);
2. builds ScarletNX's recompiler library at the pinned commit with `scarletnx.patch` for x86-64 Windows
(`x64/scarletnx/build-scarletnx.sh` with `X64_CROSS_SYSROOT` set; ScarletNX's own CMake supports this
cross-build, its `windows-cross` preset, and takes LLVM from the sysroot's CMake package);
3. builds the program (`x64/build-x64.sh`, same script, llvm-mingw's x86-64 tools) and collects the DLLs it
needs (`x64/collect-dlls.sh`) into `out/win-<profile>-x64-runtime`, which `package-zip.sh` and
`build-installer.sh` take as `--x64-runtime`.

The compiler, C runtime and Windows headers are llvm-mingw's; only LLVM and the DLLs come from MSYS2, so the
runtime DLLs are the same files the MSYS2 build ships. The program's own C++ (the dark mode shim) links libc++
and libunwind statically, so the process has one libc++ DLL, the one `libLLVM-23.dll` brings, and the program
imports only `libLLVM-23.dll` and `libwinpthread-1.dll` besides Windows' own. `collect-dlls.sh` stops when a
program imports a `lib*.dll` it cannot find, so a missing runtime DLL fails the build, not the player's start.
A cross-built program starts, translates the game from scratch and plays under CrossOver on a Mac; the MSYS2
build stays the one the release workflow publishes until the cross-built one has run on a Windows PC. The
workflow cross-builds it on every Windows run (`windows-x64-cross`) and starts it twice in the MSYS2 zip's place
(`smoke-x64-cross`); neither holds a release back.

## ANGLE

The program draws through ANGLE over Direct3D 11: `libEGL.dll` and `libGLESv2.dll` beside it,
Expand Down
49 changes: 49 additions & 0 deletions runtime/win/build-x64-cross.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/sh
# Build the x86-64 Windows program on a Mac or Linux, with no Windows and no MSYS2:
#
# TL_WIN_TOOLCHAIN=<toolchain folder> runtime/win/build-x64-cross.sh [game-portable|game|starttest]
#
# It runs the same steps the Windows build runs in MSYS2's CLANG64 shell, with llvm-mingw's x86-64 compiler:
# 1. x64/cross/setup-sysroot.sh the pinned MSYS2 packages: LLVM 23 for Windows and the DLLs the program ships with
# 2. fetch-zlib.sh zlib for the runtime and for the guest
# 3. x64/scarletnx/build-scarletnx.sh ScarletNX's recompiler library at the pinned commit, with scarletnx.patch
# 4. x64/build-x64.sh the program (the installed one, game, also takes WinSparkle: fetch-winsparkle.sh)
# 5. x64/collect-dlls.sh the DLLs it needs, for package-zip.sh and build-installer.sh (--x64-runtime)
#
# Needs llvm-mingw (runtime/win/setup-toolchain.sh unpacks it in $TL_WIN_TOOLCHAIN, or LLVM_MINGW names another
# copy, for a Linux host its Linux release), cmake, ninja, git, curl, zstd, python3 and a C compiler named clang
# (the build's one helper that runs on this machine). Keep the folders' paths free of spaces.
#
# Output: out/win-<profile>-x64 (game) or out/win-<profile>-x64-portable (game-portable), the DLLs in
# out/win-<profile>-x64-runtime, and the work (sysroot, zlib, ScarletNX) in out/win-x64-cross-work, which
# X64_CROSS_WORK moves. PROFILE, APP_VERSION, SPARKLE_FEED_URL and SPARKLE_PUBLIC_KEY work as in build-win.sh.
set -e
H="$(cd "$(dirname "$0")" && pwd)"
REPO="$(cd "$H/../.." && pwd)"
PROFILE="${PROFILE:-altverz}"
. "$REPO/scripts/profile.sh"
profile_generate "$REPO/out/win-profile-$PROFILE"
export PROFILE_DIR

LLVM_MINGW="${LLVM_MINGW:-${TL_WIN_TOOLCHAIN:?set TL_WIN_TOOLCHAIN (runtime/win/setup-toolchain.sh) or LLVM_MINGW}/llvm-mingw-20261020-ucrt-macos-universal}"
[ -x "$LLVM_MINGW/bin/x86_64-w64-mingw32-clang" ] || {
echo "build-x64-cross: no $LLVM_MINGW/bin/x86_64-w64-mingw32-clang; set LLVM_MINGW to an llvm-mingw folder" >&2; exit 1; }
WORK="${X64_CROSS_WORK:-$REPO/out/win-x64-cross-work}"
X64_CROSS_SYSROOT="${X64_CROSS_SYSROOT:-$WORK/sysroot}"
export LLVM_MINGW X64_CROSS_SYSROOT
target="${1:-game-portable}"
OUT="$REPO/out/win-$PROFILE-x64"

"$H/x64/cross/setup-sysroot.sh" "$X64_CROSS_SYSROOT"
"$H/fetch-zlib.sh" "$WORK/zlib"
"$H/x64/scarletnx/build-scarletnx.sh" "$WORK/scarletnx"
[ "$target" = game ] && "$H/fetch-winsparkle.sh"
sh "$H/x64/build-x64.sh" "$REPO/runtime" "$WORK/scarletnx" "$WORK/zlib" "$OUT" "$target"

case "$target" in
game) EXE="$OUT/$PROFILE_APP_NAME x64.exe" ;;
game-portable) EXE="$OUT-portable/$PROFILE_APP_NAME x64.exe" ;;
*) exit 0 ;;
esac
CLANG64_BIN="$X64_CROSS_SYSROOT/clang64/bin" PATH="$LLVM_MINGW/bin:$PATH" \
bash "$H/x64/collect-dlls.sh" "$EXE" "$OUT-runtime"
30 changes: 22 additions & 8 deletions runtime/win/x64/build-x64.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#!/bin/sh
# Build the x86-64 Windows programs, in MSYS2's CLANG64 shell (clang, LLVM 23):
# build-x64.sh <runtime folder> <ScarletNX checkout, its library built in build/lib> <zlib folder> <out folder> [starttest|game|game-portable]
#
# Cross-built on a Mac or Linux instead when X64_CROSS_SYSROOT (the folder cross/setup-sysroot.sh made) and
# LLVM_MINGW (the llvm-mingw folder) are set: the tools are llvm-mingw's x86-64 ones, the program links LLVM's
# import library from the sysroot, and its own C++ (the dark mode shim) links libc++ and libunwind statically, so
# the one libc++.dll in the process is the one libLLVM-23.dll brings. runtime/win/build-x64-cross.sh runs the steps.
# <zlib folder> holds zlib-1.3.1 and zlib-guest (setup-toolchain.sh makes both) and include/ with their headers.
#
# game is the installed build: it links WinSparkle from prebuilt/winsparkle/x64 and carries
Expand All @@ -24,7 +29,16 @@ WS="$R/../prebuilt/winsparkle"
FEED="${SPARKLE_FEED_URL:-$(pj sparkle_feed_url | sed 's|/appcast.xml$|/windows-appcast.xml|')}"
KEY="${SPARKLE_PUBLIC_KEY:-$(cat "$R/../sparkle/public-key" 2>/dev/null || true)}"
OBJ="$OUT/obj"; mkdir -p "$OBJ" "$OUT"
CC=clang
if [ -n "${X64_CROSS_SYSROOT:-}" ]; then
MB="${LLVM_MINGW:?set LLVM_MINGW to the llvm-mingw folder}/bin"
CC="$MB/x86_64-w64-mingw32-clang"; CXX="$MB/x86_64-w64-mingw32-clang++"
AR="$MB/x86_64-w64-mingw32-llvm-ar"; WINDRES="$MB/x86_64-w64-mingw32-windres"
# the import library by its file: LLVM's DLL is the one library the program takes from the sysroot
LLVM_LINK="$X64_CROSS_SYSROOT/clang64/lib/libLLVM-23.dll.a"; CXX_RT="-static-libstdc++ -static-libgcc"
[ -f "$LLVM_LINK" ] || { echo "no $LLVM_LINK: run runtime/win/x64/cross/setup-sysroot.sh" >&2; exit 1; }
else
CC=clang; CXX=clang++; AR=llvm-ar; WINDRES=windres; LLVM_LINK="-lLLVM-23"; CXX_RT=""
fi
CFLAGS="-std=gnu11 -g -O1 -D_GNU_SOURCE -DTL_WINDOWS=1 -D_WIN32_WINNT=0x0A00 -DWINVER=0x0A00 -Wno-unused-function
-include $H/compat/win-compat.h -I$H/compat -I$T -I$N -I$R/tools -I$Z/include -I$PROFILE_DIR -I$X -I$SNX/src"

Expand All @@ -34,8 +48,8 @@ if [ ! -f "$OUT/libz-guest.a" ]; then
mkdir -p "$OBJ/zh" "$OBJ/zg"
for f in $ZS; do $CC -O2 -c "$Z/zlib-1.3.1/$f.c" -o "$OBJ/zh/$f.o"; done
for f in $ZS; do $CC -O2 -DZ_PREFIX -Dz_errmsg=tl_guestz_errmsg -c "$Z/zlib-guest/$f.c" -o "$OBJ/zg/$f.o"; done
llvm-ar rcs "$OUT/libz.a" "$OBJ"/zh/*.o
llvm-ar rcs "$OUT/libz-guest.a" "$OBJ"/zg/*.o
$AR rcs "$OUT/libz.a" "$OBJ"/zh/*.o
$AR rcs "$OUT/libz-guest.a" "$OBJ"/zg/*.o
fi

. "$H/sources.sh"
Expand Down Expand Up @@ -73,23 +87,23 @@ if [ "$target" = game ] || [ "$target" = game-portable ]; then
RC="$OBJ/win-manifest.o"
if [ ! -f "$RC" ] || [ "$H/win-manifest.rc" -nt "$RC" ] || [ "$H/win-manifest.xml" -nt "$RC" ] || [ "$H/pvz2.ico" -nt "$RC" ]; then
echo " windres win-manifest.rc"
windres -I"$H" -O coff -i "$H/win-manifest.rc" -o "$RC"
$WINDRES -I"$H" -O coff -i "$H/win-manifest.rc" -o "$RC"
fi
OBJS="$OBJS $RC"
# The dark mode library and its one C++ shim (runtime/win/build-darkmode.sh).
"$H/build-darkmode.sh" clang++ llvm-ar "$OUT"
"$H/build-darkmode.sh" "$CXX" "$AR" "$OUT"
DM="$OBJ/pvz2-windows-darkmode.o"
DMSRC="$R/tools/pvz2-windows-darkmode.cpp"
if [ ! -f "$DM" ] || [ "$DMSRC" -nt "$DM" ] || [ "$R/tools/pvz2-windows-darkmode.h" -nt "$DM" ] || [ "$PROFILE_DIR/pvz2-profile-generated.h" -nt "$DM" ]; then
echo " c++ pvz2-windows-darkmode.cpp"
clang++ -std=c++20 -O1 -g -D_WIN32_WINNT=0x0A00 -DWINVER=0x0A00 \
$CXX -std=c++20 -O1 -g -D_WIN32_WINNT=0x0A00 -DWINVER=0x0A00 \
-I"$R/third_party/darkmodelib/include" -I"$N" -I"$PROFILE_DIR" -I"$R/tools" -c "$DMSRC" -o "$DM"
fi
OBJS="$OBJS $DM $OUT/libdarkmode.a"
fi
L="$SNX/build/lib"
clang++ -o "$EXE" $OBJS -Wl,--start-group "$L/recompiler-library/libscarletnx-recompiler.a" "$L/llvm-backend/libsnx_llvm.a" \
$CXX $CXX_RT -o "$EXE" $OBJS -Wl,--start-group "$L/recompiler-library/libscarletnx-recompiler.a" "$L/llvm-backend/libsnx_llvm.a" \
"$L/src/common/libscarletnx-common.a" "$L/llvm-backend/arm-backend/libsnx_arm_llvm.a" "$L/llvm-backend/arm-backend/libsnx_arm_rt.a" \
"$L/llvm-backend/arm-backend/libsnx_arm_decode.a" "$L/libsnx_yyjson.a" "$L/libsnx_libdeflate.a" -Wl,--end-group \
$LDX $UPD_LIBS -L"$OUT" -lz -lz-guest -lLLVM-23 -lpsapi -lws2_32 -lbcrypt -lsynchronization -lpthread -Wl,--error-limit=0
$LDX $UPD_LIBS -L"$OUT" -lz -lz-guest "$LLVM_LINK" -lpsapi -lws2_32 -lbcrypt -lsynchronization -lpthread -Wl,--error-limit=0
echo "built $EXE"
9 changes: 8 additions & 1 deletion runtime/win/x64/collect-dlls.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,14 @@ queue=("$EXE")
while [ ${#queue[@]} -gt 0 ]; do
file="${queue[0]}"; queue=("${queue[@]:1}")
while read -r dll; do
[ -n "$dll" ] && [ -f "$BIN/$dll" ] || continue
[ -n "$dll" ] || continue
if [ ! -f "$BIN/$dll" ]; then
# Windows' own DLLs are not in $BIN; a lib* one that is missing would be a program that does not start
case "$dll" in
lib*|LIB*) echo "collect-dlls: $file imports $dll, which is not in $BIN" >&2; exit 1 ;;
esac
continue
fi
case " ${found[*]-} " in *" $dll "*) continue ;; esac
found+=("$dll")
cp "$BIN/$dll" "$OUT/"
Expand Down
21 changes: 21 additions & 0 deletions runtime/win/x64/cross/msys2-sysroot.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# The MSYS2 CLANG64 packages the cross-built x86-64 Windows program needs on a Mac or Linux, at the
# versions runtime/win/x64/msys2-clang64.txt pins, with the SHA-256 of each package file:
# <package without the mingw-w64-clang-x86_64- prefix> <version> <sha256 of the .pkg.tar.zst>.
# runtime/win/x64/cross/setup-sysroot.sh downloads exactly these from repo.msys2.org, checks every file
# against its hash and unpacks them into one folder (<folder>/clang64: include, lib, bin).
#
# What each is for: llvm has LLVM's headers, CMake package and static libraries (ScarletNX's recompiler
# is built against them), llvm-tools has the import library libLLVM-23.dll.a, and llvm-libs, libc++,
# libffi, libiconv, libwinpthread, libxml2, zstd and zlib are the DLLs the program ships with
# (collect-dlls.sh). The compiler, the C runtime and the Windows headers come from llvm-mingw instead.
# A new version here is a different program: change it on purpose, together with msys2-clang64.txt.
llvm 23.1.5-1 0950f095f3393c0f1fa3d2cf42a37f6e8b82b327dc2a34befd7f9fd3b047ded0
llvm-libs 23.1.5-1 4ef627dced07ac2c01072c6d7768d5c6c6683323b9c2fed38472f5e08bc74dba
llvm-tools 23.1.5-1 6e9bca9df29203873f080dd25abceaeaf4ca155494043379c970f00d69e7232a
libc++ 23.1.5-1 459ac050114cd40b3cea0622643077f725c0d71403b38b6405cee44fc4a984dd
libffi 3.8.0-1 4d27339b52eabae86a1dff79cf432191ad8dd6acfa653b1179b12490234c66a6
libiconv 1.19.1-1 8d16ca846553838f36ea4098dc543e0261bc248f77228d6765f3419a2dfd48da
libwinpthread 14.0.0.r598.ge3d18511f-1 117d14b88ae27e1de1374ca49f32c37cb6c3d7631507220f4396a000c4c8c48c
libxml2 2.15.4-3 10fecf310113c94e1c318b54a42647b58d6d9df4cfa5673de56a5a7ad1f7af18
zstd 1.5.7-2 2d75c4ddf8f4f7b76fe33e3f1eea16450f9b3aede14285c886462d72f0ffd87d
zlib 1.3.2-3 9dd6bee01521295224c2edeaa69e12dec3fdc0d33823047bb191a24c8bb68229
Loading
Loading