Skip to content

Commit a057897

Browse files
authored
llama : add xcframework build script (#11996)
* llama : add xcframework build script This commit adds a script to build an XCFramework for Apple ios, macos, visionos, and tvos platforms. The generated XCFramework can then be added to a project and used in the same way as a regular framework. The llama.swiftui example project has been updated to use the XCFramework and can be started using the following command: ```console $ open examples/llama.swiftui/llama.swiftui.xcodeproj/ ``` Refs: #10747 * examples : remove llama.cpp (source dir ref) from project.pbxproj This commit removes the reference to llama.cpp from the project.pbxproj file since Package.swift has been removed. * ci : updated build.yml to use build-xcframework.sh * ci : add xcframework build to github releases This commit adds the ability to create a GitHub release with the xcframework build artifact. * scripts : add apple app validation scripts This commit adds scripts that can validate the iOS, macOS, tvOS, and VisionOS applications. The scripts create a simple test app project, copy the llama.xcframework to the test project, build and archive the app, create an IPA from the archive, and validate the IPA using altool. The motivation for this is to provide some basic validation and hopefully avoid having to manually validate apps in Xcode. * llama : remove Package.swift This commit removes the Package.swift file, as we are now building an XCFramework for the project. * llama : remove Sources and spm-headers directories * llama : use TargetConditionals.h for visionOS/tvOS
1 parent 5bbe6a9 commit a057897

20 files changed

+3822
-51
lines changed

.github/workflows/build.yml

+28-5
Original file line numberDiff line numberDiff line change
@@ -710,12 +710,36 @@ jobs:
710710
-DLLAMA_BUILD_SERVER=OFF \
711711
-DCMAKE_OSX_ARCHITECTURES="arm64;x86_64"
712712
cmake --build build --config Release -j $(sysctl -n hw.logicalcpu)
713-
sudo cmake --install build --config Release
714713
715714
- name: xcodebuild for swift package
716715
id: xcodebuild
717716
run: |
718-
xcodebuild -scheme llama-Package -destination "${{ matrix.destination }}"
717+
./build-xcframework.sh
718+
719+
- name: Determine tag name
720+
id: tag
721+
shell: bash
722+
run: |
723+
BUILD_NUMBER="$(git rev-list --count HEAD)"
724+
SHORT_HASH="$(git rev-parse --short=7 HEAD)"
725+
if [[ "${{ env.BRANCH_NAME }}" == "master" ]]; then
726+
echo "name=b${BUILD_NUMBER}" >> $GITHUB_OUTPUT
727+
else
728+
SAFE_NAME=$(echo "${{ env.BRANCH_NAME }}" | tr '/' '-')
729+
echo "name=${SAFE_NAME}-b${BUILD_NUMBER}-${SHORT_HASH}" >> $GITHUB_OUTPUT
730+
fi
731+
732+
- name: Pack artifacts
733+
id: pack_artifacts
734+
if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }}
735+
run: |
736+
zip -r llama-${{ steps.tag.outputs.name }}-xcframework.zip build-apple/llama.xcframework
737+
738+
- name: Upload artifacts
739+
if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }}
740+
uses: actions/upload-artifact@v4
741+
with:
742+
path: llama-${{ steps.tag.outputs.name }}-xcframework.zip
719743

720744
windows-msys2:
721745
runs-on: windows-latest
@@ -1336,15 +1360,14 @@ jobs:
13361360
-DCMAKE_OSX_DEPLOYMENT_TARGET=14.0 \
13371361
-DCMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM=ggml
13381362
cmake --build build --config Release -j $(sysctl -n hw.logicalcpu) -- CODE_SIGNING_ALLOWED=NO
1339-
sudo cmake --install build --config Release
13401363
13411364
- name: xcodebuild for swift package
13421365
id: xcodebuild
13431366
run: |
1344-
xcodebuild -scheme llama-Package -destination 'generic/platform=iOS'
1367+
./build-xcframework.sh
13451368
13461369
- name: Build Xcode project
1347-
run: xcodebuild -project examples/llama.swiftui/llama.swiftui.xcodeproj -scheme llama.swiftui -sdk iphoneos CODE_SIGNING_REQUIRED=NO CODE_SIGN_IDENTITY= -destination 'generic/platform=iOS' build
1370+
run: xcodebuild -project examples/llama.swiftui/llama.swiftui.xcodeproj -scheme llama.swiftui -sdk iphoneos CODE_SIGNING_REQUIRED=NO CODE_SIGN_IDENTITY= -destination 'generic/platform=iOS' FRAMEWORK_FOLDER_PATH=./build-ios build
13481371

13491372
android-build:
13501373
runs-on: ubuntu-latest

Package.swift

-19
This file was deleted.

Sources/llama/llama.h

-4
This file was deleted.

Sources/llama/module.modulemap

-5
This file was deleted.

0 commit comments

Comments
 (0)