@@ -31,6 +31,7 @@ use std::cell::{Cell, RefCell};
31
31
use std:: collections:: { BTreeSet , HashMap as StdHashMap } ;
32
32
use std:: mem;
33
33
use std:: path:: Path ;
34
+ use tempfile:: TempDir ;
34
35
35
36
/// An identifier for some kind of IR item.
36
37
#[ derive( Debug , Copy , Clone , Eq , PartialOrd , Ord , Hash ) ]
@@ -555,7 +556,7 @@ impl BindgenContext {
555
556
556
557
clang:: TranslationUnit :: parse (
557
558
& index,
558
- "" ,
559
+ None ,
559
560
& options. clang_args ,
560
561
input_unsaved_files,
561
562
parse_options,
@@ -2040,20 +2041,18 @@ If you encounter an error missing from this list, please file an issue or a PR!"
2040
2041
& mut self ,
2041
2042
) -> Option < & mut clang:: FallbackTranslationUnit > {
2042
2043
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" ) ;
2050
2047
2051
2048
let index = clang:: Index :: new ( false , false ) ;
2052
2049
2053
2050
let mut header_names_to_compile = Vec :: new ( ) ;
2054
2051
let mut header_paths = Vec :: new ( ) ;
2055
2052
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 ( ) ;
2057
2056
for input_header in & self . options . input_headers
2058
2057
[ ..self . options . input_headers . len ( ) - 1 ]
2059
2058
{
@@ -2072,14 +2071,9 @@ If you encounter an error missing from this list, please file an issue or a PR!"
2072
2071
header_names_to_compile
2073
2072
. push ( header_name. split ( ".h" ) . next ( ) ?. to_string ( ) ) ;
2074
2073
}
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" ) ;
2083
2077
2084
2078
let mut c_args = self . options . fallback_clang_args . clone ( ) ;
2085
2079
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!"
2093
2087
}
2094
2088
let mut tu = clang:: TranslationUnit :: parse (
2095
2089
& index,
2096
- & single_header,
2090
+ Some ( & single_header) ,
2097
2091
& c_args,
2098
2092
& [ ] ,
2099
2093
clang_sys:: CXTranslationUnit_ForSerialization ,
@@ -2102,7 +2096,7 @@ If you encounter an error missing from this list, please file an issue or a PR!"
2102
2096
2103
2097
let mut c_args = vec ! [
2104
2098
"-include-pch" . to_string( ) . into_boxed_str( ) ,
2105
- pch. clone ( ) . into_boxed_str( ) ,
2099
+ pch. to_string_lossy ( ) . into_owned ( ) . into_boxed_str( ) ,
2106
2100
] ;
2107
2101
let mut skip_next = false ;
2108
2102
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!"
2114
2108
c_args. push ( arg. clone ( ) )
2115
2109
}
2116
2110
}
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
+ ) ?) ;
2119
2114
}
2120
2115
2121
2116
self . fallback_tu . as_mut ( )
0 commit comments