Files
ICCery-CPU/Scripts/swiftc_build.sh
T
Local Admin 23995f18e5
Build macOS Packages / Build macOS (Apple Silicon) (push) Failing after 2m1s
Build macOS Packages / Build macOS (Intel) (push) Failing after 2m6s
Build macOS Packages / Build macOS (Universal) (push) Skipped
fix build sxriots for command line xcode
2026-09-07 05:36:51 -07:00

110 lines
3.2 KiB
Bash

#!/bin/bash
# Build TargetPrint.app with CLT swiftc (no Xcode.app / xcodebuild required).
# Usage: swiftc_build.sh <arch> [Release|Debug]
set -euo pipefail
ARCH="${1:?arch required: x86_64 | arm64}"
CONFIGURATION="${2:-Release}"
case "$ARCH" in
x86_64|arm64) ;;
*) echo "arch must be x86_64 or arm64" >&2; exit 2 ;;
esac
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
OUT_DIR="$ROOT/build/apps/$ARCH"
APP="$OUT_DIR/TargetPrint.app"
MACOS_DIR="$APP/Contents/MacOS"
RES_DIR="$APP/Contents/Resources"
BIN="$MACOS_DIR/TargetPrint"
SDKROOT="${SDKROOT:-$(xcrun --sdk macosx --show-sdk-path)}"
SWIFT="${SWIFT:-$(xcrun --find swiftc)}"
TARGET="${ARCH}-apple-macos10.15"
MIN_OS="10.15"
echo "==> swiftc build ($CONFIGURATION, $ARCH)"
echo " SDKROOT=$SDKROOT"
echo " SWIFT=$SWIFT"
echo " TARGET=$TARGET"
rm -rf "$APP"
mkdir -p "$MACOS_DIR" "$RES_DIR"
SOURCES=()
while IFS= read -r src; do
SOURCES+=("$src")
done < <(find "$ROOT/Sources" -name '*.swift' | LC_ALL=C sort)
if [ "${#SOURCES[@]}" -eq 0 ]; then
echo "no Swift sources under $ROOT/Sources" >&2
exit 1
fi
OPT_FLAGS=(-O)
if [ "$CONFIGURATION" != "Release" ]; then
OPT_FLAGS=(-Onone -g)
fi
"$SWIFT" \
-sdk "$SDKROOT" \
-target "$TARGET" \
-swift-version 5 \
"${OPT_FLAGS[@]}" \
-whole-module-optimization \
-module-name TargetPrint \
-import-objc-header "$ROOT/Bridging-Header.h" \
-Xcc "-I${SDKROOT}/usr/include" \
-framework AppKit \
-framework Foundation \
-framework CoreGraphics \
-framework ImageIO \
-framework ApplicationServices \
-lcups \
-o "$BIN" \
"${SOURCES[@]}"
test -x "$BIN"
# Info.plist — expand the Xcode build-setting placeholder.
sed 's/\$(PRODUCT_BUNDLE_IDENTIFIER)/com.iccery.TargetPrint/g' \
"$ROOT/Info.plist" > "$APP/Contents/Info.plist"
printf 'APPL????' > "$APP/Contents/PkgInfo"
# Resources
cp "$ROOT/Resources/ICCery-logo.svg" "$RES_DIR/" 2>/dev/null || true
cp "$ROOT/Resources/app-icon.svg" "$RES_DIR/" 2>/dev/null || true
cp "$ROOT/Resources/sample.targetjob" "$RES_DIR/" 2>/dev/null || true
ICON_SRC="$ROOT/Resources/Assets.xcassets/AppIcon.appiconset/icon_1024.png"
if [ -f "$ICON_SRC" ] && command -v sips >/dev/null 2>&1; then
ICONSET="$(mktemp -d /tmp/tp-iconset-XXXXXX)"
mkdir -p "$ICONSET/AppIcon.iconset"
for pair in 16:icon_16x16 32:icon_32x32 128:icon_128x128 256:icon_256x256 512:icon_512x512; do
size="${pair%%:*}"
name="${pair##*:}"
sips -z "$size" "$size" "$ICON_SRC" --out "$ICONSET/AppIcon.iconset/${name}.png" >/dev/null
sips -z $((size * 2)) $((size * 2)) "$ICON_SRC" --out "$ICONSET/AppIcon.iconset/${name}@2x.png" >/dev/null
done
if command -v iconutil >/dev/null 2>&1 && iconutil -c icns "$ICONSET/AppIcon.iconset" -o "$RES_DIR/AppIcon.icns" 2>/dev/null; then
echo " AppIcon.icns"
else
cp "$ICON_SRC" "$RES_DIR/AppIcon.png"
fi
rm -rf "$ICONSET"
fi
# shellcheck source=lib.sh
source "$(dirname "$0")/lib.sh"
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"