#!/bin/zsh
set -o pipefail  # Fail if xcodebuild fails, even with xcbeautify

# --- Configuration ---
SCHEME="EzTimer"
DEVICE_NAME="iPhone 17 Pro"
BUILD_PATH="./build"

echo "🔍 Checking compilation for $SCHEME..."

# Build Only (No Install/Launch)
# We use 'env -u' to hide Homebrew variables
# We use '-derivedDataPath' to keep it isolated
env -u CC -u CXX -u LIBCLANG_PATH xcodebuild \
  -scheme "$SCHEME" \
  -destination "platform=iOS Simulator,name=$DEVICE_NAME" \
  -configuration Debug \
  -derivedDataPath "$BUILD_PATH" \
  build

# Check exit code of the pipeline
if [ $? -eq 0 ]; then
    echo "✅ Build Succeeded. No errors found."
else
    echo "❌ Build Failed."
    exit 1
fi
