gglib_core/paths/
llama.rs1use std::path::PathBuf;
7
8use super::error::PathError;
9use super::platform::resource_root;
10
11pub fn gglib_data_dir() -> Result<PathBuf, PathError> {
16 Ok(resource_root()?.join(".llama"))
17}
18
19pub 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
32pub 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
49pub fn llama_cpp_dir() -> Result<PathBuf, PathError> {
51 let gglib_dir = gglib_data_dir()?;
52 Ok(gglib_dir.join("llama.cpp"))
53}
54
55pub 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}