Skip to content

Commit 4cfd06e

Browse files
committed
make BindgenOptions clonable
1 parent 2963d05 commit 4cfd06e

File tree

4 files changed

+20
-21
lines changed

4 files changed

+20
-21
lines changed

src/deps.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/// Generating build depfiles from parsed bindings.
22
use std::{collections::BTreeSet, path::PathBuf};
33

4-
#[derive(Debug)]
4+
#[derive(Clone, Debug)]
55
pub(crate) struct DepfileSpec {
66
pub output_module: String,
77
pub depfile_path: PathBuf,

src/ir/context.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,10 @@ impl<'ctx> AllowlistedItemsTraversal<'ctx> {
505505

506506
impl BindgenContext {
507507
/// Construct the context for the given `options`.
508-
pub(crate) fn new(options: BindgenOptions) -> Self {
508+
pub(crate) fn new(
509+
options: BindgenOptions,
510+
input_unsaved_files: &[clang::UnsavedFile],
511+
) -> Self {
509512
// TODO(emilio): Use the CXTargetInfo here when available.
510513
//
511514
// see: https://reviews.llvm.org/D32389
@@ -522,7 +525,7 @@ impl BindgenContext {
522525
&index,
523526
"",
524527
&options.clang_args,
525-
&options.input_unsaved_files,
528+
&input_unsaved_files,
526529
parse_options,
527530
).expect("libclang error; possible causes include:
528531
- Invalid flag syntax

src/lib.rs

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ use std::fs::{File, OpenOptions};
8383
use std::io::{self, Write};
8484
use std::path::{Path, PathBuf};
8585
use std::process::{Command, Stdio};
86+
use std::rc::Rc;
8687
use std::{env, iter};
8788

8889
// Some convenient typedefs for a fast hash map and hash set.
@@ -1466,7 +1467,7 @@ impl Builder {
14661467
mut self,
14671468
cb: Box<dyn callbacks::ParseCallbacks>,
14681469
) -> Self {
1469-
self.options.parse_callbacks = Some(cb);
1470+
self.options.parse_callbacks = Some(Rc::from(cb));
14701471
self
14711472
}
14721473

@@ -1575,15 +1576,13 @@ impl Builder {
15751576
}),
15761577
);
15771578

1578-
self.options.input_unsaved_files.extend(
1579-
self.input_header_contents
1580-
.drain(..)
1581-
.map(|(name, contents)| {
1582-
clang::UnsavedFile::new(&name, &contents)
1583-
}),
1584-
);
1579+
let input_unsaved_files = self
1580+
.input_header_contents
1581+
.into_iter()
1582+
.map(|(name, contents)| clang::UnsavedFile::new(&name, &contents))
1583+
.collect::<Vec<_>>();
15851584

1586-
Bindings::generate(self.options)
1585+
Bindings::generate(self.options, input_unsaved_files)
15871586
}
15881587

15891588
/// Preprocess and dump the input header files to disk.
@@ -1775,7 +1774,7 @@ impl Builder {
17751774
}
17761775

17771776
/// Configuration options for generated bindings.
1778-
#[derive(Debug)]
1777+
#[derive(Clone, Debug)]
17791778
struct BindgenOptions {
17801779
/// The set of types that have been blocklisted and should not appear
17811780
/// anywhere in the generated code.
@@ -1978,12 +1977,9 @@ struct BindgenOptions {
19781977
/// Any additional input header files.
19791978
extra_input_headers: Vec<String>,
19801979

1981-
/// Unsaved files for input.
1982-
input_unsaved_files: Vec<clang::UnsavedFile>,
1983-
19841980
/// A user-provided visitor to allow customizing different kinds of
19851981
/// situations.
1986-
parse_callbacks: Option<Box<dyn callbacks::ParseCallbacks>>,
1982+
parse_callbacks: Option<Rc<dyn callbacks::ParseCallbacks>>,
19871983

19881984
/// Which kind of items should we generate? By default, we'll generate all
19891985
/// of them.
@@ -2236,7 +2232,6 @@ impl Default for BindgenOptions {
22362232
clang_args: vec![],
22372233
input_header: None,
22382234
extra_input_headers: vec![],
2239-
input_unsaved_files: vec![],
22402235
parse_callbacks: None,
22412236
codegen_config: CodegenConfig::all(),
22422237
conservative_inline_namespaces: false,
@@ -2394,6 +2389,7 @@ impl Bindings {
23942389
/// Generate bindings for the given options.
23952390
pub(crate) fn generate(
23962391
mut options: BindgenOptions,
2392+
input_unsaved_files: Vec<clang::UnsavedFile>,
23972393
) -> Result<Bindings, BindgenError> {
23982394
ensure_libclang_is_loaded();
23992395

@@ -2528,7 +2524,7 @@ impl Bindings {
25282524
}
25292525
}
25302526

2531-
for (idx, f) in options.input_unsaved_files.iter().enumerate() {
2527+
for (idx, f) in input_unsaved_files.iter().enumerate() {
25322528
if idx != 0 || options.input_header.is_some() {
25332529
options.clang_args.push("-include".to_owned());
25342530
}
@@ -2538,7 +2534,7 @@ impl Bindings {
25382534
debug!("Fixed-up options: {:?}", options);
25392535

25402536
let time_phases = options.time_phases;
2541-
let mut context = BindgenContext::new(options);
2537+
let mut context = BindgenContext::new(options, &input_unsaved_files);
25422538

25432539
if is_host_build {
25442540
debug_assert_eq!(

src/regex_set.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use regex::RegexSet as RxSet;
44
use std::cell::Cell;
55

66
/// A dynamic set of regular expressions.
7-
#[derive(Debug, Default)]
7+
#[derive(Clone, Debug, Default)]
88
pub struct RegexSet {
99
items: Vec<String>,
1010
/// Whether any of the items in the set was ever matched. The length of this

0 commit comments

Comments
 (0)