Skip to main content

llama_cpp_wrapper_sources/
system_include_flags.rs

1use std::path::Path;
2
3use crate::vendored_include_dirs::VENDORED_INCLUDE_DIRS;
4
5/// The compiler flags that include every vendored header directory under `sys_dir` as a system
6/// directory, so warnings in vendored headers do not surface while ours still do.
7#[must_use]
8pub fn system_include_flags(sys_dir: &Path) -> Vec<String> {
9    VENDORED_INCLUDE_DIRS
10        .iter()
11        .map(|include_dir| format!("-isystem{}", sys_dir.join(include_dir).display()))
12        .collect()
13}
14
15#[cfg(test)]
16mod tests {
17    use std::path::Path;
18
19    use super::system_include_flags;
20
21    #[test]
22    fn every_vendored_include_dir_becomes_a_system_include_under_the_sys_dir() {
23        assert_eq!(
24            system_include_flags(Path::new("/repo/llama-cpp-bindings-sys")),
25            [
26                "-isystem/repo/llama-cpp-bindings-sys/GSL/include",
27                "-isystem/repo/llama-cpp-bindings-sys/llama.cpp",
28                "-isystem/repo/llama-cpp-bindings-sys/llama.cpp/common",
29                "-isystem/repo/llama-cpp-bindings-sys/llama.cpp/include",
30                "-isystem/repo/llama-cpp-bindings-sys/llama.cpp/ggml/include",
31                "-isystem/repo/llama-cpp-bindings-sys/llama.cpp/vendor",
32            ]
33        );
34    }
35}