Skip to content

Commit 1d87908

Browse files
committed
Try to build for darwin
Signed-off-by: Ettore Di Giacinto <[email protected]>
1 parent ede3293 commit 1d87908

File tree

3 files changed

+72
-4
lines changed

3 files changed

+72
-4
lines changed

.github/workflows/test.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,14 @@ jobs:
205205
brew install protobuf grpc make protoc-gen-go protoc-gen-go-grpc libomp llvm
206206
pip install --user --no-cache-dir grpcio-tools==1.71.0 grpcio==1.71.0
207207
go install github.com/GeertJohan/go.rice/rice@latest
208+
- name: Build llama-cpp-darwin
209+
run: |
210+
make protogen-go
211+
make build-api
212+
bash scripts/build-llama-cpp-darwin.sh
213+
ls -la build/darwin.tar
214+
mv build/darwin.tar build/llama-cpp.tar
215+
./local-ai backends install "ocifile://$PWD/build/llama-cpp.tar"
208216
- name: Test
209217
run: |
210218
export C_INCLUDE_PATH=/usr/local/include

backend/cpp/llama-cpp/run.sh

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,30 @@ BINARY=llama-cpp-fallback
1414

1515
if grep -q -e "\savx\s" /proc/cpuinfo ; then
1616
echo "CPU: AVX found OK"
17-
BINARY=llama-cpp-avx
17+
if [ -e $CURDIR/llama-cpp-avx ]; then
18+
BINARY=llama-cpp-avx
19+
fi
1820
fi
1921

2022
if grep -q -e "\savx2\s" /proc/cpuinfo ; then
2123
echo "CPU: AVX2 found OK"
22-
BINARY=llama-cpp-avx2
24+
if [ -e $CURDIR/llama-cpp-avx2 ]; then
25+
BINARY=llama-cpp-avx2
26+
fi
2327
fi
2428

2529
# Check avx 512
2630
if grep -q -e "\savx512f\s" /proc/cpuinfo ; then
2731
echo "CPU: AVX512F found OK"
28-
BINARY=llama-cpp-avx512
32+
if [ -e $CURDIR/llama-cpp-avx512 ]; then
33+
BINARY=llama-cpp-avx512
34+
fi
2935
fi
3036

3137
if [ -n "$LLAMACPP_GRPC_SERVERS" ]; then
32-
BINARY=llama-cpp-grpc
38+
if [ -e $CURDIR/llama-cpp-grpc ]; then
39+
BINARY=llama-cpp-grpc
40+
fi
3341
fi
3442

3543
# Extend ld library path with the dir where this script is located/lib

scripts/build-llama-cpp-darwin.sh

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/bin/bash
2+
3+
set -ex
4+
5+
IMAGE_NAME="${IMAGE_NAME:-localai/llama-cpp-darwin}"
6+
7+
pushd backend/cpp/llama-cpp
8+
9+
# make llama-cpp-avx && \
10+
# make llama-cpp-avx2 && \
11+
# make llama-cpp-avx512 && \
12+
make llama-cpp-fallback && \
13+
make llama-cpp-grpc && \
14+
make llama-cpp-rpc-server
15+
16+
popd
17+
18+
mkdir -p build/darwin
19+
20+
# cp -rf backend/cpp/llama-cpp/llama-cpp-avx build/darwin/
21+
# cp -rf backend/cpp/llama-cpp/llama-cpp-avx2 build/darwin/
22+
# cp -rf backend/cpp/llama-cpp/llama-cpp-avx512 build/darwin/
23+
cp -rf backend/cpp/llama-cpp/llama-cpp-fallback build/darwin/
24+
cp -rf backend/cpp/llama-cpp/llama-cpp-grpc build/darwin/
25+
cp -rf backend/cpp/llama-cpp/llama-cpp-rpc-server build/darwin/
26+
27+
for file in build/darwin/*; do
28+
LIBS="$(otool -L $file | awk 'NR > 1 { system("echo " $1) } ' | xargs echo)"
29+
30+
for lib in $LIBS; do
31+
mkdir -p build/darwin/lib
32+
# only libraries ending in dylib
33+
if [[ "$lib" == *.dylib ]]; then
34+
if [ -e "$lib" ]; then
35+
cp -rvf "$lib" build/darwin/lib
36+
fi
37+
fi
38+
done
39+
done
40+
41+
cp -rf backend/cpp/llama-cpp/run.sh build/darwin/
42+
43+
PLATFORMARCH="${PLATFORMARCH:-darwin/arm64}"
44+
45+
./local-ai util create-oci-image \
46+
build/darwin \
47+
--output build/darwin.tar \
48+
--image-name $IMAGE_NAME \
49+
--platform $PLATFORMARCH
50+
51+
rm -rf build/darwin
52+

0 commit comments

Comments
 (0)