char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
e9b6350e6
char/aliceai-t5-moe
1#!/usr/bin/env bash 2# validate-ios.sh - Validate iOS Application with embedded llama.xcframework using SwiftUI 3 4# Authentication options (optional) (can be set via environment variables) 5# To use: export APPLE_ID=your.email@example.com 6# export APPLE_PASSWORD=your-app-specific-password 7# ./validate-ios.sh 8APPLE_ID =${ APPLE_ID :- "" } 9APPLE_PASSWORD =${ APPLE_PASSWORD :- "" } 10 11# Ensure the script exits on error 12set -e 13 14# Function to print usage instructions 15print_usage () { 16echo "Usage: ./validate-ios.sh [OPTIONS]" 17echo "" 18echo "Options:" 19echo " --help Show this help message" 20echo " --apple-id EMAIL Apple ID email for validation" 21echo " --apple-password PWD App-specific password for Apple ID" 22echo "" 23echo "Environment variables:" 24echo " APPLE_ID Apple ID email for validation" 25echo " APPLE_PASSWORD App-specific password for Apple ID" 26echo "" 27echo "Notes:" 28echo " - Command line options take precedence over environment variables" 29echo " - Authentication is optional. If not provided, alternative validation will be performed" 30echo " - For APPLE_PASSWORD, use an app-specific password generated at https://appleid.apple.com/account/manage" 31} 32 33# Parse command line arguments 34while [[$ # -gt 0 ]];do 35case $ 1 in 36 --help) 37print_usage 38exit 0 39 ;; 40 --apple-id) 41APPLE_ID =" $ 2 " 42shift 2 43 ;; 44 --apple-password) 45APPLE_PASSWORD =" $ 2 " 46shift 2 47 ;; 48 *) 49echo "Unknown option: $ 1 " 50print_usage 51exit 1 52 ;; 53esac 54done 55 56# Function to clean up in case of error 57cleanup () { 58# Don't clean up temp files on error to help with debugging 59echo "===== iOS Validation Process Failed =====" 60exit 1 61} 62 63# Set up trap to call cleanup function on error 64trap cleanup ERR 65 66set -e # Exit on any error 67 68ROOT_DIR =" $( cd " $( dirname " ${ BASH_SOURCE [0]} " ) /../.." && pwd ) " 69BUILD_DIR =" ${ ROOT_DIR } /validation-builds/ios" 70 71# Configuration 72APP_NAME ="iOSLlamaTest" 73BUNDLE_ID ="org.ggml.iOSLlamaTest" 74XCFRAMEWORK_PATH =" ${ ROOT_DIR } /build-apple/llama.xcframework" 75TEMP_DIR =" ${ BUILD_DIR } /temp" 76ARCHIVE_PATH =" ${ BUILD_DIR } / ${ APP_NAME } .xcarchive" 77IPA_PATH =" ${ BUILD_DIR } / ${ APP_NAME } .ipa" 78VALIDATION_DIR =" ${ BUILD_DIR } /validation" 79 80# Create necessary directories 81mkdir -p " ${ BUILD_DIR } " 82mkdir -p " ${ TEMP_DIR } " 83mkdir -p " ${ VALIDATION_DIR } " 84 85echo "===== iOS Validation Process Started =====" 86 87# 1. Create a simple test app project 88echo "Creating test iOS app project..." 89mkdir -p " ${ TEMP_DIR } / ${ APP_NAME } / ${ APP_NAME } " 90cat > " ${ TEMP_DIR } / ${ APP_NAME } / ${ APP_NAME } /Info.plist" <<EOF 91<?xml version="1.0" encoding="UTF-8"?> 92<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> 93<plist version="1.0"> 94<dict> 95<key>CFBundleDevelopmentRegion</key> 96<string>en</string> 97<key>CFBundleExecutable</key> 98<string> ${ APP_NAME } </string> 99<key>CFBundleIdentifier</key> 100<string> ${ BUNDLE_ID } </string> 101<key>CFBundleInfoDictionaryVersion</key> 102<string>6.0</string> 103<key>CFBundleName</key> 104<string> ${ APP_NAME } </string> 105<key>CFBundlePackageType</key> 106<string>APPL</string> 107<key>CFBundleShortVersionString</key> 108<string>1.0</string> 109<key>CFBundleVersion</key> 110<string>1</string> 111<key>LSRequiresIPhoneOS</key> 112<true/> 113<key>UILaunchScreen</key> 114<dict/> 115<key>UIRequiredDeviceCapabilities</key> 116<array> 117<string>armv7</string> 118</array> 119<key>UISupportedInterfaceOrientations</key> 120<array> 121<string>UIInterfaceOrientationPortrait</string> 122</array> 123</dict> 124</plist> 125EOF 126 127# Create SwiftUI app files 128mkdir -p " ${ TEMP_DIR } / ${ APP_NAME } / ${ APP_NAME } /Sources" 129 130# Create App.swift 131cat > " ${ TEMP_DIR } / ${ APP_NAME } / ${ APP_NAME } /Sources/App.swift" <<EOF 132import SwiftUI 133import llama 134 135@main 136struct LlamaTestApp: App { 137var body: some Scene { 138WindowGroup { 139ContentView() 140} 141} 142} 143EOF 144 145# Create ContentView.swift 146cat > " ${ TEMP_DIR } / ${ APP_NAME } / ${ APP_NAME } /Sources/ContentView.swift" <<EOF 147import SwiftUI 148import llama 149 150struct ContentView: View { 151// Test that we can initialize a llama context params struct 152let params = llama_context_default_params() 153 154var body: some View { 155VStack(spacing: 20) { 156Text("Llama Framework Test") 157.font(.largeTitle) 158.padding() 159 160Text("llama_context_default_params() created successfully") 161.font(.headline) 162.multilineTextAlignment(.center) 163.padding() 164 165// Display some param values to confirm the framework is working 166Text("n_ctx: \(params.n_ctx)") 167.font(.body) 168 169Text("n_batch: \(params.n_batch)") 170.font(.body) 171 172Spacer() 173} 174.padding() 175} 176} 177 178struct ContentView_Previews: PreviewProvider { 179static var previews: some View { 180ContentView() 181} 182} 183EOF 184 185# Create project.pbxproj, fixing the framework search paths issues 186mkdir -p " ${ TEMP_DIR } / ${ APP_NAME } / ${ APP_NAME } .xcodeproj" 187cat > " ${ TEMP_DIR } / ${ APP_NAME } / ${ APP_NAME } .xcodeproj/project.pbxproj" <<'EOF' 188// !$*UTF8*$! 189{ 190archiveVersion = 1; 191classes = { 192}; 193objectVersion = 54; 194objects = { 195 196/* Begin PBXBuildFile section */ 19711111111111111111111111 /* App.swift in Sources */ = {isa = PBXBuildFile; fileRef = 22222222222222222222222; }; 19833333333333333333333333 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 44444444444444444444444; }; 19955555555555555555555555 /* llama.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = 66666666666666666666666; }; 20077777777777777777777777 /* llama.xcframework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 66666666666666666666666; }; 201/* End PBXBuildFile section */ 202 203/* Begin PBXCopyFilesBuildPhase section */ 20488888888888888888888888 /* Embed Frameworks */ = { 205isa = PBXCopyFilesBuildPhase; 206buildActionMask = 2147483647; 207dstPath = ""; 208dstSubfolderSpec = 10; 209files = ( 21077777777777777777777777 /* llama.xcframework in Embed Frameworks */, 211); 212name = "Embed Frameworks"; 213runOnlyForDeploymentPostprocessing = 0; 214}; 215/* End PBXCopyFilesBuildPhase section */ 216 217/* Begin PBXFileReference section */ 218EOF 219 220# Continue with the project.pbxproj file, using the APP_NAME variable appropriately 221cat >> " ${ TEMP_DIR } / ${ APP_NAME } / ${ APP_NAME } .xcodeproj/project.pbxproj" <<EOF 22299999999999999999999999 /* ${ APP_NAME } .app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = " ${ APP_NAME } .app"; sourceTree = BUILT_PRODUCTS_DIR; }; 22322222222222222222222222 /* App.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = App.swift; sourceTree = "<group>"; }; 22444444444444444444444444 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; }; 225AAAAAAAAAAAAAAAAAAAAAAA /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; }; 22666666666666666666666666 /* llama.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; path = llama.xcframework; sourceTree = "<group>"; }; 227/* End PBXFileReference section */ 228EOF 229 230# Add the rest of the project file with fixed framework search paths 231cat >> " ${ TEMP_DIR } / ${ APP_NAME } / ${ APP_NAME } .xcodeproj/project.pbxproj" <<'EOF' 232/* Begin PBXFrameworksBuildPhase section */ 233BBBBBBBBBBBBBBBBBBBBBBBB /* Frameworks */ = { 234isa = PBXFrameworksBuildPhase; 235buildActionMask = 2147483647; 236files = ( 23755555555555555555555555 /* llama.xcframework in Frameworks */, 238); 239runOnlyForDeploymentPostprocessing = 0; 240}; 241/* End PBXFrameworksBuildPhase section */ 242 243/* Begin PBXGroup section */ 244EOF 245 246# Continue with the project.pbxproj file, using the APP_NAME variable appropriately 247cat >> " ${ TEMP_DIR } / ${ APP_NAME } / ${ APP_NAME } .xcodeproj/project.pbxproj" <<EOF 248CCCCCCCCCCCCCCCCCCCCCCCC /* Products */ = { 249isa = PBXGroup; 250children = ( 25199999999999999999999999 /* ${ APP_NAME } .app */, 252); 253name = Products; 254sourceTree = "<group>"; 255}; 256EOF 257 258cat >> " ${ TEMP_DIR } / ${ APP_NAME } / ${ APP_NAME } .xcodeproj/project.pbxproj" <<'EOF' 259DDDDDDDDDDDDDDDDDDDDDDDD /* Frameworks */ = { 260isa = PBXGroup; 261children = ( 26266666666666666666666666 /* llama.xcframework */, 263); 264name = Frameworks; 265sourceTree = "<group>"; 266}; 267EEEEEEEEEEEEEEEEEEEEEEEE = { 268isa = PBXGroup; 269children = ( 270FFFFFFFFFFFFFFFFFFFFFFFF /* iOSLlamaTest */, 271CCCCCCCCCCCCCCCCCCCCCCCC /* Products */, 272DDDDDDDDDDDDDDDDDDDDDDDD /* Frameworks */, 273); 274sourceTree = "<group>"; 275}; 276FFFFFFFFFFFFFFFFFFFFFFFF /* iOSLlamaTest */ = { 277isa = PBXGroup; 278children = ( 2791111111111111111111111AA /* Sources */, 280AAAAAAAAAAAAAAAAAAAAAAA /* Info.plist */, 281); 282path = "iOSLlamaTest"; 283sourceTree = "<group>"; 284}; 2851111111111111111111111AA /* Sources */ = { 286isa = PBXGroup; 287children = ( 28822222222222222222222222 /* App.swift */, 28944444444444444444444444 /* ContentView.swift */, 290); 291path = Sources; 292sourceTree = "<group>"; 293}; 294/* End PBXGroup section */ 295EOF 296 297# Continue with the project.pbxproj file, using the APP_NAME variable appropriately 298cat >> " ${ TEMP_DIR } / ${ APP_NAME } / ${ APP_NAME } .xcodeproj/project.pbxproj" <<EOF 299/* Begin PBXNativeTarget section */ 3003333333333333333333333AA /* ${ APP_NAME } */ = { 301isa = PBXNativeTarget; 302buildConfigurationList = 4444444444444444444444AA /* Build configuration list for PBXNativeTarget " ${ APP_NAME } " */; 303buildPhases = ( 3045555555555555555555555AA /* Sources */, 305BBBBBBBBBBBBBBBBBBBBBBBB /* Frameworks */, 3066666666666666666666666AA /* Resources */, 30788888888888888888888888 /* Embed Frameworks */, 308); 309buildRules = ( 310); 311dependencies = ( 312); 313name = " ${ APP_NAME } "; 314productName = " ${ APP_NAME } "; 315productReference = 99999999999999999999999 /* ${ APP_NAME } .app */; 316productType = "com.apple.product-type.application"; 317}; 318/* End PBXNativeTarget section */ 319 320/* Begin PBXProject section */ 3217777777777777777777777AA /* Project object */ = { 322isa = PBXProject; 323attributes = { 324LastSwiftUpdateCheck = 1240; 325LastUpgradeCheck = 1240; 326TargetAttributes = { 3273333333333333333333333AA = { 328CreatedOnToolsVersion = 12.4; 329}; 330}; 331}; 332buildConfigurationList = 8888888888888888888888AA /* Build configuration list for PBXProject " ${ APP_NAME } " */; 333compatibilityVersion = "Xcode 12.0"; 334developmentRegion = en; 335hasScannedForEncodings = 0; 336knownRegions = ( 337en, 338Base, 339); 340mainGroup = EEEEEEEEEEEEEEEEEEEEEEEE; 341productRefGroup = CCCCCCCCCCCCCCCCCCCCCCCC /* Products */; 342projectDirPath = ""; 343projectRoot = ""; 344targets = ( 3453333333333333333333333AA /* ${ APP_NAME } */, 346); 347}; 348/* End PBXProject section */ 349EOF 350 351# Add the rest of the file with correct FRAMEWORK_SEARCH_PATHS 352cat >> " ${ TEMP_DIR } / ${ APP_NAME } / ${ APP_NAME } .xcodeproj/project.pbxproj" <<'EOF' 353/* Begin PBXResourcesBuildPhase section */ 3546666666666666666666666AA /* Resources */ = { 355isa = PBXResourcesBuildPhase; 356buildActionMask = 2147483647; 357files = ( 358); 359runOnlyForDeploymentPostprocessing = 0; 360}; 361/* End PBXResourcesBuildPhase section */ 362 363/* Begin PBXSourcesBuildPhase section */ 3645555555555555555555555AA /* Sources */ = { 365isa = PBXSourcesBuildPhase; 366buildActionMask = 2147483647; 367files = ( 36833333333333333333333333 /* ContentView.swift in Sources */, 36911111111111111111111111 /* App.swift in Sources */, 370); 371runOnlyForDeploymentPostprocessing = 0; 372}; 373/* End PBXSourcesBuildPhase section */ 374 375/* Begin XCBuildConfiguration section */ 3769999999999999999999999AA /* Debug */ = { 377isa = XCBuildConfiguration; 378buildSettings = { 379ALWAYS_SEARCH_USER_PATHS = NO; 380CLANG_ANALYZER_NONNULL = YES; 381CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 382CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 383CLANG_CXX_LIBRARY = "libc++"; 384CLANG_ENABLE_MODULES = YES; 385CLANG_ENABLE_OBJC_ARC = YES; 386CLANG_ENABLE_OBJC_WEAK = YES; 387CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 388CLANG_WARN_BOOL_CONVERSION = YES; 389CLANG_WARN_COMMA = YES; 390CLANG_WARN_CONSTANT_CONVERSION = YES; 391CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 392CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 393CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 394CLANG_WARN_EMPTY_BODY = YES; 395CLANG_WARN_ENUM_CONVERSION = YES; 396CLANG_WARN_INFINITE_RECURSION = YES; 397CLANG_WARN_INT_CONVERSION = YES; 398CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 399CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 400CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 401CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 402CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 403CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 404CLANG_WARN_STRICT_PROTOTYPES = YES; 405CLANG_WARN_SUSPICIOUS_MOVE = YES; 406CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 407CLANG_WARN_UNREACHABLE_CODE = YES; 408CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 409COPY_PHASE_STRIP = NO; 410DEBUG_INFORMATION_FORMAT = dwarf; 411ENABLE_STRICT_OBJC_MSGSEND = YES; 412ENABLE_TESTABILITY = YES; 413GCC_C_LANGUAGE_STANDARD = gnu11; 414GCC_DYNAMIC_NO_PIC = NO; 415GCC_NO_COMMON_BLOCKS = YES; 416GCC_OPTIMIZATION_LEVEL = 0; 417GCC_PREPROCESSOR_DEFINITIONS = ( 418"DEBUG=1", 419"$(inherited)", 420); 421GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 422GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 423GCC_WARN_UNDECLARED_SELECTOR = YES; 424GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 425GCC_WARN_UNUSED_FUNCTION = YES; 426GCC_WARN_UNUSED_VARIABLE = YES; 427IPHONEOS_DEPLOYMENT_TARGET = 16.4; 428MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 429MTL_FAST_MATH = YES; 430ONLY_ACTIVE_ARCH = YES; 431SDKROOT = iphoneos; 432SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 433SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 434}; 435name = Debug; 436}; 437AAAAAAAAAAAAAAAAAAAAABBB /* Release */ = { 438isa = XCBuildConfiguration; 439buildSettings = { 440ALWAYS_SEARCH_USER_PATHS = NO; 441CLANG_ANALYZER_NONNULL = YES; 442CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 443CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 444CLANG_CXX_LIBRARY = "libc++"; 445CLANG_ENABLE_MODULES = YES; 446CLANG_ENABLE_OBJC_ARC = YES; 447CLANG_ENABLE_OBJC_WEAK = YES; 448CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 449CLANG_WARN_BOOL_CONVERSION = YES; 450CLANG_WARN_COMMA = YES; 451CLANG_WARN_CONSTANT_CONVERSION = YES; 452CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 453CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 454CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 455CLANG_WARN_EMPTY_BODY = YES; 456CLANG_WARN_ENUM_CONVERSION = YES; 457CLANG_WARN_INFINITE_RECURSION = YES; 458CLANG_WARN_INT_CONVERSION = YES; 459CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 460CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 461CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 462CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 463CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 464CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 465CLANG_WARN_STRICT_PROTOTYPES = YES; 466CLANG_WARN_SUSPICIOUS_MOVE = YES; 467CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 468CLANG_WARN_UNREACHABLE_CODE = YES; 469CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 470COPY_PHASE_STRIP = NO; 471DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 472ENABLE_NS_ASSERTIONS = NO; 473ENABLE_STRICT_OBJC_MSGSEND = YES; 474GCC_C_LANGUAGE_STANDARD = gnu11; 475GCC_NO_COMMON_BLOCKS = YES; 476GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 477GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 478GCC_WARN_UNDECLARED_SELECTOR = YES; 479GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 480GCC_WARN_UNUSED_FUNCTION = YES; 481GCC_WARN_UNUSED_VARIABLE = YES; 482IPHONEOS_DEPLOYMENT_TARGET = 16.4; 483MTL_ENABLE_DEBUG_INFO = NO; 484MTL_FAST_MATH = YES; 485SDKROOT = iphoneos; 486SWIFT_COMPILATION_MODE = wholemodule; 487SWIFT_OPTIMIZATION_LEVEL = "-O"; 488VALIDATE_PRODUCT = YES; 489}; 490name = Release; 491}; 492BBBBBBBBBBBBBBBBBBBBBBCCC /* Debug */ = { 493isa = XCBuildConfiguration; 494buildSettings = { 495ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 496ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 497CODE_SIGN_STYLE = Manual; 498DEVELOPMENT_TEAM = ""; 499ENABLE_PREVIEWS = YES; 500FRAMEWORK_SEARCH_PATHS = "$(PROJECT_DIR)"; 501INFOPLIST_FILE = "iOSLlamaTest/Info.plist"; 502LD_RUNPATH_SEARCH_PATHS = ( 503"$(inherited)", 504"@executable_path/Frameworks", 505); 506PRODUCT_BUNDLE_IDENTIFIER = "org.ggml.iOSLlamaTest"; 507PRODUCT_NAME = "$(TARGET_NAME)"; 508PROVISIONING_PROFILE_SPECIFIER = ""; 509SWIFT_VERSION = 5.0; 510TARGETED_DEVICE_FAMILY = "1,2"; 511}; 512name = Debug; 513}; 514CCCCCCCCCCCCCCCCCCCCCCDDD /* Release */ = { 515isa = XCBuildConfiguration; 516buildSettings = { 517ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 518ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 519CODE_SIGN_STYLE = Manual; 520DEVELOPMENT_TEAM = ""; 521ENABLE_PREVIEWS = YES; 522FRAMEWORK_SEARCH_PATHS = ( 523"$(inherited)", 524"$(PROJECT_DIR)", 525); 526INFOPLIST_FILE = "iOSLlamaTest/Info.plist"; 527LD_RUNPATH_SEARCH_PATHS = ( 528"$(inherited)", 529"@executable_path/Frameworks", 530); 531PRODUCT_BUNDLE_IDENTIFIER = "org.ggml.iOSLlamaTest"; 532PRODUCT_NAME = "$(TARGET_NAME)"; 533PROVISIONING_PROFILE_SPECIFIER = ""; 534SWIFT_VERSION = 5.0; 535TARGETED_DEVICE_FAMILY = "1,2"; 536}; 537name = Release; 538}; 539/* End XCBuildConfiguration section */ 540EOF 541 542# Finish the project.pbxproj file 543cat >> " ${ TEMP_DIR } / ${ APP_NAME } / ${ APP_NAME } .xcodeproj/project.pbxproj" <<EOF 544/* Begin XCConfigurationList section */ 5458888888888888888888888AA /* Build configuration list for PBXProject " ${ APP_NAME } " */ = { 546isa = XCConfigurationList; 547buildConfigurations = ( 5489999999999999999999999AA /* Debug */, 549AAAAAAAAAAAAAAAAAAAAABBB /* Release */, 550); 551defaultConfigurationIsVisible = 0; 552defaultConfigurationName = Release; 553}; 5544444444444444444444444AA /* Build configuration list for PBXNativeTarget " ${ APP_NAME } " */ = { 555isa = XCConfigurationList; 556buildConfigurations = ( 557BBBBBBBBBBBBBBBBBBBBBBCCC /* Debug */, 558CCCCCCCCCCCCCCCCCCCCCCDDD /* Release */, 559); 560defaultConfigurationIsVisible = 0; 561defaultConfigurationName = Release; 562}; 563/* End XCConfigurationList section */ 564}; 565rootObject = 7777777777777777777777AA /* Project object */; 566} 567EOF 568 569# 2. Copy XCFramework to test project 570echo "Copying XCFramework to test project..." 571cp -R " ${ XCFRAMEWORK_PATH } " " ${ TEMP_DIR } / ${ APP_NAME } /" 572 573# 3. Build and archive the app 574echo "Building and archiving test app..." 575cd " ${ TEMP_DIR } / ${ APP_NAME } " 576 577# Create a simple xcscheme file to avoid xcodebuild scheme issues 578mkdir -p " ${ APP_NAME } .xcodeproj/xcshareddata/xcschemes" 579cat > " ${ APP_NAME } .xcodeproj/xcshareddata/xcschemes/ ${ APP_NAME } .xcscheme" <<EOF 580<?xml version="1.0" encoding="UTF-8"?> 581<Scheme 582LastUpgradeVersion = "1240" 583version = "1.3"> 584<BuildAction 585parallelizeBuildables = "YES" 586buildImplicitDependencies = "YES"> 587<BuildActionEntries> 588<BuildActionEntry 589buildForTesting = "YES" 590buildForRunning = "YES" 591buildForProfiling = "YES" 592buildForArchiving = "YES" 593buildForAnalyzing = "YES"> 594<BuildableReference 595BuildableIdentifier = "primary" 596BlueprintIdentifier = "3333333333333333333333AA" 597BuildableName = " ${ APP_NAME } .app" 598BlueprintName = " ${ APP_NAME } " 599ReferencedContainer = "container: ${ APP_NAME } .xcodeproj"> 600</BuildableReference> 601</BuildActionEntry> 602</BuildActionEntries> 603</BuildAction> 604<TestAction 605buildConfiguration = "Debug" 606selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" 607selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" 608shouldUseLaunchSchemeArgsEnv = "YES"> 609<Testables> 610</Testables> 611</TestAction> 612<LaunchAction 613buildConfiguration = "Debug" 614selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" 615selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" 616launchStyle = "0" 617useCustomWorkingDirectory = "NO" 618ignoresPersistentStateOnLaunch = "NO" 619debugDocumentVersioning = "YES" 620debugServiceExtension = "internal" 621allowLocationSimulation = "YES"> 622<BuildableProductRunnable 623runnableDebuggingMode = "0"> 624<BuildableReference 625BuildableIdentifier = "primary" 626BlueprintIdentifier = "3333333333333333333333AA" 627BuildableName = " ${ APP_NAME } .app" 628BlueprintName = " ${ APP_NAME } " 629ReferencedContainer = "container: ${ APP_NAME } .xcodeproj"> 630</BuildableReference> 631</BuildableProductRunnable> 632</LaunchAction> 633<ProfileAction 634buildConfiguration = "Release" 635shouldUseLaunchSchemeArgsEnv = "YES" 636savedToolIdentifier = "" 637useCustomWorkingDirectory = "NO" 638debugDocumentVersioning = "YES"> 639<BuildableProductRunnable 640runnableDebuggingMode = "0"> 641<BuildableReference 642BuildableIdentifier = "primary" 643BlueprintIdentifier = "3333333333333333333333AA" 644BuildableName = " ${ APP_NAME } .app" 645BlueprintName = " ${ APP_NAME } " 646ReferencedContainer = "container: ${ APP_NAME } .xcodeproj"> 647</BuildableReference> 648</BuildableProductRunnable> 649</ProfileAction> 650<AnalyzeAction 651buildConfiguration = "Debug"> 652</AnalyzeAction> 653<ArchiveAction 654buildConfiguration = "Release" 655revealArchiveInOrganizer = "YES"> 656</ArchiveAction> 657</Scheme> 658EOF 659 660# Now use xcodebuild with an explicitly defined product name 661xcodebuild -project " ${ APP_NAME } .xcodeproj" -scheme " ${ APP_NAME } " -sdk iphoneos-configuration Release archive-archivePath " ${ ARCHIVE_PATH } " CODE_SIGN_IDENTITY="-" CODE_SIGNING_REQUIRED=NO CODE_SIGNING_ALLOWED=NO PRODUCT_NAME=" ${ APP_NAME } " SWIFT_OPTIMIZATION_LEVEL="-Onone" -quiet 662 663# 4. Create IPA from archive 664echo "Creating IPA from archive..." 665mkdir -p " ${ TEMP_DIR } /Payload" 666cp -R " ${ ARCHIVE_PATH } /Products/Applications/ ${ APP_NAME } .app" " ${ TEMP_DIR } /Payload/" 667 668# Check and log app structure before zipping 669echo "App structure:" 670ls -la " ${ TEMP_DIR } /Payload/ ${ APP_NAME } .app/" 671echo "Frameworks:" 672ls -la " ${ TEMP_DIR } /Payload/ ${ APP_NAME } .app/Frameworks/" 2 > /dev/null ||echo "No Frameworks directory found" 673 674cd " ${ TEMP_DIR } " 675zip -r " ${ IPA_PATH } " Payload 676 677# Check embedded provisioning profile 678echo "Checking provisioning profile (if any)..." 679PROVISIONING_PROFILE =$( find " ${ ARCHIVE_PATH } /Products/Applications/ ${ APP_NAME } .app" -name "embedded.mobileprovision" 2 > /dev/null) 680if [ -n" $ PROVISIONING_PROFILE " ];then 681echo "Found embedded provisioning profile:" 682security cms-D -i " $ PROVISIONING_PROFILE " ||echo "Unable to decode provisioning profile" 683else 684echo "No embedded provisioning profile found (expected for ad-hoc builds)" 685fi 686 687# 5. Validate the IPA 688echo "Validating IPA..." 689VALIDATION_OUTPUT =" ${ VALIDATION_DIR } /validation_output.txt" 690 691# Check if authentication credentials are provided 692AUTH_ARGS ="" 693if [ -n" $ APPLE_ID " ]&& [ -n" $ APPLE_PASSWORD " ];then 694echo "Using Apple ID authentication for validation..." 695AUTH_ARGS ="--username \" $ APPLE_ID \" --password \" $ APPLE_PASSWORD \"" 696else 697echo "No authentication credentials provided. Will perform basic validation." 698echo "To use your personal developer account, you can run the script with:" 699echo " APPLE_ID='your.email@example.com' APPLE_PASSWORD='your-app-specific-password' ./validate-ios.sh" 700echo "Note: You need to create an app-specific password at https://appleid.apple.com/account/manage" 701fi 702 703# Run validation with detailed output 704echo "Running validation with altool..." 705if [ -n" $ AUTH_ARGS " ];then 706# Use eval to properly handle the quoted arguments 707eval "xcrun altool --validate-app -f \" ${ IPA_PATH } \" --type ios --output-format xml $ AUTH_ARGS " 2 >&1| tee " ${ VALIDATION_OUTPUT } " 708else 709xcrun altool--validate-app -f " ${ IPA_PATH } " --type ios--output-format xml2 >&1| tee " ${ VALIDATION_OUTPUT } " 710fi 711VALIDATION_RESULT =$ ? 712 713# Final validation result 714FINAL_VALIDATION_RESULT =0 715 716# Check if validation failed because the app isn't in App Store Connect 717if grep -q "No suitable application records were found" " ${ VALIDATION_OUTPUT } " ;then 718echo "⚠️ App Store Connect Warning: The app bundle identifier is not found in App Store Connect" 719echo "This is expected for apps that haven't been registered in App Store Connect yet." 720echo "This doesn't indicate a problem with the build or framework." 721 722# Perform alternative validation 723echo "Performing alternative validation checks..." 724 725# Check if IPA was created successfully 726if [ -f" ${ IPA_PATH } " ]&& [ -s" ${ IPA_PATH } " ];then 727echo "✅ IPA file created successfully" 728else 729echo "❌ IPA file not created or empty" 730FINAL_VALIDATION_RESULT =1 731fi 732 733# Check if app binary exists and is executable 734if [ -f" ${ TEMP_DIR } /Payload/ ${ APP_NAME } .app/ ${ APP_NAME } " ]&& [ -x" ${ TEMP_DIR } /Payload/ ${ APP_NAME } .app/ ${ APP_NAME } " ];then 735echo "✅ App binary exists and is executable" 736else 737echo "❌ App binary missing or not executable" 738FINAL_VALIDATION_RESULT =1 739fi 740 741# Check if framework was properly embedded 742if [ -d" ${ TEMP_DIR } /Payload/ ${ APP_NAME } .app/Frameworks/llama.framework" ];then 743echo "✅ llama.framework properly embedded" 744else 745echo "❌ llama.framework not properly embedded" 746FINAL_VALIDATION_RESULT =1 747fi 748 749# Check if framework binary exists 750if [ -f" ${ TEMP_DIR } /Payload/ ${ APP_NAME } .app/Frameworks/llama.framework/llama" ];then 751echo "✅ Framework binary exists" 752 753# Further validate framework by checking architecture 754ARCHS =$( lipo -info " ${ TEMP_DIR } /Payload/ ${ APP_NAME } .app/Frameworks/llama.framework/llama" 2 > /dev/null | grep -o "arm64\\|armv7\\|x86_64" | tr '\n' ' ' ) 755if [ -n" $ ARCHS " ];then 756echo "✅ Framework architecture(s): $ ARCHS " 757else 758echo "⚠️ Could not determine framework architecture" 759fi 760else 761echo "❌ Framework binary missing" 762FINAL_VALIDATION_RESULT =1 763fi 764 765if [$ FINAL_VALIDATION_RESULT -eq 0 ];then 766echo "✅ Alternative validation PASSED: App built successfully with embedded framework" 767else 768echo "❌ Alternative validation FAILED: Issues found with the app or framework" 769fi 770elif grep -q "You must specify authentication credentials" " ${ VALIDATION_OUTPUT } " && [ -z" $ AUTH_ARGS " ];then 771echo "✅ iOS Validation PASSED: IPA successfully validated" 772echo "Results saved to ${ VALIDATION_OUTPUT } " 773else 774echo "❌ iOS Validation FAILED: IPA validation found issues" 775echo "See validation output at ${ VALIDATION_OUTPUT } " 776echo "" 777echo "==== VALIDATION ERRORS ====" 778 779# Try to extract specific errors from the output 780if grep -q "Error" " ${ VALIDATION_OUTPUT } " ;then 781grep -A 5"Error" " ${ VALIDATION_OUTPUT } " 782else 783# If no specific error found, show the whole log 784cat " ${ VALIDATION_OUTPUT } " 785fi 786 787# Additional debugging: check IPA contents 788echo "" 789echo "==== IPA CONTENTS ====" 790mkdir -p " ${ TEMP_DIR } /ipa_contents" 791unzip -q " ${ IPA_PATH } " -d " ${ TEMP_DIR } /ipa_contents" 792ls -la " ${ TEMP_DIR } /ipa_contents/Payload/ ${ APP_NAME } .app/" 793 794# Check for code signing issues 795echo "" 796echo "==== CODE SIGNING INFO ====" 797codesign -vv -d " ${ TEMP_DIR } /ipa_contents/Payload/ ${ APP_NAME } .app" 2 >&1 ||echo "Code signing verification failed" 798 799# Check embedded frameworks 800echo "" 801echo "==== FRAMEWORK INFO ====" 802ls -la " ${ TEMP_DIR } /ipa_contents/Payload/ ${ APP_NAME } .app/Frameworks/" 2 > /dev/null ||echo "No Frameworks directory found" 803fi 804 805# Don't clean up on error to allow inspection 806if [$ FINAL_VALIDATION_RESULT -ne 0 ];then 807echo "" 808echo "Temporary files kept for inspection at: ${ TEMP_DIR } " 809echo "===== iOS Validation Process Failed =====" 810exit 1 811fi 812 813# Clean up temporary files but keep build artifacts 814if [$ FINAL_VALIDATION_RESULT -eq 0 ];then 815echo "Cleaning up temporary files..." 816#rm -rf "${TEMP_DIR}" 817fi 818 819echo "===== iOS Validation Process Completed =====" 820exit $ FINAL_VALIDATION_RESULT