Skip to content

Commit 976c159

Browse files
authored
chore(ci): Build some Go based backends on Darwin (#6164)
* chore(ci): Build Go based backends on Darwin Signed-off-by: Richard Palethorpe <[email protected]> * chore(stablediffusion-ggml): Fixes for building on Darwin Signed-off-by: Richard Palethorpe <[email protected]> * chore(whisper): Build on Darwin Signed-off-by: Richard Palethorpe <[email protected]> --------- Signed-off-by: Richard Palethorpe <[email protected]>
1 parent 969922f commit 976c159

File tree

13 files changed

+142
-77
lines changed

13 files changed

+142
-77
lines changed

.github/workflows/backend.yml

Lines changed: 30 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ jobs:
230230
runs-on: 'ubuntu-latest'
231231
base-image: "ubuntu:22.04"
232232
skip-drivers: 'false'
233-
backend: "diffusers"
233+
backend: "diffusers"
234234
dockerfile: "./backend/Dockerfile.python"
235235
context: "./backend"
236236
# CUDA 12 additional backends
@@ -957,53 +957,38 @@ jobs:
957957
backend: "kitten-tts"
958958
dockerfile: "./backend/Dockerfile.python"
959959
context: "./backend"
960-
diffusers-darwin:
961-
uses: ./.github/workflows/backend_build_darwin.yml
962-
with:
963-
backend: "diffusers"
964-
build-type: "mps"
965-
go-version: "1.24.x"
966-
tag-suffix: "-metal-darwin-arm64-diffusers"
967-
use-pip: true
968-
runs-on: "macOS-14"
969-
secrets:
970-
dockerUsername: ${{ secrets.DOCKERHUB_USERNAME }}
971-
dockerPassword: ${{ secrets.DOCKERHUB_PASSWORD }}
972-
quayUsername: ${{ secrets.LOCALAI_REGISTRY_USERNAME }}
973-
quayPassword: ${{ secrets.LOCALAI_REGISTRY_PASSWORD }}
974-
mlx-darwin:
975-
uses: ./.github/workflows/backend_build_darwin.yml
976-
with:
977-
backend: "mlx"
978-
build-type: "mps"
979-
go-version: "1.24.x"
980-
tag-suffix: "-metal-darwin-arm64-mlx"
981-
runs-on: "macOS-14"
982-
secrets:
983-
dockerUsername: ${{ secrets.DOCKERHUB_USERNAME }}
984-
dockerPassword: ${{ secrets.DOCKERHUB_PASSWORD }}
985-
quayUsername: ${{ secrets.LOCALAI_REGISTRY_USERNAME }}
986-
quayPassword: ${{ secrets.LOCALAI_REGISTRY_PASSWORD }}
987-
mlx-vlm-darwin:
988-
uses: ./.github/workflows/backend_build_darwin.yml
989-
with:
990-
backend: "mlx-vlm"
991-
build-type: "mps"
992-
go-version: "1.24.x"
993-
tag-suffix: "-metal-darwin-arm64-mlx-vlm"
994-
runs-on: "macOS-14"
995-
secrets:
996-
dockerUsername: ${{ secrets.DOCKERHUB_USERNAME }}
997-
dockerPassword: ${{ secrets.DOCKERHUB_PASSWORD }}
998-
quayUsername: ${{ secrets.LOCALAI_REGISTRY_USERNAME }}
999-
quayPassword: ${{ secrets.LOCALAI_REGISTRY_PASSWORD }}
1000-
mlx-audio-darwin:
960+
backend-jobs-darwin:
1001961
uses: ./.github/workflows/backend_build_darwin.yml
962+
strategy:
963+
matrix:
964+
include:
965+
- backend: "diffusers"
966+
tag-suffix: "-metal-darwin-arm64-diffusers"
967+
build-type: "mps"
968+
- backend: "mlx"
969+
tag-suffix: "-metal-darwin-arm64-mlx"
970+
build-type: "mps"
971+
- backend: "mlx-vlm"
972+
tag-suffix: "-metal-darwin-arm64-mlx-vlm"
973+
build-type: "mps"
974+
- backend: "mlx-audio"
975+
tag-suffix: "-metal-darwin-arm64-mlx-audio"
976+
build-type: "mps"
977+
- backend: "stablediffusion-ggml"
978+
tag-suffix: "-metal-darwin-arm64-stablediffusion-ggml"
979+
build-type: "metal"
980+
lang: "go"
981+
- backend: "whisper"
982+
tag-suffix: "-metal-darwin-arm64-whisper"
983+
build-type: "metal"
984+
lang: "go"
1002985
with:
1003-
backend: "mlx-audio"
1004-
build-type: "mps"
986+
backend: ${{ matrix.backend }}
987+
build-type: ${{ matrix.build-type }}
1005988
go-version: "1.24.x"
1006-
tag-suffix: "-metal-darwin-arm64-mlx-audio"
989+
tag-suffix: ${{ matrix.tag-suffix }}
990+
lang: ${{ matrix.lang || '' }}
991+
use-pip: ${{ matrix.backend == 'diffusers' }}
1007992
runs-on: "macOS-14"
1008993
secrets:
1009994
dockerUsername: ${{ secrets.DOCKERHUB_USERNAME }}

.github/workflows/backend_build_darwin.yml

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ on:
1616
description: 'Use pip to install dependencies'
1717
default: false
1818
type: boolean
19+
lang:
20+
description: 'Programming language (e.g. go)'
21+
default: 'python'
22+
type: string
1923
go-version:
2024
description: 'Go version to use'
2125
default: '1.24.x'
@@ -49,26 +53,26 @@ jobs:
4953
uses: actions/checkout@v5
5054
with:
5155
submodules: true
52-
56+
5357
- name: Setup Go ${{ matrix.go-version }}
5458
uses: actions/setup-go@v5
5559
with:
5660
go-version: ${{ matrix.go-version }}
5761
cache: false
58-
62+
5963
# You can test your matrix by printing the current Go version
6064
- name: Display Go version
6165
run: go version
62-
66+
6367
- name: Dependencies
6468
run: |
6569
brew install protobuf grpc make protoc-gen-go protoc-gen-go-grpc libomp llvm
66-
70+
6771
- name: Build ${{ inputs.backend }}-darwin
6872
run: |
6973
make protogen-go
70-
BACKEND=${{ inputs.backend }} BUILD_TYPE=${{ inputs.build-type }} USE_PIP=${{ inputs.use-pip }} make build-darwin-python-backend
71-
74+
BACKEND=${{ inputs.backend }} BUILD_TYPE=${{ inputs.build-type }} USE_PIP=${{ inputs.use-pip }} make build-darwin-${{ inputs.lang }}-backend
75+
7276
- name: Upload ${{ inputs.backend }}.tar
7377
uses: actions/upload-artifact@v4
7478
with:
@@ -85,20 +89,20 @@ jobs:
8589
with:
8690
name: ${{ inputs.backend }}-tar
8791
path: .
88-
92+
8993
- name: Install crane
9094
run: |
9195
curl -L https://github.com/google/go-containerregistry/releases/latest/download/go-containerregistry_Linux_x86_64.tar.gz | tar -xz
9296
sudo mv crane /usr/local/bin/
93-
97+
9498
- name: Log in to DockerHub
9599
run: |
96100
echo "${{ secrets.dockerPassword }}" | crane auth login docker.io -u "${{ secrets.dockerUsername }}" --password-stdin
97-
101+
98102
- name: Log in to quay.io
99103
run: |
100104
echo "${{ secrets.quayPassword }}" | crane auth login quay.io -u "${{ secrets.quayUsername }}" --password-stdin
101-
105+
102106
- name: Docker meta
103107
id: meta
104108
uses: docker/metadata-action@v5
@@ -112,7 +116,7 @@ jobs:
112116
flavor: |
113117
latest=auto
114118
suffix=${{ inputs.tag-suffix }},onlatest=true
115-
119+
116120
- name: Docker meta
117121
id: quaymeta
118122
uses: docker/metadata-action@v5
@@ -126,13 +130,13 @@ jobs:
126130
flavor: |
127131
latest=auto
128132
suffix=${{ inputs.tag-suffix }},onlatest=true
129-
133+
130134
- name: Push Docker image (DockerHub)
131135
run: |
132136
for tag in $(echo "${{ steps.meta.outputs.tags }}" | tr ',' '\n'); do
133137
crane push ${{ inputs.backend }}.tar $tag
134138
done
135-
139+
136140
- name: Push Docker image (Quay)
137141
run: |
138142
for tag in $(echo "${{ steps.quaymeta.outputs.tags }}" | tr ',' '\n'); do

.github/workflows/backend_pr.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ jobs:
1212
runs-on: ubuntu-latest
1313
outputs:
1414
matrix: ${{ steps.set-matrix.outputs.matrix }}
15+
matrix-darwin: ${{ steps.set-matrix.outputs.matrix-darwin }}
1516
has-backends: ${{ steps.set-matrix.outputs.has-backends }}
17+
has-backends-darwin: ${{ steps.set-matrix.outputs.has-backends-darwin }}
1618
steps:
1719
- name: Checkout repository
1820
uses: actions/checkout@v5
@@ -56,3 +58,21 @@ jobs:
5658
strategy:
5759
fail-fast: true
5860
matrix: ${{ fromJson(needs.generate-matrix.outputs.matrix) }}
61+
backend-jobs-darwin:
62+
needs: generate-matrix
63+
uses: ./.github/workflows/backend_build_darwin.yml
64+
if: needs.generate-matrix.outputs.has-backends-darwin == 'true'
65+
with:
66+
backend: ${{ matrix.backend }}
67+
build-type: ${{ matrix.build-type }}
68+
go-version: "1.24.x"
69+
tag-suffix: ${{ matrix.tag-suffix }}
70+
lang: ${{ matrix.lang || '' }}
71+
use-pip: ${{ matrix.backend == 'diffusers' }}
72+
runs-on: "macOS-14"
73+
secrets:
74+
quayUsername: ${{ secrets.LOCALAI_REGISTRY_USERNAME }}
75+
quayPassword: ${{ secrets.LOCALAI_REGISTRY_PASSWORD }}
76+
strategy:
77+
fail-fast: true
78+
matrix: ${{ fromJson(needs.generate-matrix.outputs.matrix-darwin) }}

Makefile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,9 @@ backends/llama-cpp-darwin: build
376376
build-darwin-python-backend: build
377377
bash ./scripts/build/python-darwin.sh
378378

379+
build-darwin-go-backend: build
380+
bash ./scripts/build/golang-darwin.sh
381+
379382
backends/mlx:
380383
BACKEND=mlx $(MAKE) build-darwin-python-backend
381384
./local-ai backends install "ocifile://$(abspath ./backend-images/mlx.tar)"
@@ -392,6 +395,10 @@ backends/mlx-audio:
392395
BACKEND=mlx-audio $(MAKE) build-darwin-python-backend
393396
./local-ai backends install "ocifile://$(abspath ./backend-images/mlx-audio.tar)"
394397

398+
backends/stablediffusion-ggml-darwin:
399+
BACKEND=stablediffusion-ggml BUILD_TYPE=metal $(MAKE) build-darwin-go-backend
400+
./local-ai backends install "ocifile://$(abspath ./backend-images/stablediffusion-ggml.tar)"
401+
395402
backend-images:
396403
mkdir -p backend-images
397404

@@ -537,4 +544,4 @@ build-launcher-darwin: build-launcher
537544
--outputDir "dist/"
538545

539546
build-launcher-linux:
540-
cd cmd/launcher && go run fyne.io/tools/cmd/fyne@latest package -os linux -icon ../../core/http/static/logo.png --executable $(LAUNCHER_BINARY_NAME)-linux && mv launcher.tar.xz ../../$(LAUNCHER_BINARY_NAME)-linux.tar.xz
547+
cd cmd/launcher && go run fyne.io/tools/cmd/fyne@latest package -os linux -icon ../../core/http/static/logo.png --executable $(LAUNCHER_BINARY_NAME)-linux && mv launcher.tar.xz ../../$(LAUNCHER_BINARY_NAME)-linux.tar.xz
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package/
2+
sources/
3+
libgosd.so
4+
stablediffusion-ggml

backend/go/stablediffusion-ggml/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON)
55
add_subdirectory(./sources/stablediffusion-ggml.cpp)
66

