@@ -88,9 +88,19 @@ impl CargoCmd for Command {
8888 // use CC_<triplet> as this is the highest priority for cc-rs
8989 // see https://docs.rs/cc/latest/cc/#external-configuration-via-environment-variables
9090 self . env ( format ! ( "CC_{}" , triplet. as_ref( ) ) , cc. as_ref ( ) ) ;
91+
92+ // bindgen uses clang-sys, which looks for clang in the CLANG_PATH env var
93+ // see https://github.com/KyleMayes/clang-sys?tab=readme-ov-file#environment-variables
94+ // TODO(jprendes): can we make this env var target-specific as well?
9195 self . env ( "CLANG_PATH" , cc. as_ref ( ) ) ;
96+
9297 // In windows, set LIBCLANG_PATH
93- if let Some ( parent) = cc. as_ref ( ) . parent ( ) {
98+ if cfg ! ( windows) && let Some ( parent) = cc. as_ref ( ) . parent ( ) {
99+ // TODO(jprendes): is this considering all possible situations?
100+ // * why is CLANG_PATH not enough on windows?
101+ // see https://rust-lang.github.io/rust-bindgen/requirements.html#windows
102+ // see https://github.com/KyleMayes/clang-sys?tab=readme-ov-file#environment-variables
103+ // TODO(jprendes): can we make this env var target-specific as well?
94104 if parent. join ( "libclang.dll" ) . exists ( ) {
95105 self . env ( "LIBCLANG_PATH" , parent. join ( "libclang.dll" ) ) ;
96106 } else if parent. join ( "clang.dll" ) . exists ( ) {
@@ -172,8 +182,11 @@ impl CargoCmd for Command {
172182 }
173183
174184 // For some reason we need to escape backslashes on Windows
185+ // TODO(jprendes): check if we need to do any better escaping for other special characters
175186 let flags = flags. as_ref ( ) . to_string_lossy ( ) . replace ( "\\ " , "\\ \\ " ) ;
176187
188+ // TODO(jprendes): account and use the target specific variants of BINDGEN_EXTRA_CLANG_ARGS
189+ // see https://github.com/rust-lang/rust-bindgen/tree/main?tab=readme-ov-file#environment-variables
177190 let mut new_flags = get_env ( self , "BINDGEN_EXTRA_CLANG_ARGS" ) . unwrap_or_default ( ) ;
178191 if !new_flags. is_empty ( ) {
179192 new_flags. push ( " " ) ;
0 commit comments