#!/bin/bash # UniFFI iOS and tvOS Build Script # Generates Swift bindings and universal framework for both iOS and tvOS set -e echo "๐Ÿ”จ Building UniFFI iOS and tvOS Framework..." # Clean previous builds echo "๐Ÿงน Cleaning previous builds..." rm -rf target/ rm -rf bindings/ mkdir -p bindings/ios # Install nightly toolchain for tvOS support echo "๐ŸŒ™ Installing nightly toolchain for tvOS support..." rustup toolchain install nightly rustup component add rust-std --toolchain nightly --target aarch64-apple-tvos rustup component add rust-std --toolchain nightly --target aarch64-apple-tvos-sim rustup component add rust-std --toolchain nightly --target x86_64-apple-tvos # 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 IOS_TARGETS=( "aarch64-apple-ios" # iOS device (ARM64) "x86_64-apple-ios" # iOS simulator (Intel) ) # tvOS targets TVOS_TARGETS=( "aarch64-apple-tvos" # tvOS device (ARM64) "aarch64-apple-tvos-sim" # tvOS simulator (Apple Silicon) "x86_64-apple-tvos" # tvOS simulator (Intel) ) echo "๐Ÿ“ฑ Installing iOS targets..." for target in "${IOS_TARGETS[@]}"; do rustup target add "$target" done echo "๐Ÿ“บ Installing tvOS targets..." for target in "${TVOS_TARGETS[@]}"; do rustup target add "$target" --toolchain nightly 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..." for target in "${TVOS_TARGETS[@]}"; do echo "Building for $target..." cargo +nightly build --release --target "$target" --features uniffi done echo "๐Ÿ”— Creating universal libraries..." # Create 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 # Create tvOS universal library lipo -create \ target/aarch64-apple-tvos/release/libchurch_core.a \ target/aarch64-apple-tvos-sim/release/libchurch_core.a \ target/x86_64-apple-tvos/release/libchurch_core.a \ -output bindings/ios/libchurch_core_tvos.a # Create combined universal library for Xcode (it will pick the right slice) lipo -create \ target/aarch64-apple-ios/release/libchurch_core.a \ target/x86_64-apple-ios/release/libchurch_core.a \ target/aarch64-apple-tvos/release/libchurch_core.a \ target/x86_64-apple-tvos/release/libchurch_core.a \ -output bindings/ios/libchurch_core_universal.a echo "โšก Generating Swift bindings..." # Generate Swift bindings using uniffi_bindgen 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..." # Create module map for Swift integration cat > bindings/ios/church_coreFFI.modulemap << EOF module church_coreFFI { header "church_coreFFI.h" export * } EOF echo "๐Ÿ“ฆ Moving files to iOS project..." # Copy generated 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" echo "โœ… UniFFI iOS and tvOS framework build complete!" echo "๐Ÿ“ Generated files:" echo " - church_core.swift (Swift bindings)" echo " - church_coreFFI.h (C header)" echo " - church_coreFFI.modulemap (Module map)" echo " - libchurch_core.a (Universal static library - iOS + tvOS)" echo "" echo "๐ŸŽฏ Files copied to: $IOS_PROJECT_DIR" echo "๐Ÿ’ก You can now build your iOS/tvOS project in Xcode!" echo "" echo "๐Ÿ“บ Libraries also available separately:" echo " - bindings/ios/libchurch_core_ios.a (iOS only)" echo " - bindings/ios/libchurch_core_tvos.a (tvOS only)"