mirror of
https://gitee.com/openharmony/third_party_rust_bindgen
synced 2024-12-11 17:14:31 +00:00
Merge pull request #2285 from ferrous-systems/clone-options
Make `BindgenOptions` clonable
This commit is contained in:
commit
15aef5e43b
@ -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,
|
||||
|
@ -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
|
||||
|
30
src/lib.rs
30
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.
|
||||
@ -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!(
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user