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
25 changes: 17 additions & 8 deletions llama-cpp-sys-2/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,36 +427,45 @@ fn main() {
let out_dir = env::var("OUT_DIR").unwrap();
let dummy_c = Path::new(&out_dir).join("dummy.c");
std::fs::write(&dummy_c, "int main() { return 0; }").unwrap();

// Use cc crate to get compiler with proper environment setup
let mut build = cc::Build::new();
build.file(&dummy_c);

// Get the actual compiler command cc would use
let compiler = build.try_get_compiler().unwrap();

// Extract include paths by checking compiler's environment
// cc crate sets up MSVC environment internally
let env_include = compiler.env().iter()
let env_include = compiler
.env()
.iter()
.find(|(k, _)| k.eq_ignore_ascii_case("INCLUDE"))
.map(|(_, v)| v);

if let Some(include_paths) = env_include {
for include_path in include_paths.to_string_lossy().split(';').filter(|s| !s.is_empty()) {
for include_path in include_paths
.to_string_lossy()
.split(';')
.filter(|s| !s.is_empty())
{
bindings_builder = bindings_builder
.clang_arg("-isystem")
.clang_arg(include_path);
debug_log!("Added MSVC include path: {}", include_path);
}
}

// Add MSVC compatibility flags
bindings_builder = bindings_builder
.clang_arg(format!("--target={}", target_triple))
.clang_arg("-fms-compatibility")
.clang_arg("-fms-extensions");

debug_log!("Configured bindgen with MSVC toolchain for target: {}", target_triple);
debug_log!(
"Configured bindgen with MSVC toolchain for target: {}",
target_triple
);
}
let bindings = bindings_builder
.generate()
Expand Down
2 changes: 1 addition & 1 deletion llama-cpp-sys-2/llama.cpp
Submodule llama.cpp updated 991 files
Loading