@@ -31,6 +31,7 @@ use std::cell::{Cell, RefCell};
3131use std:: collections:: { BTreeSet , HashMap as StdHashMap } ;
3232use std:: mem;
3333use std:: path:: Path ;
34+ use tempfile:: TempDir ;
3435
3536/// An identifier for some kind of IR item.
3637#[ derive( Debug , Copy , Clone , Eq , PartialOrd , Ord , Hash ) ]
@@ -555,7 +556,7 @@ impl BindgenContext {
555556
556557 clang:: TranslationUnit :: parse (
557558 & index,
558- "" ,
559+ None ,
559560 & options. clang_args ,
560561 input_unsaved_files,
561562 parse_options,
@@ -2040,20 +2041,18 @@ If you encounter an error missing from this list, please file an issue or a PR!"
20402041 & mut self ,
20412042 ) -> Option < & mut clang:: FallbackTranslationUnit > {
20422043 if self . fallback_tu . is_none ( ) {
2043- let file = format ! (
2044- "{}/.macro_eval.c" ,
2045- match self . options( ) . clang_macro_fallback_build_dir {
2046- Some ( ref path) => path. as_os_str( ) . to_str( ) ?,
2047- None => "." ,
2048- }
2049- ) ;
2044+ let temp_dir = TempDir :: new ( ) . unwrap ( ) ;
2045+
2046+ let file = temp_dir. path ( ) . join ( ".macro_eval.c" ) ;
20502047
20512048 let index = clang:: Index :: new ( false , false ) ;
20522049
20532050 let mut header_names_to_compile = Vec :: new ( ) ;
20542051 let mut header_paths = Vec :: new ( ) ;
20552052 let mut header_includes = Vec :: new ( ) ;
2056- let single_header = self . options ( ) . input_headers . last ( ) . cloned ( ) ?;
2053+ let single_header =
2054+ Path :: new ( & self . options ( ) . input_headers . last ( ) ?. as_ref ( ) )
2055+ . to_owned ( ) ;
20572056 for input_header in & self . options . input_headers
20582057 [ ..self . options . input_headers . len ( ) - 1 ]
20592058 {
@@ -2072,14 +2071,9 @@ If you encounter an error missing from this list, please file an issue or a PR!"
20722071 header_names_to_compile
20732072 . push ( header_name. split ( ".h" ) . next ( ) ?. to_string ( ) ) ;
20742073 }
2075- let pch = format ! (
2076- "{}/{}" ,
2077- match self . options( ) . clang_macro_fallback_build_dir {
2078- Some ( ref path) => path. as_os_str( ) . to_str( ) ?,
2079- None => "." ,
2080- } ,
2081- header_names_to_compile. join( "-" ) + "-precompile.h.pch"
2082- ) ;
2074+ let pch = temp_dir
2075+ . path ( )
2076+ . join ( header_names_to_compile. join ( "-" ) + "-precompile.h.pch" ) ;
20832077
20842078 let mut c_args = self . options . fallback_clang_args . clone ( ) ;
20852079 c_args. push ( "-x" . to_string ( ) . into_boxed_str ( ) ) ;
@@ -2093,7 +2087,7 @@ If you encounter an error missing from this list, please file an issue or a PR!"
20932087 }
20942088 let mut tu = clang:: TranslationUnit :: parse (
20952089 & index,
2096- & single_header,
2090+ Some ( & single_header) ,
20972091 & c_args,
20982092 & [ ] ,
20992093 clang_sys:: CXTranslationUnit_ForSerialization ,
@@ -2102,7 +2096,7 @@ If you encounter an error missing from this list, please file an issue or a PR!"
21022096
21032097 let mut c_args = vec ! [
21042098 "-include-pch" . to_string( ) . into_boxed_str( ) ,
2105- pch. clone ( ) . into_boxed_str( ) ,
2099+ pch. to_string_lossy ( ) . into_owned ( ) . into_boxed_str( ) ,
21062100 ] ;
21072101 let mut skip_next = false ;
21082102 for arg in self . options . fallback_clang_args . iter ( ) {
@@ -2114,8 +2108,9 @@ If you encounter an error missing from this list, please file an issue or a PR!"
21142108 c_args. push ( arg. clone ( ) )
21152109 }
21162110 }
2117- self . fallback_tu =
2118- Some ( clang:: FallbackTranslationUnit :: new ( file, pch, & c_args) ?) ;
2111+ self . fallback_tu = Some ( clang:: FallbackTranslationUnit :: new (
2112+ temp_dir, file, pch, & c_args,
2113+ ) ?) ;
21192114 }
21202115
21212116 self . fallback_tu . as_mut ( )
0 commit comments