Skip to main content

gglib_core/paths/
llama.rs

1//! Llama.cpp binary path resolution.
2//!
3//! Provides paths to the managed llama-server binary,
4//! as well as the llama.cpp repository and configuration files.
5
6use std::path::PathBuf;
7
8use super::error::PathError;
9use super::platform::resource_root;
10
11/// Get the gglib data directory containing llama binaries.
12///
13/// Returns the `.llama/` directory containing helper binaries.
14/// In dev, this is in the repo. In release, this is in the user data dir.
15pub fn gglib_data_dir() -> Result<PathBuf, PathError> {
16    Ok(resource_root()?.join(".llama"))
17}
18
19/// Get the path to the managed llama-server binary.
20pub fn llama_server_path() -> Result<PathBuf, PathError> {
21    let gglib_dir = gglib_data_dir()?;
22
23    #[cfg(target_os = "windows")]
24    let binary_name = "llama-server.exe";
25
26    #[cfg(not(target_os = "windows"))]
27    let binary_name = "llama-server";
28
29    Ok(gglib_dir.join("bin").join(binary_name))
30}
31
32/// Get the path to the managed `llama-bench` binary.
33///
34/// `llama-bench` is included in the pre-built binary archives alongside
35/// `llama-server`. For source builds it requires `-DLLAMA_BUILD_BENCH=ON`
36/// (see Phase 6 of the benchmark implementation plan).
37pub fn llama_bench_path() -> Result<PathBuf, PathError> {
38    let gglib_dir = gglib_data_dir()?;
39
40    #[cfg(target_os = "windows")]
41    let binary_name = "llama-bench.exe";
42
43    #[cfg(not(target_os = "windows"))]
44    let binary_name = "llama-bench";
45
46    Ok(gglib_dir.join("bin").join(binary_name))
47}
48
49/// Get the path to the llama.cpp repository directory.
50pub fn llama_cpp_dir() -> Result<PathBuf, PathError> {
51    let gglib_dir = gglib_data_dir()?;
52    Ok(gglib_dir.join("llama.cpp"))
53}
54
55/// Get the path to the llama build configuration file.
56pub fn llama_config_path() -> Result<PathBuf, PathError> {
57    let gglib_dir = gglib_data_dir()?;
58    Ok(gglib_dir.join("llama-config.json"))
59}
60
61#[cfg(test)]
62mod tests {
63    use super::*;
64
65    #[test]
66    fn test_llama_server_path() {
67        let result = llama_server_path();
68        assert!(result.is_ok());
69
70        let path = result.unwrap();
71        #[cfg(target_os = "windows")]
72        assert!(path.to_string_lossy().ends_with("llama-server.exe"));
73
74        #[cfg(not(target_os = "windows"))]
75        assert!(path.to_string_lossy().ends_with("llama-server"));
76    }
77
78    #[test]
79    fn test_llama_bench_path() {
80        let result = llama_bench_path();
81        assert!(result.is_ok());
82
83        let path = result.unwrap();
84        #[cfg(target_os = "windows")]
85        assert!(path.to_string_lossy().ends_with("llama-bench.exe"));
86
87        #[cfg(not(target_os = "windows"))]
88        assert!(path.to_string_lossy().ends_with("llama-bench"));
89    }
90}