Skip to content

Commit

Permalink
Metal ios build
Browse files Browse the repository at this point in the history
  • Loading branch information
Macoron committed Nov 2, 2024
1 parent c68e559 commit 4ab3895
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/build_cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,35 @@ jobs:
path: ${{ github.workspace }}/whisper-cpp/build/libwhisper.a
if-no-files-found: error

build-ios-metal:
name: Build for iOS (Metal)
if: ${{ contains(fromJson('["ios_metal", "all"]'), github.event.inputs.target_platform) }}
runs-on: macOS-latest
steps:
- name: Clone whisper.unity
uses: actions/checkout@v3
with:
path: whisper-unity

- name: Clone whisper.cpp
uses: actions/checkout@v3
with:
repository: ${{ github.event.inputs.whisper_cpp_repo }}
ref: ${{ github.event.inputs.whisper_cpp_repo_ref }}
path: whisper-cpp

- name: Run build script
run: |
cd whisper-unity
sh build_cpp.sh ../whisper-cpp/ ios
- name: Upload results
uses: actions/upload-artifact@v3
with:
name: ios-metal
path: ${{ github.workspace }}/whisper-cpp/build/libwhisper_metal.a
if-no-files-found: error

build-android:
name: Build for Android (arm64-v8a)
if: ${{ contains(fromJson('["android", "all"]'), github.event.inputs.target_platform) }}
Expand Down
27 changes: 25 additions & 2 deletions build_cpp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ build_mac_metal() {

build_ios() {
clean_build
echo "Starting building for ios..."
echo "Starting building for iOS..."

cmake -DBUILD_SHARED_LIBS=OFF -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_OSX_ARCHITECTURES="x86_64;arm64" -DWHISPER_METAL=OFF \
-DCMAKE_SYSTEM_PROCESSOR=arm64 -DCMAKE_IOS_INSTALL_COMBINED=YES \
-DWHISPER_BUILD_TESTS=OFF -DWHISPER_BUILD_EXAMPLES=OFF ../
make

echo "Build for ios complete!"
echo "Build for iOS complete!"

artifact_path="$build_path/libwhisper.a"
target_path="$unity_project/Packages/com.whisper.unity/Plugins/iOS/libwhisper.a"
Expand All @@ -67,6 +67,25 @@ build_ios() {
echo "Build files copied to $target_path"
}

build_ios_metal() {
clean_build
echo "Starting building for iOS (Metal)..."

cmake -DBUILD_SHARED_LIBS=OFF -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_OSX_ARCHITECTURES="arm64" -DWHISPER_METAL=ON -DWHISPER_METAL_EMBED_LIBRARY=ON \
-DCMAKE_SYSTEM_PROCESSOR=arm64 -DCMAKE_IOS_INSTALL_COMBINED=YES \
-DWHISPER_BUILD_TESTS=OFF -DWHISPER_BUILD_EXAMPLES=OFF ../
make

echo "Build for iOS complete!"

artifact_path="$build_path/libwhisper.a"
target_path="$unity_project/Packages/com.whisper.unity/Plugins/iOS/libwhisper_metal.a"
cp "$artifact_path" "$target_path"

echo "Build files copied to $target_path"
}

build_android() {
clean_build
echo "Starting building for Android..."
Expand All @@ -86,14 +105,18 @@ build_android() {

if [ "$targets" = "all" ]; then
build_mac
build_mac_metal
build_ios
build_ios_metal
build_android
elif [ "$targets" = "mac" ]; then
build_mac
elif [ "$targets" = "mac_metal" ]; then
build_mac_metal
elif [ "$targets" = "ios" ]; then
build_ios
elif [ "$targets" = "ios_metal" ]; then
build_ios_metal
elif [ "$targets" = "android" ]; then
build_android
else
Expand Down

0 comments on commit 4ab3895

Please sign in to comment.