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-macos.sh - Validate macOS 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-macos.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-macos.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 "===== macOS 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 ="MacOSLlamaTest" 73BUNDLE_ID ="org.ggml.MacOSLlamaTest" 74XCFRAMEWORK_PATH =" ${ ROOT_DIR } /build-apple/llama.xcframework" 75TEMP_DIR =" ${ BUILD_DIR } /temp" 76ARCHIVE_PATH =" ${ BUILD_DIR } / ${ APP_NAME } .xcarchive" 77APP_PATH =" ${ BUILD_DIR } / ${ APP_NAME } .app" 78ZIP_PATH =" ${ BUILD_DIR } / ${ APP_NAME } .zip" 79VALIDATION_DIR =" ${ BUILD_DIR } /validation" 80 81# Create necessary directories 82mkdir -p " ${ BUILD_DIR } " 83mkdir -p " ${ TEMP_DIR } " 84mkdir -p " ${ VALIDATION_DIR } " 85 86echo "===== macOS Validation Process Started =====" 87 88# 1. Create a simple test app project 89echo "Creating test macOS app project..." 90mkdir -p " ${ TEMP_DIR } / ${ APP_NAME } / ${ APP_NAME } " 91cat > " ${ TEMP_DIR } / ${ APP_NAME } / ${ APP_NAME } /Info.plist" <<EOF 92<?xml version="1.0" encoding="UTF-8"?> 93<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> 94<plist version="1.0"> 95<dict> 96<key>CFBundleDevelopmentRegion</key> 97<string>en</string> 98<key>CFBundleExecutable</key> 99<string> ${ APP_NAME } </string> 100<key>CFBundleIdentifier</key> 101<string> ${ BUNDLE_ID } </string> 102<key>CFBundleInfoDictionaryVersion</key> 103<string>6.0</string> 104<key>CFBundleName</key> 105<string> ${ APP_NAME } </string> 106<key>CFBundlePackageType</key> 107<string>APPL</string> 108<key>CFBundleShortVersionString</key> 109<string>1.0</string> 110<key>CFBundleVersion</key> 111<string>1</string> 112<key>LSMinimumSystemVersion</key> 113<string>12.0</string> 114<key>NSHumanReadableCopyright</key> 115<string>Copyright © 2025 GGML. All rights reserved.</string> 116<key>NSPrincipalClass</key> 117<string>NSApplication</string> 118</dict> 119</plist> 120EOF 121 122# Create SwiftUI app files 123mkdir -p " ${ TEMP_DIR } / ${ APP_NAME } / ${ APP_NAME } /Sources" 124 125# Create App.swift 126cat > " ${ TEMP_DIR } / ${ APP_NAME } / ${ APP_NAME } /Sources/App.swift" <<EOF 127import SwiftUI 128import llama 129 130@main 131struct LlamaTestApp: App { 132var body: some Scene { 133WindowGroup { 134ContentView() 135} 136} 137} 138EOF 139 140# Create ContentView.swift with macOS specific elements 141cat > " ${ TEMP_DIR } / ${ APP_NAME } / ${ APP_NAME } /Sources/ContentView.swift" <<EOF 142import SwiftUI 143import llama 144 145struct ContentView: View { 146// Test that we can initialize a llama context params struct 147let params = llama_context_default_params() 148 149var body: some View { 150VStack(spacing: 20) { 151Text("Llama Framework Test on macOS") 152.font(.largeTitle) 153.padding() 154 155Text("llama_context_default_params() created successfully") 156.font(.headline) 157.multilineTextAlignment(.center) 158.padding() 159 160// Display some param values to confirm the framework is working 161Text("n_ctx: \(params.n_ctx)") 162.font(.body) 163 164Text("n_batch: \(params.n_batch)") 165.font(.body) 166 167Spacer() 168} 169.padding() 170.frame(width: 600, height: 400) 171} 172} 173 174struct ContentView_Previews: PreviewProvider { 175static var previews: some View { 176ContentView() 177} 178} 179EOF 180 181# Create project.pbxproj, fixing the framework search paths issues 182mkdir -p " ${ TEMP_DIR } / ${ APP_NAME } / ${ APP_NAME } .xcodeproj" 183cat > " ${ TEMP_DIR } / ${ APP_NAME } / ${ APP_NAME } .xcodeproj/project.pbxproj" <<'EOF' 184// !$*UTF8*$! 185{ 186archiveVersion = 1; 187classes = { 188}; 189objectVersion = 54; 190objects = { 191 192/* Begin PBXBuildFile section */ 19311111111111111111111111 /* App.swift in Sources */ = {isa = PBXBuildFile; fileRef = 22222222222222222222222; }; 19433333333333333333333333 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 44444444444444444444444; }; 19555555555555555555555555 /* llama.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = 66666666666666666666666; }; 19677777777777777777777777 /* llama.xcframework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 66666666666666666666666; }; 197/* End PBXBuildFile section */ 198 199/* Begin PBXCopyFilesBuildPhase section */ 20088888888888888888888888 /* Embed Frameworks */ = { 201isa = PBXCopyFilesBuildPhase; 202buildActionMask = 2147483647; 203dstPath = ""; 204dstSubfolderSpec = 10; 205files = ( 20677777777777777777777777 /* llama.xcframework in Embed Frameworks */, 207); 208name = "Embed Frameworks"; 209runOnlyForDeploymentPostprocessing = 0; 210}; 211/* End PBXCopyFilesBuildPhase section */ 212 213/* Begin PBXFileReference section */ 214EOF 215 216# Continue with the project.pbxproj file, using the APP_NAME variable appropriately 217cat >> " ${ TEMP_DIR } / ${ APP_NAME } / ${ APP_NAME } .xcodeproj/project.pbxproj" <<EOF 21899999999999999999999999 /* ${ APP_NAME } .app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = " ${ APP_NAME } .app"; sourceTree = BUILT_PRODUCTS_DIR; }; 21922222222222222222222222 /* App.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = App.swift; sourceTree = "<group>"; }; 22044444444444444444444444 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; }; 221AAAAAAAAAAAAAAAAAAAAAAA /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; }; 22266666666666666666666666 /* llama.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; path = llama.xcframework; sourceTree = "<group>"; }; 223/* End PBXFileReference section */ 224EOF 225 226# Add the rest of the project file with fixed framework search paths 227cat >> " ${ TEMP_DIR } / ${ APP_NAME } / ${ APP_NAME } .xcodeproj/project.pbxproj" <<'EOF' 228/* Begin PBXFrameworksBuildPhase section */ 229BBBBBBBBBBBBBBBBBBBBBBBB /* Frameworks */ = { 230isa = PBXFrameworksBuildPhase; 231buildActionMask = 2147483647; 232files = ( 23355555555555555555555555 /* llama.xcframework in Frameworks */, 234); 235runOnlyForDeploymentPostprocessing = 0; 236}; 237/* End PBXFrameworksBuildPhase section */ 238 239/* Begin PBXGroup section */ 240EOF 241 242# Continue with the project.pbxproj file, using the APP_NAME variable appropriately 243cat >> " ${ TEMP_DIR } / ${ APP_NAME } / ${ APP_NAME } .xcodeproj/project.pbxproj" <<EOF 244CCCCCCCCCCCCCCCCCCCCCCCC /* Products */ = { 245isa = PBXGroup; 246children = ( 24799999999999999999999999 /* ${ APP_NAME } .app */, 248); 249name = Products; 250sourceTree = "<group>"; 251}; 252EOF 253 254cat >> " ${ TEMP_DIR } / ${ APP_NAME } / ${ APP_NAME } .xcodeproj/project.pbxproj" <<'EOF' 255DDDDDDDDDDDDDDDDDDDDDDDD /* Frameworks */ = { 256isa = PBXGroup; 257children = ( 25866666666666666666666666 /* llama.xcframework */, 259); 260name = Frameworks; 261sourceTree = "<group>"; 262}; 263EEEEEEEEEEEEEEEEEEEEEEEE = { 264isa = PBXGroup; 265children = ( 266FFFFFFFFFFFFFFFFFFFFFFFF /* MacOSLlamaTest */, 267CCCCCCCCCCCCCCCCCCCCCCCC /* Products */, 268DDDDDDDDDDDDDDDDDDDDDDDD /* Frameworks */, 269); 270sourceTree = "<group>"; 271}; 272FFFFFFFFFFFFFFFFFFFFFFFF /* MacOSLlamaTest */ = { 273isa = PBXGroup; 274children = ( 2751111111111111111111111AA /* Sources */, 276AAAAAAAAAAAAAAAAAAAAAAA /* Info.plist */, 277); 278path = "MacOSLlamaTest"; 279sourceTree = "<group>"; 280}; 2811111111111111111111111AA /* Sources */ = { 282isa = PBXGroup; 283children = ( 28422222222222222222222222 /* App.swift */, 28544444444444444444444444 /* ContentView.swift */, 286); 287path = Sources; 288sourceTree = "<group>"; 289}; 290/* End PBXGroup section */ 291EOF 292 293# Continue with the project.pbxproj file, using the APP_NAME variable appropriately 294cat >> " ${ TEMP_DIR } / ${ APP_NAME } / ${ APP_NAME } .xcodeproj/project.pbxproj" <<EOF 295/* Begin PBXNativeTarget section */ 2963333333333333333333333AA /* ${ APP_NAME } */ = { 297isa = PBXNativeTarget; 298buildConfigurationList = 4444444444444444444444AA /* Build configuration list for PBXNativeTarget " ${ APP_NAME } " */; 299buildPhases = ( 3005555555555555555555555AA /* Sources */, 301BBBBBBBBBBBBBBBBBBBBBBBB /* Frameworks */, 3026666666666666666666666AA /* Resources */, 30388888888888888888888888 /* Embed Frameworks */, 304); 305buildRules = ( 306); 307dependencies = ( 308); 309name = " ${ APP_NAME } "; 310productName = " ${ APP_NAME } "; 311productReference = 99999999999999999999999 /* ${ APP_NAME } .app */; 312productType = "com.apple.product-type.application"; 313}; 314/* End PBXNativeTarget section */ 315 316/* Begin PBXProject section */ 3177777777777777777777777AA /* Project object */ = { 318isa = PBXProject; 319attributes = { 320LastSwiftUpdateCheck = 1240; 321LastUpgradeCheck = 1240; 322TargetAttributes = { 3233333333333333333333333AA = { 324CreatedOnToolsVersion = 12.4; 325}; 326}; 327}; 328buildConfigurationList = 8888888888888888888888AA /* Build configuration list for PBXProject " ${ APP_NAME } " */; 329compatibilityVersion = "Xcode 12.0"; 330developmentRegion = en; 331hasScannedForEncodings = 0; 332knownRegions = ( 333en, 334Base, 335); 336mainGroup = EEEEEEEEEEEEEEEEEEEEEEEE; 337productRefGroup = CCCCCCCCCCCCCCCCCCCCCCCC /* Products */; 338projectDirPath = ""; 339projectRoot = ""; 340targets = ( 3413333333333333333333333AA /* ${ APP_NAME } */, 342); 343}; 344/* End PBXProject section */ 345EOF 346 347# Add the rest of the file with correct FRAMEWORK_SEARCH_PATHS and macOS settings 348cat >> " ${ TEMP_DIR } / ${ APP_NAME } / ${ APP_NAME } .xcodeproj/project.pbxproj" <<'EOF' 349/* Begin PBXResourcesBuildPhase section */ 3506666666666666666666666AA /* Resources */ = { 351isa = PBXResourcesBuildPhase; 352buildActionMask = 2147483647; 353files = ( 354); 355runOnlyForDeploymentPostprocessing = 0; 356}; 357/* End PBXResourcesBuildPhase section */ 358 359/* Begin PBXSourcesBuildPhase section */ 3605555555555555555555555AA /* Sources */ = { 361isa = PBXSourcesBuildPhase; 362buildActionMask = 2147483647; 363files = ( 36433333333333333333333333 /* ContentView.swift in Sources */, 36511111111111111111111111 /* App.swift in Sources */, 366); 367runOnlyForDeploymentPostprocessing = 0; 368}; 369/* End PBXSourcesBuildPhase section */ 370 371/* Begin XCBuildConfiguration section */ 3729999999999999999999999AA /* Debug */ = { 373isa = XCBuildConfiguration; 374buildSettings = { 375ALWAYS_SEARCH_USER_PATHS = NO; 376CLANG_ANALYZER_NONNULL = YES; 377CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 378CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 379CLANG_CXX_LIBRARY = "libc++"; 380CLANG_ENABLE_MODULES = YES; 381CLANG_ENABLE_OBJC_ARC = YES; 382CLANG_ENABLE_OBJC_WEAK = YES; 383CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 384CLANG_WARN_BOOL_CONVERSION = YES; 385CLANG_WARN_COMMA = YES; 386CLANG_WARN_CONSTANT_CONVERSION = YES; 387CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 388CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 389CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 390CLANG_WARN_EMPTY_BODY = YES; 391CLANG_WARN_ENUM_CONVERSION = YES; 392CLANG_WARN_INFINITE_RECURSION = YES; 393CLANG_WARN_INT_CONVERSION = YES; 394CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 395CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 396CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 397CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 398CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 399CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 400CLANG_WARN_STRICT_PROTOTYPES = YES; 401CLANG_WARN_SUSPICIOUS_MOVE = YES; 402CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 403CLANG_WARN_UNREACHABLE_CODE = YES; 404CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 405COPY_PHASE_STRIP = NO; 406DEBUG_INFORMATION_FORMAT = dwarf; 407ENABLE_STRICT_OBJC_MSGSEND = YES; 408ENABLE_TESTABILITY = YES; 409GCC_C_LANGUAGE_STANDARD = gnu11; 410GCC_DYNAMIC_NO_PIC = NO; 411GCC_NO_COMMON_BLOCKS = YES; 412GCC_OPTIMIZATION_LEVEL = 0; 413GCC_PREPROCESSOR_DEFINITIONS = ( 414"DEBUG=1", 415"$(inherited)", 416); 417GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 418GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 419GCC_WARN_UNDECLARED_SELECTOR = YES; 420GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 421GCC_WARN_UNUSED_FUNCTION = YES; 422GCC_WARN_UNUSED_VARIABLE = YES; 423MACOSX_DEPLOYMENT_TARGET = 12.0; 424MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 425MTL_FAST_MATH = YES; 426ONLY_ACTIVE_ARCH = YES; 427SDKROOT = macosx; 428SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 429SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 430}; 431name = Debug; 432}; 433AAAAAAAAAAAAAAAAAAAAABBB /* Release */ = { 434isa = XCBuildConfiguration; 435buildSettings = { 436ALWAYS_SEARCH_USER_PATHS = NO; 437CLANG_ANALYZER_NONNULL = YES; 438CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 439CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 440CLANG_CXX_LIBRARY = "libc++"; 441CLANG_ENABLE_MODULES = YES; 442CLANG_ENABLE_OBJC_ARC = YES; 443CLANG_ENABLE_OBJC_WEAK = YES; 444CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 445CLANG_WARN_BOOL_CONVERSION = YES; 446CLANG_WARN_COMMA = YES; 447CLANG_WARN_CONSTANT_CONVERSION = YES; 448CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 449CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 450CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 451CLANG_WARN_EMPTY_BODY = YES; 452CLANG_WARN_ENUM_CONVERSION = YES; 453CLANG_WARN_INFINITE_RECURSION = YES; 454CLANG_WARN_INT_CONVERSION = YES; 455CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 456CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 457CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 458CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 459CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 460CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 461CLANG_WARN_STRICT_PROTOTYPES = YES; 462CLANG_WARN_SUSPICIOUS_MOVE = YES; 463CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 464CLANG_WARN_UNREACHABLE_CODE = YES; 465CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 466COPY_PHASE_STRIP = NO; 467DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 468ENABLE_NS_ASSERTIONS = NO; 469ENABLE_STRICT_OBJC_MSGSEND = YES; 470GCC_C_LANGUAGE_STANDARD = gnu11; 471GCC_NO_COMMON_BLOCKS = YES; 472GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 473GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 474GCC_WARN_UNDECLARED_SELECTOR = YES; 475GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 476GCC_WARN_UNUSED_FUNCTION = YES; 477GCC_WARN_UNUSED_VARIABLE = YES; 478MACOSX_DEPLOYMENT_TARGET = 12.0; 479MTL_ENABLE_DEBUG_INFO = NO; 480MTL_FAST_MATH = YES; 481SDKROOT = macosx; 482SWIFT_COMPILATION_MODE = wholemodule; 483SWIFT_OPTIMIZATION_LEVEL = "-O"; 484}; 485name = Release; 486}; 487BBBBBBBBBBBBBBBBBBBBBBCCC /* Debug */ = { 488isa = XCBuildConfiguration; 489buildSettings = { 490ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 491ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 492CODE_SIGN_STYLE = Manual; 493COMBINE_HIDPI_IMAGES = YES; 494DEVELOPMENT_TEAM = ""; 495ENABLE_HARDENED_RUNTIME = YES; 496ENABLE_PREVIEWS = YES; 497FRAMEWORK_SEARCH_PATHS = "$(PROJECT_DIR)"; 498INFOPLIST_FILE = "MacOSLlamaTest/Info.plist"; 499LD_RUNPATH_SEARCH_PATHS = ( 500"$(inherited)", 501"@executable_path/../Frameworks", 502); 503PRODUCT_BUNDLE_IDENTIFIER = "org.ggml.MacOSLlamaTest"; 504PRODUCT_NAME = "$(TARGET_NAME)"; 505PROVISIONING_PROFILE_SPECIFIER = ""; 506SWIFT_VERSION = 5.0; 507}; 508name = Debug; 509}; 510CCCCCCCCCCCCCCCCCCCCCCDDD /* Release */ = { 511isa = XCBuildConfiguration; 512buildSettings = { 513ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 514ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 515CODE_SIGN_STYLE = Manual; 516COMBINE_HIDPI_IMAGES = YES; 517DEVELOPMENT_TEAM = ""; 518ENABLE_HARDENED_RUNTIME = YES; 519ENABLE_PREVIEWS = YES; 520FRAMEWORK_SEARCH_PATHS = ( 521"$(inherited)", 522"$(PROJECT_DIR)", 523); 524INFOPLIST_FILE = "MacOSLlamaTest/Info.plist"; 525LD_RUNPATH_SEARCH_PATHS = ( 526"$(inherited)", 527"@executable_path/../Frameworks", 528); 529PRODUCT_BUNDLE_IDENTIFIER = "org.ggml.MacOSLlamaTest"; 530PRODUCT_NAME = "$(TARGET_NAME)"; 531PROVISIONING_PROFILE_SPECIFIER = ""; 532SWIFT_VERSION = 5.0; 533}; 534name = Release; 535}; 536/* End XCBuildConfiguration section */ 537EOF 538 539# Finish the project.pbxproj file 540cat >> " ${ TEMP_DIR } / ${ APP_NAME } / ${ APP_NAME } .xcodeproj/project.pbxproj" <<EOF 541/* Begin XCConfigurationList section */ 5428888888888888888888888AA /* Build configuration list for PBXProject " ${ APP_NAME } " */ = { 543isa = XCConfigurationList; 544buildConfigurations = ( 5459999999999999999999999AA /* Debug */, 546AAAAAAAAAAAAAAAAAAAAABBB /* Release */, 547); 548defaultConfigurationIsVisible = 0; 549defaultConfigurationName = Release; 550}; 5514444444444444444444444AA /* Build configuration list for PBXNativeTarget " ${ APP_NAME } " */ = { 552isa = XCConfigurationList; 553buildConfigurations = ( 554BBBBBBBBBBBBBBBBBBBBBBCCC /* Debug */, 555CCCCCCCCCCCCCCCCCCCCCCDDD /* Release */, 556); 557defaultConfigurationIsVisible = 0; 558defaultConfigurationName = Release; 559}; 560/* End XCConfigurationList section */ 561}; 562rootObject = 7777777777777777777777AA /* Project object */; 563} 564EOF 565 566# 2. Copy XCFramework to test project 567echo "Copying XCFramework to test project..." 568cp -R " ${ XCFRAMEWORK_PATH } " " ${ TEMP_DIR } / ${ APP_NAME } /" 569 570# 3. Build and archive the app 571echo "Building and archiving test app..." 572cd " ${ TEMP_DIR } / ${ APP_NAME } " 573 574# Create a simple xcscheme file to avoid xcodebuild scheme issues 575mkdir -p " ${ APP_NAME } .xcodeproj/xcshareddata/xcschemes" 576cat > " ${ APP_NAME } .xcodeproj/xcshareddata/xcschemes/ ${ APP_NAME } .xcscheme" <<EOF 577<?xml version="1.0" encoding="UTF-8"?> 578<Scheme 579LastUpgradeVersion = "1240" 580version = "1.3"> 581<BuildAction 582parallelizeBuildables = "YES" 583buildImplicitDependencies = "YES"> 584<BuildActionEntries> 585<BuildActionEntry 586buildForTesting = "YES" 587buildForRunning = "YES" 588buildForProfiling = "YES" 589buildForArchiving = "YES" 590buildForAnalyzing = "YES"> 591<BuildableReference 592BuildableIdentifier = "primary" 593BlueprintIdentifier = "3333333333333333333333AA" 594BuildableName = " ${ APP_NAME } .app" 595BlueprintName = " ${ APP_NAME } " 596ReferencedContainer = "container: ${ APP_NAME } .xcodeproj"> 597</BuildableReference> 598</BuildActionEntry> 599</BuildActionEntries> 600</BuildAction> 601<TestAction 602buildConfiguration = "Debug" 603selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" 604selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" 605shouldUseLaunchSchemeArgsEnv = "YES"> 606<Testables> 607</Testables> 608</TestAction> 609<LaunchAction 610buildConfiguration = "Debug" 611selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" 612selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" 613launchStyle = "0" 614useCustomWorkingDirectory = "NO" 615ignoresPersistentStateOnLaunch = "NO" 616debugDocumentVersioning = "YES" 617debugServiceExtension = "internal" 618allowLocationSimulation = "YES"> 619<BuildableProductRunnable 620runnableDebuggingMode = "0"> 621<BuildableReference 622BuildableIdentifier = "primary" 623BlueprintIdentifier = "3333333333333333333333AA" 624BuildableName = " ${ APP_NAME } .app" 625BlueprintName = " ${ APP_NAME } " 626ReferencedContainer = "container: ${ APP_NAME } .xcodeproj"> 627</BuildableReference> 628</BuildableProductRunnable> 629</LaunchAction> 630<ProfileAction 631buildConfiguration = "Release" 632shouldUseLaunchSchemeArgsEnv = "YES" 633savedToolIdentifier = "" 634useCustomWorkingDirectory = "NO" 635debugDocumentVersioning = "YES"> 636<BuildableProductRunnable 637runnableDebuggingMode = "0"> 638<BuildableReference 639BuildableIdentifier = "primary" 640BlueprintIdentifier = "3333333333333333333333AA" 641BuildableName = " ${ APP_NAME } .app" 642BlueprintName = " ${ APP_NAME } " 643ReferencedContainer = "container: ${ APP_NAME } .xcodeproj"> 644</BuildableReference> 645</BuildableProductRunnable> 646</ProfileAction> 647<AnalyzeAction 648buildConfiguration = "Debug"> 649</AnalyzeAction> 650<ArchiveAction 651buildConfiguration = "Release" 652revealArchiveInOrganizer = "YES"> 653</ArchiveAction> 654</Scheme> 655EOF 656 657# Now use xcodebuild with an explicitly defined product name for macOS 658xcodebuild -project " ${ APP_NAME } .xcodeproj" -scheme " ${ APP_NAME } " -sdk macosx-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 659 660# 4. Create a package for distribution 661echo "Creating distributable package from archive..." 662cp -R " ${ ARCHIVE_PATH } /Products/Applications/ ${ APP_NAME } .app" " ${ APP_PATH } " 663 664# Check and log app structure 665echo "App structure:" 666ls -la " ${ APP_PATH } " 667echo "Frameworks:" 668ls -la " ${ APP_PATH } /Contents/Frameworks/" 2 > /dev/null ||echo "No Frameworks directory found" 669 670# Create a zip file for potential distribution 671cd " ${ BUILD_DIR } " 672zip -r " ${ ZIP_PATH } " " ${ APP_NAME } .app" 673 674# Check embedded provisioning profile 675echo "Checking provisioning profile (if any)..." 676PROVISIONING_PROFILE =$( find " ${ APP_PATH } /Contents" -name "embedded.provisionprofile" 2 > /dev/null) 677if [ -n" $ PROVISIONING_PROFILE " ];then 678echo "Found embedded provisioning profile:" 679security cms-D -i " $ PROVISIONING_PROFILE " ||echo "Unable to decode provisioning profile" 680else 681echo "No embedded provisioning profile found (expected for ad-hoc builds)" 682fi 683 684# 5. Validate the app 685echo "Validating macOS app..." 686VALIDATION_OUTPUT =" ${ VALIDATION_DIR } /validation_output.txt" 687 688# Check if authentication credentials are provided 689AUTH_ARGS ="" 690if [ -n" $ APPLE_ID " ]&& [ -n" $ APPLE_PASSWORD " ];then 691echo "Using Apple ID authentication for validation..." 692AUTH_ARGS ="--username \" $ APPLE_ID \" --password \" $ APPLE_PASSWORD \"" 693else 694echo "No authentication credentials provided. Will perform basic validation." 695echo "To use your personal developer account, you can run the script with:" 696echo " APPLE_ID='your.email@example.com' APPLE_PASSWORD='your-app-specific-password' ./validate-macos.sh" 697echo "Note: You need to create an app-specific password at https://appleid.apple.com/account/manage" 698fi 699 700# For macOS we need to use notarytool or alternative checks because altool doesn't support macOS apps in the same way 701echo "Note: For macOS, formal notarization process would require Apple Developer credentials." 702echo "Performing alternative validation checks..." 703 704# Final validation result 705FINAL_VALIDATION_RESULT =0 706 707# Check if app was created successfully 708if [ -d" ${ APP_PATH } " ]&& [ -s" ${ APP_PATH } /Contents/MacOS/ ${ APP_NAME } " ];then 709echo "✅ App package created successfully" 710else 711echo "❌ App package not created or binary missing" 712FINAL_VALIDATION_RESULT =1 713fi 714 715# Check if app binary exists and is executable 716if [ -f" ${ APP_PATH } /Contents/MacOS/ ${ APP_NAME } " ]&& [ -x" ${ APP_PATH } /Contents/MacOS/ ${ APP_NAME } " ];then 717echo "✅ App binary exists and is executable" 718else 719echo "❌ App binary missing or not executable" 720FINAL_VALIDATION_RESULT =1 721fi 722 723# Check if framework was properly embedded 724if [ -d" ${ APP_PATH } /Contents/Frameworks/llama.framework" ];then 725echo "✅ llama.framework properly embedded" 726else 727echo "❌ llama.framework not properly embedded" 728FINAL_VALIDATION_RESULT =1 729fi 730 731# Check if framework binary exists 732if [ -f" ${ APP_PATH } /Contents/Frameworks/llama.framework/Versions/A/llama" ];then 733echo "✅ Framework binary exists" 734 735# Further validate framework by checking architecture 736ARCHS =$( lipo -info " ${ APP_PATH } /Contents/Frameworks/llama.framework/Versions/A/llama" 2 > /dev/null | grep -o "arm64\\|x86_64" | tr '\n' ' ' ) 737if [ -n" $ ARCHS " ];then 738echo "✅ Framework architecture(s): $ ARCHS " 739else 740echo "⚠️ Could not determine framework architecture" 741fi 742else 743echo "❌ Framework binary missing" 744FINAL_VALIDATION_RESULT =1 745fi 746 747# Check code signing 748echo "" 749echo "==== CODE SIGNING INFO ====" 750codesign -vv -d " ${ APP_PATH } " 2 >&1 ||echo "Code signing verification not available (expected for ad-hoc builds)" 751 752if [$ FINAL_VALIDATION_RESULT -eq 0 ];then 753if [ -n" $ AUTH_ARGS " ];then 754echo "" 755echo "To notarize this app with Apple (requires Apple Developer account):" 756echo "xcrun notarytool submit \" ${ ZIP_PATH } \" --apple-id \"your-apple-id\" --password \"your-app-specific-password\" --team-id \"your-team-id\" --wait" 757echo "" 758fi 759echo "✅ Validation PASSED: macOS app built successfully with embedded framework" 760else 761echo "❌ Validation FAILED: Issues found with the app or framework" 762fi 763 764# Don't clean up on error to allow inspection 765if [$ FINAL_VALIDATION_RESULT -ne 0 ];then 766echo "" 767echo "Temporary files kept for inspection at: ${ TEMP_DIR } " 768echo "===== macOS Validation Process Failed =====" 769exit 1 770fi 771 772# Clean up temporary files but keep build artifacts 773if [$ FINAL_VALIDATION_RESULT -eq 0 ];then 774echo "Cleaning up temporary files..." 775#rm -rf "${TEMP_DIR}" 776fi 777 778echo "===== macOS Validation Process Completed =====" 779echo "App package available at: ${ APP_PATH } " 780echo "Zipped app available at: ${ ZIP_PATH } " 781exit $ FINAL_VALIDATION_RESULT