Skip to content

Tell the dependent crates where the ggml CMake package is - #1091

Merged
MarcusDunn merged 1 commit into
utilityai:mainfrom
bogdanr:pr/publish-ggml-cmake-dir
Aug 4, 2026
Merged

Tell the dependent crates where the ggml CMake package is#1091
MarcusDunn merged 1 commit into
utilityai:mainfrom
bogdanr:pr/publish-ggml-cmake-dir

Conversation

@bogdanr

@bogdanr bogdanr commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

The CMake build already installs a ggml package config, but no crate can find
it, because the build script does not print the path. This change prints it:

cargo:ggml_cmake_dir=<OUT_DIR>/lib64/cmake

Cargo gives the value to dependent crates in DEP_LLAMA_GGML_CMAKE_DIR. This
is the same method as the backends_dir value above it. The build script looks
in lib64/cmake/ggml and then lib/cmake/ggml, and prints nothing if it finds
neither.

Why

A program that uses llama-cpp-2 and whisper-rs together contains two copies
of ggml, and they are not the same: GGML_TYPE_COUNT is 42 in recent llama.cpp
and 40 in whisper-rs-sys 0.15.0. Users must give the linker
--allow-multiple-definition or /FORCE:MULTIPLE. The linker then discards one
copy, and half of the program uses a 42-entry table through code that expects
40 entries. We saw this stop a program with STATUS_HEAP_CORRUPTION.

whisper-rs has an open PR for WHISPER_USE_SYSTEM_GGML
(#260), but it needs the
path of an installed ggml. This change supplies that path.

Test

We made a program that starts a LlamaBackend and whisper, and built it two
times on Linux with rust-lld and no linker flag.

Without whisper-rs/system-ggml:

rust-lld: error: duplicate symbol: ggml_backend_buft_name
... (lld stops after 20 errors)

With whisper-rs/system-ggml and CMAKE_PREFIX_PATH set to the new path, it
links and runs. whisper-rs-sys builds 0 ggml archives instead of 6, and
nm --defined-only <bin> | grep -cw ggml_init gives 1.

Limits and risk

Cargo gives DEP_LLAMA_GGML_CMAKE_DIR only to direct dependents.
whisper-rs-sys is not one today, so users must set CMAKE_PREFIX_PATH, as in
the test. A subsequent change to whisper-rs-sys can add an optional dependency
on this crate and read the variable.

Risk is low: no new feature, no new dependency, no change to a build step.
cargo fmt and cargo clippy are clean.

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.
@MarcusDunn
MarcusDunn merged commit aae10bb into utilityai:main Aug 4, 2026
3 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants