|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +################################################################################ |
| 4 | +# Build XCFramework Script for BEMCheckBox |
| 5 | +# |
| 6 | +# This script builds a universal XCFramework that works on both |
| 7 | +# iOS Simulator and iOS Device platforms. |
| 8 | +# |
| 9 | +# Usage: |
| 10 | +# ./Scripts/build-xcframework.sh [--help] |
| 11 | +# |
| 12 | +# Output: |
| 13 | +# Temp/Release-fat/BEMCheckBox.xcframework |
| 14 | +# |
| 15 | +################################################################################ |
| 16 | + |
| 17 | +set -e # Exit on error |
| 18 | +set -o pipefail # Catch errors in pipes |
| 19 | + |
| 20 | +# Configuration |
| 21 | +PROJECT_PATH="Sample Project/CheckBox.xcodeproj" |
| 22 | +SCHEME="BEMCheckBox" |
| 23 | +CONFIGURATION="Release" |
| 24 | +ARCHIVE_DIR="Temp/Archives" |
| 25 | +OUTPUT_DIR="Temp/Release-fat" |
| 26 | + |
| 27 | +# Archive paths |
| 28 | +IOS_SIMULATOR_ARCHIVE="$ARCHIVE_DIR/BEMCheckBox-iOS_Simulator.xcarchive" |
| 29 | +IOS_DEVICE_ARCHIVE="$ARCHIVE_DIR/BEMCheckBox-iOS.xcarchive" |
| 30 | + |
| 31 | +# Colors for output |
| 32 | +RED='\033[0;31m' |
| 33 | +GREEN='\033[0;32m' |
| 34 | +YELLOW='\033[1;33m' |
| 35 | +BLUE='\033[0;34m' |
| 36 | +NC='\033[0m' # No Color |
| 37 | + |
| 38 | +################################################################################ |
| 39 | +# Helper Functions |
| 40 | +################################################################################ |
| 41 | + |
| 42 | +print_header() { |
| 43 | + echo "" |
| 44 | + echo -e "${BLUE}===================================================================${NC}" |
| 45 | + echo -e "${BLUE}$1${NC}" |
| 46 | + echo -e "${BLUE}===================================================================${NC}" |
| 47 | + echo "" |
| 48 | +} |
| 49 | + |
| 50 | +print_success() { |
| 51 | + echo -e "${GREEN}✓ $1${NC}" |
| 52 | +} |
| 53 | + |
| 54 | +print_error() { |
| 55 | + echo -e "${RED}✗ $1${NC}" |
| 56 | +} |
| 57 | + |
| 58 | +print_info() { |
| 59 | + echo -e "${BLUE}ℹ $1${NC}" |
| 60 | +} |
| 61 | + |
| 62 | +show_help() { |
| 63 | + cat << EOF |
| 64 | +Build XCFramework Script for BEMCheckBox |
| 65 | +
|
| 66 | +This script builds a universal XCFramework that works on both |
| 67 | +iOS Simulator and iOS Device platforms. |
| 68 | +
|
| 69 | +USAGE: |
| 70 | + ./Scripts/build-xcframework.sh [--help] |
| 71 | +
|
| 72 | +OUTPUT: |
| 73 | + Temp/Release-fat/BEMCheckBox.xcframework |
| 74 | +
|
| 75 | +EOF |
| 76 | +} |
| 77 | + |
| 78 | +# Reusable build function |
| 79 | +build_archive() { |
| 80 | + local platform_name="$1" |
| 81 | + local destination="$2" |
| 82 | + local archive_path="$3" |
| 83 | + |
| 84 | + print_header "Building for $platform_name" |
| 85 | + |
| 86 | + xcodebuild archive \ |
| 87 | + -project "$PROJECT_PATH" \ |
| 88 | + -scheme "$SCHEME" \ |
| 89 | + -destination "$destination" \ |
| 90 | + -configuration "$CONFIGURATION" \ |
| 91 | + -archivePath "$archive_path" \ |
| 92 | + SKIP_INSTALL=NO \ |
| 93 | + BUILD_LIBRARY_FOR_DISTRIBUTION=YES |
| 94 | + |
| 95 | + print_success "$platform_name build completed" |
| 96 | + echo "" |
| 97 | + echo "Listing: $archive_path" |
| 98 | + ls -laR "$archive_path" |
| 99 | + echo "" |
| 100 | +} |
| 101 | + |
| 102 | +# Validate environment |
| 103 | +validate_environment() { |
| 104 | + if ! command -v xcodebuild &> /dev/null; then |
| 105 | + print_error "xcodebuild not found. Please install Xcode." |
| 106 | + exit 1 |
| 107 | + fi |
| 108 | + |
| 109 | + if [[ ! -d "$PROJECT_PATH" ]]; then |
| 110 | + print_error "Project not found: $PROJECT_PATH" |
| 111 | + exit 1 |
| 112 | + fi |
| 113 | +} |
| 114 | + |
| 115 | +################################################################################ |
| 116 | +# Parse Arguments |
| 117 | +################################################################################ |
| 118 | + |
| 119 | +if [[ "$1" == "--help" ]]; then |
| 120 | + show_help |
| 121 | + exit 0 |
| 122 | +fi |
| 123 | + |
| 124 | +################################################################################ |
| 125 | +# Main Build Process |
| 126 | +################################################################################ |
| 127 | + |
| 128 | +START_TIME=$(date +%s) |
| 129 | + |
| 130 | +print_header "BEMCheckBox XCFramework Build" |
| 131 | + |
| 132 | +print_info "Configuration: $CONFIGURATION" |
| 133 | +print_info "Project: $PROJECT_PATH" |
| 134 | +print_info "Scheme: $SCHEME" |
| 135 | +echo "" |
| 136 | + |
| 137 | +# Validate environment |
| 138 | +validate_environment |
| 139 | + |
| 140 | +# Clean up previous builds |
| 141 | +print_info "Cleaning previous builds..." |
| 142 | +rm -rf "$ARCHIVE_DIR" |
| 143 | +rm -rf "$OUTPUT_DIR" |
| 144 | + |
| 145 | +# Build for iOS Simulator |
| 146 | +build_archive \ |
| 147 | + "iOS Simulator" \ |
| 148 | + "generic/platform=iOS Simulator" \ |
| 149 | + "$IOS_SIMULATOR_ARCHIVE" |
| 150 | + |
| 151 | +# Build for iOS Device |
| 152 | +build_archive \ |
| 153 | + "iOS Device" \ |
| 154 | + "generic/platform=iOS" \ |
| 155 | + "$IOS_DEVICE_ARCHIVE" |
| 156 | + |
| 157 | +# Create XCFramework |
| 158 | +print_header "Creating XCFramework" |
| 159 | + |
| 160 | +xcodebuild -create-xcframework \ |
| 161 | + -archive "$IOS_SIMULATOR_ARCHIVE" -framework "BEMCheckBox.framework" \ |
| 162 | + -archive "$IOS_DEVICE_ARCHIVE" -framework "BEMCheckBox.framework" \ |
| 163 | + -output "$OUTPUT_DIR/BEMCheckBox.xcframework" |
| 164 | + |
| 165 | +print_success "XCFramework created successfully" |
| 166 | +echo "" |
| 167 | + |
| 168 | +# Show final output details |
| 169 | +print_info "Output location: $OUTPUT_DIR/BEMCheckBox.xcframework" |
| 170 | +ls -laR "$OUTPUT_DIR/BEMCheckBox.xcframework" |
| 171 | +echo "" |
| 172 | + |
| 173 | +# Show supported architectures |
| 174 | +print_header "Supported Architectures" |
| 175 | + |
| 176 | +print_info "iOS Simulator architectures:" |
| 177 | +file "$OUTPUT_DIR/BEMCheckBox.xcframework/ios-arm64_x86_64-simulator/BEMCheckBox.framework/BEMCheckBox" |
| 178 | +echo "" |
| 179 | + |
| 180 | +print_info "iOS Device architectures:" |
| 181 | +file "$OUTPUT_DIR/BEMCheckBox.xcframework/ios-arm64/BEMCheckBox.framework/BEMCheckBox" |
| 182 | +echo "" |
| 183 | + |
| 184 | +# Build summary |
| 185 | +END_TIME=$(date +%s) |
| 186 | +DURATION=$((END_TIME - START_TIME)) |
| 187 | + |
| 188 | +print_header "Build Summary" |
| 189 | +print_success "XCFramework: $OUTPUT_DIR/BEMCheckBox.xcframework" |
| 190 | +print_info "Size: $(du -sh "$OUTPUT_DIR/BEMCheckBox.xcframework" | cut -f1)" |
| 191 | +print_info "Configuration: $CONFIGURATION" |
| 192 | +print_info "Build time: ${DURATION}s" |
| 193 | +echo "" |
0 commit comments