Skip to content

Commit ba54a23

Browse files
committed
llama : update structure of XCFramework to meet App Store requirements
This commit updates the structure of the XCFramework to meet the requirements for App Store submission. This involved generating debug symbols and the creation of dSYM bundles for each platform. While having the dSYM bundles should allow this framework to pass App Store validation. One thing to note though is that the UUID for the dSYM is missing for this combined static library but the object files them selfes contains debugging symbols which I've verified by running a simple macos application in lldb and stepping through the llama library code. Hopefully this will be enough for reports that are generated by the App Store but I don't now for sure yet as I currently don't have a developer account set up to test this.
1 parent bd5ff80 commit ba54a23

File tree

1 file changed

+104
-35
lines changed

1 file changed

+104
-35
lines changed

build-xcframework.sh

Lines changed: 104 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ GGML_BLAS_DEFAULT=ON
1515
GGML_METAL_USE_BF16=ON
1616
GGML_OPENMP=OFF
1717

18-
COMMON_C_FLAGS="-Wno-macro-redefined -Wno-shorten-64-to-32 -Wno-unused-command-line-argument"
19-
COMMON_CXX_FLAGS="-Wno-macro-redefined -Wno-shorten-64-to-32 -Wno-unused-command-line-argument"
18+
COMMON_C_FLAGS="-Wno-macro-redefined -Wno-shorten-64-to-32 -Wno-unused-command-line-argument -g"
19+
COMMON_CXX_FLAGS="-Wno-macro-redefined -Wno-shorten-64-to-32 -Wno-unused-command-line-argument -g"
2020

