-
-
Notifications
You must be signed in to change notification settings - Fork 119
/
Copy pathbuild_cpp.sh
106 lines (81 loc) · 3.01 KB
/
build_cpp.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/bin/bash
whisper_path="$1"
targets=${2:-all}
android_sdk_path="$3"
unity_project="$PWD"
build_path="$1/build"
clean_build(){
rm -rf "$build_path"
mkdir "$build_path"
cd "$build_path"
}
build_mac() {
clean_build
echo "Starting building for Mac (Metal)..."
cmake -DCMAKE_OSX_ARCHITECTURES="x86_64;arm64" -DGGML_METAL=ON -DCMAKE_BUILD_TYPE=Release \
-DWHISPER_BUILD_TESTS=OFF -DWHISPER_BUILD_EXAMPLES=OFF -DGGML_METAL_EMBED_LIBRARY=ON ../
make
echo "Build for Mac (Metal) complete!"
rm $unity_project/Packages/com.whisper.unity/Plugins/MacOS/*.dylib
artifact_path="$build_path/src/libwhisper.dylib"
target_path="$unity_project/Packages/com.whisper.unity/Plugins/MacOS/libwhisper.dylib"
cp "$artifact_path" "$target_path"
artifact_path=$build_path/ggml/src
target_path=$unity_project/Packages/com.whisper.unity/Plugins/MacOS/
cp "$artifact_path"/*.dylib "$target_path"
cp "$artifact_path"/*/*.dylib "$target_path"
# Required by Unity to properly find the dependencies
for file in "$target_path"*.dylib; do
install_name_tool -add_rpath @loader_path $file
done
echo "Build files copied to $target_path"
}
build_ios() {
clean_build
echo "Starting building for ios..."
cmake -DBUILD_SHARED_LIBS=OFF -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_OSX_ARCHITECTURES="x86_64;arm64" -DGGML_METAL=ON \
-DCMAKE_SYSTEM_PROCESSOR=arm64 -DCMAKE_IOS_INSTALL_COMBINED=YES \
-DWHISPER_BUILD_TESTS=OFF -DWHISPER_BUILD_EXAMPLES=OFF ../
make
echo "Build for ios complete!"
rm $unity_project/Packages/com.whisper.unity/Plugins/iOS/*.a
artifact_path="$build_path/src/libwhisper.a"
target_path="$unity_project/Packages/com.whisper.unity/Plugins/iOS/libwhisper.a"
cp "$artifact_path" "$target_path"
artifact_path=$build_path/ggml/src
target_path=$unity_project/Packages/com.whisper.unity/Plugins/iOS/
cp "$artifact_path"/*.a "$target_path"
cp "$artifact_path"/*/*.a "$target_path"
echo "Build files copied to $target_path"
}
build_android() {
clean_build
echo "Starting building for Android..."
cmake -DCMAKE_TOOLCHAIN_FILE="$android_sdk_path" -DANDROID_ABI=arm64-v8a -DGGML_OPENMP=OFF -DBUILD_SHARED_LIBS=OFF \
-DWHISPER_BUILD_TESTS=OFF -DWHISPER_BUILD_EXAMPLES=OFF -DCMAKE_BUILD_TYPE=Release ../
make
echo "Build for Android complete!"
rm $unity_project/Packages/com.whisper.unity/Plugins/Android/*.a
artifact_path="$build_path/src/libwhisper.a"
target_path="$unity_project/Packages/com.whisper.unity/Plugins/Android/libwhisper.a"
cp "$artifact_path" "$target_path"
artifact_path=$build_path/ggml/src
target_path=$unity_project/Packages/com.whisper.unity/Plugins/Android/
cp "$artifact_path"/*.a "$target_path"
cp "$artifact_path"/*/*.a "$target_path"
echo "Build files copied to $target_path"
}
if [ "$targets" = "all" ]; then
build_mac
build_ios
build_android
elif [ "$targets" = "mac" ]; then
build_mac
elif [ "$targets" = "ios" ]; then
build_ios
elif [ "$targets" = "android" ]; then
build_android
else
echo "Unknown targets: $targets"
fi