@@ -83,6 +83,7 @@ use std::fs::{File, OpenOptions};
8383use std:: io:: { self , Write } ;
8484use std:: path:: { Path , PathBuf } ;
8585use std:: process:: { Command , Stdio } ;
86+ use std:: rc:: Rc ;
8687use std:: { env, iter} ;
8788
8889// Some convenient typedefs for a fast hash map and hash set.
@@ -1465,7 +1466,7 @@ impl Builder {
14651466 mut self ,
14661467 cb : Box < dyn callbacks:: ParseCallbacks > ,
14671468 ) -> Self {
1468- self . options . parse_callbacks = Some ( cb ) ;
1469+ self . options . parse_callbacks = Some ( Rc :: from ( cb ) ) ;
14691470 self
14701471 }
14711472
@@ -1574,15 +1575,13 @@ impl Builder {
15741575 } ) ,
15751576 ) ;
15761577
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 < _ > > ( ) ;
15841583
1585- Bindings :: generate ( self . options )
1584+ Bindings :: generate ( self . options , input_unsaved_files )
15861585 }
15871586
15881587 /// Preprocess and dump the input header files to disk.
@@ -1774,7 +1773,7 @@ impl Builder {
17741773}
17751774
17761775/// Configuration options for generated bindings.
1777- #[ derive( Debug ) ]
1776+ #[ derive( Clone , Debug ) ]
17781777struct BindgenOptions {
17791778 /// The set of types that have been blocklisted and should not appear
17801779 /// anywhere in the generated code.
@@ -1977,12 +1976,9 @@ struct BindgenOptions {
19771976 /// Any additional input header files.
19781977 extra_input_headers : Vec < String > ,
19791978
1980- /// Unsaved files for input.
1981- input_unsaved_files : Vec < clang:: UnsavedFile > ,
1982-
19831979 /// A user-provided visitor to allow customizing different kinds of
19841980 /// situations.
1985- parse_callbacks : Option < Box < dyn callbacks:: ParseCallbacks > > ,
1981+ parse_callbacks : Option < Rc < dyn callbacks:: ParseCallbacks > > ,
19861982
19871983 /// Which kind of items should we generate? By default, we'll generate all
19881984 /// of them.
@@ -2230,7 +2226,6 @@ impl Default for BindgenOptions {
22302226 clang_args : vec ! [ ] ,
22312227 input_header : None ,
22322228 extra_input_headers : vec ! [ ] ,
2233- input_unsaved_files : vec ! [ ] ,
22342229 parse_callbacks : None ,
22352230 codegen_config : CodegenConfig :: all ( ) ,
22362231 conservative_inline_namespaces : false ,
@@ -2388,6 +2383,7 @@ impl Bindings {
23882383 /// Generate bindings for the given options.
23892384 pub ( crate ) fn generate (
23902385 mut options : BindgenOptions ,
2386+ input_unsaved_files : Vec < clang:: UnsavedFile > ,
23912387 ) -> Result < Bindings , BindgenError > {
23922388 ensure_libclang_is_loaded ( ) ;
23932389
@@ -2522,7 +2518,7 @@ impl Bindings {
25222518 }
25232519 }
25242520
2525- for ( idx, f) in options . input_unsaved_files . iter ( ) . enumerate ( ) {
2521+ for ( idx, f) in input_unsaved_files. iter ( ) . enumerate ( ) {
25262522 if idx != 0 || options. input_header . is_some ( ) {
25272523 options. clang_args . push ( "-include" . to_owned ( ) ) ;
25282524 }
@@ -2532,7 +2528,7 @@ impl Bindings {
25322528 debug ! ( "Fixed-up options: {:?}" , options) ;
25332529
25342530 let time_phases = options. time_phases ;
2535- let mut context = BindgenContext :: new ( options) ;
2531+ let mut context = BindgenContext :: new ( options, & input_unsaved_files ) ;
25362532
25372533 if is_host_build {
25382534 debug_assert_eq ! (
0 commit comments