From ce8a04fe46aff510b81824cb76296885ba967ce4 Mon Sep 17 00:00:00 2001 From: localai-org-maint-bot Date: Sat, 15 Aug 2026 13:15:55 +0200 Subject: [PATCH] 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> --- backend/go/stablediffusion-ggml/Makefile | 13 ++++-------- .../build/stablediffusion-metal-build_test.sh | 21 +++++++++++++++++++ 2 files changed, 25 insertions(+), 9 deletions(-) create mode 100644 scripts/build/stablediffusion-metal-build_test.sh diff --git a/backend/go/stablediffusion-ggml/Makefile b/backend/go/stablediffusion-ggml/Makefile index ce5c7df3b..6b5036415 100644 --- a/backend/go/stablediffusion-ggml/Makefile +++ b/backend/go/stablediffusion-ggml/Makefile @@ -42,13 +42,9 @@ else ifeq ($(BUILD_TYPE),hipblas) CMAKE_ARGS+=-DSD_HIPBLAS=ON -DGGML_HIPBLAS=ON -DAMDGPU_TARGETS=$(AMDGPU_TARGETS) else ifeq ($(BUILD_TYPE),vulkan) CMAKE_ARGS+=-DSD_VULKAN=ON -DGGML_VULKAN=ON -else ifeq ($(OS),Darwin) - ifneq ($(BUILD_TYPE),metal) - CMAKE_ARGS+=-DSD_METAL=OFF -DGGML_METAL=OFF - else - CMAKE_ARGS+=-DSD_METAL=ON -DGGML_METAL=ON - CMAKE_ARGS+=-DGGML_METAL_EMBED_LIBRARY=ON - endif +else ifeq ($(BUILD_TYPE),metal) + CMAKE_ARGS+=-DSD_METAL=ON -DGGML_METAL=ON + CMAKE_ARGS+=-DGGML_METAL_EMBED_LIBRARY=ON endif ifeq ($(BUILD_TYPE),sycl_f16) @@ -72,7 +68,6 @@ sources/stablediffusion-ggml.cpp: git checkout $(STABLEDIFFUSION_GGML_VERSION) && \ git submodule update --init --recursive --depth 1 --single-branch -# Detect OS UNAME_S := $(shell uname -s) # Only build CPU variants on Linux @@ -134,4 +129,4 @@ libgosd-custom: CMakeLists.txt cpp/gosd.cpp cpp/gosd.h (mv build-$(SO_TARGET)/libgosd.so ./$(SO_TARGET) 2>/dev/null || \ mv build-$(SO_TARGET)/libgosd.dylib ./$(SO_TARGET) 2>/dev/null) -all: stablediffusion-ggml package \ No newline at end of file +all: stablediffusion-ggml package diff --git a/scripts/build/stablediffusion-metal-build_test.sh b/scripts/build/stablediffusion-metal-build_test.sh new file mode 100644 index 000000000..80fdb2379 --- /dev/null +++ b/scripts/build/stablediffusion-metal-build_test.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash +set -euo pipefail + +CURDIR=$(dirname "$(realpath "$0")") +BACKEND_DIR="$CURDIR/../../backend/go/stablediffusion-ggml" + +build_commands=$(make -Bn -C "$BACKEND_DIR" \ + BUILD_TYPE=metal \ + libgosd-fallback.so) + +for expected_flag in \ + -DSD_METAL=ON \ + -DGGML_METAL=ON \ + -DGGML_METAL_EMBED_LIBRARY=ON; do + if ! grep -Fq -- "$expected_flag" <<<"$build_commands"; then + echo "FAIL: Darwin Metal build omitted $expected_flag" + exit 1 + fi +done + +echo "PASS: stablediffusion-ggml embeds its Darwin Metal library"