#!/bin/bash
set -e

SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
OUTPUT_DIR="$PROJECT_DIR/target/ios"

echo "Building AIP for iOS..."
echo "Project directory: $PROJECT_DIR"

install_target() {
    local TARGET=$1
    if ! rustup target list | grep -q "$TARGET (installed)"; then
        echo "Installing $TARGET..."
        rustup target add "$TARGET"
    fi
}

echo ""
echo "Building for aarch64-apple-ios (device)..."
install_target "aarch64-apple-ios"
cargo build --release --target "aarch64-apple-ios" --features ffi

echo ""
echo "Building for aarch64-apple-ios-sim (simulator - Apple Silicon)..."
install_target "aarch64-apple-ios-sim"
cargo build --release --target "aarch64-apple-ios-sim" --features ffi

echo ""
echo "Building for x86_64-apple-ios (simulator - Intel)..."
install_target "x86_64-apple-ios"
cargo build --release --target "x86_64-apple-ios" --features ffi
