diff options
author | Christian Poveda <31802960+pvdrz@users.noreply.github.com> | 2022-10-03 11:17:18 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-03 11:17:18 -0500 |
commit | 15aef5e43b9ad756887e4329b87908da638bcc60 (patch) | |
tree | 789eb6ab710f0856dec50a0ce902eabb0dc47d7c /src | |
parent | 8b69ba05aa685d3bf02f7f21bc5cab63262e1de5 (diff) | |
parent | 17252c73fa2820da7a4c4f0027545b976fd95dc3 (diff) |
Merge pull request #2285 from ferrous-systems/clone-options
Make `BindgenOptions` clonable
Diffstat (limited to 'src')
-rw-r--r-- | src/deps.rs | 2 | ||||
-rw-r--r-- | src/ir/context.rs | 7 | ||||
-rw-r--r-- | src/lib.rs | 30 | ||||
-rw-r--r-- | src/regex_set.rs | 2 |
4 files changed, 20 insertions, 21 deletions
diff --git a/src/deps.rs b/src/deps.rs index 479c396c..987225b2 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 d470efa9..12373952 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 @@ -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. @@ -1465,7 +1466,7 @@ impl Builder { mut self, cb: Box<dyn callbacks::ParseCallbacks>, ) -> Self { - self.options.parse_callbacks = Some(cb); + self.options.parse_callbacks = Some(Rc::from(cb)); self } @@ -1574,15 +1575,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::<Vec<_>>(); - Bindings::generate(self.options) + Bindings::generate(self.options, input_unsaved_files) } /// Preprocess and dump the input header files to disk. @@ -1774,7 +1773,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. @@ -1977,12 +1976,9 @@ struct BindgenOptions { /// Any additional input header files. extra_input_headers: Vec<String>, - /// Unsaved files for input. - input_unsaved_files: Vec<clang::UnsavedFile>, - /// A user-provided visitor to allow customizing different kinds of /// situations. - parse_callbacks: Option<Box<dyn callbacks::ParseCallbacks>>, + parse_callbacks: Option<Rc<dyn callbacks::ParseCallbacks>>, /// Which kind of items should we generate? By default, we'll generate all /// of them. @@ -2230,7 +2226,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, @@ -2388,6 +2383,7 @@ impl Bindings { /// Generate bindings for the given options. pub(crate) fn generate( mut options: BindgenOptions, + input_unsaved_files: Vec<clang::UnsavedFile>, ) -> Result<Bindings, BindgenError> { ensure_libclang_is_loaded(); @@ -2522,7 +2518,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()); } @@ -2532,7 +2528,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 127c0018..9262c4ee 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<String>, /// Whether any of the items in the set was ever matched. The length of this |