Skip to content

Commit b2769a7

Browse files
committed
Rewrite bindgen Callback
1 parent e0801d8 commit b2769a7

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

build.rs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use bindgen::{self, callbacks, Bindings, CargoCallbacks};
22
use once_cell::sync::Lazy;
33

4-
use std::{collections::HashSet, env, fs, path};
4+
use std::{collections::HashSet, default::Default, env, fs, ops::Deref, path};
55

66
/// All the libs that FFmpeg has
77
static LIBS: Lazy<[&str; 8]> = Lazy::new(|| {
@@ -90,28 +90,36 @@ static HEADERS: Lazy<[&str; 64]> = Lazy::new(|| {
9090
/// Filter out all symbols in the HashSet, and for others things it will act
9191
/// exactly the same as `CargoCallback`.
9292
#[derive(Debug)]
93-
struct FilterCargoCallbacks(CargoCallbacks, HashSet<String>);
93+
struct FilterCargoCallbacks {
94+
inner: CargoCallbacks,
95+
emitted_macro: HashSet<String>,
96+
}
97+
98+
impl FilterCargoCallbacks {
99+
fn new(set: HashSet<String>) -> Self {
100+
Self {
101+
inner: CargoCallbacks,
102+
emitted_macro: set,
103+
}
104+
}
105+
}
94106

95107
impl callbacks::ParseCallbacks for FilterCargoCallbacks {
96-
fn will_parse_macro(&self, _name: &str) -> callbacks::MacroParsingBehavior {
97-
if self.1.contains(_name) {
108+
fn will_parse_macro(&self, name: &str) -> callbacks::MacroParsingBehavior {
109+
if self.emitted_macro.contains(name) {
98110
callbacks::MacroParsingBehavior::Ignore
99111
} else {
100112
callbacks::MacroParsingBehavior::Default
101113
}
102114
}
103-
fn include_file(&self, _filename: &str) {
104-
self.0.include_file(_filename);
105-
}
106115
}
107116

108117
fn generate_bindings(
109118
include_paths: &HashSet<path::PathBuf>,
110119
headers: &[&str],
111120
) -> Result<Bindings, ()> {
112121
// Because the strange `FP_*` in `math.h` https://github.com/rust-lang/rust-bindgen/issues/687
113-
let filter_callback = FilterCargoCallbacks(
114-
CargoCallbacks,
122+
let filter_callback = FilterCargoCallbacks::new(
115123
vec![
116124
"FP_NAN".to_owned(),
117125
"FP_INFINITE".to_owned(),

0 commit comments

Comments
 (0)