77
add_library(gosd MODULE gosd.cpp)
8-
target_link_libraries(gosd PRIVATE stable-diffusion ggml stdc++fs)
8+
target_link_libraries(gosd PRIVATE stable-diffusion ggml)
9+
10+
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.0)
11+
target_link_libraries(gosd PRIVATE stdc++fs)
12+
endif()
913

1014
target_include_directories(gosd PUBLIC
1115
stable-diffusion.cpp

backend/go/stablediffusion-ggml/Makefile

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ else ifeq ($(BUILD_TYPE),clblas)
2929
# If it's hipblas we do have also to set CC=/opt/rocm/llvm/bin/clang CXX=/opt/rocm/llvm/bin/clang++
3030
else ifeq ($(BUILD_TYPE),hipblas)
3131
CMAKE_ARGS+=-DSD_HIPBLAS=ON -DGGML_HIPBLAS=ON
32-
# If it's OSX, DO NOT embed the metal library - -DGGML_METAL_EMBED_LIBRARY=ON requires further investigation
33-
# But if it's OSX without metal, disable it here
3432
else ifeq ($(BUILD_TYPE),vulkan)
3533
CMAKE_ARGS+=-DSD_VULKAN=ON -DGGML_VULKAN=ON
3634
else ifeq ($(OS),Darwin)
@@ -74,10 +72,10 @@ libgosd.so: sources/stablediffusion-ggml.cpp CMakeLists.txt gosd.cpp gosd.h
7472
stablediffusion-ggml: main.go gosd.go libgosd.so
7573
CGO_ENABLED=0 $(GOCMD) build -tags "$(GO_TAGS)" -o stablediffusion-ggml ./
7674

77-
package:
75+
package: stablediffusion-ggml
7876
bash package.sh
7977

80-
build: stablediffusion-ggml package
78+
build: package
8179

8280
clean:
83-
rm -rf libgosd.o build stablediffusion-ggml
81+
rm -rf libgosd.so build stablediffusion-ggml package sources

backend/go/stablediffusion-ggml/package.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ CURDIR=$(dirname "$(realpath $0)")
1010
# Create lib directory
1111
mkdir -p $CURDIR/package/lib
1212

13-
cp -avrf $CURDIR/libgosd.so $CURDIR/package/
14-
cp -avrf $CURDIR/stablediffusion-ggml $CURDIR/package/
15-
cp -rfv $CURDIR/run.sh $CURDIR/package/
13+
cp -avf $CURDIR/libgosd.so $CURDIR/package/
14+
cp -avf $CURDIR/stablediffusion-ggml $CURDIR/package/
15+
cp -fv $CURDIR/run.sh $CURDIR/package/
1616

1717
# Detect architecture and copy appropriate libraries
1818
if [ -f "/lib64/ld-linux-x86-64.so.2" ]; then
@@ -43,6 +43,8 @@ elif [ -f "/lib/ld-linux-aarch64.so.1" ]; then
4343
cp -arfLv /lib/aarch64-linux-gnu/libdl.so.2 $CURDIR/package/lib/libdl.so.2
4444
cp -arfLv /lib/aarch64-linux-gnu/librt.so.1 $CURDIR/package/lib/librt.so.1
4545
cp -arfLv /lib/aarch64-linux-gnu/libpthread.so.0 $CURDIR/package/lib/libpthread.so.0
46+
elif [ $(uname -s) = "Darwin" ]; then
47+
echo "Detected Darwin"
4648
else
4749
echo "Error: Could not detect architecture"
4850
exit 1

backend/go/whisper/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
66
add_subdirectory(./sources/whisper.cpp)
77

88
add_library(gowhisper MODULE gowhisper.cpp)
9-
target_link_libraries(gowhisper PRIVATE whisper ggml stdc++fs)
9+
target_link_libraries(gowhisper PRIVATE whisper ggml)
10+
11+
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.0)
12+
target_link_libraries(gosd PRIVATE stdc++fs)
13+
endif()
1014

1115
set_property(TARGET gowhisper PROPERTY CXX_STANDARD 17)
1216
set_target_properties(gowhisper PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})

backend/go/whisper/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,10 @@ libgowhisper.so: sources/whisper.cpp CMakeLists.txt gowhisper.cpp gowhisper.h
6868
whisper: main.go gowhisper.go libgowhisper.so
6969
CGO_ENABLED=0 $(GOCMD) build -tags "$(GO_TAGS)" -o whisper ./
7070

71-
package:
71+
package: whisper
7272
bash package.sh
7373

74-
build: whisper package
74+
build: package
7575

7676
clean:
7777
rm -rf libgowhisper.o build whisper

0 commit comments

Comments
 (0)