#!/usr/bin/env bash# A Release Cotton Dev for an iOS simulator, stamped with the commit it was# built from — the build a walker walks and a measurement times (timings on a# Debug build are not evidence). No other script builds Release for the# simulator: ios-install-device.sh builds Debug.## scripts/ios-sim-release.sh --sim <udid> [--copy-to <dir>/Cotton.app] [--skip-ffi]## Derived data is the one root every xcodebuild names (`scripts/lib/derived-data.sh`;# COTTON_DERIVED_DATA moves it).## The commit is stamped AT BUILD TIME as `CottonBuildCommit`# (`scripts/lib/build-commit.sh`, the rule every local runner uses), so the# dev corner reads "<commit> · <build> · schema N", never "unstamped"# (walker, 16 Oct 2026: a Release copied for the signing Mac carried no commit).## Simulator Release builds every architecture unless told otherwise, and the# simulator core (`build-xcframework.sh --simulator-only`) is arm64 only, so# the share extension failed to link x86_64; the build is held to arm64.## `--copy-to` puts a `ditto` copy (signature kept) where a walker reads it.## Heavy steps take the machine's build lock (`with-build-lock.sh`).set -euo pipefailROOT="$(cd "$(dirname "$0")/.." && pwd)"# A walk's builds go ahead of other local runs waiting on the build lock# (`with-build-lock.sh`, "A WALK GOES BEFORE OTHER LOCAL RUNS").. "$ROOT/scripts/lib/caller-class.sh"rank_as_walksource"$ROOT/scripts/lib/owned-root.sh"SIM=""COPY_TO=""SKIP_FFI=""while [ $# -gt 0 ]; docase"$1"in --sim) SIM="$2"; shift2 ;; --copy-to) COPY_TO="$2"; shift2 ;; --skip-ffi) SKIP_FFI=1; shift ;; *) echo "ios-sim-release: unknown argument $1" >&2; exit2 ;;esacdone[ -n "$SIM" ] || { echo "ios-sim-release: --sim <udid> is required (your own simulator, by UDID)" >&2; exit2; }# shellcheck source=lib/build-commit.shsource"$ROOT/scripts/lib/build-commit.sh"COMMIT="$(cotton_build_commit "$ROOT")"DERIVED="$(bash "$ROOT/scripts/lib/derived-data.sh")"echo "ios-sim-release: commit ${COMMIT:-<none>}, simulator $SIM"cd "$ROOT"[ -n "$SKIP_FFI" ] || bash scripts/with-build-lock.sh bash scripts/build-xcframework.sh --simulator-onlybash scripts/gen-ios-project.sh# Package.swift reads COTTON_FLAVOR from the ENVIRONMENT to decide COTTON_DEV; a# build setting alone never reaches the manifest (dev-tools-real-flavor guard).export COTTON_FLAVOR="${COTTON_FLAVOR:-dev}"bash scripts/with-build-lock.sh xcodebuild build \ -project apps/cotton/Cotton.xcodeproj -scheme tinmen-cotton -configuration Release \ -destination "id=$SIM" -derivedDataPath "$DERIVED" \ COTTON_FLAVOR="$COTTON_FLAVOR" ${COMMIT:+COTTON_BUILD_COMMIT="$COMMIT"} ONLY_ACTIVE_ARCH=YES ARCHS=arm64 -quietAPP="$DERIVED/Build/Products/Release-iphonesimulator/Cotton.app"[ -d "$APP" ] || { echo "ios-sim-release: xcodebuild wrote no app at $APP" >&2; exit1; }echo "ios-sim-release: $APP ($(/usr/libexec/PlistBuddy -c 'Print CottonBuildCommit' "$APP/Info.plist" 2>/dev/null || echo unstamped))"if [ -n "$COPY_TO" ]; then refuse_wide_root "the simulator app copy (--copy-to)""$COPY_TO" rm -rf "$COPY_TO" mkdir -p "$(dirname "$COPY_TO")" ditto "$APP""$COPY_TO" codesign -v "$COPY_TO" echo "ios-sim-release: copied to $COPY_TO"fi