Skip to content

Commit c45a061

Browse files
committed
Feature guard mtmd + cleanup
Signed-off-by: Dennis Keck <[email protected]>
1 parent 222df6e commit c45a061

File tree

6 files changed

+18
-67
lines changed

6 files changed

+18
-67
lines changed

examples/mtmd/Cargo.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,8 @@ version = "0.1.86"
44
edition = "2021"
55

66
[dependencies]
7-
llama-cpp-2 = { path = "../../llama-cpp-2", version = "0.1.86" }
7+
llama-cpp-2 = { path = "../../llama-cpp-2", version = "0.1.86", features = ["mtmd"] }
88
clap = { workspace = true, features = ["derive"] }
9-
# hf-hub = { workspace = true }
10-
# anyhow = { workspace = true }
11-
# encoding_rs = { workspace = true }
129

1310
[features]
1411
cuda = ["llama-cpp-2/cuda"]

examples/reranker/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ native = ["llama-cpp-2/native"]
1717
vulkan = ["llama-cpp-2/vulkan"]
1818

1919
[lints]
20-
workspace = true
20+
workspace = true

llama-cpp-2/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ openmp = ["llama-cpp-sys-2/openmp"]
3030
sampler = []
3131
# Only has an impact on Android.
3232
android-shared-stdcxx = ["llama-cpp-sys-2/shared-stdcxx"]
33+
mtmd = ["llama-cpp-sys-2/mtmd"]
3334

3435

3536
[target.'cfg(all(target_os = "macos", any(target_arch = "aarch64", target_arch = "arm64")))'.dependencies]

llama-cpp-2/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ pub mod llama_backend;
2727
pub mod llama_batch;
2828
mod log;
2929
pub mod model;
30+
#[cfg(feature = "mtmd")]
3031
pub mod mtmd;
3132
pub mod sampling;
3233
pub mod timing;

llama-cpp-sys-2/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,4 @@ native = []
7979
openmp = []
8080
# Only has an impact on Android.
8181
shared-stdcxx = []
82+
mtmd = []

llama-cpp-sys-2/build.rs

Lines changed: 13 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -272,10 +272,15 @@ fn main() {
272272
.allowlist_type("ggml_.*")
273273
.allowlist_function("llama_.*")
274274
.allowlist_type("llama_.*")
275-
.allowlist_function("mtmd_.*")
276-
.allowlist_type("mtmd_.*")
277275
.prepend_enum_name(false);
278276

277+
// Configure mtmd feature if enabled
278+
if cfg!(feature = "mtmd") {
279+
bindings_builder = bindings_builder
280+
.allowlist_function("mtmd_.*")
281+
.allowlist_type("mtmd_.*");
282+
}
283+
279284
// Configure Android-specific bindgen settings
280285
if matches!(target_os, TargetOs::Android) {
281286
// Detect Android NDK from environment variables
@@ -440,11 +445,14 @@ fn main() {
440445
config.define("LLAMA_BUILD_TESTS", "OFF");
441446
config.define("LLAMA_BUILD_EXAMPLES", "OFF");
442447
config.define("LLAMA_BUILD_SERVER", "OFF");
448+
config.define("LLAMA_BUILD_TOOLS", "OFF");
443449
config.define("LLAMA_CURL", "OFF");
444450

445-
// Required for mtmd.rs
446-
config.define("LLAMA_BUILD_COMMON", "ON");
447-
config.define("LLAMA_BUILD_TOOLS", "ON");
451+
if cfg!(feature = "mtmd") {
452+
config.define("LLAMA_BUILD_COMMON", "ON");
453+
// mtmd support in llama-cpp is within the tools directory
454+
config.define("LLAMA_BUILD_TOOLS", "ON");
455+
}
448456

449457
// Pass CMAKE_ environment variables down to CMake
450458
for (key, value) in env::vars() {
@@ -634,63 +642,6 @@ fn main() {
634642

635643
let build_dir = config.build();
636644

637-
let lib_dir = out_dir.join("lib");
638-
debug_log!("Lib directory: {}", lib_dir.display());
639-
640-
// Copy common library
641-
let common_lib_src = build_dir.join("build/common/libcommon.a");
642-
debug_log!(
643-
"Looking for common library at: {}",
644-
common_lib_src.display()
645-
);
646-
if common_lib_src.exists() {
647-
let common_lib_dst = lib_dir.join("libcommon.a");
648-
std::fs::copy(&common_lib_src, &common_lib_dst).unwrap_or_else(|e| {
649-
panic!("Failed to copy {common_lib_src:?} to {common_lib_dst:?}: {e:?}");
650-
});
651-
debug_log!("Copied common library: {}", common_lib_dst.display());
652-
} else {
653-
debug_log!("Common library not found at: {}", common_lib_src.display());
654-
}
655-
656-
// Copy mtmd static library
657-
let mtmd_static_src = build_dir.join("build/tools/mtmd/libmtmd_static.a");
658-
debug_log!(
659-
"Looking for mtmd static library at: {}",
660-
mtmd_static_src.display()
661-
);
662-
if mtmd_static_src.exists() {
663-
let mtmd_static_dst = lib_dir.join("libmtmd_static.a");
664-
std::fs::copy(&mtmd_static_src, &mtmd_static_dst).unwrap_or_else(|e| {
665-
panic!("Failed to copy {mtmd_static_src:?} to {mtmd_static_dst:?}: {e:?}");
666-
});
667-
debug_log!("Copied mtmd static library: {}", mtmd_static_dst.display());
668-
} else {
669-
debug_log!(
670-
"Mtmd static library not found at: {}",
671-
mtmd_static_src.display()
672-
);
673-
}
674-
675-
// Copy mtmd audio library
676-
let mtmd_audio_src = build_dir.join("build/tools/mtmd/libmtmd_audio.a");
677-
debug_log!(
678-
"Looking for mtmd audio library at: {}",
679-
mtmd_audio_src.display()
680-
);
681-
if mtmd_audio_src.exists() {
682-
let mtmd_audio_dst = lib_dir.join("libmtmd_audio.a");
683-
std::fs::copy(&mtmd_audio_src, &mtmd_audio_dst).unwrap_or_else(|e| {
684-
panic!("Failed to copy {mtmd_audio_src:?} to {mtmd_audio_dst:?}: {e:?}");
685-
});
686-
debug_log!("Copied mtmd audio library: {}", mtmd_audio_dst.display());
687-
} else {
688-
debug_log!(
689-
"Mtmd audio library not found at: {}",
690-
mtmd_audio_src.display()
691-
);
692-
}
693-
694645
// Search paths
695646
println!("cargo:rustc-link-search={}", out_dir.join("lib").display());
696647
println!(

0 commit comments

Comments
 (0)