@@ -83,6 +83,7 @@ use std::fs::{File, OpenOptions};
83
83
use std:: io:: { self , Write } ;
84
84
use std:: path:: { Path , PathBuf } ;
85
85
use std:: process:: { Command , Stdio } ;
86
+ use std:: rc:: Rc ;
86
87
use std:: { env, iter} ;
87
88
88
89
// Some convenient typedefs for a fast hash map and hash set.
@@ -1466,7 +1467,7 @@ impl Builder {
1466
1467
mut self ,
1467
1468
cb : Box < dyn callbacks:: ParseCallbacks > ,
1468
1469
) -> Self {
1469
- self . options . parse_callbacks = Some ( cb ) ;
1470
+ self . options . parse_callbacks = Some ( Rc :: from ( cb ) ) ;
1470
1471
self
1471
1472
}
1472
1473
@@ -1575,15 +1576,13 @@ impl Builder {
1575
1576
} ) ,
1576
1577
) ;
1577
1578
1578
- self . options . input_unsaved_files . extend (
1579
- self . input_header_contents
1580
- . drain ( ..)
1581
- . map ( |( name, contents) | {
1582
- clang:: UnsavedFile :: new ( & name, & contents)
1583
- } ) ,
1584
- ) ;
1579
+ let input_unsaved_files = self
1580
+ . input_header_contents
1581
+ . into_iter ( )
1582
+ . map ( |( name, contents) | clang:: UnsavedFile :: new ( & name, & contents) )
1583
+ . collect :: < Vec < _ > > ( ) ;
1585
1584
1586
- Bindings :: generate ( self . options )
1585
+ Bindings :: generate ( self . options , input_unsaved_files )
1587
1586
}
1588
1587
1589
1588
/// Preprocess and dump the input header files to disk.
@@ -1775,7 +1774,7 @@ impl Builder {
1775
1774
}
1776
1775
1777
1776
/// Configuration options for generated bindings.
1778
- #[ derive( Debug ) ]
1777
+ #[ derive( Clone , Debug ) ]
1779
1778
struct BindgenOptions {
1780
1779
/// The set of types that have been blocklisted and should not appear
1781
1780
/// anywhere in the generated code.
@@ -1978,12 +1977,9 @@ struct BindgenOptions {
1978
1977
/// Any additional input header files.
1979
1978
extra_input_headers : Vec < String > ,
1980
1979
1981
- /// Unsaved files for input.
1982
- input_unsaved_files : Vec < clang:: UnsavedFile > ,
1983
-
1984
1980
/// A user-provided visitor to allow customizing different kinds of
1985
1981
/// situations.
1986
- parse_callbacks : Option < Box < dyn callbacks:: ParseCallbacks > > ,
1982
+ parse_callbacks : Option < Rc < dyn callbacks:: ParseCallbacks > > ,
1987
1983
1988
1984
/// Which kind of items should we generate? By default, we'll generate all
1989
1985
/// of them.
@@ -2236,7 +2232,6 @@ impl Default for BindgenOptions {
2236
2232
clang_args : vec ! [ ] ,
2237
2233
input_header : None ,
2238
2234
extra_input_headers : vec ! [ ] ,
2239
- input_unsaved_files : vec ! [ ] ,
2240
2235
parse_callbacks : None ,
2241
2236
codegen_config : CodegenConfig :: all ( ) ,
2242
2237
conservative_inline_namespaces : false ,
@@ -2394,6 +2389,7 @@ impl Bindings {
2394
2389
/// Generate bindings for the given options.
2395
2390
pub ( crate ) fn generate (
2396
2391
mut options : BindgenOptions ,
2392
+ input_unsaved_files : Vec < clang:: UnsavedFile > ,
2397
2393
) -> Result < Bindings , BindgenError > {
2398
2394
ensure_libclang_is_loaded ( ) ;
2399
2395
@@ -2528,7 +2524,7 @@ impl Bindings {
2528
2524
}
2529
2525
}
2530
2526
2531
- for ( idx, f) in options . input_unsaved_files . iter ( ) . enumerate ( ) {
2527
+ for ( idx, f) in input_unsaved_files. iter ( ) . enumerate ( ) {
2532
2528
if idx != 0 || options. input_header . is_some ( ) {
2533
2529
options. clang_args . push ( "-include" . to_owned ( ) ) ;
2534
2530
}
@@ -2538,7 +2534,7 @@ impl Bindings {
2538
2534
debug ! ( "Fixed-up options: {:?}" , options) ;
2539
2535
2540
2536
let time_phases = options. time_phases ;
2541
- let mut context = BindgenContext :: new ( options) ;
2537
+ let mut context = BindgenContext :: new ( options, & input_unsaved_files ) ;
2542
2538
2543
2539
if is_host_build {
2544
2540
debug_assert_eq ! (
0 commit comments