summaryrefslogtreecommitdiff
path: root/src/macos/build-e2e.sh
blob: 7e0d2233292086fbe83563ef53f66ae383297eb2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/sh
# Link the offscreen end-to-end harness: the app's own Swift shell, plus
# test/macos_e2e.swift as the entry point, against the same libpardes.a. Run it
# through `zig build macos-e2e -Dplatform=macos`, or by hand with the install
# prefix as $1 and the deployment target as $2.
#
# A SECOND BINARY rather than a `--e2e` flag on the app, for two reasons.
#
# Test scaffolding does not ship inside the product. A flag would put the script
# interpreter, the /tmp world-builder and the golden differ into the thing a
# user launches, and would give the app a mode in which it rewrites files under
# /tmp and calls exit() — none of which anyone should be one argv typo away from.
#
# And src/macos/Sources/main.swift holds top-level code, which IS an entry
# point: a module cannot contain both top-level statements and a @main type, so
# the harness could not join that link even if the first reason went away. Every
# other Swift file the app builds from is compiled here, so this link is also
# what proves the shell still compiles as a library rather than as an app.
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. Same string as build-app.sh, and for the
# same reason: -target is what decides LC_BUILD_VERSION and turns on the
# availability diagnostics.
minver=${2:-13.0}
lib="$out/lib/libpardes.a"
bin="$out/bin/pardes-macos-e2e"

[ -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; }

mkdir -p "$out/bin"

# -import-objc-header and -lc++ are build-app.sh's, unchanged, and have to stay
# that way: this link exists to exercise the app's link, so anything that
# differs here is something the harness cannot vouch for.
#
# -O for the same reason. A debug build of the CoreText pass and the effect
# drain settles on different timings than a user sees, and `stable` waits on
# exactly those timings.
swiftc -O -target "$(uname -m)-apple-macos$minver" \
	-import-objc-header "$root/src/macos/pardes.h" \
	-o "$bin" \
	"$root/src/macos/Sources/PardesView.swift" \
	"$root/src/macos/Sources/AppDelegate.swift" \
	"$root/test/macos_e2e.swift" \
	"$lib" -lc++ \
	-framework AppKit -framework CoreText -framework CoreGraphics

echo "built $bin"