From 5983fc7f35550c728ea99b2febbe2543f958e71f Mon Sep 17 00:00:00 2001 From: Bogdan Radulescu Date: Tue, 4 Aug 2026 15:14:23 +0300 Subject: [PATCH] Tell the dependent crates where the ggml CMake package is The CMake build installs a ggml package config, but no crate can find it. The build script now prints the path to that config. Cargo gives the path to each dependent crate in the DEP_LLAMA_GGML_CMAKE_DIR variable. A crate that also builds ggml can put this path in CMAKE_PREFIX_PATH. Then it uses this ggml, and the program contains only one ggml. Two copies of ggml in one program cause duplicate symbols and unsafe behavior. This is the same method as the backends_dir value above it. The change adds no feature and changes no build. --- llama-cpp-sys-2/build.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/llama-cpp-sys-2/build.rs b/llama-cpp-sys-2/build.rs index f8b8fe278..7d5295cdb 100644 --- a/llama-cpp-sys-2/build.rs +++ b/llama-cpp-sys-2/build.rs @@ -1001,6 +1001,18 @@ fn main() { println!("cargo:backends_dir={}", out_dir.join("backends").display()); } + // The CMake build installs a ggml package config. Tell the dependent crates where it + // is, in the DEP_LLAMA_GGML_CMAKE_DIR variable. A dependent crate that also builds + // ggml can put this path in CMAKE_PREFIX_PATH and use this ggml. Then there is only + // one ggml in the program. Two copies of ggml in one program cause duplicate symbols. + for libdir in ["lib64", "lib"] { + let cmake_dir = out_dir.join(libdir).join("cmake"); + if cmake_dir.join("ggml").is_dir() { + println!("cargo:ggml_cmake_dir={}", cmake_dir.display()); + break; + } + } + // Build mtmd directly with cc::Build, bypassing the cmake tools build. // Using LLAMA_BUILD_TOOLS=ON would pull in all tools (batched-bench, quantize, etc.) // and their CMakeLists.txt files, which are not included in the crate package.