@@ -32,6 +32,7 @@ use std::cell::{Cell, RefCell};
3232use std:: collections:: { BTreeSet , HashMap as StdHashMap } ;
3333use std:: mem;
3434use std:: path:: Path ;
35+ use tempfile:: TempDir ;
3536
3637/// An identifier for some kind of IR item.
3738#[ derive( Debug , Copy , Clone , Eq , PartialOrd , Ord , Hash ) ]
@@ -556,7 +557,7 @@ impl BindgenContext {
556557
557558 clang:: TranslationUnit :: parse (
558559 & index,
559- "" ,
560+ "" . as_ref ( ) ,
560561 & options. clang_args ,
561562 input_unsaved_files,
562563 parse_options,
@@ -2045,13 +2046,9 @@ If you encounter an error missing from this list, please file an issue or a PR!"
20452046 & mut self ,
20462047 ) -> Option < & mut clang:: FallbackTranslationUnit > {
20472048 if self . fallback_tu . is_none ( ) {
2048- let file = format ! (
2049- "{}/.macro_eval.c" ,
2050- match self . options( ) . clang_macro_fallback_build_dir {
2051- Some ( ref path) => path. as_os_str( ) . to_str( ) ?,
2052- None => "." ,
2053- }
2054- ) ;
2049+ let temp_dir = TempDir :: new ( ) . unwrap ( ) ;
2050+
2051+ let file = temp_dir. path ( ) . join ( ".macro_eval.c" ) ;
20552052
20562053 let index = clang:: Index :: new ( false , false ) ;
20572054
@@ -2079,14 +2076,9 @@ If you encounter an error missing from this list, please file an issue or a PR!"
20792076 header_names_to_compile
20802077 . push ( header_name. split ( ".h" ) . next ( ) ?. to_string ( ) ) ;
20812078 }
2082- let pch = format ! (
2083- "{}/{}" ,
2084- match self . options( ) . clang_macro_fallback_build_dir {
2085- Some ( ref path) => path. as_os_str( ) . to_str( ) ?,
2086- None => "." ,
2087- } ,
2088- header_names_to_compile. join( "-" ) + "-precompile.h.pch"
2089- ) ;
2079+ let pch = temp_dir
2080+ . path ( )
2081+ . join ( header_names_to_compile. join ( "-" ) + "-precompile.h.pch" ) ;
20902082
20912083 let mut c_args = self . options . fallback_clang_args . clone ( ) ;
20922084 c_args. push ( "-x" . to_string ( ) . into_boxed_str ( ) ) ;
@@ -2100,7 +2092,7 @@ If you encounter an error missing from this list, please file an issue or a PR!"
21002092 }
21012093 let mut tu = clang:: TranslationUnit :: parse (
21022094 & index,
2103- single_header,
2095+ ( & * * single_header) . as_ref ( ) ,
21042096 & c_args,
21052097 & [ ] ,
21062098 clang_sys:: CXTranslationUnit_ForSerialization ,
@@ -2109,7 +2101,7 @@ If you encounter an error missing from this list, please file an issue or a PR!"
21092101
21102102 let mut c_args = vec ! [
21112103 "-include-pch" . to_string( ) . into_boxed_str( ) ,
2112- pch. clone ( ) . into_boxed_str( ) ,
2104+ pch. to_string_lossy ( ) . into_owned ( ) . into_boxed_str( ) ,
21132105 ] ;
21142106 let mut skip_next = false ;
21152107 for arg in & self . options . fallback_clang_args {
@@ -2121,8 +2113,9 @@ If you encounter an error missing from this list, please file an issue or a PR!"
21212113 c_args. push ( arg. clone ( ) ) ;
21222114 }
21232115 }
2124- self . fallback_tu =
2125- Some ( clang:: FallbackTranslationUnit :: new ( file, pch, & c_args) ?) ;
2116+ self . fallback_tu = Some ( clang:: FallbackTranslationUnit :: new (
2117+ temp_dir, file, pch, & c_args,
2118+ ) ?) ;
21262119 }
21272120
21282121 self . fallback_tu . as_mut ( )
0 commit comments