@@ -29,8 +29,6 @@ use quote::ToTokens;
29
29
use std:: borrow:: Cow ;
30
30
use std:: cell:: { Cell , RefCell } ;
31
31
use std:: collections:: { BTreeSet , HashMap as StdHashMap } ;
32
- use std:: fs:: OpenOptions ;
33
- use std:: io:: Write ;
34
32
use std:: mem;
35
33
use std:: path:: Path ;
36
34
@@ -2054,8 +2052,11 @@ If you encounter an error missing from this list, please file an issue or a PR!"
2054
2052
2055
2053
let mut header_names_to_compile = Vec :: new ( ) ;
2056
2054
let mut header_paths = Vec :: new ( ) ;
2057
- let mut header_contents = String :: new ( ) ;
2058
- for input_header in & self . options . input_headers {
2055
+ let mut header_includes = Vec :: new ( ) ;
2056
+ let single_header = self . options ( ) . input_headers . last ( ) . cloned ( ) ?;
2057
+ for input_header in & self . options . input_headers
2058
+ [ ..self . options . input_headers . len ( ) - 1 ]
2059
+ {
2059
2060
let path = Path :: new ( input_header. as_ref ( ) ) ;
2060
2061
if let Some ( header_path) = path. parent ( ) {
2061
2062
if header_path == Path :: new ( "" ) {
@@ -2067,50 +2068,32 @@ If you encounter an error missing from this list, please file an issue or a PR!"
2067
2068
header_paths. push ( "." ) ;
2068
2069
}
2069
2070
let header_name = path. file_name ( ) ?. to_str ( ) ?;
2071
+ header_includes. push ( header_name. to_string ( ) ) ;
2070
2072
header_names_to_compile
2071
2073
. push ( header_name. split ( ".h" ) . next ( ) ?. to_string ( ) ) ;
2072
- header_contents +=
2073
- format ! ( "\n #include <{header_name}>" ) . as_str ( ) ;
2074
2074
}
2075
- let header_to_precompile = format ! (
2075
+ let pch = format ! (
2076
2076
"{}/{}" ,
2077
2077
match self . options( ) . clang_macro_fallback_build_dir {
2078
2078
Some ( ref path) => path. as_os_str( ) . to_str( ) ?,
2079
2079
None => "." ,
2080
2080
} ,
2081
- header_names_to_compile. join( "-" ) + "-precompile.h"
2081
+ header_names_to_compile. join( "-" ) + "-precompile.h.pch "
2082
2082
) ;
2083
- let pch = header_to_precompile. clone ( ) + ".pch" ;
2084
-
2085
- let mut header_to_precompile_file = OpenOptions :: new ( )
2086
- . create ( true )
2087
- . truncate ( true )
2088
- . write ( true )
2089
- . open ( & header_to_precompile)
2090
- . ok ( ) ?;
2091
- header_to_precompile_file
2092
- . write_all ( header_contents. as_bytes ( ) )
2093
- . ok ( ) ?;
2094
-
2095
- let mut c_args = Vec :: new ( ) ;
2083
+
2084
+ let mut c_args = self . options . fallback_clang_args . clone ( ) ;
2096
2085
c_args. push ( "-x" . to_string ( ) . into_boxed_str ( ) ) ;
2097
2086
c_args. push ( "c-header" . to_string ( ) . into_boxed_str ( ) ) ;
2098
2087
for header_path in header_paths {
2099
2088
c_args. push ( format ! ( "-I{header_path}" ) . into_boxed_str ( ) ) ;
2100
2089
}
2101
- c_args. extend (
2102
- self . options
2103
- . clang_args
2104
- . iter ( )
2105
- . filter ( |next| {
2106
- !self . options . input_headers . contains ( next) &&
2107
- next. as_ref ( ) != "-include"
2108
- } )
2109
- . cloned ( ) ,
2110
- ) ;
2090
+ for header_include in header_includes {
2091
+ c_args. push ( "-include" . to_string ( ) . into_boxed_str ( ) ) ;
2092
+ c_args. push ( header_include. into_boxed_str ( ) ) ;
2093
+ }
2111
2094
let mut tu = clang:: TranslationUnit :: parse (
2112
2095
& index,
2113
- & header_to_precompile ,
2096
+ & single_header ,
2114
2097
& c_args,
2115
2098
& [ ] ,
2116
2099
clang_sys:: CXTranslationUnit_ForSerialization ,
@@ -2121,23 +2104,18 @@ If you encounter an error missing from this list, please file an issue or a PR!"
2121
2104
"-include-pch" . to_string( ) . into_boxed_str( ) ,
2122
2105
pch. clone( ) . into_boxed_str( ) ,
2123
2106
] ;
2124
- c_args. extend (
2125
- self . options
2126
- . clang_args
2127
- . clone ( )
2128
- . iter ( )
2129
- . filter ( |next| {
2130
- !self . options . input_headers . contains ( next) &&
2131
- next. as_ref ( ) != "-include"
2132
- } )
2133
- . cloned ( ) ,
2134
- ) ;
2135
- self . fallback_tu = Some ( clang:: FallbackTranslationUnit :: new (
2136
- file,
2137
- header_to_precompile,
2138
- pch,
2139
- & c_args,
2140
- ) ?) ;
2107
+ let mut skip_next = false ;
2108
+ for arg in self . options . fallback_clang_args . iter ( ) {
2109
+ if arg. as_ref ( ) == "-include" {
2110
+ skip_next = true ;
2111
+ } else if skip_next {
2112
+ skip_next = false ;
2113
+ } else {
2114
+ c_args. push ( arg. clone ( ) )
2115
+ }
2116
+ }
2117
+ self . fallback_tu =
2118
+ Some ( clang:: FallbackTranslationUnit :: new ( file, pch, & c_args) ?) ;
2141
2119
}
2142
2120
2143
2121
self . fallback_tu . as_mut ( )
0 commit comments