72 lines
2.2 KiB
Bash
72 lines
2.2 KiB
Bash
#!/bin/bash
|
|
# Build TargetPrint.app for one architecture: x86_64 | arm64
|
|
# Prefers xcodebuild; falls back to CLT swiftc when Xcode.app is absent.
|
|
# Usage: build_macos.sh <arch> [Release|Debug]
|
|
set -euo pipefail
|
|
|
|
ARCH="${1:?arch required: x86_64 | arm64}"
|
|
CONFIGURATION="${2:-Release}"
|
|
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
|
|
SCRIPTS="$(dirname "$0")"
|
|
|
|
case "$ARCH" in
|
|
x86_64|arm64) ;;
|
|
*) echo "arch must be x86_64 or arm64 (got $ARCH)" >&2; exit 2 ;;
|
|
esac
|
|
|
|
xcodebuild_works() {
|
|
local xb="${XCODEBUILD:-}"
|
|
if [ -n "$xb" ] && [ -x "$xb" ] && "$xb" -version >/dev/null 2>&1; then
|
|
return 0
|
|
fi
|
|
if command -v xcodebuild >/dev/null 2>&1 && xcodebuild -version >/dev/null 2>&1; then
|
|
XCODEBUILD="$(command -v xcodebuild)"
|
|
return 0
|
|
fi
|
|
return 1
|
|
}
|
|
|
|
if xcodebuild_works; then
|
|
PROJECT="$ROOT/TargetPrint.xcodeproj"
|
|
SCHEME="TargetPrint"
|
|
OUT_DIR="$ROOT/build/apps/$ARCH"
|
|
DD_DIR="$ROOT/build/derived-$ARCH"
|
|
# shellcheck source=lib.sh
|
|
source "$SCRIPTS/lib.sh"
|
|
JOBS="$(cpu_jobs)"
|
|
echo "==> Building TargetPrint ($CONFIGURATION, $ARCH) with $XCODEBUILD (-jobs $JOBS)"
|
|
rm -rf "$OUT_DIR"
|
|
mkdir -p "$OUT_DIR" "$DD_DIR"
|
|
"$XCODEBUILD" \
|
|
-project "$PROJECT" \
|
|
-scheme "$SCHEME" \
|
|
-configuration "$CONFIGURATION" \
|
|
-arch "$ARCH" \
|
|
-jobs "$JOBS" \
|
|
-parallelizeTargets \
|
|
-derivedDataPath "$DD_DIR" \
|
|
CONFIGURATION_BUILD_DIR="$OUT_DIR" \
|
|
ONLY_ACTIVE_ARCH=NO \
|
|
CODE_SIGN_IDENTITY="${MACOS_CODESIGN_IDENTITY:--}" \
|
|
CODE_SIGNING_ALLOWED=YES \
|
|
ENABLE_HARDENED_RUNTIME=YES \
|
|
SWIFT_USE_PARALLEL_WHOLE_MODULE_OPTIMIZATION=YES \
|
|
build
|
|
APP="$OUT_DIR/TargetPrint.app"
|
|
test -d "$APP"
|
|
BIN="$APP/Contents/MacOS/TargetPrint"
|
|
test -x "$BIN"
|
|
sign_app "$APP" "$ROOT/TargetPrint.entitlements"
|
|
echo "==> lipo -info"
|
|
lipo -info "$BIN"
|
|
ACTUAL="$(lipo -archs "$BIN" | tr -d '[:space:]')"
|
|
if [[ "$ACTUAL" != "$ARCH" ]]; then
|
|
echo "error: expected a single-arch $ARCH binary, got '$ACTUAL'" >&2
|
|
exit 1
|
|
fi
|
|
echo "==> $APP"
|
|
else
|
|
echo "==> xcodebuild unavailable; using Command Line Tools swiftc"
|
|
exec "$SCRIPTS/swiftc_build.sh" "$ARCH" "$CONFIGURATION"
|
|
fi
|