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
24 changes: 24 additions & 0 deletions crates/llama-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,12 @@ fn build_from_source(source_dir: &Path, out_dir: &Path, manifest_dir: &Path) {
build_common_bridge(source_dir, manifest_dir, false);
emit_common_link_deps(&build_dir);
emit_install_link_search_paths(&install_dir);
// b9837 compiles build-info (llama_build_number(), llama_commit(),
// llama_build_info(), and the LLAMA_BUILD_* globals) into a separate
// `llama-common-base` archive that libllama-common depends on but that cmake
// does not install, so the install-dir scan above misses it. Link it
// explicitly — it must come after llama-common, which references the symbols.
emit_build_info_link_deps(&build_dir);
if use_cuda {
emit_cuda_link_deps();
}
Expand Down Expand Up @@ -950,6 +956,24 @@ fn has_static_lib(dir: &Path, name: &str) -> bool {
dir.join(format!("lib{name}.a")).exists() || dir.join(format!("{name}.lib")).exists()
}

/// Link the `llama-common-base` static archive, which holds the generated
/// build-info symbols (`llama_build_number()`, `llama_commit()`,
/// `llama_build_info()`, and the `LLAMA_BUILD_*` globals). Since b9837 these
/// live in their own archive that libllama-common depends on but that cmake does
/// not install, so the install-dir scan misses them. Emitting this after the
/// install libs keeps it after llama-common on the link line, which is required
/// because llama-common references these symbols.
fn emit_build_info_link_deps(build_dir: &Path) {
let common_dir = build_dir.join("common");
if has_static_lib(&common_dir, "llama-common-base") {
println!(
"cargo:rustc-link-search=native={}",
common_dir.to_string_lossy()
);
println!("cargo:rustc-link-lib=static=llama-common-base");
}
}

fn emit_common_link_deps(build_dir: &Path) {
let common_dir = build_dir.join("common");
if has_static_lib(&common_dir, "common") {
Expand Down
15 changes: 5 additions & 10 deletions crates/llama-sys/src/autocommit_common_bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,11 @@
#include "log.h"
#include "sampling.h"

// common.h defines a global `build_info` string derived from these variables.
// In this integration path libcommon.a is linked directly from the build tree
// (where build_info object may not be installed), so provide safe fallbacks.
// When using prebuilt binary releases, libllama-common already provides these.
#ifndef LLAMA_CPP_PREBUILT
int LLAMA_BUILD_NUMBER = 0;
const char * LLAMA_COMMIT = "unknown";
const char * LLAMA_COMPILER = "unknown";
const char * LLAMA_BUILD_TARGET = "unknown";
#endif
// build-info symbols (llama_build_number(), llama_commit(), the LLAMA_BUILD_*
// globals, ...) are provided by libllama-common at link time: from the prebuilt
// libllama-common.so for binary releases, and from the static llama-common-base
// archive for source builds (linked explicitly in build.rs). Defining fallbacks
// here would collide with those real definitions, so we don't.

struct autocommit_common_config {
common_params params;
Expand Down
Loading