@@ -2055,11 +2055,46 @@ If you encounter an error missing from this list, please file an issue or a PR!"
20552055
20562056 let index = clang:: Index :: new ( false , false ) ;
20572057
2058+ let build_dir =
2059+ match self . options ( ) . clang_macro_fallback_build_dir {
2060+ Some ( ref path) => path. as_os_str ( ) . to_str ( ) ?,
2061+ None => "." ,
2062+ } ;
2063+ let materialized_headers: Vec < String > = self
2064+ . options ( )
2065+ . input_header_contents
2066+ . iter ( )
2067+ . enumerate ( )
2068+ . map ( |( index, ( _, contents) ) | {
2069+ let path =
2070+ format ! ( "{build_dir}/.macro_eval_header_{index}.h" ) ;
2071+ std:: fs:: write ( & path, contents. as_ref ( ) ) . unwrap_or_else (
2072+ |error| {
2073+ panic ! (
2074+ "failed to materialize header_contents() for \
2075+ clang_macro_fallback at {path}: {error}"
2076+ )
2077+ } ,
2078+ ) ;
2079+ path
2080+ } )
2081+ . collect ( ) ;
2082+
2083+ let effective_headers: Vec < Box < str > > = self
2084+ . options ( )
2085+ . input_headers
2086+ . iter ( )
2087+ . cloned ( )
2088+ . chain ( materialized_headers. iter ( ) . map ( |path| {
2089+ path. as_str ( ) . into ( )
2090+ } ) )
2091+ . collect ( ) ;
2092+
20582093 let mut header_names_to_compile = Vec :: new ( ) ;
20592094 let mut header_paths = Vec :: new ( ) ;
20602095 let mut header_includes = Vec :: new ( ) ;
20612096 let [ input_headers @ .., single_header] =
2062- & self . options ( ) . input_headers [ ..]
2097+ & effective_headers [ ..]
20632098 else {
20642099 return None ;
20652100 } ;
@@ -2121,8 +2156,12 @@ If you encounter an error missing from this list, please file an issue or a PR!"
21212156 c_args. push ( arg. clone ( ) ) ;
21222157 }
21232158 }
2124- self . fallback_tu =
2125- Some ( clang:: FallbackTranslationUnit :: new ( file, pch, & c_args) ?) ;
2159+ self . fallback_tu = Some ( clang:: FallbackTranslationUnit :: new (
2160+ file,
2161+ pch,
2162+ & c_args,
2163+ materialized_headers,
2164+ ) ?) ;
21262165 }
21272166
21282167 self . fallback_tu . as_mut ( )
0 commit comments