diff --git a/src/deps.rs b/src/deps.rs index 479c396cbb..987225b28e 100644 --- a/src/deps.rs +++ b/src/deps.rs @@ -1,7 +1,7 @@ /// Generating build depfiles from parsed bindings. use std::{collections::BTreeSet, path::PathBuf}; -#[derive(Debug)] +#[derive(Clone, Debug)] pub(crate) struct DepfileSpec { pub output_module: String, pub depfile_path: PathBuf, diff --git a/src/ir/context.rs b/src/ir/context.rs index 7837e59491..6f16e19203 100644 --- a/src/ir/context.rs +++ b/src/ir/context.rs @@ -505,7 +505,10 @@ impl<'ctx> AllowlistedItemsTraversal<'ctx> { impl BindgenContext { /// Construct the context for the given `options`. - pub(crate) fn new(options: BindgenOptions) -> Self { + pub(crate) fn new( + options: BindgenOptions, + input_unsaved_files: &[clang::UnsavedFile], + ) -> Self { // TODO(emilio): Use the CXTargetInfo here when available. // // see: https://reviews.llvm.org/D32389 @@ -522,7 +525,7 @@ impl BindgenContext { &index, "", &options.clang_args, - &options.input_unsaved_files, + input_unsaved_files, parse_options, ).expect("libclang error; possible causes include: - Invalid flag syntax diff --git a/src/lib.rs b/src/lib.rs index 9a5887df8e..81a5811601 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -83,6 +83,7 @@ use std::fs::{File, OpenOptions}; use std::io::{self, Write}; use std::path::{Path, PathBuf}; use std::process::{Command, Stdio}; +use std::rc::Rc; use std::{env, iter}; // Some convenient typedefs for a fast hash map and hash set. @@ -1466,7 +1467,7 @@ impl Builder { mut self, cb: Box, ) -> Self { - self.options.parse_callbacks = Some(cb); + self.options.parse_callbacks = Some(Rc::from(cb)); self } @@ -1575,15 +1576,13 @@ impl Builder { }), ); - self.options.input_unsaved_files.extend( - self.input_header_contents - .drain(..) - .map(|(name, contents)| { - clang::UnsavedFile::new(&name, &contents) - }), - ); + let input_unsaved_files = self + .input_header_contents + .into_iter() + .map(|(name, contents)| clang::UnsavedFile::new(&name, &contents)) + .collect::>(); - Bindings::generate(self.options) + Bindings::generate(self.options, input_unsaved_files) } /// Preprocess and dump the input header files to disk. @@ -1775,7 +1774,7 @@ impl Builder { } /// Configuration options for generated bindings. -#[derive(Debug)] +#[derive(Clone, Debug)] struct BindgenOptions { /// The set of types that have been blocklisted and should not appear /// anywhere in the generated code. @@ -1978,12 +1977,9 @@ struct BindgenOptions { /// Any additional input header files. extra_input_headers: Vec, - /// Unsaved files for input. - input_unsaved_files: Vec, - /// A user-provided visitor to allow customizing different kinds of /// situations. - parse_callbacks: Option>, + parse_callbacks: Option>, /// Which kind of items should we generate? By default, we'll generate all /// of them. @@ -2236,7 +2232,6 @@ impl Default for BindgenOptions { clang_args: vec![], input_header: None, extra_input_headers: vec![], - input_unsaved_files: vec![], parse_callbacks: None, codegen_config: CodegenConfig::all(), conservative_inline_namespaces: false, @@ -2394,6 +2389,7 @@ impl Bindings { /// Generate bindings for the given options. pub(crate) fn generate( mut options: BindgenOptions, + input_unsaved_files: Vec, ) -> Result { ensure_libclang_is_loaded(); @@ -2528,7 +2524,7 @@ impl Bindings { } } - for (idx, f) in options.input_unsaved_files.iter().enumerate() { + for (idx, f) in input_unsaved_files.iter().enumerate() { if idx != 0 || options.input_header.is_some() { options.clang_args.push("-include".to_owned()); } @@ -2538,7 +2534,7 @@ impl Bindings { debug!("Fixed-up options: {:?}", options); let time_phases = options.time_phases; - let mut context = BindgenContext::new(options); + let mut context = BindgenContext::new(options, &input_unsaved_files); if is_host_build { debug_assert_eq!( diff --git a/src/regex_set.rs b/src/regex_set.rs index 127c001829..9262c4eeda 100644 --- a/src/regex_set.rs +++ b/src/regex_set.rs @@ -4,7 +4,7 @@ use regex::RegexSet as RxSet; use std::cell::Cell; /// A dynamic set of regular expressions. -#[derive(Debug, Default)] +#[derive(Clone, Debug, Default)] pub struct RegexSet { items: Vec, /// Whether any of the items in the set was ever matched. The length of this