Skip to content

Commit ce8a04f

Browse files
fix(stablediffusion): embed Metal library (#11531)
The Darwin workflow passes BUILD_TYPE=metal but does not define OS=Darwin. The backend therefore omitted its Metal CMake flags and shipped the runtime source path instead of the embedded library. Map the requested build type directly to the Metal flags and guard the build contract with a dry-run regression test. Assisted-by: Codex:gpt-5 Co-authored-by: localai-org-maint-bot <306269227+localai-org-maint-bot@users.noreply.github.com>
1 parent 9f17f5e commit ce8a04f

2 files changed

Lines changed: 25 additions & 9 deletions

File tree

backend/go/stablediffusion-ggml/Makefile

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,9 @@ else ifeq ($(BUILD_TYPE),hipblas)
4242
CMAKE_ARGS+=-DSD_HIPBLAS=ON -DGGML_HIPBLAS=ON -DAMDGPU_TARGETS=$(AMDGPU_TARGETS)
4343
else ifeq ($(BUILD_TYPE),vulkan)
4444
CMAKE_ARGS+=-DSD_VULKAN=ON -DGGML_VULKAN=ON
45-
else ifeq ($(OS),Darwin)
46-
ifneq ($(BUILD_TYPE),metal)
47-
CMAKE_ARGS+=-DSD_METAL=OFF -DGGML_METAL=OFF
48-
else
49-
CMAKE_ARGS+=-DSD_METAL=ON -DGGML_METAL=ON
50-
CMAKE_ARGS+=-DGGML_METAL_EMBED_LIBRARY=ON
51-
endif
45+
else ifeq ($(BUILD_TYPE),metal)
46+
CMAKE_ARGS+=-DSD_METAL=ON -DGGML_METAL=ON
47+
CMAKE_ARGS+=-DGGML_METAL_EMBED_LIBRARY=ON
5248
endif
5349

5450
ifeq ($(BUILD_TYPE),sycl_f16)
@@ -72,7 +68,6 @@ sources/stablediffusion-ggml.cpp:
7268
git checkout $(STABLEDIFFUSION_GGML_VERSION) && \
7369
git submodule update --init --recursive --depth 1 --single-branch
7470

75-
# Detect OS
7671
UNAME_S := $(shell uname -s)
7772

7873
# Only build CPU variants on Linux
@@ -134,4 +129,4 @@ libgosd-custom: CMakeLists.txt cpp/gosd.cpp cpp/gosd.h
134129
(mv build-$(SO_TARGET)/libgosd.so ./$(SO_TARGET) 2>/dev/null || \
135130
mv build-$(SO_TARGET)/libgosd.dylib ./$(SO_TARGET) 2>/dev/null)
136131

137-
all: stablediffusion-ggml package
132+
all: stablediffusion-ggml package
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
CURDIR=$(dirname "$(realpath "$0")")
5+
BACKEND_DIR="$CURDIR/../../backend/go/stablediffusion-ggml"
6+
7+
build_commands=$(make -Bn -C "$BACKEND_DIR" \
8+
BUILD_TYPE=metal \
9+
libgosd-fallback.so)
10+
11+
for expected_flag in \
12+
-DSD_METAL=ON \
13+
-DGGML_METAL=ON \
14+
-DGGML_METAL_EMBED_LIBRARY=ON; do
15+
if ! grep -Fq -- "$expected_flag" <<<"$build_commands"; then
16+
echo "FAIL: Darwin Metal build omitted $expected_flag"
17+
exit 1
18+
fi
19+
done
20+
21+
echo "PASS: stablediffusion-ggml embeds its Darwin Metal library"

0 commit comments

Comments
 (0)