#!/usr/bin/env bash # Build Navis iOS device IPA (+ optional simulator zip). # # Usage: # ./scripts/build-ios.sh # # device IPA (unsigned if no Team) + simulator zip # NAVIS_IOS_TEAM_ID=XXXXXXXXXX ./scripts/build-ios.sh # # signed archive + exported IPA # NAVIS_IOS_SKIP_SIMULATOR=1 ./scripts/build-ios.sh # # device only # # Optional: # NAVIS_IOS_SIGN_IDENTITY="Apple Development: …" # NAVIS_IOS_EXPORT_METHOD=development|ad-hoc|enterprise|app-store set -euo pipefail ROOT="$(cd "$(dirname "$0")/.." && pwd)" IOS="$ROOT/ios" OUT="$ROOT/dist/navis-release/ios" PROJECT="$IOS/Navis.xcodeproj" SCHEME=Navis CONFIG=Release # Keep VERSION_FULL in sync with internal/update/update.go (also via sync-version.py). VERSION_FULL="$( python3 - <&2 exit 1 } echo "==> Navis iOS build $VERSION_FULL" # Ensure Info.plist stays aligned with update.go. python3 "$ROOT/scripts/sync-version.py" # Ensure LibXray + Hev are present "$ROOT/scripts/fetch-ios-cores.sh" mkdir -p "$OUT" find "$OUT" -mindepth 1 -maxdepth 1 ! -name '.gitkeep' -exec rm -rf {} + TEAM="${NAVIS_IOS_TEAM_ID:-}" EXPORT_METHOD="${NAVIS_IOS_EXPORT_METHOD:-development}" DERIVED="${TMPDIR:-/tmp}/navis-ios-derived" rm -rf "$DERIVED" mkdir -p "$DERIVED" package_ipa() { local app_path="$1" local ipa_path="$2" local stage stage="$(mktemp -d)" mkdir -p "$stage/Payload" ditto "$app_path" "$stage/Payload/Navis.app" ( cd "$stage" zip -qry "$ipa_path" Payload ) rm -rf "$stage" } # --- Device (iphoneos) --- echo "==> Building iOS device ($CONFIG, sdk=iphoneos)" DEV_ARGS=( -project "$PROJECT" -scheme "$SCHEME" -configuration "$CONFIG" -destination "generic/platform=iOS" -derivedDataPath "$DERIVED" -sdk iphoneos ONLY_ACTIVE_ARCH=NO ) if [[ -n "$TEAM" ]]; then DEV_ARGS+=(DEVELOPMENT_TEAM="$TEAM") if [[ -n "${NAVIS_IOS_SIGN_IDENTITY:-}" ]]; then DEV_ARGS+=(CODE_SIGN_IDENTITY="$NAVIS_IOS_SIGN_IDENTITY") fi echo "==> Archiving (Team=$TEAM)" ARCHIVE="$OUT/Navis.xcarchive" xcodebuild "${DEV_ARGS[@]}" -archivePath "$ARCHIVE" archive EXPORT_PLIST="$OUT/ExportOptions.plist" cat >"$EXPORT_PLIST" < method ${EXPORT_METHOD} teamID ${TEAM} signingStyle automatic compileBitcode stripSwiftSymbols EOF EXPORT_DIR="$OUT/export" rm -rf "$EXPORT_DIR" mkdir -p "$EXPORT_DIR" echo "==> Exporting signed IPA (method=$EXPORT_METHOD)" xcodebuild -exportArchive \ -archivePath "$ARCHIVE" \ -exportPath "$EXPORT_DIR" \ -exportOptionsPlist "$EXPORT_PLIST" IPA="$(find "$EXPORT_DIR" -name '*.ipa' | head -n1 || true)" if [[ -n "${IPA:-}" ]]; then cp "$IPA" "$OUT/Navis-${VERSION_FULL}.ipa" cp "$IPA" "$OUT/Navis.ipa" echo "wrote $OUT/Navis-${VERSION_FULL}.ipa (signed)" else echo "error: signed export produced no .ipa" >&2 ls -la "$EXPORT_DIR" || true exit 1 fi else DEV_ARGS+=( CODE_SIGNING_ALLOWED=NO CODE_SIGNING_REQUIRED=NO CODE_SIGN_IDENTITY=- EXPAND_SDK_VARIABLES=YES ) xcodebuild "${DEV_ARGS[@]}" build DEV_APP="$(find "$DERIVED/Build/Products" -path '*iphoneos/Navis.app' -type d | head -n1 || true)" if [[ -z "${DEV_APP:-}" || ! -d "$DEV_APP" ]]; then echo "error: device Navis.app not found under $DERIVED" >&2 find "$DERIVED/Build/Products" -name 'Navis.app' -type d 2>/dev/null || true exit 1 fi cp -R "$DEV_APP" "$OUT/Navis-device.app" package_ipa "$DEV_APP" "$OUT/Navis-${VERSION_FULL}.ipa" cp "$OUT/Navis-${VERSION_FULL}.ipa" "$OUT/Navis.ipa" echo "wrote $OUT/Navis-device.app" echo "wrote $OUT/Navis-${VERSION_FULL}.ipa (UNSIGNED — re-sign before install)" echo "wrote $OUT/Navis.ipa" fi # --- Simulator (optional) --- if [[ "${NAVIS_IOS_SKIP_SIMULATOR:-}" != "1" ]]; then echo "==> Building iOS Simulator ($CONFIG)" SIM_ARGS=( -project "$PROJECT" -scheme "$SCHEME" -configuration "$CONFIG" -destination "generic/platform=iOS Simulator" -derivedDataPath "$DERIVED" ONLY_ACTIVE_ARCH=NO ) if [[ -n "$TEAM" ]]; then SIM_ARGS+=(DEVELOPMENT_TEAM="$TEAM") else SIM_ARGS+=(CODE_SIGNING_ALLOWED=NO CODE_SIGNING_REQUIRED=NO) fi xcodebuild "${SIM_ARGS[@]}" build SIM_APP="$(find "$DERIVED/Build/Products" -path '*iphonesimulator/Navis.app' -type d | head -n1 || true)" if [[ -n "${SIM_APP:-}" && -d "$SIM_APP" ]]; then cp -R "$SIM_APP" "$OUT/Navis-simulator.app" ( cd "$OUT" ditto -c -k --sequesterRsrc --keepParent Navis-simulator.app "Navis-${VERSION_FULL}-simulator.app.zip" ) echo "wrote $OUT/Navis-simulator.app" fi fi echo "done → $OUT" ls -lh "$OUT"/*.ipa "$OUT"/*.app 2>/dev/null || ls -lh "$OUT"