2121
check_required_tool() {
2222
local tool=$1
@@ -41,30 +41,38 @@ rm -rf build-ios-sim
4141
rm -rf build-ios-device
4242
rm -rf build-macos
4343
rm -rf build-visionos
44+
rm -rf build-visionos-sim
4445

4546
# Function to setup framework structure for a given architecture
4647
setup_framework_structure() {
4748
local build_dir=$1
4849
local framework_name="llama"
4950
local min_os_version=$2
5051

51-
# Create framework directory structure
52-
mkdir -p ${build_dir}/framework/${framework_name}.framework
53-
mkdir -p ${build_dir}/framework/${framework_name}.framework/Headers
54-
mkdir -p ${build_dir}/framework/${framework_name}.framework/Modules
52+
# Create framework directory structure with versions folder (macOS structure)
53+
mkdir -p ${build_dir}/framework/${framework_name}.framework/Versions/A/Headers
54+
mkdir -p ${build_dir}/framework/${framework_name}.framework/Versions/A/Modules
55+
mkdir -p ${build_dir}/framework/${framework_name}.framework/Versions/A/Resources
56+
57+
# Create symbolic links
58+
ln -sf A ${build_dir}/framework/${framework_name}.framework/Versions/Current
59+
ln -sf Versions/Current/Headers ${build_dir}/framework/${framework_name}.framework/Headers
60+
ln -sf Versions/Current/Modules ${build_dir}/framework/${framework_name}.framework/Modules
61+
ln -sf Versions/Current/Resources ${build_dir}/framework/${framework_name}.framework/Resources
62+
ln -sf Versions/Current/${framework_name} ${build_dir}/framework/${framework_name}.framework/${framework_name}
5563

5664
# Copy all required headers
57-
cp include/llama.h ${build_dir}/framework/${framework_name}.framework/Headers/
58-
cp ggml/include/ggml.h ${build_dir}/framework/${framework_name}.framework/Headers/
59-
cp ggml/include/ggml-alloc.h ${build_dir}/framework/${framework_name}.framework/Headers/
60-
cp ggml/include/ggml-backend.h ${build_dir}/framework/${framework_name}.framework/Headers/
61-
cp ggml/include/ggml-metal.h ${build_dir}/framework/${framework_name}.framework/Headers/
62-
cp ggml/include/ggml-cpu.h ${build_dir}/framework/${framework_name}.framework/Headers/
63-
cp ggml/include/ggml-blas.h ${build_dir}/framework/${framework_name}.framework/Headers/
64-
cp ggml/include/gguf.h ${build_dir}/framework/${framework_name}.framework/Headers/
65+
cp include/llama.h ${build_dir}/framework/${framework_name}.framework/Versions/A/Headers/
66+
cp ggml/include/ggml.h ${build_dir}/framework/${framework_name}.framework/Versions/A/Headers/
67+
cp ggml/include/ggml-alloc.h ${build_dir}/framework/${framework_name}.framework/Versions/A/Headers/
68+
cp ggml/include/ggml-backend.h ${build_dir}/framework/${framework_name}.framework/Versions/A/Headers/
69+
cp ggml/include/ggml-metal.h ${build_dir}/framework/${framework_name}.framework/Versions/A/Headers/
70+
cp ggml/include/ggml-cpu.h ${build_dir}/framework/${framework_name}.framework/Versions/A/Headers/
71+
cp ggml/include/ggml-blas.h ${build_dir}/framework/${framework_name}.framework/Versions/A/Headers/
72+
cp ggml/include/gguf.h ${build_dir}/framework/${framework_name}.framework/Versions/A/Headers/
6573

6674
# Create module map
67-
cat > ${build_dir}/framework/${framework_name}.framework/Modules/module.modulemap << EOF
75+
cat > ${build_dir}/framework/${framework_name}.framework/Versions/A/Modules/module.modulemap << EOF
6876
framework module llama {
6977
header "llama.h"
7078
header "ggml.h"
@@ -85,7 +93,7 @@ framework module llama {
8593
EOF
8694

8795
# Create Info.plist
88-
cat > ${build_dir}/framework/${framework_name}.framework/Info.plist << EOF
96+
cat > ${build_dir}/framework/${framework_name}.framework/Versions/A/Resources/Info.plist << EOF
8997
<?xml version="1.0" encoding="UTF-8"?>
9098
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
9199
<plist version="1.0">
@@ -113,11 +121,73 @@ EOF
113121
EOF
114122
}
115123

124+
# Function to combine static libraries
125+
combine_static_libraries() {
126+
local build_dir="$1"
127+
local platform="$2"
128+
local output_lib="${build_dir}/framework/llama.framework/Versions/A/llama"
129+
local base_dir="$(pwd)"
130+
131+
# Combine all static libraries using libtool
132+
libtool -static -no_warning_for_no_symbols -o "${base_dir}/${output_lib}" \
133+
"${base_dir}/${build_dir}/src/${platform}/libllama.a" \
134+
"${base_dir}/${build_dir}/ggml/src/${platform}/libggml.a" \
135+
"${base_dir}/${build_dir}/ggml/src/${platform}/libggml-base.a" \
136+
"${base_dir}/${build_dir}/ggml/src/${platform}/libggml-cpu.a" \
137+
"${base_dir}/${build_dir}/ggml/src/ggml-metal/${platform}/libggml-metal.a" \
138+
"${base_dir}/${build_dir}/ggml/src/ggml-blas/${platform}/libggml-blas.a"
139+
}
140+
141+
# Function to create dSYM for App Store submission
142+
create_app_store_dsym() {
143+
local build_dir="$1"
144+
local base_dir="$(pwd)"
145+
local lib_path="${base_dir}/${build_dir}/framework/llama.framework/Versions/A/llama"
146+
local dsym_path="${base_dir}/${build_dir}/framework/llama.framework/Versions/A/llama.dSYM"
147+
148+
#echo "Creating App Store compatible dSYM for ${build_dir}"
149+
150+
# Create directory structure
151+
mkdir -p "${dsym_path}/Contents/Resources/DWARF"
152+
153+
# Create Info.plist
154+
cat > "${dsym_path}/Contents/Info.plist" << EOF
155+
<?xml version="1.0" encoding="UTF-8"?>
156+
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
157+
<plist version="1.0">
158+
<dict>
159+
<key>CFBundleDevelopmentRegion</key>
160+
<string>English</string>
161+
<key>CFBundleIdentifier</key>
162+
<string>ggml-org.llama.dsym</string>
163+
<key>CFBundleInfoDictionaryVersion</key>
164+
<string>6.0</string>
165+
<key>CFBundlePackageType</key>
166+
<string>dSYM</string>
167+
<key>CFBundleSignature</key>
168+
<string>LLAM</string>
169+
<key>CFBundleShortVersionString</key>
170+
<string>1.0</string>
171+
<key>CFBundleVersion</key>
172+
<string>1</string>
173+
</dict>
174+
</plist>
175+
EOF
176+
177+
# Copy the binary to the DWARF directory
178+
cp "${lib_path}" "${dsym_path}/Contents/Resources/DWARF/llama"
179+
}
180+
116181
# Common options for all builds
117182
COMMON_CMAKE_ARGS=(
118183
-DCMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED=NO
119184
-DCMAKE_XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY=""
120185
-DCMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED=NO
186+
-DCMAKE_XCODE_ATTRIBUTE_DEBUG_INFORMATION_FORMAT="dwarf-with-dsym"
187+
-DCMAKE_XCODE_ATTRIBUTE_GCC_GENERATE_DEBUGGING_SYMBOLS=YES
188+
-DCMAKE_XCODE_ATTRIBUTE_COPY_PHASE_STRIP=NO
189+
-DCMAKE_XCODE_ATTRIBUTE_STRIP_INSTALLED_PRODUCT=NO
190+
-DCMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM=ggml
121191
-DBUILD_SHARED_LIBS=OFF
122192
-DLLAMA_BUILD_EXAMPLES=${LLAMA_BUILD_EXAMPLES}
123193
-DLLAMA_BUILD_TESTS=${LLAMA_BUILD_TESTS}
@@ -166,7 +236,6 @@ cmake -B build-macos -G Xcode \
166236
-S .
167237
cmake --build build-macos --config Release -- -quiet
168238

169-
170239
# Build for visionOS
171240
cmake -B build-visionos -G Xcode \
172241
"${COMMON_CMAKE_ARGS[@]}" \
@@ -194,44 +263,44 @@ cmake -B build-visionos-sim -G Xcode \
194263
cmake --build build-visionos-sim --config Release -- -quiet
195264

196265
# Setup frameworks and copy binaries and headers
266+
echo "Setting up framework structures..."
197267
setup_framework_structure "build-ios-sim" ${IOS_MIN_OS_VERSION}
198268
setup_framework_structure "build-ios-device" ${IOS_MIN_OS_VERSION}
199269
setup_framework_structure "build-macos" ${MACOS_MIN_OS_VERSION}
200270
setup_framework_structure "build-visionos" ${VISIONOS_MIN_OS_VERSION}
201271
setup_framework_structure "build-visionos-sim" ${VISIONOS_MIN_OS_VERSION}
202272

203-
# Function to combine static libraries
204-
combine_static_libraries() {
205-
local build_dir="$1"
206-
local platform="$2"
207-
local output_lib="${build_dir}/framework/llama.framework/llama"
208-
local base_dir="$(pwd)"
209-
210-
# Combine all static libraries using libtool
211-
libtool -static -no_warning_for_no_symbols -o "${base_dir}/${output_lib}" \
212-
"${base_dir}/${build_dir}/src/${platform}/libllama.a" \
213-
"${base_dir}/${build_dir}/ggml/src/${platform}/libggml.a" \
214-
"${base_dir}/${build_dir}/ggml/src/${platform}/libggml-base.a" \
215-
"${base_dir}/${build_dir}/ggml/src/${platform}/libggml-cpu.a" \
216-
"${base_dir}/${build_dir}/ggml/src/ggml-metal/${platform}/libggml-metal.a" \
217-
"${base_dir}/${build_dir}/ggml/src/ggml-blas/${platform}/libggml-blas.a"
218-
}
219-
220-
# Combine libraries for simulator and device builds
273+
# Combine libraries for each platform
274+
echo "Combining libraries..."
221275
combine_static_libraries "build-ios-sim" "Release-iphonesimulator"
222276
combine_static_libraries "build-ios-device" "Release-iphoneos"
223277
combine_static_libraries "build-macos" "Release"
224278
combine_static_libraries "build-visionos" "Release-xros"
225279
combine_static_libraries "build-visionos-sim" "Release-xrsimulator"
226280

281+
# Create App Store compatible dSYMs
282+
echo "Creating dSYM bundles..."
283+
create_app_store_dsym "build-ios-sim"
284+
create_app_store_dsym "build-ios-device"
285+
create_app_store_dsym "build-macos"
286+
create_app_store_dsym "build-visionos"
287+
create_app_store_dsym "build-visionos-sim"
288+
227289
# Create XCFramework
290+
echo "Creating XCFramework..."
228291
xcodebuild -create-xcframework \
229292
-framework $(pwd)/build-ios-sim/framework/llama.framework \
293+
-debug-symbols $(pwd)/build-ios-sim/framework/llama.framework/Versions/A/llama.dSYM \
230294
-framework $(pwd)/build-ios-device/framework/llama.framework \
295+
-debug-symbols $(pwd)/build-ios-device/framework/llama.framework/Versions/A/llama.dSYM \
231296
-framework $(pwd)/build-macos/framework/llama.framework \
297+
-debug-symbols $(pwd)/build-macos/framework/llama.framework/Versions/A/llama.dSYM \
232298
-framework $(pwd)/build-visionos/framework/llama.framework \
299+
-debug-symbols $(pwd)/build-visionos/framework/llama.framework/Versions/A/llama.dSYM \
233300
-framework $(pwd)/build-visionos-sim/framework/llama.framework \
301+
-debug-symbols $(pwd)/build-visionos-sim/framework/llama.framework/Versions/A/llama.dSYM \
234302
-output $(pwd)/build-apple/llama.xcframework
235303

236304
# The generated framework can be found in build-apple/llama.xcframework and
237305
# can be added to a projects "Frameworks, Libraries, and Embedded Content"
306+

0 commit comments

Comments
 (0)