Skip to main content

llama_cpp_wrapper_sources/
system_include_flags.rs

1use std::path::Path;
2
3use crate::constants::GSL_INCLUDE_DIR;
4use crate::constants::LLAMA_CPP_INCLUDE_DIRS;
5
6/// The compiler flags that include the vendored headers as system directories.
7///
8/// The GSL headers come from under `sys_dir` and the llama.cpp headers from under
9/// `llama_cpp_dir`, so warnings in vendored headers do not surface while ours still do.
10#[must_use]
11pub fn system_include_flags(sys_dir: &Path, llama_cpp_dir: &Path) -> Vec<String> {
12    [sys_dir.join(GSL_INCLUDE_DIR), llama_cpp_dir.to_path_buf()]
13        .into_iter()
14        .chain(
15            LLAMA_CPP_INCLUDE_DIRS
16                .iter()
17                .map(|include_dir| llama_cpp_dir.join(include_dir)),
18        )
19        .map(|include_dir| format!("-isystem{}", include_dir.display()))
20        .collect()
21}
22
23#[cfg(test)]
24mod tests {
25    use std::path::Path;
26
27    use super::system_include_flags;
28
29    #[test]
30    fn gsl_and_every_llama_cpp_include_dir_become_system_includes_under_their_roots() {
31        assert_eq!(
32            system_include_flags(
33                Path::new("/repo/llama-cpp-bindings-sys"),
34                Path::new("/repo/llama-cpp-native/llama.cpp")
35            ),
36            [
37                "-isystem/repo/llama-cpp-bindings-sys/GSL/include",
38                "-isystem/repo/llama-cpp-native/llama.cpp",
39                "-isystem/repo/llama-cpp-native/llama.cpp/common",
40                "-isystem/repo/llama-cpp-native/llama.cpp/include",
41                "-isystem/repo/llama-cpp-native/llama.cpp/ggml/include",
42                "-isystem/repo/llama-cpp-native/llama.cpp/vendor",
43            ]
44        );
45    }
46}