Skip to content

Commit 253b753

Browse files
authored
fix(llama-cpp/darwin): make sure to bundle libutf8 libs (#6060)
fix(darwin): make sure to bundle libutf8_validity Plus some refactoring, use makefile Signed-off-by: Ettore Di Giacinto <[email protected]>
1 parent 19c92c7 commit 253b753

File tree

5 files changed

+27
-17
lines changed

5 files changed

+27
-17
lines changed

.github/workflows/backend.yml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -969,10 +969,7 @@ jobs:
969969
- name: Build llama-cpp-darwin
970970
run: |
971971
make protogen-go
972-
make build
973-
bash scripts/build-llama-cpp-darwin.sh
974-
ls -la build/darwin.tar
975-
mv build/darwin.tar build/llama-cpp.tar
972+
make backends/llama-cpp-darwin
976973
- name: Upload llama-cpp.tar
977974
uses: actions/upload-artifact@v4
978975
with:
@@ -1060,9 +1057,7 @@ jobs:
10601057
make protogen-go
10611058
make build
10621059
export PLATFORMARCH=darwin/amd64
1063-
bash scripts/build-llama-cpp-darwin.sh
1064-
ls -la build/darwin.tar
1065-
mv build/darwin.tar build/llama-cpp.tar
1060+
make backends/llama-cpp-darwin
10661061
- name: Upload llama-cpp.tar
10671062
uses: actions/upload-artifact@v4
10681063
with:

.github/workflows/test.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,7 @@ jobs:
214214
- name: Build llama-cpp-darwin
215215
run: |
216216
make protogen-go
217-
make build
218-
bash scripts/build-llama-cpp-darwin.sh
219-
ls -la build/darwin.tar
220-
mv build/darwin.tar build/llama-cpp.tar
221-
./local-ai backends install "ocifile://$PWD/build/llama-cpp.tar"
217+
make backends/llama-cpp-darwin
222218
- name: Test
223219
run: |
224220
export C_INCLUDE_PATH=/usr/local/include

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,10 @@ backends/kitten-tts: docker-build-kitten-tts docker-save-kitten-tts build
165165
backends/kokoro: docker-build-kokoro docker-save-kokoro build
166166
./local-ai backends install "ocifile://$(abspath ./backend-images/kokoro.tar)"
167167

168+
backends/llama-cpp-darwin: build
169+
bash ./scripts/build-llama-cpp-darwin.sh
170+
./local-ai backends install "ocifile://$(abspath ./backend-images/llama-cpp.tar)"
171+
168172
########################################################
169173
## AIO tests
170174
########################################################

backend/cpp/llama-cpp/run.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ fi
4242

4343
# Extend ld library path with the dir where this script is located/lib
4444
if [ "$(uname)" == "Darwin" ]; then
45-
DYLD_FALLBACK_LIBRARY_PATH=$CURDIR/lib:$DYLD_FALLBACK_LIBRARY_PATH
45+
export DYLD_LIBRARY_PATH=$CURDIR/lib:$DYLD_LIBRARY_PATH
46+
#export DYLD_FALLBACK_LIBRARY_PATH=$CURDIR/lib:$DYLD_FALLBACK_LIBRARY_PATH
4647
else
4748
export LD_LIBRARY_PATH=$CURDIR/lib:$LD_LIBRARY_PATH
4849
fi
@@ -57,5 +58,5 @@ fi
5758
echo "Using binary: $BINARY"
5859
exec $CURDIR/$BINARY "$@"
5960

60-
# In case we fail execing, just run fallback
61+
# We should never reach this point, however just in case we do, run fallback
6162
exec $CURDIR/llama-cpp-fallback "$@"

scripts/build-llama-cpp-darwin.sh

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ make llama-cpp-rpc-server
1616
popd
1717

1818
mkdir -p build/darwin
19+
mkdir -p backend-images
20+
mkdir -p build/darwin/lib
1921

2022
# cp -rf backend/cpp/llama-cpp/llama-cpp-avx build/darwin/
2123
# cp -rf backend/cpp/llama-cpp/llama-cpp-avx2 build/darwin/
@@ -24,11 +26,15 @@ cp -rf backend/cpp/llama-cpp/llama-cpp-fallback build/darwin/
2426
cp -rf backend/cpp/llama-cpp/llama-cpp-grpc build/darwin/
2527
cp -rf backend/cpp/llama-cpp/llama-cpp-rpc-server build/darwin/
2628

29+
ADDITIONAL_LIBS=${ADDITIONAL_LIBS:-$(ls /opt/homebrew/Cellar/protobuf/**/lib/libutf8_validity.dylib)}
30+
31+
for file in $ADDITIONAL_LIBS; do
32+
cp -rfv $file build/darwin/lib
33+
done
34+
2735
for file in build/darwin/*; do
2836
LIBS="$(otool -L $file | awk 'NR > 1 { system("echo " $1) } ' | xargs echo)"
29-
3037
for lib in $LIBS; do
31-
mkdir -p build/darwin/lib
3238
# only libraries ending in dylib
3339
if [[ "$lib" == *.dylib ]]; then
3440
if [ -e "$lib" ]; then
@@ -38,13 +44,21 @@ for file in build/darwin/*; do
3844
done
3945
done
4046

47+
echo "--------------------------------"
48+
echo "ADDITIONAL_LIBS: $ADDITIONAL_LIBS"
49+
echo "--------------------------------"
50+
51+
echo "Bundled libraries:"
52+
ls -la build/darwin/lib
53+
54+
4155
cp -rf backend/cpp/llama-cpp/run.sh build/darwin/
4256

4357
PLATFORMARCH="${PLATFORMARCH:-darwin/arm64}"
4458

4559
./local-ai util create-oci-image \
4660
build/darwin/. \
47-
--output build/darwin.tar \
61+
--output ./backend-images/llama-cpp.tar \
4862
--image-name $IMAGE_NAME \
4963
--platform $PLATFORMARCH
5064

0 commit comments

Comments
 (0)