name: CrepusMobileApp
options:
  bundleIdPrefix: dev.crepuscularity
  deploymentTarget:
    iOS: "17.0"
  createIntermediateGroups: true
settings:
  base:
    SWIFT_VERSION: "5.9"
    TARGETED_DEVICE_FAMILY: "1,2"
packages:
  NativeShell:
    path: .
targets:
  CrepusMobileApp:
    type: application
    platform: iOS
    sources:
      - path: App
    settings:
      base:
        LIBRARY_SEARCH_PATHS[sdk=iphoneos*]: "$(PROJECT_DIR)/build/rust/aarch64-apple-ios"
        LIBRARY_SEARCH_PATHS[sdk=iphonesimulator*]: "$(PROJECT_DIR)/build/rust/aarch64-apple-ios-sim"
        OTHER_LDFLAGS: "-lcrepus_mobile_actions"
        EXCLUDED_ARCHS[sdk=iphonesimulator*]: "x86_64"
        GENERATE_INFOPLIST_FILE: YES
        INFOPLIST_KEY_UILaunchScreen_Generation: YES
        PRODUCT_BUNDLE_IDENTIFIER: dev.crepuscularity.mobile
    dependencies:
      - package: NativeShell
        product: NativeShell
    preBuildScripts:
      - name: Build Rust Actions
        outputFiles:
          - "$(PROJECT_DIR)/build/rust/aarch64-apple-ios/libcrepus_mobile_actions.a"
          - "$(PROJECT_DIR)/build/rust/aarch64-apple-ios-sim/libcrepus_mobile_actions.a"
        script: |
          set -euo pipefail
          export PATH="$HOME/.cargo/bin:/opt/homebrew/bin:/usr/local/bin:$PATH"
          if [ "${PLATFORM_NAME:-iphonesimulator}" = "iphoneos" ]; then
            rust_target=aarch64-apple-ios
          else
            rust_target=aarch64-apple-ios-sim
          fi
          rustup target add "$rust_target" >/dev/null
          cargo_profile=debug
          if [ "${CONFIGURATION:-Debug}" = "Release" ]; then
            cargo_profile=release
            cargo build --manifest-path "$PROJECT_DIR/../rust/Cargo.toml" --target "$rust_target" --release
          else
            cargo build --manifest-path "$PROJECT_DIR/../rust/Cargo.toml" --target "$rust_target"
          fi
          mkdir -p "$PROJECT_DIR/build/rust/$rust_target"
          cp "$PROJECT_DIR/../rust/target/$rust_target/$cargo_profile/libcrepus_mobile_actions.a" "$PROJECT_DIR/build/rust/$rust_target/"
