From 35586a74bb2d98f1c65fd08e9614782c64848e14 Mon Sep 17 00:00:00 2001 From: Rich Date: Sun, 13 Jul 2025 16:28:34 -0700 Subject: [PATCH 1/4] This commit allows for the building of a static xcframework by adding a BUILD_STATIC_XCFRAMEWORK option. When enabled, the build-xcframework.sh script builds a self-contained static whisper.xcframework. The motivation for this change is so that command line binaries can link whisper.cpp without forcing users to install the whisper.xcframework separately. --- build-xcframework.sh | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/build-xcframework.sh b/build-xcframework.sh index 337e1936a56..15ca4b72fd6 100755 --- a/build-xcframework.sh +++ b/build-xcframework.sh @@ -15,6 +15,7 @@ GGML_METAL_EMBED_LIBRARY=ON GGML_BLAS_DEFAULT=ON GGML_METAL_USE_BF16=ON GGML_OPENMP=OFF +BUILD_STATIC_XCFRAMEWORK=OFF COMMON_C_FLAGS="-Wno-macro-redefined -Wno-shorten-64-to-32 -Wno-unused-command-line-argument -g" COMMON_CXX_FLAGS="-Wno-macro-redefined -Wno-shorten-64-to-32 -Wno-unused-command-line-argument -g" @@ -327,6 +328,15 @@ combine_static_libraries() { arch_flags+=" -arch $arch" done + + if [[ "${BUILD_STATIC_XCFRAMEWORK}" == "ON" ]]; then + echo "Packaging static framework for ${platform}." + mkdir -p "$(dirname "${base_dir}/${output_lib}")" + cp "${temp_dir}/combined.a" "${base_dir}/${output_lib}" + rm -rf "${temp_dir}" + return + fi + # Create dynamic library echo "Creating dynamic library for ${platform}." xcrun -sdk $sdk clang++ -dynamiclib \ @@ -529,6 +539,20 @@ combine_static_libraries "build-tvos-device" "Release-appletvos" "tvos" "false" # Create XCFramework with correct debug symbols paths echo "Creating XCFramework..." + + if [[ "${BUILD_STATIC_XCFRAMEWORK}" == "ON" ]]; then + xcodebuild -create-xcframework \ + -framework $(pwd)/build-ios-sim/framework/whisper.framework \ + -framework $(pwd)/build-ios-device/framework/whisper.framework \ + -framework $(pwd)/build-macos/framework/whisper.framework \ + -framework $(pwd)/build-visionos/framework/whisper.framework \ + -framework $(pwd)/build-visionos-sim/framework/whisper.framework \ + -framework $(pwd)/build-tvos-device/framework/whisper.framework \ + -framework $(pwd)/build-tvos-sim/framework/whisper.framework \ + -output $(pwd)/build-apple/whisper.xcframework + exit 0 + fi + xcodebuild -create-xcframework \ -framework $(pwd)/build-ios-sim/framework/whisper.framework \ -debug-symbols $(pwd)/build-ios-sim/dSYMs/whisper.dSYM \ From e910875f61e1b7fe9bf10784b82afb08ca2f1261 Mon Sep 17 00:00:00 2001 From: Rich Waters Date: Tue, 22 Jul 2025 14:00:48 -0700 Subject: [PATCH 2/4] Update build-xcframework.sh Co-authored-by: Daniel Bevenius --- build-xcframework.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build-xcframework.sh b/build-xcframework.sh index 15ca4b72fd6..45819fd9fff 100755 --- a/build-xcframework.sh +++ b/build-xcframework.sh @@ -15,7 +15,7 @@ GGML_METAL_EMBED_LIBRARY=ON GGML_BLAS_DEFAULT=ON GGML_METAL_USE_BF16=ON GGML_OPENMP=OFF -BUILD_STATIC_XCFRAMEWORK=OFF +BUILD_STATIC_XCFRAMEWORK=${BUILD_STATIC_XCFRAMEWORK:-OFF} COMMON_C_FLAGS="-Wno-macro-redefined -Wno-shorten-64-to-32 -Wno-unused-command-line-argument -g" COMMON_CXX_FLAGS="-Wno-macro-redefined -Wno-shorten-64-to-32 -Wno-unused-command-line-argument -g" From 4d364e7be3a059f42a3d4bdc49ed15250a07a3c6 Mon Sep 17 00:00:00 2001 From: Rich Date: Tue, 22 Jul 2025 14:34:00 -0700 Subject: [PATCH 3/4] Address reviewer feedback: remove extra indentation around static xcframework creation. --- build-xcframework.sh | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/build-xcframework.sh b/build-xcframework.sh index 45819fd9fff..0171f110737 100755 --- a/build-xcframework.sh +++ b/build-xcframework.sh @@ -540,18 +540,18 @@ combine_static_libraries "build-tvos-device" "Release-appletvos" "tvos" "false" # Create XCFramework with correct debug symbols paths echo "Creating XCFramework..." - if [[ "${BUILD_STATIC_XCFRAMEWORK}" == "ON" ]]; then - xcodebuild -create-xcframework \ - -framework $(pwd)/build-ios-sim/framework/whisper.framework \ - -framework $(pwd)/build-ios-device/framework/whisper.framework \ - -framework $(pwd)/build-macos/framework/whisper.framework \ - -framework $(pwd)/build-visionos/framework/whisper.framework \ - -framework $(pwd)/build-visionos-sim/framework/whisper.framework \ - -framework $(pwd)/build-tvos-device/framework/whisper.framework \ - -framework $(pwd)/build-tvos-sim/framework/whisper.framework \ - -output $(pwd)/build-apple/whisper.xcframework - exit 0 - fi +if [[ "${BUILD_STATIC_XCFRAMEWORK}" == "ON" ]]; then + xcodebuild -create-xcframework \ + -framework $(pwd)/build-ios-sim/framework/whisper.framework \ + -framework $(pwd)/build-ios-device/framework/whisper.framework \ + -framework $(pwd)/build-macos/framework/whisper.framework \ + -framework $(pwd)/build-visionos/framework/whisper.framework \ + -framework $(pwd)/build-visionos-sim/framework/whisper.framework \ + -framework $(pwd)/build-tvos-device/framework/whisper.framework \ + -framework $(pwd)/build-tvos-sim/framework/whisper.framework \ + -output $(pwd)/build-apple/whisper.xcframework + exit 0 +fi xcodebuild -create-xcframework \ -framework $(pwd)/build-ios-sim/framework/whisper.framework \ From 49b2c697fe25d89ce3a83b30364072b4b03885e8 Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Sat, 26 Jul 2025 05:46:11 +0200 Subject: [PATCH 4/4] squash! Address reviewer feedback: remove extra indentation around static xcframework creation. Fix whitespaces. --- build-xcframework.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build-xcframework.sh b/build-xcframework.sh index 0171f110737..bbf2764d729 100755 --- a/build-xcframework.sh +++ b/build-xcframework.sh @@ -328,7 +328,7 @@ combine_static_libraries() { arch_flags+=" -arch $arch" done - + if [[ "${BUILD_STATIC_XCFRAMEWORK}" == "ON" ]]; then echo "Packaging static framework for ${platform}." mkdir -p "$(dirname "${base_dir}/${output_lib}")" @@ -551,7 +551,7 @@ if [[ "${BUILD_STATIC_XCFRAMEWORK}" == "ON" ]]; then -framework $(pwd)/build-tvos-sim/framework/whisper.framework \ -output $(pwd)/build-apple/whisper.xcframework exit 0 -fi +fi xcodebuild -create-xcframework \ -framework $(pwd)/build-ios-sim/framework/whisper.framework \