#!/bin/bash # UniFFI iOS and tvOS Build Script using -Zbuild-std # Uses nightly cargo with -Zbuild-std to build tvOS targets set -e echo "๐Ÿ”จ Building UniFFI iOS and tvOS Framework with -Zbuild-std..." # Clean previous builds echo "๐Ÿงน Cleaning previous builds..." rm -rf target/ rm -rf bindings/ mkdir -p bindings/ios # Install nightly toolchain echo "๐ŸŒ™ Installing nightly toolchain..." rustup toolchain install nightly rustup component add rust-src --toolchain nightly # Install uniffi_bindgen if not present if ! command -v uniffi-bindgen &> /dev/null; then echo "๐Ÿ“ฆ Installing uniffi_bindgen..." cargo install uniffi_bindgen --bin uniffi-bindgen fi # iOS targets (stable) IOS_TARGETS=( "aarch64-apple-ios" # iOS device (ARM64) "x86_64-apple-ios" # iOS simulator (Intel) ) # tvOS targets (require -Zbuild-std) TVOS_TARGETS=( "aarch64-apple-tvos" # tvOS device (ARM64) "x86_64-apple-tvos" # tvOS simulator (Intel) ) echo "๐Ÿ“ฑ Installing iOS targets..." for target in "${IOS_TARGETS[@]}"; do rustup target add "$target" done echo "๐Ÿ”ง Building Rust library for iOS targets..." for target in "${IOS_TARGETS[@]}"; do echo "Building for $target..." cargo build --release --target "$target" --features uniffi done echo "๐Ÿ“บ Building Rust library for tvOS targets with -Zbuild-std..." for target in "${TVOS_TARGETS[@]}"; do echo "Building for $target..." cargo +nightly build --release --target "$target" --features uniffi -Zbuild-std done echo "๐Ÿ”— Creating separate libraries..." # iOS universal library lipo -create \ target/aarch64-apple-ios/release/libchurch_core.a \ target/x86_64-apple-ios/release/libchurch_core.a \ -output bindings/ios/libchurch_core_ios.a # tvOS universal library lipo -create \ target/aarch64-apple-tvos/release/libchurch_core.a \ target/x86_64-apple-tvos/release/libchurch_core.a \ -output bindings/ios/libchurch_core_tvos.a # Default to iOS library cp bindings/ios/libchurch_core_ios.a bindings/ios/libchurch_core_universal.a echo "โšก Generating Swift bindings..." uniffi-bindgen generate \ src/church_core.udl \ --language swift \ --out-dir bindings/ios \ --lib-file target/aarch64-apple-ios/release/libchurch_core.a echo "๐Ÿ“‹ Generating module map..." cat > bindings/ios/church_coreFFI.modulemap << EOF module church_coreFFI { header "church_coreFFI.h" export * } EOF echo "๐Ÿ“ฆ Moving files to iOS project..." IOS_PROJECT_DIR="../RTSDA-iOS/RTSDA" cp bindings/ios/church_core.swift "$IOS_PROJECT_DIR/" cp bindings/ios/church_coreFFI.h "$IOS_PROJECT_DIR/" cp bindings/ios/church_coreFFI.modulemap "$IOS_PROJECT_DIR/" cp bindings/ios/libchurch_core_universal.a "$IOS_PROJECT_DIR/libchurch_core.a" # Also copy the separate libraries for manual swapping if needed cp bindings/ios/libchurch_core_ios.a "$IOS_PROJECT_DIR/" cp bindings/ios/libchurch_core_tvos.a "$IOS_PROJECT_DIR/" echo "โœ… UniFFI iOS and tvOS framework build complete!" echo "๐Ÿ“ Generated separate libraries:" echo " - libchurch_core.a (default: iOS)" echo " - libchurch_core_ios.a (iOS only)" echo " - libchurch_core_tvos.a (tvOS only)" echo "๐ŸŽฏ Files copied to: $IOS_PROJECT_DIR" echo "๐Ÿ’ก If tvOS build fails, manually swap to libchurch_core_tvos.a"