@@ -420,6 +420,44 @@ fn main() {
420420 }
421421 }
422422
423+ // Fix bindgen header discovery on Windows MSVC
424+ // Use cc crate to discover MSVC include paths by compiling a dummy file
425+ if matches ! ( target_os, TargetOs :: Windows ( WindowsVariant :: Msvc ) ) {
426+ // Create a minimal dummy C file to extract compiler flags
427+ let out_dir = env:: var ( "OUT_DIR" ) . unwrap ( ) ;
428+ let dummy_c = Path :: new ( & out_dir) . join ( "dummy.c" ) ;
429+ std:: fs:: write ( & dummy_c, "int main() { return 0; }" ) . unwrap ( ) ;
430+
431+ // Use cc crate to get compiler with proper environment setup
432+ let mut build = cc:: Build :: new ( ) ;
433+ build. file ( & dummy_c) ;
434+
435+ // Get the actual compiler command cc would use
436+ let compiler = build. try_get_compiler ( ) . unwrap ( ) ;
437+
438+ // Extract include paths by checking compiler's environment
439+ // cc crate sets up MSVC environment internally
440+ let env_include = compiler. env ( ) . iter ( )
441+ . find ( |( k, _) | k. eq_ignore_ascii_case ( "INCLUDE" ) )
442+ . map ( |( _, v) | v) ;
443+
444+ if let Some ( include_paths) = env_include {
445+ for include_path in include_paths. to_string_lossy ( ) . split ( ';' ) . filter ( |s| !s. is_empty ( ) ) {
446+ bindings_builder = bindings_builder
447+ . clang_arg ( "-isystem" )
448+ . clang_arg ( include_path) ;
449+ debug_log ! ( "Added MSVC include path: {}" , include_path) ;
450+ }
451+ }
452+
453+ // Add MSVC compatibility flags
454+ bindings_builder = bindings_builder
455+ . clang_arg ( format ! ( "--target={}" , target_triple) )
456+ . clang_arg ( "-fms-compatibility" )
457+ . clang_arg ( "-fms-extensions" ) ;
458+
459+ debug_log ! ( "Configured bindgen with MSVC toolchain for target: {}" , target_triple) ;
460+ }
423461 let bindings = bindings_builder
424462 . generate ( )
425463 . expect ( "Failed to generate bindings" ) ;
0 commit comments