File tree Expand file tree Collapse file tree 7 files changed +38
-3
lines changed Expand file tree Collapse file tree 7 files changed +38
-3
lines changed Original file line number Diff line number Diff line change @@ -156,6 +156,9 @@ struct BindgenCommand {
156156 /// Mark FILE as hidden.
157157 #[ arg( long, value_name = "FILE" ) ]
158158 blocklist_file : Vec < String > ,
159+ /// Mark VAR as hidden.
160+ #[ arg( long, value_name = "VAR" ) ]
161+ blocklist_var : Vec < String > ,
159162 /// Avoid generating layout tests for any type.
160163 #[ arg( long) ]
161164 no_layout_tests : bool ,
@@ -471,6 +474,7 @@ where
471474 blocklist_function,
472475 blocklist_item,
473476 blocklist_file,
477+ blocklist_var,
474478 no_layout_tests,
475479 no_derive_copy,
476480 no_derive_debug,
@@ -676,6 +680,10 @@ where
676680 builder = builder. blocklist_file ( file) ;
677681 }
678682
683+ for var in blocklist_var {
684+ builder = builder. blocklist_var ( var) ;
685+ }
686+
679687 if builtins {
680688 builder = builder. emit_builtins ( ) ;
681689 }
Original file line number Diff line number Diff line change 1+ // bindgen-flags: --blocklist-var should_be_blocked
2+
3+ extern int should_be_blocked;
Original file line number Diff line number Diff line change @@ -668,8 +668,11 @@ impl Item {
668668 ItemKind :: Function ( ..) => {
669669 ctx. options ( ) . blocklisted_functions . matches ( & name)
670670 }
671- // TODO: Add constant / namespace blocklisting?
672- ItemKind :: Var ( ..) | ItemKind :: Module ( ..) => false ,
671+ ItemKind :: Var ( ..) => {
672+ ctx. options ( ) . blocklisted_vars . matches ( & name)
673+ }
674+ // TODO: Add namespace blocklisting?
675+ ItemKind :: Module ( ..) => false ,
673676 }
674677 }
675678
Original file line number Diff line number Diff line change @@ -440,13 +440,14 @@ impl Builder {
440440
441441impl BindgenOptions {
442442 fn build ( & mut self ) {
443- const REGEX_SETS_LEN : usize = 28 ;
443+ const REGEX_SETS_LEN : usize = 29 ;
444444
445445 let regex_sets: [ _ ; REGEX_SETS_LEN ] = [
446446 & mut self . blocklisted_types ,
447447 & mut self . blocklisted_functions ,
448448 & mut self . blocklisted_items ,
449449 & mut self . blocklisted_files ,
450+ & mut self . blocklisted_vars ,
450451 & mut self . opaque_types ,
451452 & mut self . allowlisted_vars ,
452453 & mut self . allowlisted_types ,
@@ -483,6 +484,7 @@ impl BindgenOptions {
483484 "--blocklist-function" ,
484485 "--blocklist-item" ,
485486 "--blocklist-file" ,
487+ "--blocklist-var" ,
486488 "--opaque-type" ,
487489 "--allowlist-type" ,
488490 "--allowlist-function" ,
Original file line number Diff line number Diff line change @@ -222,6 +222,22 @@ options! {
222222 } ,
223223 as_args: "--blocklist-file" ,
224224 } ,
225+ /// Variables that have been blocklisted and should not appear in the generated code.
226+ blocklisted_vars: RegexSet {
227+ methods: {
228+ regex_option! {
229+ /// Do not generate any bindings for the given variable.
230+ ///
231+ /// This option is not recursive, meaning that it will only block variables whose
232+ /// names explicitly match the argument of this method.
233+ pub fn blocklist_var<T : AsRef <str >>( mut self , arg: T ) -> Builder {
234+ self . options. blocklisted_vars. insert( arg) ;
235+ self
236+ }
237+ }
238+ } ,
239+ as_args: "--blocklist-var" ,
240+ } ,
225241 /// Types that should be treated as opaque structures in the generated code.
226242 opaque_types: RegexSet {
227243 methods: {
Original file line number Diff line number Diff line change @@ -22,13 +22,15 @@ that are transitively included.
2222* [ ` bindgen::Builder::blocklist_function ` ] ( https://docs.rs/bindgen/latest/bindgen/struct.Builder.html#method.blocklist_function )
2323* [ ` bindgen::Builder::blocklist_item ` ] ( https://docs.rs/bindgen/latest/bindgen/struct.Builder.html#method.blocklist_item )
2424* [ ` bindgen::Builder::blocklist_type ` ] ( https://docs.rs/bindgen/latest/bindgen/struct.Builder.html#method.blocklist_type )
25+ * [ ` bindgen::Builder::blocklist_var ` ] ( https://docs.rs/bindgen/latest/bindgen/struct.Builder.html#method.blocklist_var )
2526
2627### Command Line
2728
2829* ` --blocklist-file <path> `
2930* ` --blocklist-function <function> `
3031* ` --blocklist-item <item> `
3132* ` --blocklist-type <type> `
33+ * ` --blocklist-var <var> `
3234
3335
3436### Annotations
You can’t perform that action at this time.
0 commit comments