|
1 | 1 | use bindgen::{self, callbacks, Bindings, CargoCallbacks}; |
2 | 2 | use once_cell::sync::Lazy; |
3 | 3 |
|
4 | | -use std::{collections::HashSet, env, fs, path}; |
| 4 | +use std::{collections::HashSet, default::Default, env, fs, ops::Deref, path}; |
5 | 5 |
|
6 | 6 | /// All the libs that FFmpeg has |
7 | 7 | static LIBS: Lazy<[&str; 8]> = Lazy::new(|| { |
@@ -90,28 +90,36 @@ static HEADERS: Lazy<[&str; 64]> = Lazy::new(|| { |
90 | 90 | /// Filter out all symbols in the HashSet, and for others things it will act |
91 | 91 | /// exactly the same as `CargoCallback`. |
92 | 92 | #[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 | +} |
94 | 106 |
|
95 | 107 | 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) { |
98 | 110 | callbacks::MacroParsingBehavior::Ignore |
99 | 111 | } else { |
100 | 112 | callbacks::MacroParsingBehavior::Default |
101 | 113 | } |
102 | 114 | } |
103 | | - fn include_file(&self, _filename: &str) { |
104 | | - self.0.include_file(_filename); |
105 | | - } |
106 | 115 | } |
107 | 116 |
|
108 | 117 | fn generate_bindings( |
109 | 118 | include_paths: &HashSet<path::PathBuf>, |
110 | 119 | headers: &[&str], |
111 | 120 | ) -> Result<Bindings, ()> { |
112 | 121 | // 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( |
115 | 123 | vec![ |
116 | 124 | "FP_NAN".to_owned(), |
117 | 125 | "FP_INFINITE".to_owned(), |
|
0 commit comments