@@ -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.
@@ -1465,7 +1466,7 @@ impl Builder {
1465
1466
mut self ,
1466
1467
cb : Box < dyn callbacks:: ParseCallbacks > ,
1467
1468
) -> Self {
1468
- self . options . parse_callbacks = Some ( cb ) ;
1469
+ self . options . parse_callbacks = Some ( Rc :: from ( cb ) ) ;
1469
1470
self
1470
1471
}
1471
1472
@@ -1574,15 +1575,13 @@ impl Builder {
1574
1575
} ) ,
1575
1576
) ;
1576
1577
1577
- self . options . input_unsaved_files . extend (
1578
- self . input_header_contents
1579
- . drain ( ..)
1580
- . map ( |( name, contents) | {
1581
- clang:: UnsavedFile :: new ( & name, & contents)
1582
- } ) ,
1583
- ) ;
1578
+ let input_unsaved_files = self
1579
+ . input_header_contents
1580
+ . into_iter ( )
1581
+ . map ( |( name, contents) | clang:: UnsavedFile :: new ( & name, & contents) )
1582
+ . collect :: < Vec < _ > > ( ) ;
1584
1583
1585
- Bindings :: generate ( self . options )
1584
+ Bindings :: generate ( self . options , input_unsaved_files )
1586
1585
}
1587
1586
1588
1587
/// Preprocess and dump the input header files to disk.
@@ -1774,7 +1773,7 @@ impl Builder {
1774
1773
}
1775
1774
1776
1775
/// Configuration options for generated bindings.
1777
- #[ derive( Debug ) ]
1776
+ #[ derive( Clone , Debug ) ]
1778
1777
struct BindgenOptions {
1779
1778
/// The set of types that have been blocklisted and should not appear
1780
1779
/// anywhere in the generated code.
@@ -1977,12 +1976,9 @@ struct BindgenOptions {
1977
1976
/// Any additional input header files.
1978
1977
extra_input_headers : Vec < String > ,
1979
1978
1980
- /// Unsaved files for input.
1981
- input_unsaved_files : Vec < clang:: UnsavedFile > ,
1982
-
1983
1979
/// A user-provided visitor to allow customizing different kinds of
1984
1980
/// situations.
1985
- parse_callbacks : Option < Box < dyn callbacks:: ParseCallbacks > > ,
1981
+ parse_callbacks : Option < Rc < dyn callbacks:: ParseCallbacks > > ,
1986
1982
1987
1983
/// Which kind of items should we generate? By default, we'll generate all
1988
1984
/// of them.
@@ -2230,7 +2226,6 @@ impl Default for BindgenOptions {
2230
2226
clang_args : vec ! [ ] ,
2231
2227
input_header : None ,
2232
2228
extra_input_headers : vec ! [ ] ,
2233
- input_unsaved_files : vec ! [ ] ,
2234
2229
parse_callbacks : None ,
2235
2230
codegen_config : CodegenConfig :: all ( ) ,
2236
2231
conservative_inline_namespaces : false ,
@@ -2388,6 +2383,7 @@ impl Bindings {
2388
2383
/// Generate bindings for the given options.
2389
2384
pub ( crate ) fn generate (
2390
2385
mut options : BindgenOptions ,
2386
+ input_unsaved_files : Vec < clang:: UnsavedFile > ,
2391
2387
) -> Result < Bindings , BindgenError > {
2392
2388
ensure_libclang_is_loaded ( ) ;
2393
2389
@@ -2522,7 +2518,7 @@ impl Bindings {
2522
2518
}
2523
2519
}
2524
2520
2525
- for ( idx, f) in options . input_unsaved_files . iter ( ) . enumerate ( ) {
2521
+ for ( idx, f) in input_unsaved_files. iter ( ) . enumerate ( ) {
2526
2522
if idx != 0 || options. input_header . is_some ( ) {
2527
2523
options. clang_args . push ( "-include" . to_owned ( ) ) ;
2528
2524
}
@@ -2532,7 +2528,7 @@ impl Bindings {
2532
2528
debug ! ( "Fixed-up options: {:?}" , options) ;
2533
2529
2534
2530
let time_phases = options. time_phases ;
2535
- let mut context = BindgenContext :: new ( options) ;
2531
+ let mut context = BindgenContext :: new ( options, & input_unsaved_files ) ;
2536
2532
2537
2533
if is_host_build {
2538
2534
debug_assert_eq ! (
0 commit comments