Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/integration-test-lib-infer-diffusion.yml
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ jobs:
shell: bash
env:
QASE_API_TOKEN: ${{ secrets.QASE_API_TOKEN }}
SD_CPU_ONLY: ${{ matrix.platform == 'darwin' && '1' || '' }}
SD_CPU_ONLY: '1'

- name: Run integration test (Windows)
if: ${{ matrix.platform == 'win32' }}
Expand Down
2 changes: 1 addition & 1 deletion packages/lib-infer-diffusion/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ if((ANDROID OR UNIX) AND NOT APPLE)
# loaded at runtime. ggml's cmake config does not export them as imported
# targets — find the installed .so files and create targets ourselves.
foreach(_backend ${GGML_AVAILABLE_BACKENDS})
find_library(_${_backend}_LIB "qvac-diffusion-${_backend}" REQUIRED)
find_library(_${_backend}_LIB "${_backend}" REQUIRED)
add_library(ggml::${_backend} SHARED IMPORTED)
set_target_properties(ggml::${_backend} PROPERTIES
IMPORTED_LOCATION "${_${_backend}_LIB}"
Expand Down
3 changes: 2 additions & 1 deletion packages/lib-infer-diffusion/vcpkg-configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"repository": "https://github.com/microsoft/vcpkg",
"packages": [
"gtest",
"picojson"
"picojson",
"stb"
]
}
]
Expand Down
49 changes: 29 additions & 20 deletions packages/lib-infer-diffusion/vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"dependencies": [
{
"name": "opencl",
"platform": "android"
"name": "ggml",
"version>=": "2026-01-30"
},
"picojson",
{
Expand All @@ -15,49 +15,58 @@
},
{
"name": "stable-diffusion-cpp",
"version>=": "0.0.1"
}
"version>=": "2026-03-01"
},
"stb"
],
"features": {
"tests": {
"description": "Build tests",
"cuda": {
"description": "Enable CUDA GPU backend",
"dependencies": [
"gtest"
{
"name": "stable-diffusion-cpp",
"features": [
"cuda"
]
}
]
},
"metal": {
"description": "Enable Metal GPU backend (macOS/iOS)",
"dependencies": [
{
"name": "stable-diffusion-cpp",
"features": ["metal"]
"features": [
"metal"
]
}
]
},
"vulkan": {
"description": "Enable Vulkan GPU backend",
"opencl": {
"description": "Enable OpenCL GPU backend (Android/Adreno)",
"dependencies": [
{
"name": "stable-diffusion-cpp",
"features": ["vulkan"]
"features": [
"opencl"
]
}
]
},
"cuda": {
"description": "Enable CUDA GPU backend",
"tests": {
"description": "Build tests",
"dependencies": [
{
"name": "stable-diffusion-cpp",
"features": ["cuda"]
}
"gtest"
]
},
"opencl": {
"description": "Enable OpenCL GPU backend (Android/Adreno)",
"vulkan": {
"description": "Enable Vulkan GPU backend",
"dependencies": [
{
"name": "stable-diffusion-cpp",
"features": ["opencl"]
"features": [
"vulkan"
]
}
]
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Detect the Vulkan version shipped with the Android NDK by parsing
# vulkan_core.h from the NDK sysroot. Sets `vulkan_version` in the
# caller's scope (e.g. "1.3.275").
function(detect_ndk_vulkan_version)
string(TOLOWER "${CMAKE_HOST_SYSTEM_NAME}" host_system_name_lower)

file(GLOB host_dirs LIST_DIRECTORIES true "$ENV{ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/${host_system_name_lower}-*")
if(host_dirs)
list(GET host_dirs 0 host_dir)
get_filename_component(host_arch "${host_dir}" NAME)
set(vulkan_core_h "$ENV{ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/${host_arch}/sysroot/usr/include/vulkan/vulkan_core.h")
else()
message(FATAL_ERROR "Could not find NDK host directory for ${host_system_name_lower}")
endif()

if(NOT EXISTS "${vulkan_core_h}")
message(FATAL_ERROR "vulkan_core.h not found at ${vulkan_core_h}")
endif()

file(READ "${vulkan_core_h}" header_content)
string(REGEX MATCH "VK_HEADER_VERSION ([0-9]+)" version_match "${header_content}")
if(version_match)
set(header_version_3 "${CMAKE_MATCH_1}")
else()
message(FATAL_ERROR "Could not extract VK_HEADER_VERSION from ${vulkan_core_h}")
endif()

# Extract major.minor version from VK_HEADER_VERSION_COMPLETE for download URL
string(REGEX MATCH "VK_HEADER_VERSION_COMPLETE VK_MAKE_API_VERSION\\(([0-9]+), ([0-9]+), ([0-9]+)" version_match "${header_content}")
if(version_match)
set(major "${CMAKE_MATCH_2}")
set(minor "${CMAKE_MATCH_3}")
set(vulkan_version "${major}.${minor}.${header_version_3}" PARENT_SCOPE)
else()
message(FATAL_ERROR "Could not extract VK_HEADER_VERSION_COMPLETE from ${vulkan_core_h}")
endif()
endfunction()
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
--- a/cmake/ggml-config.cmake.in
+++ b/cmake/ggml-config.cmake.in
@@ -112,7 +112,8 @@
add_library(ggml::ggml UNKNOWN IMPORTED)
set_target_properties(ggml::ggml
PROPERTIES
- IMPORTED_LOCATION "${GGML_LIBRARY}")
+ IMPORTED_LOCATION "${GGML_LIBRARY}"
+ INTERFACE_INCLUDE_DIRECTORIES "${GGML_INCLUDE_DIR}")

find_library(GGML_BASE_LIBRARY ggml-base
REQUIRED
@@ -120,6 +121,7 @@
NO_CMAKE_FIND_ROOT_PATH)

add_library(ggml::ggml-base UNKNOWN IMPORTED)
+ set_property(TARGET ggml::ggml-base PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${GGML_INCLUDE_DIR}")
set_target_properties(ggml::ggml-base
PROPERTIES
IMPORTED_LOCATION "${GGML_BASE_LIBRARY}")
31 changes: 31 additions & 0 deletions packages/lib-infer-diffusion/vcpkg/ports/ggml/ggml-max-name.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
diff --git a/cmake/ggml-config.cmake.in b/cmake/ggml-config.cmake.in
index 91c9d5c..b7d8ec2 100644
--- a/cmake/ggml-config.cmake.in
+++ b/cmake/ggml-config.cmake.in
@@ -124,6 +124,11 @@ if(NOT TARGET ggml::ggml)
PROPERTIES
IMPORTED_LOCATION "${GGML_BASE_LIBRARY}")

+ if(GGML_MAX_NAME)
+ set_property(TARGET ggml::ggml-base APPEND PROPERTY
+ INTERFACE_COMPILE_DEFINITIONS "GGML_MAX_NAME=${GGML_MAX_NAME}")
+ endif()
+
set(_ggml_all_targets "")
if (NOT GGML_BACKEND_DL)
foreach(_ggml_backend ${GGML_AVAILABLE_BACKENDS})
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 2650237..d0987d1 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -221,6 +221,10 @@ if (GGML_SCHED_NO_REALLOC)
target_compile_definitions(ggml-base PUBLIC GGML_SCHED_NO_REALLOC)
endif()

+if (DEFINED GGML_MAX_NAME)
+ target_compile_definitions(ggml-base PUBLIC GGML_MAX_NAME=${GGML_MAX_NAME})
+endif()
+
add_library(ggml
ggml-backend-dl.cpp
ggml-backend-reg.cpp)
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -319,6 +319,7 @@
include/ggml-cpp.h
include/ggml-cuda.h
include/ggml-opt.h
+ include/ggml-opencl.h
include/ggml-metal.h
include/ggml-rpc.h
include/ggml-virtgpu.h
166 changes: 166 additions & 0 deletions packages/lib-infer-diffusion/vcpkg/ports/ggml/portfile.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
# ggml vcpkg overlay port
#
# Builds the ggml tensor library from ggml-org/ggml.
# Pinned to the commit used by stable-diffusion.cpp tag master-514-5792c66.
#
# Installed artefacts:
# include/ggml.h (+ other ggml public headers)
# lib/libggml.a, lib/libggml-base.a, lib/libggml-cpu.a, …
# lib/cmake/ggml/ (CMake package config)
#
# GPU backend selection via vcpkg features:
# metal -> GGML_METAL=ON (macOS/iOS, default-feature on Apple platforms)
# vulkan -> GGML_VULKAN=ON
# cuda -> GGML_CUDA=ON
# opencl -> GGML_OPENCL=ON

vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH
REPO ggml-org/ggml
REF a8db410a252c8c8f2d120c6f2e7133ebe032f35d
SHA512 bbca42948d994a33f1d6b2a65b254606f8b563d84d2b456db161cf55b6e01ed6b5eae7ad2c878bc4f03afc664c4209c2e87438fd4171a6f7c77dd907706e51bf
HEAD_REF master
PATCHES
ggml-max-name.patch
ggml-opencl-public-header.patch
ggml-config-include-dir.patch
)

# --- GPU feature flags ---
set(GGML_METAL OFF)
set(GGML_VULKAN OFF)
set(GGML_CUDA OFF)
set(GGML_OPENCL OFF)

if("metal" IN_LIST FEATURES)
set(GGML_METAL ON)
endif()

if("vulkan" IN_LIST FEATURES)
set(GGML_VULKAN ON)
endif()

set(GGML_CUDA_COMPILER_OPTION "")

if("cuda" IN_LIST FEATURES)
set(GGML_CUDA ON)
# Locate nvcc explicitly — /usr/local/cuda/bin may not be on the PATH that
# vcpkg's isolated cmake process inherits.
find_program(NVCC_EXECUTABLE nvcc
PATHS /usr/local/cuda/bin /usr/local/cuda-12.8/bin
NO_DEFAULT_PATH
)
if(NOT NVCC_EXECUTABLE)
find_program(NVCC_EXECUTABLE nvcc REQUIRED)
endif()
set(GGML_CUDA_COMPILER_OPTION "-DCMAKE_CUDA_COMPILER=${NVCC_EXECUTABLE}")
message(STATUS "CUDA compiler: ${NVCC_EXECUTABLE}")
endif()

if("opencl" IN_LIST FEATURES)
set(GGML_OPENCL ON)
endif()

# --- Android: fetch NDK-matched Vulkan C++ headers ---
# The NDK ships vulkan/vulkan_core.h (C) but not vulkan/vulkan.hpp (C++).
# Rather than pulling the vcpkg vulkan-headers package (which may be a
# different version), we detect the NDK's exact Vulkan version and download
# the matching C++ headers from KhronosGroup/Vulkan-Headers.
if(VCPKG_TARGET_IS_ANDROID AND "vulkan" IN_LIST FEATURES)
include(${CMAKE_CURRENT_LIST_DIR}/android-vulkan-version.cmake)
detect_ndk_vulkan_version()
message(STATUS "NDK Vulkan version: ${vulkan_version}")

file(DOWNLOAD
"https://github.com/KhronosGroup/Vulkan-Headers/archive/refs/tags/v${vulkan_version}.tar.gz"
"${SOURCE_PATH}/vulkan-hpp-${vulkan_version}.tar.gz"
TLS_VERIFY ON
)
file(ARCHIVE_EXTRACT
INPUT "${SOURCE_PATH}/vulkan-hpp-${vulkan_version}.tar.gz"
DESTINATION "${SOURCE_PATH}"
PATTERNS "*.hpp"
)
# ggml_add_backend_library adds target_include_directories(${backend} PRIVATE ..)
# which resolves to src/ for backends under src/ggml-vulkan/. Placing the
# headers at src/vulkan/*.hpp makes #include <vulkan/vulkan.hpp> resolve.
file(COPY "${SOURCE_PATH}/Vulkan-Headers-${vulkan_version}/include/"
DESTINATION "${SOURCE_PATH}/src/")
endif()

# --- Platform options ---
set(PLATFORM_OPTIONS)

if(VCPKG_TARGET_IS_ANDROID)
# GGML_BACKEND_DL compiles each GPU backend as a MODULE (.so) loaded at
# runtime via dlopen. Requires BUILD_SHARED_LIBS=ON so ggml-base is a
# shared library that MODULE backends can link against.
set(VCPKG_LIBRARY_LINKAGE dynamic)
list(APPEND PLATFORM_OPTIONS
-DGGML_BACKEND_DL=ON
-DGGML_CPU_ALL_VARIANTS=ON
-DGGML_CPU_REPACK=ON
-DGGML_VULKAN_DISABLE_COOPMAT=ON
-DGGML_VULKAN_DISABLE_COOPMAT2=ON
)
endif()

# --- Configure & build ---
vcpkg_cmake_configure(
SOURCE_PATH "${SOURCE_PATH}"
OPTIONS
-DBUILD_SHARED_LIBS=OFF
-DGGML_NATIVE=OFF
-DGGML_CCACHE=OFF
-DGGML_OPENMP=OFF
-DGGML_LLAMAFILE=OFF
-DGGML_BUILD_TESTS=OFF
-DGGML_BUILD_EXAMPLES=OFF
-DGGML_METAL=${GGML_METAL}
-DGGML_VULKAN=${GGML_VULKAN}
-DGGML_CUDA=${GGML_CUDA}
-DGGML_OPENCL=${GGML_OPENCL}
-DGGML_MAX_NAME=128 # stable-diffusion.cpp requires >= 128
${GGML_CUDA_COMPILER_OPTION}
${PLATFORM_OPTIONS}
)

vcpkg_cmake_install()

# --- Install DL backend .so files for Android ---
# When GGML_BACKEND_DL is ON, ggml builds each backend as a MODULE target
# but does NOT install them via cmake install(). They sit in the build
# output directory (bin/). Copy them into the vcpkg packages lib/ so the
# consuming addon can find and bundle them.
if(VCPKG_TARGET_IS_ANDROID)
file(GLOB _backend_sos "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel/bin/libggml-*.so")
if(_backend_sos)
file(INSTALL ${_backend_sos} DESTINATION "${CURRENT_PACKAGES_DIR}/lib")
endif()
endif()

# Fix up the CMake package config installed by ggml's own build system.
vcpkg_cmake_config_fixup(PACKAGE_NAME ggml CONFIG_PATH lib/cmake/ggml)

# ggml installs a .pc to share/pkgconfig; move it to lib/pkgconfig and fix
# absolute paths so vcpkg's post-build checks pass.
if(EXISTS "${CURRENT_PACKAGES_DIR}/share/pkgconfig/ggml.pc")
file(MAKE_DIRECTORY "${CURRENT_PACKAGES_DIR}/lib/pkgconfig")
file(RENAME "${CURRENT_PACKAGES_DIR}/share/pkgconfig/ggml.pc"
"${CURRENT_PACKAGES_DIR}/lib/pkgconfig/ggml.pc")
endif()
if(EXISTS "${CURRENT_PACKAGES_DIR}/debug/share/pkgconfig/ggml.pc")
file(MAKE_DIRECTORY "${CURRENT_PACKAGES_DIR}/debug/lib/pkgconfig")
file(RENAME "${CURRENT_PACKAGES_DIR}/debug/share/pkgconfig/ggml.pc"
"${CURRENT_PACKAGES_DIR}/debug/lib/pkgconfig/ggml.pc")
endif()
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/share/pkgconfig"
"${CURRENT_PACKAGES_DIR}/debug/share/pkgconfig")
vcpkg_fixup_pkgconfig()

file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include")
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/share")

file(INSTALL "${CMAKE_CURRENT_LIST_DIR}/usage" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}")
vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE")

10 changes: 10 additions & 0 deletions packages/lib-infer-diffusion/vcpkg/ports/ggml/usage
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
The package ggml provides CMake integration:

find_package(ggml CONFIG REQUIRED)
target_link_libraries(main PRIVATE ggml::ggml)

Available vcpkg features:
metal - Metal GPU backend (macOS/iOS, auto-enabled on Apple)
vulkan - Vulkan GPU backend
cuda - CUDA GPU backend
opencl - OpenCL GPU backend
Loading
Loading