From eb11ab331b4e13e2b9e5a673a4c012d22fdd1d9c Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Mon, 10 Aug 2026 09:58:31 -0300 Subject: macos: the AppKit shell, its icon, and the offscreen e2e harness --- src/macos/build-app.sh | 55 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 52 insertions(+), 3 deletions(-) (limited to 'src/macos/build-app.sh') diff --git a/src/macos/build-app.sh b/src/macos/build-app.sh index 6734f8d3..a54e76b8 100755 --- a/src/macos/build-app.sh +++ b/src/macos/build-app.sh @@ -1,7 +1,8 @@ #!/bin/sh # Assemble pardes.app from libpardes.a and the Swift sources. Run it through # `zig build macos-app -Dplatform=macos`, or by hand with the install prefix as -# $1 once `zig build -Dplatform=macos` has produced the library. +# $1, the deployment target as $2 and the Zig optimize mode as $3 once +# `zig build -Dplatform=macos` has produced the library. # # There is no Xcode project on purpose. An .app is a directory with a plist and # a binary in it, swiftc ships with the Command Line Tools, and a hand-written @@ -13,8 +14,28 @@ set -eu root=$(cd "$(dirname "$0")/../.." && pwd) out=${1:-"$root/zig-out"} +# Keep in step with macos_min_version in build.zig, which passes it in. The +# default is only for a by-hand run. +minver=${2:-13.0} +# Both swiftc invocations below take the same triple; the note above the app +# link is why -target is not optional for either of them. +target="$(uname -m)-apple-macos$minver" app="$out/pardes.app" lib="$out/lib/libpardes.a" +# The two halves of this program are compiled by two compilers, and before this +# only one of them was told anything: swiftc was hardcoded to -O while the Zig +# core followed -Doptimize, so the ordinary `zig build macos-app` produced an +# optimized shell around a DEBUG core. It does not read as "I built Debug", it +# reads as "the mac backend is slow" — measured on this machine, one frame at +# 190x56 cost 4.5 ms with a Debug core and 0.88 ms with a ReleaseFast one, and +# 4.1 ms of that 4.5 was pardes_frame alone. So the mode travels, both halves +# agree, and a slow bundle says why. +zigmode=${3:-Debug} +case $zigmode in +Debug) swiftmode=-Onone ;; +ReleaseSmall) swiftmode=-Osize ;; +*) swiftmode=-O ;; +esac [ -f "$lib" ] || { echo "missing $lib — run: zig build -Dplatform=macos" >&2; exit 1; } command -v swiftc >/dev/null || { echo "swiftc not found (needs macOS + Command Line Tools)" >&2; exit 1; } @@ -22,6 +43,26 @@ command -v swiftc >/dev/null || { echo "swiftc not found (needs macOS + Command rm -rf "$app" mkdir -p "$app/Contents/MacOS" "$app/Contents/Resources" cp "$root/src/macos/Info.plist" "$app/Contents/Info.plist" +# One version, three consumers: the plist's claim is set from the same string +# the link below enforces, so a bumped deployment target cannot leave a stale +# LSMinimumSystemVersion behind. +/usr/libexec/PlistBuddy -c "Set :LSMinimumSystemVersion $minver" "$app/Contents/Info.plist" >/dev/null + +# The icon is generated rather than committed. The mark is drawn out of the +# same palette PardesView.swift renders cells with — #121212 body, the tag bar +# and the block cursor straight from ansi16 — so a colour that moves there +# moves here on the next build, instead of a binary blob sitting in the tree +# quietly disagreeing with the app it ships in. Info.plist's CFBundleIconFile +# names the pardes.icns this drops into Resources; without both halves the Dock +# falls back to the generic blank page. +# +# The trap covers the compiled generator; the generator clears its own scratch +# iconset. set -eu means a failure here takes the whole build down, which is +# the point: a bundle that ships a blank icon should not have built. +icontmp=$(mktemp -d) +trap 'rm -rf "$icontmp"' EXIT +swiftc -O -target "$target" -o "$icontmp/pardes-icon" "$root/src/macos/icon.swift" +"$icontmp/pardes-icon" "$app/Contents/Resources" # -import-objc-header rather than a module map: the header is consumed straight # from the source tree, so there is nothing to stage and nothing to keep in @@ -35,11 +76,19 @@ cp "$root/src/macos/Info.plist" "$app/Contents/Info.plist" # launch it on anything older — the Info.plist's LSMinimumSystemVersion is a # claim, not the enforcement. It is also what turns on the availability # diagnostics that catch a post-13 API before a user does. -swiftc -O -target "$(uname -m)-apple-macos13.0" \ +swiftc "$swiftmode" -target "$target" \ -import-objc-header "$root/src/macos/pardes.h" \ -o "$app/Contents/MacOS/pardes" \ "$root"/src/macos/Sources/*.swift \ "$lib" -lc++ \ -framework AppKit -framework CoreText -framework CoreGraphics -echo "built $app" +# An .app whose mtime never moves is an .app Launch Services keeps serving from +# its cache, icon and plist and all. +touch "$app" + +if [ "$zigmode" = Debug ]; then + echo "built $app (Debug core — rebuild with -Doptimize=ReleaseFast to use it)" +else + echo "built $app" +fi -- cgit v1.3