Skip to content

armgit / cua

Public Imported from GitHub
0

Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.

feat(images): build the macOS Space with developer tools on the user's own Mac (#6303)

ddupont758da89fda95
diff --git a/libs/images/macos/build.sh b/libs/images/macos/build.sh
index ecf5dfe44e..08108210ba 100755
--- a/libs/images/macos/build.sh
+++ b/libs/images/macos/build.sh
@@ -33,7 +33,8 @@
# $CUA_MACOS_SPACESD_SOURCE. Recorded in the image manifest
# and /etc/cua-image/spacesd-source. With --app the doctor
# expects the bundle's own build-info git_sha.
-# --push TAG after the gate passes, `lume push` TAG to the macos repo.
+# --push TAG after the gate passes, `lume push` TAG to the macos repo
+# (slim and full only: the xcode tier is never pushed).
# TAG must be a new immutable pin of this tier
# (<version>[-slim|-xcode[-X.Y]]-<yyyymmdd>-<sha7>);
# scripts/images/check-tag-safety.sh refuses anything else.
@@ -98,6 +99,10 @@ if [ "$TIER" != slim ] && [ -z "$BASE_VM" ]; then
echo "--tier $TIER builds on the gated VM of the tier below: pass --base-vm" >&2; exit 2
fi
[ -n "$MEMORY" ] || { [ "$TIER" = xcode ] && MEMORY=8GB || MEMORY=4GB; }
+if [ -n "$PUSH_TAG" ] && [ "$TIER" = xcode ]; then
+ echo "the xcode tier is never pushed: it carries Xcode, which Apple's terms do not let us redistribute (each Mac derives it: derive-local.sh)" >&2
+ exit 2
+fi
MACOS_BASE_IMAGE="$MACOS_BASE_REPO:$MACOS_BASE_TAG"
BASE_IMAGE="${BASE_IMAGE:-$MACOS_BASE_IMAGE}"
VM="${VM:-cua-e2e-macos-$TIER-$$}"
@@ -133,6 +138,8 @@ want = { # claim -> versions.env key, per tier
("full", "tools", "pnpm"): "PNPM_VERSION", ("full", "tools", "go"): "GO_VERSION",
("full", "tools", "rustc"): "RUST_VERSION", ("full", "tools", "cargo"): "RUST_VERSION",
("xcode", "tools", "xcodebuild"): "XCODE_VERSION",
+ ("xcode", "tools", "sccache"): "SCCACHE_VERSION", ("xcode", "tools", "xcodegen"): "XCODEGEN_VERSION",
+ ("xcode", "tools", "pod"): "COCOAPODS_VERSION",
}
bad = []
for (tier, kind, name), key in want.items():
@@ -168,17 +175,8 @@ cp "$HERE"/files/*.sh "$HERE"/files/*.plist "$HERE/image.json" "$HERE/versions.e
# This tier's downloads: fetched once into the cache, checked, then linked
# into the setup share (cache/).
mkdir -p "$CACHE" "$SETUP/cache"
-fetch() { # URL SHA256
- local f; f="$CACHE/$(basename "$1")"
- if [ ! -f "$f" ] || [ "$(shasum -a 256 "$f" | cut -d' ' -f1)" != "$2" ]; then
- log "fetching $1"
- curl -fsSL --retry 3 -o "$f.part" "$1"
- [ "$(shasum -a 256 "$f.part" | cut -d' ' -f1)" = "$2" ] ||
- { rm -f "$f.part"; echo "checksum mismatch: $1" >&2; exit 1; }
- mv "$f.part" "$f"
- fi
- ln -f "$f" "$SETUP/cache/" 2>/dev/null || cp "$f" "$SETUP/cache/"
-}
+# shellcheck source=files/fetch.sh
+. "$HERE/files/fetch.sh"
case "$TIER" in
slim) fetch "$CHROME_URL" "$CHROME_SHA256" ;;
full)
@@ -190,7 +188,8 @@ case "$TIER" in
[ -f "$xip" ] || { echo "$xip is missing: put the Xcode $XCODE_VERSION .xip in CUA_XCODE_CACHE" >&2; exit 2; }
[ "$(shasum -a 1 "$xip" | cut -d' ' -f1)" = "$XCODE_XIP_SHA1" ] ||
{ echo "checksum mismatch: $xip" >&2; exit 1; }
- ln -f "$xip" "$SETUP/cache/" 2>/dev/null || cp "$xip" "$SETUP/cache/" ;;
+ ln -f "$xip" "$SETUP/cache/" 2>/dev/null || cp "$xip" "$SETUP/cache/"
+ fetch_xcode_tools ;;
esac
"$SETUP/Cua Spacesd.app/Contents/MacOS/cua-spacesd" build-info >"$OUT/build-info.json"
# A prebuilt bundle: the doctor checks the guest runs exactly that build.
diff --git a/libs/images/macos/derive-local.sh b/libs/images/macos/derive-local.sh
new file mode 100755
index 0000000000..1a81bb0b5d
--- /dev/null
+++ b/libs/images/macos/derive-local.sh
@@ -0,0 +1,191 @@
+#!/usr/bin/env bash
+# Derive the macOS Space with developer tools (the xcode tier) on THIS Mac,
+# from the published full tier and an Xcode that is already here. Nothing it
+# makes is ever pushed: Apple's terms let you run Xcode on your own Mac, in a
+# VM on it, but not hand it to others (see versions.env, check-tag-safety.sh).
+#
+# libs/images/macos/derive-local.sh --base-vm NAME [--name VM] [--xcode PATH]
+# [--out DIR] [--memory 8GB] [--keep-going-low-disk] [--json]
+#
+# --base-vm NAME the local Lume VM of the full tier to clone (the SDK keeps
+# it as cua-base-<sha12>); it is never modified
+# --name VM the derived VM (default cua-dev-macos-<pid>)
+# --xcode PATH an Xcode.app or Xcode .xip to use; default: the Mac's own
+# (xcode-select, then /Applications/Xcode*.app, newest first,
+# then an .xip in $CUA_XCODE_CACHE, ~/XcodesCache or
+# ~/Downloads)
+# --out DIR staging and logs (default ~/.cache/cua-images/macos-dev)
+# --memory memory for the build boot (default 8GB; the VM keeps the
+# base's own value afterwards)
+# --json print one JSON line of results (sizes and timings) at the end
+#
+# Exit codes: 0 done; 2 usage; 3 no Xcode on this Mac (Apple needs a sign-in to
+# download one: install it from the App Store or download the .xip from
+# developer.apple.com, then run again); 4 not enough free disk; 5 the guest's
+# macOS is older than the Xcode needs.
+#
+# CUA_LUME_BIN is the lume binary (default: lume on PATH).
+# CUA_LUME_STORAGE is a Lume storage directory to use instead of the default
+# one (every lume call gets --storage with it): the base VM must be there, and
+# so is the derived VM.
+set -euo pipefail
+HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+BASE_VM="" VM="cua-dev-macos-$$" XCODE="" MEMORY=8GB JSON=0
+OUT="${CUA_IMAGES_OUT:-$HOME/.cache/cua-images}/macos-dev"
+# The volume must keep this much free after the derive (the build stops there).
+FLOOR_GB="${CUA_DEV_IMAGE_FLOOR_GB:-10}"
+# Growth the derive needs beyond Xcode itself: iOS runtime, Metal toolchain,
+# tools, Simulator data and caches while building.
+EXTRA_GB="${CUA_DEV_IMAGE_EXTRA_GB:-18}"
+while [ $# -gt 0 ]; do
+ case "$1" in
+ --base-vm) BASE_VM="$2"; shift 2 ;;
+ --name) VM="$2"; shift 2 ;;
+ --xcode) XCODE="$2"; shift 2 ;;
+ --out) OUT="$2"; shift 2 ;;
+ --memory) MEMORY="$2"; shift 2 ;;
+ --json) JSON=1; shift ;;
+ -h|--help) sed -n '2,29p' "$0"; exit 0 ;;
+ *) echo "unknown option $1" >&2; exit 2 ;;
+ esac
+done
+[ -n "$BASE_VM" ] || { echo "--base-vm is required (the local VM of the full tier)" >&2; exit 2; }
+# shellcheck source=versions.env
+. "$HERE/versions.env"
+log() { echo "[macos-dev $(date +%T)] $*" >&2; }
+ST="${CUA_LUME_STORAGE:-}"
+LUME_BIN="${CUA_LUME_BIN:-$(type -P lume || echo lume)}"
+# lume SUBCOMMAND ARGS...: with CUA_LUME_STORAGE set, on that storage.
+lume() {
+ local sub="$1"; shift
+ case "$sub" in
+ clone) if [ -n "$ST" ]; then "$LUME_BIN" clone --source-storage "$ST" --dest-storage "$ST" "$@"; else "$LUME_BIN" clone "$@"; fi ;;
+ run|ssh|get|set|stop|delete) if [ -n "$ST" ]; then "$LUME_BIN" "$sub" --storage "$ST" "$@"; else "$LUME_BIN" "$sub" "$@"; fi ;;
+ *) "$LUME_BIN" "$sub" "$@" ;;
+ esac
+}
+guest() { lume ssh -t "${2:-120}" "$VM" "$1" </dev/null; }
+plist() { /usr/libexec/PlistBuddy -c "Print :$2" "$1/Contents/Info.plist" 2>/dev/null; }
+
+# --- the Xcode on this Mac -------------------------------------------------------
+find_xcode() {
+ local c best="" bestv="" v
+ if [ -n "$XCODE" ]; then echo "$XCODE"; return 0; fi
+ if [ -n "${CUA_XCODE_APP:-}" ]; then echo "$CUA_XCODE_APP"; return 0; fi
+ local sel; sel="$(xcode-select -p 2>/dev/null || true)"
+ case "$sel" in */Xcode*.app/Contents/Developer) c="${sel%/Contents/Developer}"; [ -d "$c" ] && { echo "$c"; return 0; } ;; esac
+ for c in /Applications/Xcode*.app; do
+ [ -d "$c" ] || continue
+ v="$(plist "$c" CFBundleShortVersionString || true)"; [ -n "$v" ] || continue
+ if [ -z "$best" ] || [ "$(printf '%s\n%s\n' "$bestv" "$v" | sort -V | tail -1)" = "$v" ]; then best="$c" bestv="$v"; fi
+ done
+ [ -z "$best" ] || { echo "$best"; return 0; }
+ for c in "${CUA_XCODE_CACHE:-$HOME/XcodesCache}"/Xcode*.xip "$HOME"/Downloads/Xcode*.xip; do
+ [ -f "$c" ] && { echo "$c"; return 0; }
+ done
+ return 1
+}
+if ! SRC="$(find_xcode)"; then
+ cat >&2 <<'MSG'
+No Xcode on this Mac. Apple requires a signed-in download, so Cua cannot fetch one for you.
+Install Xcode from the App Store, or download the Xcode .xip from developer.apple.com/download
+and put it in ~/XcodesCache, then create the macOS Space with developer tools again.
+MSG
+ exit 3
+fi
+[ -e "$SRC" ] || { echo "$SRC does not exist" >&2; exit 2; }
+log "Xcode source: $SRC"
+case "$SRC" in
+ *.app) XVER="$(plist "$SRC" CFBundleShortVersionString)"; XMIN="$(plist "$SRC" LSMinimumSystemVersion || true)"
+ SRC_KB="$(( $(du -sk "$SRC" | cut -f1) * 2 ))" ;; # the archive and the copy
+ *.xip) XVER="$(basename "$SRC" | sed -n 's/^Xcode[_ -]\{0,1\}\([0-9][0-9.]*\).*/\1/p')"; XMIN=""
+ SRC_KB="$(( $(stat -f %z "$SRC") * 3 / 1024 ))" ;; # an .xip expands to about 3x
+ *) echo "--xcode takes an Xcode.app or an .xip" >&2; exit 2 ;;
+esac
+
+# --- disk ---------------------------------------------------------------------------
+LUME_DIR="${CUA_LUME_STORAGE:-$HOME/.lume}"
+mkdir -p "$LUME_DIR" "$OUT"
+free_gb() { df -k "$1" | awk 'NR==2 {print int($4/1024/1024)}'; }
+need_gb=$(( SRC_KB / 1024 / 1024 + 1 + EXTRA_GB ))
+have_gb="$(free_gb "$LUME_DIR")"
+if [ "$have_gb" -lt $(( need_gb + FLOOR_GB )) ]; then
+ cat >&2 <<MSG
+Not enough free disk to build the macOS Space with developer tools: it needs about ${need_gb} GB
+and the Mac should keep ${FLOOR_GB} GB free, but only ${have_gb} GB is free.
+Make room: remove Spaces and images you no longer use, empty the Trash, or delete old Xcode caches
+(~/Library/Developer/Xcode/DerivedData, ~/Library/Developer/CoreSimulator).
+MSG
+ exit 4
+fi
+
+command -v "$LUME_BIN" >/dev/null || { echo "lume is required" >&2; exit 2; }
+
+# --- stage: scripts, pins, tools ----------------------------------------------------------
+CACHE="${CUA_MACOS_CACHE:-$HOME/.cache/cua-images/macos-cache}"
+SETUP="$OUT/setup"
+rm -rf "$SETUP"; mkdir -p "$SETUP/cache" "$SETUP/xcode" "$CACHE"; chmod 700 "$SETUP"
+cp "$HERE/files/tier-xcode.sh" "$HERE/versions.env" "$SETUP/"
+# shellcheck source=files/fetch.sh
+. "$HERE/files/fetch.sh"
+fetch_xcode_tools
+# The Xcode, as one archive: the guest reads the share over virtiofs, which
+# cannot follow an app bundle's framework links, but a zip keeps them, the
+# signatures and the extended attributes. An .xip goes in as it is.
+case "$SRC" in
+ *.app) log "archiving $(basename "$SRC") for the guest"
+ ditto -c -k --sequesterRsrc --keepParent "$SRC" "$SETUP/xcode/$(basename "$SRC").zip" ;;
+ *) cp -c "$SRC" "$SETUP/xcode/" 2>/dev/null || cp "$SRC" "$SETUP/xcode/" ;;
+esac
+
+cleanup() {
+ lume stop "$VM" >/dev/null 2>&1 || true
+ for pid in $(pgrep -f "lume run .*$VM" || true); do kill "$pid" 2>/dev/null || true; done
+ rm -rf "$SETUP"
+ [ "${KEEP:-1}" = 1 ] || lume delete --force "$VM" >/dev/null 2>&1 || true
+}
+KEEP=0
+trap cleanup EXIT
+
+t0=$(date +%s)
+log "cloning $BASE_VM -> $VM"
+lume clone "$BASE_VM" "$VM"
+base_memory="$(lume get --format json "$VM" | python3 -c 'import json,sys;d=json.load(sys.stdin);d=d[0] if isinstance(d,list) else d;print(d["memorySize"])')"
+lume set --memory "$MEMORY" "$VM"
+log "booting $VM"
+lume run --display none --detach --shared-dir "$SETUP:ro" --log-file "$OUT/vm.log" "$VM" >/dev/null
+up=0
+for _ in $(seq 1 60); do guest 'echo up' 2>/dev/null | grep -q up && { up=1; break; }; sleep 5; done
+[ "$up" = 1 ] || { echo "$VM never answered over ssh (see $OUT/vm.log)" >&2; exit 1; }
+for _ in $(seq 1 36); do guest 'pgrep -qx Dock && pgrep -qx Finder' 2>/dev/null && break; sleep 5; done
+t_boot=$(date +%s)
+os="$(guest 'sw_vers -productVersion')"
+if [ -n "${XMIN:-}" ] && [ "$(printf '%s\n%s\n' "$XMIN" "$os" | sort -V | head -1)" != "$XMIN" ]; then
+ echo "Xcode $XVER needs macOS $XMIN; this Space's macOS is $os. Use an older Xcode (or a newer macOS image)." >&2
+ exit 5
+fi
+
+S="/Volumes/My Shared Files/setup"
+log "installing the developer tools (Xcode ${XVER:-?}, iOS runtime, tools)"
+guest "bash '$S/tier-xcode.sh' '$S'" 5400 2>&1 | tee "$OUT/tier-xcode.log" | sed 's/^/ /' >&2
+t_tier=$(date +%s)
+
+log "shutting down"
+guest "printf '%s\n' lume | sudo -S -p '' shutdown -h now" 30 >/dev/null 2>&1 || true
+for _ in $(seq 1 60); do
+ st="$(lume get --format json "$VM" 2>/dev/null | python3 -c 'import json,sys;d=json.load(sys.stdin);d=d[0] if isinstance(d,list) else d;print(d["status"])' 2>/dev/null || true)"
+ [ "$st" = stopped ] && break; sleep 5
+done
+[ "$st" = stopped ] || lume stop "$VM" >/dev/null
+lume set --memory "$((base_memory / 1024 / 1024))MB" "$VM"
+KEEP=1
+t_end=$(date +%s)
+sizes="$(lume get --format json "$VM" | python3 -c 'import json,sys;d=json.load(sys.stdin);d=d[0] if isinstance(d,list) else d;print(json.dumps({"vm":d["name"],"disk_used_bytes":d["diskSize"]["allocated"],"disk_total_bytes":d["diskSize"]["total"]}))')"
+log "derived $VM in $((t_end - t0)) s ($sizes)"
+if [ "$JSON" = 1 ]; then
+ python3 - "$sizes" "$XVER" "$((t_boot - t0))" "$((t_tier - t_boot))" "$((t_end - t0))" <<'PY'
+import json, sys
+d = json.loads(sys.argv[1]); d.update(xcode=sys.argv[2], clone_boot_seconds=int(sys.argv[3]), tier_seconds=int(sys.argv[4]), total_seconds=int(sys.argv[5]))
+print(json.dumps(d))
+PY
+fi
diff --git a/libs/images/macos/dev-image-gate.sh b/libs/images/macos/dev-image-gate.sh
new file mode 100755
index 0000000000..9bd5a6e501
--- /dev/null
+++ b/libs/images/macos/dev-image-gate.sh
@@ -0,0 +1,94 @@
+#!/usr/bin/env bash
+# Live gate for the macOS Space with developer tools (opt-in; needs Apple
+# silicon, lume and a derived base from derive-local.sh): boot a Space cloned
+# from the derived base and, inside it, build and test an iOS app on the
+# Simulator, build a Rust core for the iOS Simulator target, run the app and
+# take real screenshots. Writes timings, logs and pictures to --out.
+#
+# libs/images/macos/dev-image-gate.sh --base-vm NAME --out DIR [--name VM] [--keep]
+#
+# --base-vm the derived base VM (derive-local.sh --name)
+# --out results: timings.json, tools.txt, logs, simulator.png, desktop.png,
+# ui-screenshots/ (taken by the UI test)
+# --name the Space's VM name (default cua-dev-gate-<pid>); removed at the end
+# unless --keep
+#
+# CUA_LUME_BIN / CUA_LUME_STORAGE select the lume binary and storage directory,
+# as for derive-local.sh.
+set -euo pipefail
+HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+BASE_VM="" OUT="" VM="cua-dev-gate-$$" KEEP=0
+while [ $# -gt 0 ]; do
+ case "$1" in
+ --base-vm) BASE_VM="$2"; shift 2 ;;
+ --out) OUT="$2"; shift 2 ;;
+ --name) VM="$2"; shift 2 ;;
+ --keep) KEEP=1; shift ;;
+ -h|--help) sed -n '2,17p' "$0"; exit 0 ;;
+ *) echo "unknown option $1" >&2; exit 2 ;;
+ esac
+done
+[ -n "$BASE_VM" ] && [ -n "$OUT" ] || { echo "--base-vm and --out are required" >&2; exit 2; }
+ST="${CUA_LUME_STORAGE:-}"
+LUME_BIN="${CUA_LUME_BIN:-$(type -P lume || echo lume)}"
+lume() {
+ local sub="$1"; shift
+ case "$sub" in
+ clone) if [ -n "$ST" ]; then "$LUME_BIN" clone --source-storage "$ST" --dest-storage "$ST" "$@"; else "$LUME_BIN" clone "$@"; fi ;;
+ run|ssh|get|set|stop|delete) if [ -n "$ST" ]; then "$LUME_BIN" "$sub" --storage "$ST" "$@"; else "$LUME_BIN" "$sub" "$@"; fi ;;
+ *) "$LUME_BIN" "$sub" "$@" ;;
+ esac
+}
+guest() { lume ssh -t "${2:-300}" "$VM" "$1" </dev/null; }
+log() { echo "[dev-image-gate $(date +%T)] $*" >&2; }
+now() { date +%s; }
+
+mkdir -p "$OUT"
+STAGE="$OUT/stage"
+rm -rf "$STAGE"; mkdir -p "$STAGE/fixture" "$STAGE/results"
+cp -R "$HERE/fixtures/HelloSim/." "$STAGE/fixture/"
+cp "$HERE/files/dev-image-gate-guest.sh" "$STAGE/"
+
+cleanup() {
+ lume stop "$VM" >/dev/null 2>&1 || true
+ for pid in $(pgrep -f "lume run .*$VM" || true); do kill "$pid" 2>/dev/null || true; done
+ [ "$KEEP" = 1 ] || lume delete --force "$VM" >/dev/null 2>&1 || true
+}
+trap cleanup EXIT
+
+t0=$(now)
+log "cloning $BASE_VM -> $VM"
+lume clone "$BASE_VM" "$VM"
+t_clone=$(now)
+lume set --memory 8GB "$VM"
+log "booting"
+lume run --display none --detach --shared-dir "$STAGE" --log-file "$OUT/vm.log" "$VM" >/dev/null
+up=0
+for _ in $(seq 1 120); do guest 'echo up' 10 2>/dev/null | grep -q up && { up=1; break; }; sleep 2; done
+[ "$up" = 1 ] || { echo "$VM never answered over ssh (see $OUT/vm.log)" >&2; exit 1; }
+t_ssh=$(now)
+for _ in $(seq 1 60); do guest 'pgrep -qx Dock && pgrep -qx Finder' 10 2>/dev/null && break; sleep 2; done
+t_desktop=$(now)
+
+S="/Volumes/My Shared Files/$(basename "$STAGE")"
+log "build, test and drive the app in the Simulator"
+guest "bash '$S/dev-image-gate-guest.sh' '$S'" 3600 2>&1 | sed 's/^/ /' >&2
+t_guest=$(now)
+
+log "desktop screenshot (the Simulator on the Space's screen)"
+guest "uid=\$(id -u); sudo -n launchctl asuser \$uid /usr/sbin/screencapture -x '$S/results/desktop.png' || printf '%s\n' lume | sudo -S -p '' launchctl asuser \$uid /usr/sbin/screencapture -x '$S/results/desktop.png'" 60 || true
+guest 'df -h / | tail -1' 30 >"$STAGE/results/guest-df.txt" || true
+
+cp -R "$STAGE/results/." "$OUT/"
+rm -rf "$STAGE"
+size="$(lume get --format json "$VM" | python3 -c 'import json,sys;d=json.load(sys.stdin);d=d[0] if isinstance(d,list) else d;print(d["diskSize"]["allocated"])')"
+python3 - "$OUT/timings.txt" "$OUT/timings.json" "$((t_clone - t0))" "$((t_ssh - t_clone))" "$((t_desktop - t_clone))" "$((t_guest - t_desktop))" "$size" <<'PY'
+import json, sys
+src, dst, clone, ssh, desktop, guest, size = sys.argv[1:]
+d = {k: int(v) for k, v in (l.split() for l in open(src).read().splitlines() if l.strip())}
+d.update(clone_seconds=int(clone), first_boot_to_ssh_seconds=int(ssh), first_boot_to_desktop_seconds=int(desktop),
+ guest_gate_seconds=int(guest), space_disk_allocated_bytes=int(size))
+json.dump(d, open(dst, "w"), indent=2)
+print(json.dumps(d, indent=2))
+PY
+log "done: $OUT"
diff --git a/libs/images/macos/files/dev-image-gate-guest.sh b/libs/images/macos/files/dev-image-gate-guest.sh
new file mode 100755
index 0000000000..f899234771
--- /dev/null
+++ b/libs/images/macos/files/dev-image-gate-guest.sh
@@ -0,0 +1,90 @@
+#!/bin/bash
+# The developer tools image's gate, IN the guest (dev-image-gate.sh runs it):
+# build and test the HelloSim fixture on the iOS Simulator, build its Rust core
+# for the iOS Simulator target, drive the app, take screenshots and write
+# timings. Everything lands in STAGE/results.
+#
+# dev-image-gate-guest.sh STAGE_DIR
+set -euo pipefail
+STAGE="${1:?staging directory}"
+R="$STAGE/results"
+mkdir -p "$R"
+export PATH="$HOME/.cargo/bin:/usr/local/bin:$PATH"
+W="$HOME/gate-work"
+rm -rf "$W"; mkdir -p "$W"
+cp -R "$STAGE/fixture/." "$W/"
+cd "$W"
+t() { date +%s; }
+: >"$R/timings.txt"
+mark() { echo "$1 $2" >>"$R/timings.txt"; }
+DEST='platform=iOS Simulator,name=Cua iPhone'
+
+{
+ echo "== tools"
+ xcodebuild -version
+ xcrun simctl list runtimes
+ xcrun simctl list devices available | grep -i "cua iphone" || true
+ xcodegen --version; pod --version; sccache --version; rustup target list --installed
+ git --version; gh --version | head -1; node --version; pnpm --version
+ DevToolsSecurity -status
+ df -h /
+} >"$R/tools.txt" 2>&1
+
+echo "== xcodegen"
+xcodegen generate >"$R/xcodegen.log" 2>&1
+
+echo "== cold build and test (build + unit + UI tests on the Simulator)"
+s=$(t)
+xcodebuild test -project HelloSim.xcodeproj -scheme HelloSim -destination "$DEST" \
+ -derivedDataPath "$W/dd" -resultBundlePath "$R/cold.xcresult" >"$R/xcodebuild-cold.log" 2>&1 || {
+ tail -40 "$R/xcodebuild-cold.log" >&2; exit 1; }
+mark cold_xcode_seconds $(( $(t) - s ))
+
+echo "== warm build and test (nothing changed)"
+s=$(t)
+xcodebuild test -project HelloSim.xcodeproj -scheme HelloSim -destination "$DEST" \
+ -derivedDataPath "$W/dd" -resultBundlePath "$R/warm.xcresult" >"$R/xcodebuild-warm.log" 2>&1 || {
+ tail -40 "$R/xcodebuild-warm.log" >&2; exit 1; }
+mark warm_xcode_seconds $(( $(t) - s ))
+
+echo "== incremental build after an edit"
+printf '\n// edited\n' >>HelloSim/Counter.swift
+s=$(t)
+xcodebuild build-for-testing -project HelloSim.xcodeproj -scheme HelloSim -destination "$DEST" \
+ -derivedDataPath "$W/dd" >"$R/xcodebuild-incremental.log" 2>&1
+mark incremental_xcode_seconds $(( $(t) - s ))
+
+xcrun xcresulttool get test-results summary --path "$R/cold.xcresult" >"$R/cold-summary.json"
+mkdir -p "$R/ui-screenshots"
+xcrun xcresulttool export attachments --path "$R/cold.xcresult" --output-path "$R/ui-screenshots" >/dev/null
+
+echo "== Rust core for the iOS Simulator (sccache)"
+cd rust
+export RUSTC_WRAPPER=sccache CARGO_INCREMENTAL=0
+sccache --stop-server >/dev/null 2>&1 || true
+sccache --start-server >/dev/null 2>&1
+s=$(t)
+cargo build --release --target aarch64-apple-ios-sim >"$R/cargo-cold.log" 2>&1
+mark cold_rust_seconds $(( $(t) - s ))
+cargo clean >/dev/null 2>&1
+s=$(t)
+cargo build --release --target aarch64-apple-ios-sim >"$R/cargo-warm.log" 2>&1
+mark warm_rust_seconds $(( $(t) - s ))
+sccache --show-stats >"$R/sccache.txt" 2>&1 || true
+ls -la target/aarch64-apple-ios-sim/release/libhellosim_core.a >>"$R/tools.txt"
+cd ..
+
+echo "== run the app in the Simulator and take a screenshot"
+udid="$(xcrun simctl list devices available | sed -n 's/.*Cua iPhone (\([0-9A-F-]*\)).*/\1/p' | head -1)"
+s=$(t)
+xcrun simctl boot "$udid" 2>/dev/null || true
+xcrun simctl bootstatus "$udid" -b >/dev/null
+mark simulator_boot_seconds $(( $(t) - s ))
+app="$(find "$W/dd/Build/Products" -name HelloSim.app -maxdepth 3 | head -1)"
+xcrun simctl install "$udid" "$app"
+xcrun simctl launch "$udid" ai.cua.fixture.HelloSim >/dev/null
+sleep 3
+xcrun simctl io "$udid" screenshot "$R/simulator.png" >/dev/null
+open -a Simulator || true
+sleep 5
+echo "done"
diff --git a/libs/images/macos/files/fetch.sh b/libs/images/macos/files/fetch.sh
new file mode 100644
index 0000000000..db34f7cd87
--- /dev/null
+++ b/libs/images/macos/files/fetch.sh
@@ -0,0 +1,23 @@
+# shellcheck shell=bash
+# Sourced by build.sh and derive-local.sh: the checksummed download cache.
+# CACHE the host cache directory
+# SETUP the share the guest reads (cache/ inside it)
+# log a logging function
+# fetch URL SHA256 downloads once into $CACHE, checks the hash and links the
+# file into $SETUP/cache.
+fetch() {
+ local f; f="$CACHE/$(basename "$1")"
+ if [ ! -f "$f" ] || [ "$(shasum -a 256 "$f" | cut -d' ' -f1)" != "$2" ]; then
+ log "fetching $1"
+ curl -fsSL --retry 3 -o "$f.part" "$1"
+ [ "$(shasum -a 256 "$f.part" | cut -d' ' -f1)" = "$2" ] ||
+ { rm -f "$f.part"; echo "checksum mismatch: $1" >&2; exit 1; }
+ mv "$f.part" "$f"
+ fi
+ ln -f "$f" "$SETUP/cache/" 2>/dev/null || cp "$f" "$SETUP/cache/"
+}
+# The downloads of the xcode tier's tools (everything but Xcode itself).
+fetch_xcode_tools() {
+ fetch "$SCCACHE_URL" "$SCCACHE_SHA256"
+ fetch "$XCODEGEN_URL" "$XCODEGEN_SHA256"
+}
diff --git a/libs/images/macos/files/tier-xcode.sh b/libs/images/macos/files/tier-xcode.sh
index c42716ff0e..ea0652c96c 100755
--- a/libs/images/macos/files/tier-xcode.sh
+++ b/libs/images/macos/files/tier-xcode.sh
@@ -1,53 +1,181 @@
#!/bin/bash
-# The xcode tier: full plus one pinned Xcode, its iOS simulator runtime and
-# the Metal toolchain. Runs IN the guest as the desktop user, on a clone of
-# the full VM that just passed the doctor.
+# The xcode tier (the macOS Space with developer tools): full plus Xcode, its
+# iOS simulator runtime, the Metal toolchain and the Apple developer tools
+# below. Runs IN the guest as the desktop user, on a clone of the full VM
+# that already passed the doctor.
#
# tier-xcode.sh STAGE_DIR
#
-# STAGE_DIR/cache/$XCODE_XIP comes from the runner's Xcode cache (build.sh
-# checks its SHA-1 on the host; checked again here, and xip verifies Apple's
-# signature while it expands). Xcode lands at /Applications/Xcode_<v>.app,
-# selected, licensed and first-launched. The simulator runtime and the Metal
-# toolchain come from Apple through xcodebuild.
+# The Xcode comes from the first of:
+# STAGE/cache/$XCODE_XIP the pinned archive of CI's runner (build.sh); its
+# SHA-1 is checked here and the build must be
+# $XCODE_BUILD
+# STAGE/xcode/*.zip|*.app an Xcode already installed on the host Mac
+# (derive-local.sh sends a ditto zip), copied as is
+# STAGE/xcode/*.xip an archive the user downloaded (derive-local.sh);
+# xip checks Apple's signature while it expands
+# and lands at /Applications/Xcode_<version>.app, selected, licensed and
+# first-launched. This tier is never published (Apple's terms), so the Xcode
+# is always the one the Mac's owner already has or downloaded.
+#
+# Installs, all pinned in versions.env:
+# Xcode, Metal toolchain, iOS simulator runtime Apple (no sign-in)
+# Rust targets $RUST_IOS_TARGETS rustup
+# sccache, XcodeGen /usr/local/bin (release archives)
+# CocoaPods Homebrew bottle (checked)
+# developer mode, SwiftPM macro/plugin prompts off, one warmed Simulator device
set -euo pipefail
STAGE="${1:?staging directory}"
# shellcheck source=/dev/null # STAGE/versions.env, a copy of ../versions.env
. "$STAGE/versions.env"
+C="$STAGE/cache"
# The password on a here-string, not a pipe: with sudo's credential cache
# warm, sudo never reads it, and a printf pipe then dies of SIGPIPE, which
# pipefail turns into a failed step.
sudo_run() { sudo -S -p '' "$@" <<<"${CUA_SUDO_PW:-lume}"; }
say() { echo "==> $*"; }
-APP="/Applications/Xcode_${XCODE_VERSION}.app"
-
-xip_file="$STAGE/cache/$XCODE_XIP"
-[ -f "$xip_file" ] || { echo "missing $xip_file" >&2; exit 1; }
-say "checking $XCODE_XIP"
-[ "$(shasum -a 1 "$xip_file" | cut -d' ' -f1)" = "$XCODE_XIP_SHA1" ] ||
- { echo "checksum mismatch: $xip_file" >&2; exit 1; }
-
-say "expanding Xcode $XCODE_VERSION"
+verified() { # URL SHA256 -> the cached file, checked
+ local f; f="$C/$(basename "$1")"
+ [ "$(shasum -a 256 "$f" | cut -d' ' -f1)" = "$2" ] || { echo "checksum mismatch: $f" >&2; exit 1; }
+ echo "$f"
+}
W="$(mktemp -d /tmp/cua-build-xcode.XXXXXX)"
trap 'rm -rf "$W"' EXIT
-(cd "$W" && xip --expand "$xip_file" >/dev/null)
-sudo_run rm -rf "$APP"
-sudo_run mv "$W/Xcode.app" "$APP"
+export PATH="$HOME/.cargo/bin:/usr/local/bin:$PATH"
+
+# --- Xcode -------------------------------------------------------------------
+src="" pinned=0
+if [ -f "$C/$XCODE_XIP" ]; then
+ say "checking $XCODE_XIP"
+ [ "$(shasum -a 1 "$C/$XCODE_XIP" | cut -d' ' -f1)" = "$XCODE_XIP_SHA1" ] ||
+ { echo "checksum mismatch: $C/$XCODE_XIP" >&2; exit 1; }
+ src="$C/$XCODE_XIP" pinned=1
+else
+ for f in "$STAGE"/xcode/*.zip "$STAGE"/xcode/*.app "$STAGE"/xcode/*.xip; do
+ [ -e "$f" ] && { src="$f"; break; }
+ done
+fi
+[ -n "$src" ] || { echo "no Xcode to install: expected $C/$XCODE_XIP or an Xcode.app or .xip in $STAGE/xcode" >&2; exit 1; }
+
+case "$src" in
+ *.xip)
+ say "expanding $(basename "$src") (xip checks Apple's signature)"
+ (cd "$W" && xip --expand "$src" >/dev/null)
+ app="$(ls -d "$W"/Xcode*.app | head -1)"
+ version="$(/usr/libexec/PlistBuddy -c 'Print :CFBundleShortVersionString' "$app/Contents/Info.plist")"
+ APP="/Applications/Xcode_${version}.app"
+ sudo_run rm -rf "$APP"
+ sudo_run mv "$app" "$APP" ;;
+ *.zip)
+ # The host's own Xcode, archived by ditto (links, signature, xattrs kept).
+ say "extracting $(basename "$src")"
+ sudo_run ditto -x -k "$src" "$W"
+ app="$(ls -d "$W"/Xcode*.app | head -1)"
+ version="$(/usr/libexec/PlistBuddy -c 'Print :CFBundleShortVersionString' "$app/Contents/Info.plist")"
+ APP="/Applications/Xcode_${version}.app"
+ sudo_run rm -rf "$APP"
+ sudo_run mv "$app" "$APP" ;;
+ *)
+ # A bundle copy straight into place: ditto keeps the code signature,
+ # links and xattrs, and the source is only read.
+ version="$(/usr/libexec/PlistBuddy -c 'Print :CFBundleShortVersionString' "$src/Contents/Info.plist")"
+ APP="/Applications/Xcode_${version}.app"
+ say "copying $(basename "$src") to $APP"
+ sudo_run rm -rf "$APP"
+ sudo_run ditto "$src" "$APP" ;;
+esac
+say "Xcode $version at $APP"
+codesign --verify --deep --strict "$APP" 2>&1 | head -3 || true
sudo_run xcode-select --switch "$APP/Contents/Developer"
sudo_run xcodebuild -license accept
sudo_run xcodebuild -runFirstLaunch
-got="$(xcodebuild -version | sed -n 's/^Build version //p')"
-[ "$got" = "$XCODE_BUILD" ] || { echo "Xcode build is $got, not $XCODE_BUILD" >&2; exit 1; }
+build="$(xcodebuild -version | sed -n 's/^Build version //p')"
+if [ "$pinned" = 1 ] && [ "$build" != "$XCODE_BUILD" ]; then
+ echo "Xcode build is $build, not $XCODE_BUILD" >&2; exit 1
+fi
+echo " Xcode $version ($build)"
-say "iOS $XCODE_IOS_RUNTIME simulator runtime and Metal toolchain"
-xcodebuild -downloadPlatform iOS -buildVersion "$XCODE_IOS_RUNTIME"
+# --- simulator runtime and Metal toolchain --------------------------------------
+# Disk first: the runtime is several GB and the build volume is the guest's.
+free_gb="$(df -g / | awk 'NR==2 {print $4}')"
+[ "${free_gb:-0}" -ge 20 ] || { echo "the guest has ${free_gb} GB free; the iOS runtime needs about 20" >&2; exit 1; }
+if [ "$pinned" = 1 ]; then
+ say "iOS $XCODE_IOS_RUNTIME simulator runtime and Metal toolchain"
+ xcodebuild -downloadPlatform iOS -buildVersion "$XCODE_IOS_RUNTIME"
+else
+ say "iOS simulator runtime of Xcode $version and Metal toolchain"
+ xcodebuild -downloadPlatform iOS
+fi
xcodebuild -downloadComponent MetalToolchain
# The first boot of a new runtime builds its dyld shared cache; do it now so
-# the first `simctl boot` in a sandbox is not minutes long.
+# the first `simctl boot` in a Space is not minutes long.
xcrun simctl runtime dyld_shared_cache update --all >/dev/null 2>&1 || true
xcrun simctl delete unavailable || true
+# --- developer tools ---------------------------------------------------------------
+say "Rust targets: $RUST_IOS_TARGETS"
+# shellcheck disable=SC2086 # a list
+"$HOME/.cargo/bin/rustup" target add $RUST_IOS_TARGETS
+rm -rf "$HOME/.rustup/downloads" "$HOME/.rustup/tmp"
+
+say "sccache $SCCACHE_VERSION, XcodeGen $XCODEGEN_VERSION"
+f="$(verified "$SCCACHE_URL" "$SCCACHE_SHA256")"; tar -xzf "$f" -C "$W"
+sudo_run install -m 0755 "$W"/sccache-*/sccache /usr/local/bin/sccache
+f="$(verified "$XCODEGEN_URL" "$XCODEGEN_SHA256")"; ditto -x -k "$f" "$W/xcodegen"
+sudo_run rm -rf /usr/local/lib/xcodegen
+sudo_run mkdir -p /usr/local/lib/xcodegen
+sudo_run ditto "$W/xcodegen/xcodegen" /usr/local/lib/xcodegen
+# A wrapper, not a link: XcodeGen finds its setting presets (share/) relative to
+# the path it was started by, and a link in /usr/local/bin has none.
+printf '#!/bin/sh\nexec /usr/local/lib/xcodegen/bin/xcodegen "$@"\n' >"$W/xcodegen-wrapper"
+sudo_run install -m 0755 "$W/xcodegen-wrapper" /usr/local/bin/xcodegen
+
+say "CocoaPods $COCOAPODS_VERSION"
+HOMEBREW_NO_AUTO_UPDATE=1 HOMEBREW_NO_ANALYTICS=1 HOMEBREW_NO_ENV_HINTS=1 /opt/homebrew/bin/brew install cocoapods
+got="$(LANG=en_US.UTF-8 /opt/homebrew/bin/pod --version)"
+[ "$got" = "$COCOAPODS_VERSION" ] || { echo "CocoaPods is $got, not $COCOAPODS_VERSION: Homebrew's formula moved; update versions.env" >&2; exit 1; }
+sudo_run ln -sfn /opt/homebrew/bin/pod /usr/local/bin/pod
+# CocoaPods insists on a UTF-8 locale.
+grep -q 'LANG=en_US.UTF-8' "$HOME/.zprofile" 2>/dev/null || printf 'export LANG=en_US.UTF-8\n' >>"$HOME/.zprofile"
+/opt/homebrew/bin/brew cleanup -s >/dev/null 2>&1 || true
+rm -rf "$HOME/Library/Caches/Homebrew"
+
+say "developer mode"
+# No debugger or Instruments authorization prompts for the agent's account,
+# and no SwiftPM macro or build-plugin trust dialogs (the agent cannot click
+# through a trust prompt in a headless build).
+sudo_run DevToolsSecurity -enable
+sudo_run dseditgroup -o edit -a "$(id -un)" -t user _developer
+defaults write com.apple.dt.Xcode IDESkipMacroFingerprintValidation -bool YES
+defaults write com.apple.dt.Xcode IDESkipPackagePluginFingerprintValidatation -bool YES
+defaults write com.apple.dt.Xcode IDEPackageSupportDisableManifestSandbox -bool YES
+
+say "Simulator device"
+runtime="$(xcrun simctl list runtimes -j | python3 -c '
+import json, sys
+rs = [r for r in json.load(sys.stdin)["runtimes"] if r.get("isAvailable") and r["identifier"].split(".")[-1].startswith("iOS")]
+print(rs[-1]["identifier"] if rs else "")')"
+[ -n "$runtime" ] || { echo "no iOS simulator runtime is available" >&2; exit 1; }
+devtype="$(xcrun simctl list devicetypes -j | python3 -c '
+import json, sys
+t = [d["identifier"] for d in json.load(sys.stdin)["devicetypes"] if "iPhone" in d["name"] and "Pro" in d["name"] and "Max" not in d["name"]]
+print(t[-1] if t else "")')"
+[ -n "$devtype" ] || devtype="$(xcrun simctl list devicetypes | sed -n 's/.*(\(com.apple.CoreSimulator.SimDeviceType.iPhone[^)]*\)).*/\1/p' | tail -1)"
+xcrun simctl delete "$SIMULATOR_DEVICE_NAME" >/dev/null 2>&1 || true
+udid="$(xcrun simctl create "$SIMULATOR_DEVICE_NAME" "$devtype" "$runtime")"
+echo " $SIMULATOR_DEVICE_NAME $udid ($runtime)"
+# Boot it once and shut it down: the first boot builds the runtime's caches.
+xcrun simctl boot "$udid" || true
+xcrun simctl bootstatus "$udid" -b || true
+xcrun simctl shutdown "$udid" || true
+
say "runtimes"
xcrun simctl list runtimes
-rm -rf "$HOME/Library/Caches/com.apple.dt.Xcode" "$HOME/Library/Developer/Xcode/DerivedData"
+rm -rf "$HOME/Library/Caches/com.apple.dt.Xcode" "$HOME/Library/Developer/Xcode/DerivedData" "$HOME/Library/Caches/CocoaPods"
+rm -rf "$HOME/Library/Developer/CoreSimulator/Caches" 2>/dev/null || true
+
+say "versions"
+xcodebuild -version | head -2
+"$HOME/.cargo/bin/rustup" target list --installed
+/usr/local/bin/sccache --version; /usr/local/bin/xcodegen --version; pod --version 2>/dev/null || /usr/local/bin/pod --version
echo "xcode tier installed"
diff --git a/libs/images/macos/fixtures/HelloSim/HelloSim/ContentView.swift b/libs/images/macos/fixtures/HelloSim/HelloSim/ContentView.swift
new file mode 100644
index 0000000000..d7630e3d1c
--- /dev/null
+++ b/libs/images/macos/fixtures/HelloSim/HelloSim/ContentView.swift
@@ -0,0 +1,19 @@
+import SwiftUI
+
+struct ContentView: View {
+ @State private var counter = Counter()
+
+ var body: some View {
+ VStack(spacing: 24) {
+ Text("Built in a macOS Space")
+ .font(.title2.bold())
+ Text(counter.label)
+ .font(.headline)
+ .accessibilityIdentifier("label")
+ Button("Tap") { counter.tap() }
+ .buttonStyle(.borderedProminent)
+ .accessibilityIdentifier("tap")
+ }
+ .padding()
+ }
+}
diff --git a/libs/images/macos/fixtures/HelloSim/HelloSim/Counter.swift b/libs/images/macos/fixtures/HelloSim/HelloSim/Counter.swift
new file mode 100644
index 0000000000..56ae834ae4
--- /dev/null
+++ b/libs/images/macos/fixtures/HelloSim/HelloSim/Counter.swift
@@ -0,0 +1,7 @@
+/// The state the screen shows; the unit tests drive it without a screen.
+struct Counter: Equatable {
+ private(set) var value = 0
+
+ mutating func tap() { value += 1 }
+ var label: String { value == 0 ? "Not tapped yet" : "Tapped \(value) time\(value == 1 ? "" : "s")" }
+}
diff --git a/libs/images/macos/fixtures/HelloSim/HelloSim/HelloSimApp.swift b/libs/images/macos/fixtures/HelloSim/HelloSim/HelloSimApp.swift
new file mode 100644
index 0000000000..18aeba257c
--- /dev/null
+++ b/libs/images/macos/fixtures/HelloSim/HelloSim/HelloSimApp.swift
@@ -0,0 +1,8 @@
+import SwiftUI
+
+@main
+struct HelloSimApp: App {
+ var body: some Scene {
+ WindowGroup { ContentView() }
+ }
+}
diff --git a/libs/images/macos/fixtures/HelloSim/HelloSimTests/CounterTests.swift b/libs/images/macos/fixtures/HelloSim/HelloSimTests/CounterTests.swift
new file mode 100644
index 0000000000..aba7902c70
--- /dev/null
+++ b/libs/images/macos/fixtures/HelloSim/HelloSimTests/CounterTests.swift
@@ -0,0 +1,16 @@
+import XCTest
+@testable import HelloSim
+
+final class CounterTests: XCTestCase {
+ func testStartsUntapped() {
+ XCTAssertEqual(Counter().label, "Not tapped yet")
+ }
+
+ func testTapsAreCounted() {
+ var c = Counter()
+ c.tap()
+ XCTAssertEqual(c.label, "Tapped 1 time")
+ c.tap()
+ XCTAssertEqual(c.label, "Tapped 2 times")
+ }
+}
diff --git a/libs/images/macos/fixtures/HelloSim/HelloSimUITests/TapUITests.swift b/libs/images/macos/fixtures/HelloSim/HelloSimUITests/TapUITests.swift
new file mode 100644
index 0000000000..74e2b85e92
--- /dev/null
+++ b/libs/images/macos/fixtures/HelloSim/HelloSimUITests/TapUITests.swift
@@ -0,0 +1,23 @@
+import XCTest
+
+/// Drives the running app in the Simulator and leaves screenshots of what it
+/// sees as test attachments (xcresulttool exports them).
+final class TapUITests: XCTestCase {
+ func testTapUpdatesTheLabel() throws {
+ let app = XCUIApplication()
+ app.launch()
+ attach(app, "before")
+ XCTAssertTrue(app.staticTexts["Not tapped yet"].waitForExistence(timeout: 20))
+ app.buttons["tap"].tap()
+ app.buttons["tap"].tap()
+ XCTAssertTrue(app.staticTexts["Tapped 2 times"].waitForExistence(timeout: 10))
+ attach(app, "after")
+ }
+
+ private func attach(_ app: XCUIApplication, _ name: String) {
+ let shot = XCTAttachment(screenshot: app.screenshot())
+ shot.name = name
+ shot.lifetime = .keepAlways
+ add(shot)
+ }
+}
diff --git a/libs/images/macos/fixtures/HelloSim/project.yml b/libs/images/macos/fixtures/HelloSim/project.yml
new file mode 100644
index 0000000000..c7dcedb9f9
--- /dev/null
+++ b/libs/images/macos/fixtures/HelloSim/project.yml
@@ -0,0 +1,45 @@
+name: HelloSim
+options:
+ bundleIdPrefix: ai.cua.fixture
+ deploymentTarget:
+ iOS: "17.0"
+settings:
+ base:
+ SWIFT_VERSION: "6.0"
+ GENERATE_INFOPLIST_FILE: YES
+ CODE_SIGNING_ALLOWED: NO
+targets:
+ HelloSim:
+ type: application
+ platform: iOS
+ sources: [HelloSim]
+ settings:
+ base:
+ INFOPLIST_KEY_UIApplicationSceneManifest_Generation: YES
+ INFOPLIST_KEY_UILaunchScreen_Generation: YES
+ PRODUCT_BUNDLE_IDENTIFIER: ai.cua.fixture.HelloSim
+ HelloSimTests:
+ type: bundle.unit-test
+ platform: iOS
+ sources: [HelloSimTests]
+ dependencies:
+ - target: HelloSim
+ settings:
+ base:
+ PRODUCT_BUNDLE_IDENTIFIER: ai.cua.fixture.HelloSimTests
+ HelloSimUITests:
+ type: bundle.ui-testing
+ platform: iOS
+ sources: [HelloSimUITests]
+ dependencies:
+ - target: HelloSim
+ settings:
+ base:
+ PRODUCT_BUNDLE_IDENTIFIER: ai.cua.fixture.HelloSimUITests
+schemes:
+ HelloSim:
+ build:
+ targets:
+ HelloSim: all
+ test:
+ targets: [HelloSimTests, HelloSimUITests]
diff --git a/libs/images/macos/fixtures/HelloSim/rust/Cargo.lock b/libs/images/macos/fixtures/HelloSim/rust/Cargo.lock
new file mode 100644
index 0000000000..a2d216307f
--- /dev/null
+++ b/libs/images/macos/fixtures/HelloSim/rust/Cargo.lock
@@ -0,0 +1,7 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+version = 4
+
+[[package]]
+name = "hellosim-core"
+version = "0.1.0"
diff --git a/libs/images/macos/fixtures/HelloSim/rust/Cargo.toml b/libs/images/macos/fixtures/HelloSim/rust/Cargo.toml
new file mode 100644
index 0000000000..ca8d94e1cf
--- /dev/null
+++ b/libs/images/macos/fixtures/HelloSim/rust/Cargo.toml
@@ -0,0 +1,7 @@
+[package]
+name = "hellosim-core"
+version = "0.1.0"
+edition = "2021"
+
+[lib]
+crate-type = ["staticlib"]
diff --git a/libs/images/macos/fixtures/HelloSim/rust/src/lib.rs b/libs/images/macos/fixtures/HelloSim/rust/src/lib.rs
new file mode 100644
index 0000000000..6e09d38be4
--- /dev/null
+++ b/libs/images/macos/fixtures/HelloSim/rust/src/lib.rs
@@ -0,0 +1,5 @@
+/// A function an iOS app could link: proves the Rust iOS targets build.
+#[no_mangle]
+pub extern "C" fn hellosim_add(a: i32, b: i32) -> i32 {
+ a + b
+}
diff --git a/libs/images/macos/image.json b/libs/images/macos/image.json
index f2699fd14d..3638d21270 100644
--- a/libs/images/macos/image.json
+++ b/libs/images/macos/image.json
@@ -240,7 +240,7 @@
},
"xcode": {
"from": "full",
- "description": "Full plus Xcode 26.6 (selected), its iOS 26.5 simulator runtime and the Metal toolchain.",
+ "description": "Full plus Xcode (the Mac's own, copied in when the image is built on it), the matching iOS simulator runtime, the Metal toolchain, Rust iOS targets, CocoaPods, XcodeGen, sccache and a warmed Simulator device: the macOS Space with developer tools. Built on each user's Mac and never published (Apple's terms).",
"claims": {
"tools": {
"xcodebuild": {
@@ -249,6 +249,27 @@
"-version"
],
"expect": "^Xcode 26\\.6$"
+ },
+ "sccache": {
+ "argv": [
+ "/usr/local/bin/sccache",
+ "--version"
+ ],
+ "expect": "^sccache 0\\.19\\.0$"
+ },
+ "xcodegen": {
+ "argv": [
+ "/usr/local/bin/xcodegen",
+ "--version"
+ ],
+ "expect": "Version: 2\\.46\\.0"
+ },
+ "pod": {
+ "argv": [
+ "/usr/local/bin/pod",
+ "--version"
+ ],
+ "expect": "^1\\.17\\.0$"
}
},
"simulator_runtimes": [
diff --git a/libs/images/macos/release-tier.sh b/libs/images/macos/release-tier.sh
index 45b9d75833..e0c1d4c71f 100755
--- a/libs/images/macos/release-tier.sh
+++ b/libs/images/macos/release-tier.sh
@@ -54,6 +54,12 @@ while [ $# -gt 0 ]; do
done
# shellcheck source=versions.env
. "$HERE/versions.env"
+# The xcode tier carries Xcode, SDKs and simulator runtimes: Apple's terms do
+# not allow redistributing them, so it is built and gated here but never
+# pushed. Each Mac derives it (derive-local.sh).
+never_xcode() {
+ [ "$TIER" != xcode ] || { echo "the xcode tier is never $1: it carries Xcode (see versions.env)" >&2; exit 2; }
+}
pin() {
[[ "$STAMP" =~ ^[0-9]{8}-[0-9a-f]{7}$ ]] || { echo "--stamp is <yyyymmdd>-<sha7>" >&2; exit 2; }
local p
@@ -136,6 +142,7 @@ PY
cp "$d"/* "$EVIDENCE/doctor/arm64-lume/"
;;
push)
+ never_xcode pushed
p="$(pin)"; vm="$(vm_name "$TIER")"
digest="$("$HERE/push.sh" "$vm" "$p-raw" | tail -1)"
python3 -c 'import json,sys;json.dump({"tag":sys.argv[1],"digest":sys.argv[2],"vm":sys.argv[3]},open(sys.argv[4],"w"))' \
@@ -143,6 +150,7 @@ push)
cat "$EVIDENCE/raw.json"
;;
publish)
+ never_xcode published
p="$(pin)"
[ "$(crane digest "$REPOSITORY:$p-raw")" = "$(jget "$EVIDENCE/raw.json" digest)" ] ||
{ echo "$p-raw no longer holds the pushed digest" >&2; exit 1; }
@@ -184,6 +192,7 @@ print(f"verified {rec['repo']}:{rec['tag']} {rec['lume']} ({len(pin.get('layers'
PY
;;
promote)
+ never_xcode promoted
rec="$EVIDENCE/pushed.json"
tag="$(jget "$rec" tag)" digest="$(jget "$rec" lume)"
[ "$(jget "$rec" tier)" = "$TIER" ] || { echo "$rec is not the $TIER tier" >&2; exit 1; }
diff --git a/libs/images/macos/versions.env b/libs/images/macos/versions.env
index 75b9afff37..52ac80d460 100644
--- a/libs/images/macos/versions.env
+++ b/libs/images/macos/versions.env
@@ -55,14 +55,38 @@ GO_URL=https://go.dev/dl/go1.27.1.darwin-arm64.tar.gz
GO_SHA256=ee215d57e0ec269c60cc9ceca68e6bda321ba9ee5afe24f4b0988703c2d87d12
# --- xcode --------------------------------------------------------------------
-# Apple needs a signed-in download, so the .xip comes from a runner-side
-# cache (CUA_XCODE_CACHE, default ~/XcodesCache), never from the network.
-# Apple and xcodereleases.com publish SHA-1 for the archive; xip also checks
-# Apple's signature on expand.
+# The macOS Space with developer tools. Apple's terms allow Xcode on the Mac
+# that runs the VM, not redistribution, so this tier is never pushed to a
+# registry (check-tag-safety.sh, release-tier.sh and the image workflow refuse
+# it); each Mac derives it from the published full tier (derive-local.sh) with
+# an Xcode that is already on that Mac. Apple needs a signed-in download for a
+# new copy, so the Xcode is, in order: an installed Xcode.app, or an .xip from
+# CUA_XCODE_CACHE (default ~/XcodesCache). Apple and xcodereleases.com publish
+# SHA-1 for the archive; xip also checks Apple's signature on expand.
+# XCODE_* below is the version CI builds and gates the tier with (build.sh
+# --tier xcode needs that .xip in the runner's cache); a Mac deriving it
+# locally may use any Xcode its guest macOS supports.
XCODE_VERSION=26.6
XCODE_BUILD=17F113
XCODE_XIP=Xcode_26.6_Apple_silicon.xip
XCODE_XIP_SHA1=02ce6fccf6c46c12cbef005fbd48f9eaf7489912
-# The iOS simulator runtime of that Xcode (xcodebuild -downloadPlatform iOS),
-# the only runtime the tier claims (image.json simulator_runtimes).
+# The iOS simulator runtime of that Xcode (xcodebuild -downloadPlatform iOS,
+# from Apple's CDN, no sign-in), the only runtime the tier claims
+# (image.json simulator_runtimes).
XCODE_IOS_RUNTIME=26.5
+# Rust targets for iOS (rustup, on the full tier's pinned toolchain).
+RUST_IOS_TARGETS="aarch64-apple-ios aarch64-apple-ios-sim"
+SCCACHE_VERSION=0.19.0
+SCCACHE_URL=https://github.com/mozilla/sccache/releases/download/v0.19.0/sccache-v0.19.0-aarch64-apple-darwin.tar.gz
+SCCACHE_SHA256=a35a0b7d622618774bc1bb8102d72562dfb21e619f88b153b370d7f89bc286af
+XCODEGEN_VERSION=2.46.0
+XCODEGEN_URL=https://github.com/yonaskolb/XcodeGen/releases/download/2.46.0/xcodegen.zip
+XCODEGEN_SHA256=4d9e34b62172d645eed6457cac13fc222569974098ef4ee9c3368bedf0196806
+# CocoaPods from Homebrew's bottle (the system Ruby is 2.6, which CocoaPods
+# 1.17 and its gems cannot install on: measured in a real guest). Brew checks
+# the bottle's checksum; the tier fails unless `pod --version` is this exact
+# version, so a moved formula is a visible change, not a silent one.
+COCOAPODS_VERSION=1.17.0
+# The Simulator device the tier creates and warms (first boot of a runtime
+# builds its caches). Looked up by name in the runtime's device types.
+SIMULATOR_DEVICE_NAME="Cua iPhone"
diff --git a/scripts/images/check-tag-safety.sh b/scripts/images/check-tag-safety.sh
index ecd299e4b6..ced843c0da 100755
--- a/scripts/images/check-tag-safety.sh
+++ b/scripts/images/check-tag-safety.sh
@@ -126,6 +126,12 @@ for ref in "${refs[@]}"; do
if [ "$tag" = latest ] && in_list "$nrepo" "${CANONICAL_REPOS[@]}"; then
echo "REFUSED $ref: canonical repos never carry latest" >&2; refused=1; continue
fi
+ # Xcode (with its SDKs and simulator runtimes) is Apple's: the macOS Space
+ # with developer tools is built on each user's own Mac and never pushed.
+ if [[ "$nrepo" == ghcr.io/trycua/macos && "$tag" == *-xcode* ]]; then
+ echo "REFUSED $ref: images with Xcode are not redistributable and are never published (libs/images/macos/derive-local.sh builds one per Mac)" >&2
+ refused=1; continue
+ fi
rc=0; cur="$(remote_digest "$ref")" || rc=$?
[ "$rc" = 0 ] || exit 2
if [ -z "$cur" ]; then echo "ok $ref (new tag)"; continue; fi
diff --git a/scripts/images/test-check-tag-safety.sh b/scripts/images/test-check-tag-safety.sh
index 6357b7be82..08cedc14b0 100755
--- a/scripts/images/test-check-tag-safety.sh
+++ b/scripts/images/test-check-tag-safety.sh
@@ -44,8 +44,10 @@ L=ghcr.io/trycua/linux M=ghcr.io/trycua/macos W=ghcr.io/trycua/windows
check 0 --moving $L:24.04-slim
check 0 --moving $L:24.04-slim-disk
check 0 --moving $M:26
-check 0 --moving $M:26-xcode
-check 0 --moving $M:26-xcode-26.1
+check 1 --moving $M:26-xcode # Xcode images are never published
+check 1 --moving $M:26-xcode-26.1
+check 1 $M:26-xcode-26.1-20261101-abcdef1 # not even a new pin
+check 0 --moving $M:26-slim
check 0 --moving $W:15-disk
check 1 --moving $L:main # not in the grammar
check 1 --moving $L:24.04-full # full is the unsuffixed tag
diff --git a/scripts/images/tests/test_macos_dev_image.py b/scripts/images/tests/test_macos_dev_image.py
new file mode 100644
index 0000000000..7254f81b21
--- /dev/null
+++ b/scripts/images/tests/test_macos_dev_image.py
@@ -0,0 +1,204 @@
+"""Recipe lint and drift guards for the macOS Space with developer tools (the
+xcode tier of libs/images/macos): its pins, claims and catalog entry agree,
+every script parses, and nothing can publish an image that carries Xcode
+(Apple's terms do not let us redistribute it)."""
+
+from __future__ import annotations
+
+import json
+import os
+import re
+import shutil
+import subprocess
+import sys
+import tempfile
+import unittest
+
+HERE = os.path.dirname(os.path.abspath(__file__))
+ROOT = os.path.abspath(os.path.join(HERE, "..", "..", ".."))
+MACOS = os.path.join(ROOT, "libs", "images", "macos")
+CATALOG = os.path.join(ROOT, "libs", "images", "sandbox-images.json")
+SCRIPTS = [
+ "build.sh",
+ "derive-local.sh",
+ "release-tier.sh",
+ "push.sh",
+ "tiers.sh",
+ "files/tier-xcode.sh",
+ "files/tier-full.sh",
+ "files/fetch.sh",
+ "dev-image-gate.sh",
+ "files/dev-image-gate-guest.sh",
+]
+# The xcode tier's tools: image.json claim -> versions.env key.
+XCODE_TOOLS = {
+ "xcodebuild": "XCODE_VERSION",
+ "sccache": "SCCACHE_VERSION",
+ "xcodegen": "XCODEGEN_VERSION",
+ "pod": "COCOAPODS_VERSION",
+}
+MACOS_REPO = "ghcr.io/trycua/" + "macos" # not a catalog ref: a repository
+
+
+def versions() -> dict[str, str]:
+ env = {}
+ for line in open(os.path.join(MACOS, "versions.env")).read().splitlines():
+ if line and not line.startswith("#") and "=" in line:
+ k, v = line.split("=", 1)
+ env[k] = v.strip('"')
+ return env
+
+
+def run(args, **kw):
+ return subprocess.run(args, capture_output=True, text=True, **kw)
+
+
+class Recipe(unittest.TestCase):
+ def test_scripts_parse(self):
+ for s in SCRIPTS:
+ r = run(["bash", "-n", os.path.join(MACOS, s)])
+ self.assertEqual(r.returncode, 0, f"{s}: {r.stderr}")
+
+ @unittest.skipUnless(shutil.which("shellcheck"), "shellcheck not installed")
+ def test_new_scripts_pass_shellcheck(self):
+ for s in ["derive-local.sh", "files/tier-xcode.sh", "files/fetch.sh"]:
+ r = run(["shellcheck", "-x", "-S", "warning", os.path.join(MACOS, s)])
+ self.assertEqual(r.returncode, 0, f"{s}: {r.stdout}")
+
+ def test_pins_are_complete_and_checksummed(self):
+ env = versions()
+ for name in ("SCCACHE", "XCODEGEN"):
+ self.assertIn(f"{name}_VERSION", env)
+ self.assertTrue(env[f"{name}_URL"].startswith("https://"), name)
+ self.assertIn(env[f"{name}_VERSION"], env[f"{name}_URL"], name)
+ self.assertRegex(env[f"{name}_SHA256"], r"^[0-9a-f]{64}$", name)
+ self.assertRegex(env["COCOAPODS_VERSION"], r"^\d+\.\d+\.\d+$")
+ self.assertTrue(env["RUST_IOS_TARGETS"].split())
+ for t in env["RUST_IOS_TARGETS"].split():
+ self.assertTrue(t.endswith("-ios") or t.endswith("-ios-sim"), t)
+
+ def test_xcode_claims_name_the_pinned_versions(self):
+ env = versions()
+ claims = json.load(open(os.path.join(MACOS, "image.json")))["tiers"]["xcode"]["claims"]
+ for tool, key in XCODE_TOOLS.items():
+ expect = claims["tools"][tool]["expect"]
+ version = env[key]
+ self.assertTrue(
+ re.search(expect, version) or re.escape(version) in expect,
+ f"{tool}: {expect!r} does not name {key}={version}",
+ )
+ self.assertEqual(claims["simulator_runtimes"], ["iOS " + env["XCODE_IOS_RUNTIME"]])
+
+ def test_tier_script_installs_every_pinned_tool(self):
+ script = open(os.path.join(MACOS, "files", "tier-xcode.sh")).read()
+ for needle in ("RUST_IOS_TARGETS", "SCCACHE_URL", "XCODEGEN_URL", "COCOAPODS_VERSION",
+ "DevToolsSecurity", "_developer", "xcodebuild -license accept",
+ "-downloadPlatform iOS", "simctl create"):
+ self.assertIn(needle, script)
+
+ def test_lume_wrapper_never_calls_itself(self):
+ # A `lume` shell function defaulting to the program named lume would
+ # recurse until bash crashes: the default must be a resolved path.
+ for s in ("derive-local.sh", "dev-image-gate.sh"):
+ text = open(os.path.join(MACOS, s)).read()
+ self.assertIn("type -P lume", text, s)
+ self.assertNotIn("command lume", text, s)
+
+ def test_derive_stages_what_the_tier_script_reads(self):
+ derive = open(os.path.join(MACOS, "derive-local.sh")).read()
+ for needle in ("tier-xcode.sh", "versions.env", "fetch_xcode_tools", "xcode/"):
+ self.assertIn(needle, derive)
+
+
+class Gate(unittest.TestCase):
+ def test_fixture_covers_what_the_gate_claims(self):
+ fx = os.path.join(MACOS, "fixtures", "HelloSim")
+ spec = open(os.path.join(fx, "project.yml")).read()
+ for target in ("HelloSim:", "HelloSimTests:", "HelloSimUITests:"):
+ self.assertIn(target, spec)
+ self.assertTrue(os.path.isfile(os.path.join(fx, "rust", "Cargo.lock")), "locked: the gate builds offline-stable")
+ guest = open(os.path.join(MACOS, "files", "dev-image-gate-guest.sh")).read()
+ env = versions()
+ for needle in ("xcodebuild test", "aarch64-apple-ios-sim", "xcresulttool export attachments",
+ "simctl io", "RUSTC_WRAPPER=sccache", env["SIMULATOR_DEVICE_NAME"]):
+ self.assertIn(needle, guest)
+
+
+class NeverPublished(unittest.TestCase):
+ def test_no_xcode_ref_is_published_in_the_catalog(self):
+ for e in json.load(open(CATALOG))["images"]:
+ if "xcode" in e["ref"]:
+ self.assertFalse(e["published"], e["ref"])
+
+ def test_tag_safety_refuses_xcode_tags(self):
+ tmp = tempfile.mkdtemp()
+ self.addCleanup(shutil.rmtree, tmp, True)
+ crane = os.path.join(tmp, "crane")
+ with open(crane, "w") as f:
+ f.write("#!/bin/sh\necho 'MANIFEST_UNKNOWN' >&2\nexit 1\n")
+ os.chmod(crane, 0o755)
+ guard = os.path.join(ROOT, "scripts", "images", "check-tag-safety.sh")
+ env = dict(os.environ, CRANE=crane)
+ for tag in ("26-xcode", "26-xcode-26.6", "26-xcode-26.6-20261101-abcdef1"):
+ for extra in ([], ["--moving"]):
+ r = run([guard, *extra, f"{MACOS_REPO}:{tag}"], env=env)
+ self.assertEqual(r.returncode, 1, f"{tag} {extra}: {r.stdout}{r.stderr}")
+ self.assertIn("never published", r.stderr)
+ ok = run([guard, f"{MACOS_REPO}:26-slim-20261101-abcdef1"], env=env)
+ self.assertEqual(ok.returncode, 0, ok.stderr)
+
+ def test_release_tier_and_build_refuse_to_push_xcode(self):
+ for args in (["push", "--tier", "xcode", "--prefix", "cua-e2e-x", "--stamp", "20261101-abcdef1", "--evidence", "/nonexistent"],
+ ["publish", "--tier", "xcode", "--stamp", "20261101-abcdef1", "--evidence", "/nonexistent"],
+ ["promote", "--tier", "xcode", "--evidence", "/nonexistent"]):
+ r = run([os.path.join(MACOS, "release-tier.sh"), *args])
+ self.assertEqual(r.returncode, 2, r.stderr)
+ self.assertIn("never", r.stderr)
+ r = run([os.path.join(MACOS, "build.sh"), "--tier", "xcode", "--base-vm", "x", "--push", "26-xcode-26.6-20261101-abcdef1"])
+ self.assertEqual(r.returncode, 2, r.stderr)
+ self.assertIn("never pushed", r.stderr)
+
+
[email protected](sys.platform == "darwin", "derive-local.sh reads Xcode bundles (macOS)")
+class DeriveLocal(unittest.TestCase):
+ script = os.path.join(MACOS, "derive-local.sh")
+
+ def fake_xcode(self, tmp: str) -> str:
+ app = os.path.join(tmp, "Xcode.app", "Contents")
+ os.makedirs(app)
+ with open(os.path.join(app, "Info.plist"), "w") as f:
+ f.write('<?xml version="1.0" encoding="UTF-8"?><plist version="1.0"><dict>'
+ "<key>CFBundleShortVersionString</key><string>26.6</string>"
+ "<key>LSMinimumSystemVersion</key><string>26.2</string></dict></plist>")
+ return os.path.dirname(app)
+
+ def test_needs_a_base_vm(self):
+ r = run([self.script])
+ self.assertEqual(r.returncode, 2)
+ self.assertIn("--base-vm", r.stderr)
+
+ def test_refuses_early_when_the_disk_is_short(self):
+ tmp = tempfile.mkdtemp()
+ self.addCleanup(shutil.rmtree, tmp, True)
+ env = dict(os.environ, CUA_DEV_IMAGE_FLOOR_GB="100000000", CUA_LUME_STORAGE=os.path.join(tmp, "lume"))
+ r = run([self.script, "--base-vm", "x", "--xcode", self.fake_xcode(tmp), "--out", os.path.join(tmp, "out")], env=env)
+ self.assertEqual(r.returncode, 4, r.stderr)
+ self.assertIn("Make room", r.stderr)
+ self.assertIn("Not enough free disk", r.stderr)
+ self.assertFalse(os.path.exists(os.path.join(tmp, "out", "setup")), "nothing is staged before the disk check")
+
+ def test_says_what_is_needed_when_there_is_no_xcode(self):
+ if (shutil.which("xcode-select") and "Xcode" in run(["xcode-select", "-p"]).stdout) or any(
+ n.startswith("Xcode") for n in os.listdir("/Applications")
+ ):
+ self.skipTest("this Mac has an Xcode")
+ env = dict(os.environ, HOME=tempfile.mkdtemp())
+ self.addCleanup(shutil.rmtree, env["HOME"], True)
+ r = run([self.script, "--base-vm", "x"], env=env)
+ self.assertEqual(r.returncode, 3, r.stderr)
+ self.assertIn("App Store", r.stderr)
+ self.assertIn("developer.apple.com", r.stderr)
+
+
+if __name__ == "__main__":
+ unittest.main()