The project includes llama.cpp as a submodule and requires native binaries for various platforms. Follow these steps to build the binaries:
- Xcode with Command Line Tools
- A valid Apple Developer Team ID
-
Make sure you've initialized the submodules:
git submodule update --init --recursive
-
Navigate to the
darwin
directory:cd darwin
-
Create a custom build script (
build.sh
) with these contents:#!/bin/bash # Exit on error set -e # Get the directory where the script is located script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # Function to build and fix rpaths for a platform build_platform() { local platform=$1 local dev_team=$2 echo "Building for ${platform}..." bash "${script_dir}/run_build.sh" src/llama.cpp $dev_team ${platform} cd "${script_dir}" echo "Fixing rpaths for ${platform}..." bash "fix_rpath.sh" ${platform} cd "${script_dir}/.." } # Replace YOUR_DEVELOPER_TEAM_ID with your actual Apple Developer Team ID # Uncomment the platforms you need to build build_platform "MAC_ARM64" "YOUR_DEVELOPER_TEAM_ID" # build_platform "OS64" "YOUR_DEVELOPER_TEAM_ID" # build_platform "SIMULATOR64" "YOUR_DEVELOPER_TEAM_ID" # build_platform "SIMULATORARM64" "YOUR_DEVELOPER_TEAM_ID" # build_platform "MAC_CATALYST_ARM64" "YOUR_DEVELOPER_TEAM_ID" echo "Build completed successfully for all platforms."
-
Make your build script executable:
chmod +x build.sh
-
Run the build script:
./build.sh
You can build for various Apple platforms by uncommenting the relevant lines in the build script:
MAC_ARM64
- For Apple Silicon MacsOS64
- For iOS devices with arm64 architectureSIMULATOR64
- For iOS Simulator on Intel MacsSIMULATORARM64
- For iOS Simulator on Apple Silicon MacsMAC_CATALYST_ARM64
- For Mac Catalyst on Apple Silicon
- If you encounter "code signature invalid" errors, make sure your Developer Team ID is correct
- For deployment target issues, you may need to modify the
run_build.sh
script to set a higher iOS version (13.0 or above) - If libraries fail to load at runtime, check the output of:
DYLD_PRINT_LIBRARIES=1 DYLD_PRINT_RPATHS=1 dart example/simple.dart
- The built libraries will be placed in the
bin/[PLATFORM]
directory - The build process automatically handles fixing rpaths and code signing for each platform
- Model compatibility depends on the llama.cpp version - ensure you're using a version that supports your target models