1 //! Declarations and setter methods for `bindgen` options.
2 //!
3 //! The main entry point of this module is the `options` macro.
4 #[macro_use]
5 mod helpers;
6 mod as_args;
7 
8 use crate::callbacks::ParseCallbacks;
9 use crate::codegen::{
10     AliasVariation, EnumVariation, MacroTypeVariation, NonCopyUnionStyle,
11 };
12 use crate::deps::DepfileSpec;
13 use crate::features::{RustFeatures, RustTarget};
14 use crate::regex_set::RegexSet;
15 use crate::Abi;
16 use crate::Builder;
17 use crate::CodegenConfig;
18 use crate::FieldVisibilityKind;
19 use crate::Formatter;
20 use crate::HashMap;
21 use crate::DEFAULT_ANON_FIELDS_PREFIX;
22 
23 use std::env;
24 #[cfg(feature = "experimental")]
25 use std::path::Path;
26 use std::path::PathBuf;
27 use std::rc::Rc;
28 
29 use as_args::AsArgs;
30 use helpers::ignore;
31 
32 /// Macro used to generate the [`BindgenOptions`] type and the [`Builder`] setter methods for each
33 /// one of the fields of `BindgenOptions`.
34 ///
35 /// The input format of this macro resembles a `struct` pattern. Each field of the `BindgenOptions`
36 /// type is declared by adding the name of the field and its type using the `name: type` syntax and
37 /// a block of code with the following items:
38 ///
39 /// - `default`: The default value for the field. If this item is omitted, `Default::default()` is
40 /// used instead, meaning that the type of the field must implement `Default`.
41 /// - `methods`: A block of code containing methods for the `Builder` type. These methods should be
42 /// related to the field being declared.
43 /// - `as_args`: This item declares how the field should be converted into a valid CLI argument for
44 /// `bindgen` and is used in the [`Builder::command_line_flags`] method which is used to do a
45 /// roundtrip test of the CLI args in the `bindgen-test` crate. This item can take one of the
46 /// following:
47 ///   - A string literal with the flag if the type of the field implements the [`AsArgs`] trait.
48 ///   - A closure with the signature `|field, args: &mut Vec<String>| -> ()` that pushes arguments
49 ///   into the `args` buffer based on the value of the field. This is used if the field does not
50 ///   implement `AsArgs` or if the implementation of the trait is not logically correct for the
51 ///   option and a custom behavior must be taken into account.
52 ///   - The `ignore` literal, which does not emit any CLI arguments for this field. This is useful
53 ///   if the field cannot be used from the `bindgen` CLI.
54 ///
55 /// As an example, this would be the declaration of a `bool` field called `be_fun` whose default
56 /// value is `false` (the `Default` value for `bool`):
57 /// ```rust,ignore
58 /// be_fun: bool {
59 ///    methods: {
60 ///        /// Ask `bindgen` to be fun. This option is disabled by default.
61 ///        fn be_fun(mut self) -> Self {
62 ///            self.options.be_fun = true;
63 ///            self
64 ///        }
65 ///    },
66 ///    as_args: "--be-fun",
67 /// }
68 /// ```
69 ///
70 /// However, we could also set the `be_fun` field to `true` by default and use a `--not-fun` flag
71 /// instead. This means that we have to add the `default` item and use a closure in the `as_args`
72 /// item:
73 /// ```rust,ignore
74 /// be_fun: bool {
75 ///    default: true,
76 ///    methods: {
77 ///        /// Ask `bindgen` to not be fun. `bindgen` is fun by default.
78 ///        fn not_fun(mut self) -> Self {
79 ///            self.options.be_fun = false;
80 ///            self
81 ///        }
82 ///    },
83 ///    as_args: |be_fun, args| (!be_fun).as_args(args, "--not-fun"),
84 /// }
85 /// ```
86 /// More complex examples can be found in the sole invocation of this macro.
87 macro_rules! options {
88     ($(
89         $(#[doc = $docs:literal])+
90         $field:ident: $ty:ty {
91             $(default: $default:expr,)?
92             methods: {$($methods_tokens:tt)*}$(,)?
93             as_args: $as_args:expr$(,)?
94         }$(,)?
95     )*) => {
96         #[derive(Debug, Clone)]
97         pub(crate) struct BindgenOptions {
98             $($(#[doc = $docs])* pub(crate) $field: $ty,)*
99         }
100 
101         impl Default for BindgenOptions {
102             fn default() -> Self {
103                 Self {
104                     $($field: default!($($default)*),)*
105                 }
106             }
107         }
108 
109         impl Builder {
110             /// Generates the command line flags used to create this [`Builder`].
111             pub fn command_line_flags(&self) -> Vec<String> {
112                 let mut args = vec![];
113 
114                 let headers = match self.options.input_headers.split_last() {
115                     Some((header, headers)) => {
116                         // The last input header is passed as an argument in the first position.
117                         args.push(header.clone().into());
118                         headers
119                     },
120                     None => &[]
121                 };
122 
123                 $({
124                     let func: fn(&$ty, &mut Vec<String>) = as_args!($as_args);
125                     func(&self.options.$field, &mut args);
126                 })*
127 
128                 // Add the `--experimental` flag if `bindgen` is built with the `experimental`
129                 // feature.
130                 if cfg!(feature = "experimental") {
131                     args.push("--experimental".to_owned());
132                 }
133 
134                 // Add all the clang arguments.
135                 args.push("--".to_owned());
136 
137                 if !self.options.clang_args.is_empty() {
138                     args.extend(self.options.clang_args.iter().map(|s| s.clone().into()));
139                 }
140 
141                 // We need to pass all but the last header via the `-include` clang argument.
142                 for header in headers {
143                     args.push("-include".to_owned());
144                     args.push(header.clone().into());
145                 }
146 
147                 args
148             }
149 
150             $($($methods_tokens)*)*
151         }
152     };
153 }
154 
155 options! {
156     /// Types that have been blocklisted and should not appear anywhere in the generated code.
157     blocklisted_types: RegexSet {
158         methods: {
159             regex_option! {
160                 /// Do not generate any bindings for the given type.
161                 ///
162                 /// This option is not recursive, meaning that it will only block types whose names
163                 /// explicitly match the argument of this method.
164                 pub fn blocklist_type<T: AsRef<str>>(mut self, arg: T) -> Builder {
165                     self.options.blocklisted_types.insert(arg);
166                     self
167                 }
168             }
169         },
170         as_args: "--blocklist-type",
171     },
172     /// Functions that have been blocklisted and should not appear in the generated code.
173     blocklisted_functions: RegexSet {
174         methods: {
175             regex_option! {
176                 /// Do not generate any bindings for the given function.
177                 ///
178                 /// This option is not recursive, meaning that it will only block functions whose
179                 /// names explicitly match the argument of this method.
180                 pub fn blocklist_function<T: AsRef<str>>(mut self, arg: T) -> Builder {
181                     self.options.blocklisted_functions.insert(arg);
182                     self
183                 }
184             }
185         },
186         as_args: "--blocklist-function",
187     },
188     /// Items that have been blocklisted and should not appear in the generated code.
189     blocklisted_items: RegexSet {
190         methods: {
191             regex_option! {
192                 /// Do not generate any bindings for the given item, regardless of whether it is a
193                 /// type, function, module, etc.
194                 ///
195                 /// This option is not recursive, meaning that it will only block items whose names
196                 /// explicitly match the argument of this method.
197                 pub fn blocklist_item<T: AsRef<str>>(mut self, arg: T) -> Builder {
198                     self.options.blocklisted_items.insert(arg);
199                     self
200                 }
201             }
202         },
203         as_args: "--blocklist-item",
204     },
205     /// Files whose contents should be blocklisted and should not appear in the generated code.
206     blocklisted_files: RegexSet {
207         methods: {
208             regex_option! {
209                 /// Do not generate any bindings for the contents of the given file, regardless of
210                 /// whether the contents of the file are types, functions, modules, etc.
211                 ///
212                 /// This option is not recursive, meaning that it will only block files whose names
213                 /// explicitly match the argument of this method.
214                 ///
215                 /// This method will use the argument to match the complete path of the file
216                 /// instead of a section of it.
217                 pub fn blocklist_file<T: AsRef<str>>(mut self, arg: T) -> Builder {
218                     self.options.blocklisted_files.insert(arg);
219                     self
220                 }
221             }
222         },
223         as_args: "--blocklist-file",
224     },
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     },
241     /// Types that should be treated as opaque structures in the generated code.
242     opaque_types: RegexSet {
243         methods: {
244             regex_option! {
245                 /// Treat the given type as opaque in the generated bindings.
246                 ///
247                 /// Opaque in this context means that none of the generated bindings will contain
248                 /// information about the inner representation of the type and the type itself will
249                 /// be represented as a chunk of bytes with the alignment and size of the type.
250                 pub fn opaque_type<T: AsRef<str>>(mut self, arg: T) -> Builder {
251                     self.options.opaque_types.insert(arg);
252                     self
253                 }
254             }
255         },
256         as_args: "--opaque-type",
257     },
258     /// The explicit `rustfmt` path.
259     rustfmt_path: Option<PathBuf> {
260         methods: {
261             /// Set an explicit path to the `rustfmt` binary.
262             ///
263             /// This option only comes into effect if `rustfmt` is set to be the formatter used by
264             /// `bindgen`. Check the documentation of the [`Builder::formatter`] method for more
265             /// information.
266             pub fn with_rustfmt<P: Into<PathBuf>>(mut self, path: P) -> Self {
267                 self.options.rustfmt_path = Some(path.into());
268                 self
269             }
270         },
271         // This option cannot be set from the CLI.
272         as_args: ignore,
273     },
274     /// The path to which we should write a Makefile-syntax depfile (if any).
275     depfile: Option<DepfileSpec> {
276         methods: {
277             /// Add a depfile output which will be written alongside the generated bindings.
278             pub fn depfile<H: Into<String>, D: Into<PathBuf>>(
279                 mut self,
280                 output_module: H,
281                 depfile: D,
282             ) -> Builder {
283                 self.options.depfile = Some(DepfileSpec {
284                     output_module: output_module.into(),
285                     depfile_path: depfile.into(),
286                 });
287                 self
288             }
289         },
290         as_args: |depfile, args| {
291             if let Some(depfile) = depfile {
292                 args.push("--depfile".into());
293                 args.push(depfile.depfile_path.display().to_string());
294             }
295         },
296     },
297     /// Types that have been allowlisted and should appear in the generated code.
298     allowlisted_types: RegexSet {
299         methods: {
300             regex_option! {
301                 /// Generate bindings for the given type.
302                 ///
303                 /// This option is transitive by default. Check the documentation of the
304                 /// [`Builder::allowlist_recursively`] method for further information.
305                 pub fn allowlist_type<T: AsRef<str>>(mut self, arg: T) -> Builder {
306                     self.options.allowlisted_types.insert(arg);
307                     self
308                 }
309             }
310         },
311         as_args: "--allowlist-type",
312     },
313     /// Functions that have been allowlisted and should appear in the generated code.
314     allowlisted_functions: RegexSet {
315         methods: {
316             regex_option! {
317                 /// Generate bindings for the given function.
318                 ///
319                 /// This option is transitive by default. Check the documentation of the
320                 /// [`Builder::allowlist_recursively`] method for further information.
321                 pub fn allowlist_function<T: AsRef<str>>(mut self, arg: T) -> Builder {
322                     self.options.allowlisted_functions.insert(arg);
323                     self
324                 }
325             }
326         },
327         as_args: "--allowlist-function",
328     },
329     /// Variables that have been allowlisted and should appear in the generated code.
330     allowlisted_vars: RegexSet {
331         methods: {
332             regex_option! {
333                 /// Generate bindings for the given variable.
334                 ///
335                 /// This option is transitive by default. Check the documentation of the
336                 /// [`Builder::allowlist_recursively`] method for further information.
337                 pub fn allowlist_var<T: AsRef<str>>(mut self, arg: T) -> Builder {
338                     self.options.allowlisted_vars.insert(arg);
339                     self
340                 }
341             }
342         },
343         as_args: "--allowlist-var",
344     },
345     /// Files whose contents have been allowlisted and should appear in the generated code.
346     allowlisted_files: RegexSet {
347         methods: {
348             regex_option! {
349                 /// Generate bindings for the content of the given file.
350                 ///
351                 /// This option is transitive by default. Check the documentation of the
352                 /// [`Builder::allowlist_recursively`] method for further information.
353                 ///
354                 /// This method will use the argument to match the complete path of the file
355                 /// instead of a section of it.
356                 pub fn allowlist_file<T: AsRef<str>>(mut self, arg: T) -> Builder {
357                     self.options.allowlisted_files.insert(arg);
358                     self
359                 }
360             }
361         },
362         as_args: "--allowlist-file",
363     },
364     /// Items that have been allowlisted and should appear in the generated code.
365     allowlisted_items: RegexSet {
366         methods: {
367             regex_option! {
368                 /// Generate bindings for the given item, regardless of whether it is a type,
369                 /// function, module, etc.
370                 ///
371                 /// This option is transitive by default. Check the documentation of the
372                 /// [`Builder::allowlist_recursively`] method for further information.
373                 pub fn allowlist_item<T: AsRef<str>>(mut self, arg: T) -> Builder {
374                     self.options.allowlisted_items.insert(arg);
375                     self
376                 }
377             }
378         },
379         as_args: "--allowlist-item",
380     },
381     /// The default style of for generated `enum`s.
382     default_enum_style: EnumVariation {
383         methods: {
384             /// Set the default style for generated `enum`s.
385             ///
386             /// If this method is not called, the [`EnumVariation::Consts`] style will be used by
387             /// default.
388             ///
389             /// To set the style for individual `enum`s, use [`Builder::bitfield_enum`],
390             /// [`Builder::newtype_enum`], [`Builder::newtype_global_enum`],
391             /// [`Builder::rustified_enum`], [`Builder::rustified_non_exhaustive_enum`],
392             /// [`Builder::constified_enum_module`] or [`Builder::constified_enum`].
393             pub fn default_enum_style(
394                 mut self,
395                 arg: EnumVariation,
396             ) -> Builder {
397                 self.options.default_enum_style = arg;
398                 self
399             }
400         },
401         as_args: |variation, args| {
402             if *variation != Default::default() {
403                 args.push("--default-enum-style".to_owned());
404                 args.push(variation.to_string());
405             }
406         },
407     },
408     /// `enum`s marked as bitfield-like. This is, newtypes with bitwise operations.
409     bitfield_enums: RegexSet {
410         methods: {
411             regex_option! {
412                 /// Mark the given `enum` as being bitfield-like.
413                 ///
414                 /// This is similar to the [`Builder::newtype_enum`] style, but with the bitwise
415                 /// operators implemented.
416                 pub fn bitfield_enum<T: AsRef<str>>(mut self, arg: T) -> Builder {
417                     self.options.bitfield_enums.insert(arg);
418                     self
419                 }
420             }
421         },
422         as_args: "--bitfield-enum",
423     },
424     /// `enum`s marked as newtypes.
425     newtype_enums: RegexSet {
426         methods: {
427             regex_option! {
428                 /// Mark the given `enum` as a newtype.
429                 ///
430                 /// This means that an integer newtype will be declared to represent the `enum`
431                 /// type and its variants will be represented as constants inside of this type's
432                 /// `impl` block.
433                 pub fn newtype_enum<T: AsRef<str>>(mut self, arg: T) -> Builder {
434                     self.options.newtype_enums.insert(arg);
435                     self
436                 }
437             }
438         },
439         as_args: "--newtype-enum",
440     },
441     /// `enum`s marked as global newtypes .
442     newtype_global_enums: RegexSet {
443         methods: {
444             regex_option! {
445                 /// Mark the given `enum` as a global newtype.
446                 ///
447                 /// This is similar to the [`Builder::newtype_enum`] style, but the constants for
448                 /// each variant are free constants instead of being declared inside an `impl`
449                 /// block for the newtype.
450                 pub fn newtype_global_enum<T: AsRef<str>>(mut self, arg: T) -> Builder {
451                     self.options.newtype_global_enums.insert(arg);
452                     self
453                 }
454             }
455         },
456         as_args: "--newtype-global-enum",
457     },
458     /// `enum`s marked as Rust `enum`s.
459     rustified_enums: RegexSet {
460         methods: {
461             regex_option! {
462                 /// Mark the given `enum` as a Rust `enum`.
463                 ///
464                 /// This means that each variant of the `enum` will be represented as a Rust `enum`
465                 /// variant.
466                 ///
467                 /// **Use this with caution**, creating an instance of a Rust `enum` with an
468                 /// invalid value will cause undefined behaviour. To avoid this, use the
469                 /// [`Builder::newtype_enum`] style instead.
470                 pub fn rustified_enum<T: AsRef<str>>(mut self, arg: T) -> Builder {
471                     self.options.rustified_enums.insert(arg);
472                     self
473                 }
474             }
475         },
476         as_args: "--rustified-enum",
477     },
478     /// `enum`s marked as non-exhaustive Rust `enum`s.
479     rustified_non_exhaustive_enums: RegexSet {
480         methods: {
481             regex_option! {
482                 /// Mark the given `enum` as a non-exhaustive Rust `enum`.
483                 ///
484                 /// This is similar to the [`Builder::rustified_enum`] style, but the `enum` is
485                 /// tagged with the `#[non_exhaustive]` attribute.
486                 pub fn rustified_non_exhaustive_enum<T: AsRef<str>>(mut self, arg: T) -> Builder {
487                     self.options.rustified_non_exhaustive_enums.insert(arg);
488                     self
489                 }
490             }
491         },
492         as_args: "--rustified-non-exhaustive-enums",
493     },
494     /// `enum`s marked as modules of constants.
495     constified_enum_modules: RegexSet {
496         methods: {
497             regex_option! {
498                 /// Mark the given `enum` as a module with a set of integer constants.
499                 pub fn constified_enum_module<T: AsRef<str>>(mut self, arg: T) -> Builder {
500                     self.options.constified_enum_modules.insert(arg);
501                     self
502                 }
503             }
504         },
505         as_args: "--constified-enum-module",
506     },
507     /// `enum`s marked as a set of constants.
508     constified_enums: RegexSet {
509         methods: {
510             regex_option! {
511                 /// Mark the given `enum` as a set o integer constants.
512                 ///
513                 /// This is similar to the [`Builder::constified_enum_module`] style, but the
514                 /// constants are generated in the current module instead of in a new module.
515                 pub fn constified_enum<T: AsRef<str>>(mut self, arg: T) -> Builder {
516                     self.options.constified_enums.insert(arg);
517                     self
518                 }
519             }
520         },
521         as_args: "--constified-enum",
522     },
523     /// The default type signedness for C macro constants.
524     default_macro_constant_type: MacroTypeVariation {
525         methods: {
526             /// Set the default type signedness to be used for macro constants.
527             ///
528             /// If this method is not called, [`MacroTypeVariation::Unsigned`] is used by default.
529             ///
530             /// To set the type for individual macro constants, use the
531             /// [`ParseCallbacks::int_macro`] method.
532             pub fn default_macro_constant_type(mut self, arg: MacroTypeVariation) -> Builder {
533                 self.options.default_macro_constant_type = arg;
534                 self
535             }
536 
537         },
538         as_args: |variation, args| {
539             if *variation != Default::default() {
540                 args.push("--default-macro-constant-type".to_owned());
541                 args.push(variation.to_string());
542             }
543         },
544     },
545     /// The default style of code generation for `typedef`s.
546     default_alias_style: AliasVariation {
547         methods: {
548             /// Set the default style of code generation for `typedef`s.
549             ///
550             /// If this method is not called, the [`AliasVariation::TypeAlias`] style is used by
551             /// default.
552             ///
553             /// To set the style for individual `typedefs`s, use [`Builder::type_alias`],
554             /// [`Builder::new_type_alias`] or [`Builder::new_type_alias_deref`].
555             pub fn default_alias_style(
556                 mut self,
557                 arg: AliasVariation,
558             ) -> Builder {
559                 self.options.default_alias_style = arg;
560                 self
561             }
562         },
563         as_args: |variation, args| {
564             if *variation != Default::default() {
565                 args.push("--default-alias-style".to_owned());
566                 args.push(variation.to_string());
567             }
568         },
569     },
570     /// `typedef` patterns that will use regular type aliasing.
571     type_alias: RegexSet {
572         methods: {
573             regex_option! {
574                 /// Mark the given `typedef` as a regular Rust `type` alias.
575                 ///
576                 /// This is the default behavior, meaning that this method only comes into effect
577                 /// if a style different from [`AliasVariation::TypeAlias`] was passed to the
578                 /// [`Builder::default_alias_style`] method.
579                 pub fn type_alias<T: AsRef<str>>(mut self, arg: T) -> Builder {
580                     self.options.type_alias.insert(arg);
581                     self
582                 }
583             }
584         },
585         as_args: "--type-alias",
586     },
587     /// `typedef` patterns that will be aliased by creating a newtype.
588     new_type_alias: RegexSet {
589         methods: {
590             regex_option! {
591                 /// Mark the given `typedef` as a Rust newtype by having the aliased
592                 /// type be wrapped in a `struct` with `#[repr(transparent)]`.
593                 ///
594                 /// This method can be used to enforce stricter type checking.
595                 pub fn new_type_alias<T: AsRef<str>>(mut self, arg: T) -> Builder {
596                     self.options.new_type_alias.insert(arg);
597                     self
598                 }
599             }
600         },
601         as_args: "--new-type-alias",
602     },
603     /// `typedef` patterns that will be wrapped in a newtype implementing `Deref` and `DerefMut`.
604     new_type_alias_deref: RegexSet {
605         methods: {
606             regex_option! {
607                 /// Mark the given `typedef` to be generated as a newtype that can be dereferenced.
608                 ///
609                 /// This is similar to the [`Builder::new_type_alias`] style, but the newtype
610                 /// implements `Deref` and `DerefMut` with the aliased type as a target.
611                 pub fn new_type_alias_deref<T: AsRef<str>>(mut self, arg: T) -> Builder {
612                     self.options.new_type_alias_deref.insert(arg);
613                     self
614                 }
615             }
616         },
617         as_args: "--new-type-alias-deref",
618     },
619     /// The default style of code to generate for `union`s containing non-`Copy` members.
620     default_non_copy_union_style: NonCopyUnionStyle {
621         methods: {
622             /// Set the default style of code to generate for `union`s with non-`Copy` members.
623             ///
624             /// If this method is not called, the [`NonCopyUnionStyle::BindgenWrapper`] style is
625             /// used by default.
626             ///
627             /// To set the style for individual `union`s, use [`Builder::bindgen_wrapper_union`] or
628             /// [`Builder::manually_drop_union`].
629             pub fn default_non_copy_union_style(mut self, arg: NonCopyUnionStyle) -> Self {
630                 self.options.default_non_copy_union_style = arg;
631                 self
632             }
633         },
634         as_args: |style, args| {
635             if *style != Default::default() {
636                 args.push("--default-non-copy-union-style".to_owned());
637                 args.push(style.to_string());
638             }
639         },
640     },
641     /// The patterns marking non-`Copy` `union`s as using the `bindgen` generated wrapper.
642     bindgen_wrapper_union: RegexSet {
643         methods: {
644             regex_option! {
645                 /// Mark the given `union` to use a `bindgen`-generated wrapper for its members if at
646                 /// least one them is not `Copy`.
647                 ///
648                 /// This is the default behavior, meaning that this method only comes into effect
649                 /// if a style different from [`NonCopyUnionStyle::BindgenWrapper`] was passed to
650                 /// the [`Builder::default_non_copy_union_style`] method.
651                 pub fn bindgen_wrapper_union<T: AsRef<str>>(mut self, arg: T) -> Self {
652                     self.options.bindgen_wrapper_union.insert(arg);
653                     self
654                 }
655             }
656         },
657         as_args: "--bindgen-wrapper-union",
658     },
659     /// The patterns marking non-`Copy` `union`s as using the `ManuallyDrop` wrapper.
660     manually_drop_union: RegexSet {
661         methods: {
662             regex_option! {
663                 /// Mark the given `union` to use [`::core::mem::ManuallyDrop`] for its members if
664                 /// at least one of them is not `Copy`.
665                 ///
666                 /// The `ManuallyDrop` type was stabilized in Rust 1.20.0, do not use this option
667                 /// if your target version is lower than this.
668                 pub fn manually_drop_union<T: AsRef<str>>(mut self, arg: T) -> Self {
669                     self.options.manually_drop_union.insert(arg);
670                     self
671                 }
672             }
673 
674         },
675         as_args: "--manually-drop-union",
676     },
677 
678 
679     /// Whether we should generate built-in definitions.
680     builtins: bool {
681         methods: {
682             /// Generate Rust bindings for built-in definitions (for example `__builtin_va_list`).
683             ///
684             /// Bindings for built-in definitions are not emitted by default.
685             pub fn emit_builtins(mut self) -> Builder {
686                 self.options.builtins = true;
687                 self
688             }
689         },
690         as_args: "--builtins",
691     },
692     /// Whether we should dump the Clang AST for debugging purposes.
693     emit_ast: bool {
694         methods: {
695             /// Emit the Clang AST to `stdout` for debugging purposes.
696             ///
697             /// The Clang AST is not emitted by default.
698             pub fn emit_clang_ast(mut self) -> Builder {
699                 self.options.emit_ast = true;
700                 self
701             }
702         },
703         as_args: "--emit-clang-ast",
704     },
705     /// Whether we should dump our IR for debugging purposes.
706     emit_ir: bool {
707         methods: {
708             /// Emit the `bindgen` internal representation to `stdout` for debugging purposes.
709             ///
710             /// This internal representation is not emitted by default.
711             pub fn emit_ir(mut self) -> Builder {
712                 self.options.emit_ir = true;
713                 self
714             }
715         },
716         as_args: "--emit-ir",
717     },
718     /// Output path for the `graphviz` DOT file.
719     emit_ir_graphviz: Option<String> {
720         methods: {
721             /// Set the path for the file where the`bindgen` internal representation will be
722             /// emitted as a graph using the `graphviz` DOT language.
723             ///
724             /// This graph representation is not emitted by default.
725             pub fn emit_ir_graphviz<T: Into<String>>(mut self, path: T) -> Builder {
726                 let path = path.into();
727                 self.options.emit_ir_graphviz = Some(path);
728                 self
729             }
730         },
731         as_args: "--emit-ir-graphviz",
732     },
733 
734     /// Whether we should emulate C++ namespaces with Rust modules.
735     enable_cxx_namespaces: bool {
736         methods: {
737             /// Emulate C++ namespaces using Rust modules in the generated bindings.
738             ///
739             /// C++ namespaces are not emulated by default.
740             pub fn enable_cxx_namespaces(mut self) -> Builder {
741                 self.options.enable_cxx_namespaces = true;
742                 self
743             }
744         },
745         as_args: "--enable-cxx-namespaces",
746     },
747     /// Whether we should try to find unexposed attributes in functions.
748     enable_function_attribute_detection: bool {
749         methods: {
750             /// Enable detecting function attributes on C functions.
751             ///
752             /// This enables the following features:
753             /// - Add `#[must_use]` attributes to Rust items whose C counterparts are marked as so.
754             /// This feature also requires that the Rust target version supports the attribute.
755             /// - Set `!` as the return type for Rust functions whose C counterparts are marked as
756             /// diverging.
757             ///
758             /// This option can be quite slow in some cases (check [#1465]), so it is disabled by
759             /// default.
760             ///
761             /// [#1465]: https://github.com/rust-lang/rust-bindgen/issues/1465
762             pub fn enable_function_attribute_detection(mut self) -> Self {
763                 self.options.enable_function_attribute_detection = true;
764                 self
765             }
766 
767         },
768         as_args: "--enable-function-attribute-detection",
769     },
770     /// Whether we should avoid mangling names with namespaces.
771     disable_name_namespacing: bool {
772         methods: {
773             /// Disable name auto-namespacing.
774             ///
775             /// By default, `bindgen` mangles names like `foo::bar::Baz` to look like `foo_bar_Baz`
776             /// instead of just `Baz`. This method disables that behavior.
777             ///
778             /// Note that this does not change the names used for allowlisting and blocklisting,
779             /// which should still be mangled with the namespaces. Additionally, this option may
780             /// cause `bindgen` to generate duplicate names.
781             pub fn disable_name_namespacing(mut self) -> Builder {
782                 self.options.disable_name_namespacing = true;
783                 self
784             }
785         },
786         as_args: "--disable-name-namespacing",
787     },
788     /// Whether we should avoid generating nested `struct` names.
789     disable_nested_struct_naming: bool {
790         methods: {
791             /// Disable nested `struct` naming.
792             ///
793             /// The following `struct`s have different names for C and C++. In C, they are visible
794             /// as `foo` and `bar`. In C++, they are visible as `foo` and `foo::bar`.
795             ///
796             /// ```c
797             /// struct foo {
798             ///     struct bar {
799             ///     } b;
800             /// };
801             /// ```
802             ///
803             /// `bindgen` tries to avoid duplicate names by default, so it follows the C++ naming
804             /// convention and it generates `foo` and `foo_bar` instead of just `foo` and `bar`.
805             ///
806             /// This method disables this behavior and it is indented to be used only for headers
807             /// that were written in C.
808             pub fn disable_nested_struct_naming(mut self) -> Builder {
809                 self.options.disable_nested_struct_naming = true;
810                 self
811             }
812         },
813         as_args: "--disable-nested-struct-naming",
814     },
815     /// Whether we should avoid embedding version identifiers into source code.
816     disable_header_comment: bool {
817         methods: {
818             /// Do not insert the `bindgen` version identifier into the generated bindings.
819             ///
820             /// This identifier is inserted by default.
821             pub fn disable_header_comment(mut self) -> Self {
822                 self.options.disable_header_comment = true;
823                 self
824             }
825 
826         },
827         as_args: "--disable-header-comment",
828     },
829     /// Whether we should generate layout tests for generated `struct`s.
830     layout_tests: bool {
831         default: true,
832         methods: {
833             /// Set whether layout tests should be generated.
834             ///
835             /// Layout tests are generated by default.
836             pub fn layout_tests(mut self, doit: bool) -> Self {
837                 self.options.layout_tests = doit;
838                 self
839             }
840         },
841         as_args: |value, args| (!value).as_args(args, "--no-layout-tests"),
842     },
843     /// Whether we should implement `Debug` for types that cannot derive it.
844     impl_debug: bool {
845         methods: {
846             /// Set whether `Debug` should be implemented for types that cannot derive it.
847             ///
848             /// This option is disabled by default.
849             pub fn impl_debug(mut self, doit: bool) -> Self {
850                 self.options.impl_debug = doit;
851                 self
852             }
853 
854         },
855         as_args: "--impl-debug",
856     },
857     /// Whether we should implement `PartialEq` types that cannot derive it.
858     impl_partialeq: bool {
859         methods: {
860             /// Set whether `PartialEq` should be implemented for types that cannot derive it.
861             ///
862             /// This option is disabled by default.
863             pub fn impl_partialeq(mut self, doit: bool) -> Self {
864                 self.options.impl_partialeq = doit;
865                 self
866             }
867         },
868         as_args: "--impl-partialeq",
869     },
870     /// Whether we should derive `Copy` when possible.
871     derive_copy: bool {
872         default: true,
873         methods: {
874             /// Set whether the `Copy` trait should be derived when possible.
875             ///
876             /// `Copy` is derived by default.
877             pub fn derive_copy(mut self, doit: bool) -> Self {
878                 self.options.derive_copy = doit;
879                 self
880             }
881         },
882         as_args: |value, args| (!value).as_args(args, "--no-derive-copy"),
883     },
884 
885     /// Whether we should derive `Debug` when possible.
886     derive_debug: bool {
887         default: true,
888         methods: {
889             /// Set whether the `Debug` trait should be derived when possible.
890             ///
891             /// The [`Builder::impl_debug`] method can be used to implement `Debug` for types that
892             /// cannot derive it.
893             ///
894             /// `Debug` is derived by default.
895             pub fn derive_debug(mut self, doit: bool) -> Self {
896                 self.options.derive_debug = doit;
897                 self
898             }
899         },
900         as_args: |value, args| (!value).as_args(args, "--no-derive-debug"),
901     },
902 
903     /// Whether we should derive `Default` when possible.
904     derive_default: bool {
905         methods: {
906             /// Set whether the `Default` trait should be derived when possible.
907             ///
908             /// `Default` is not derived by default.
909             pub fn derive_default(mut self, doit: bool) -> Self {
910                 self.options.derive_default = doit;
911                 self
912             }
913         },
914         as_args: |&value, args| {
915             let arg = if value {
916                 "--with-derive-default"
917             } else {
918                 "--no-derive-default"
919             };
920 
921             args.push(arg.to_owned());
922         },
923     },
924     /// Whether we should derive `Hash` when possible.
925     derive_hash: bool {
926         methods: {
927             /// Set whether the `Hash` trait should be derived when possible.
928             ///
929             /// `Hash` is not derived by default.
930             pub fn derive_hash(mut self, doit: bool) -> Self {
931                 self.options.derive_hash = doit;
932                 self
933             }
934         },
935         as_args: "--with-derive-hash",
936     },
937     /// Whether we should derive `PartialOrd` when possible.
938     derive_partialord: bool {
939         methods: {
940             /// Set whether the `PartialOrd` trait should be derived when possible.
941             ///
942             /// Take into account that `Ord` cannot be derived for a type that does not implement
943             /// `PartialOrd`. For this reason, setting this method to `false` also sets
944             /// automatically [`Builder::derive_ord`] to `false`.
945             ///
946             /// `PartialOrd` is not derived by default.
947             pub fn derive_partialord(mut self, doit: bool) -> Self {
948                 self.options.derive_partialord = doit;
949                 if !doit {
950                     self.options.derive_ord = false;
951                 }
952                 self
953             }
954         },
955         as_args: "--with-derive-partialord",
956     },
957     /// Whether we should derive `Ord` when possible.
958     derive_ord: bool {
959         methods: {
960             /// Set whether the `Ord` trait should be derived when possible.
961             ///
962             /// Take into account that `Ord` cannot be derived for a type that does not implement
963             /// `PartialOrd`. For this reason, the value set with this method will also be set
964             /// automatically for [`Builder::derive_partialord`].
965             ///
966             /// `Ord` is not derived by default.
967             pub fn derive_ord(mut self, doit: bool) -> Self {
968                 self.options.derive_ord = doit;
969                 self.options.derive_partialord = doit;
970                 self
971             }
972         },
973         as_args: "--with-derive-ord",
974     },
975     /// Whether we should derive `PartialEq` when possible.
976     derive_partialeq: bool {
977         methods: {
978             /// Set whether the `PartialEq` trait should be derived when possible.
979             ///
980             /// Take into account that `Eq` cannot be derived for a type that does not implement
981             /// `PartialEq`. For this reason, setting this method to `false` also sets
982             /// automatically [`Builder::derive_eq`] to `false`.
983             ///
984             /// The [`Builder::impl_partialeq`] method can be used to implement `PartialEq` for
985             /// types that cannot derive it.
986             ///
987             /// `PartialEq` is not derived by default.
988             pub fn derive_partialeq(mut self, doit: bool) -> Self {
989                 self.options.derive_partialeq = doit;
990                 if !doit {
991                     self.options.derive_eq = false;
992                 }
993                 self
994             }
995         },
996         as_args: "--with-derive-partialeq",
997     },
998     /// Whether we should derive `Eq` when possible.
999     derive_eq: bool {
1000         methods: {
1001             /// Set whether the `Eq` trait should be derived when possible.
1002             ///
1003             /// Take into account that `Eq` cannot be derived for a type that does not implement
1004             /// `PartialEq`. For this reason, the value set with this method will also be set
1005             /// automatically for [`Builder::derive_partialeq`].
1006             ///
1007             /// `Eq` is not derived by default.
1008             pub fn derive_eq(mut self, doit: bool) -> Self {
1009                 self.options.derive_eq = doit;
1010                 if doit {
1011                     self.options.derive_partialeq = doit;
1012                 }
1013                 self
1014             }
1015         },
1016         as_args: "--with-derive-eq",
1017     },
1018     /// Whether we should use `core` instead of `std`.
1019     ///
1020     /// If this option is enabled and the Rust target version is greater than 1.64, the prefix for
1021     /// C platform-specific types will be `::core::ffi` instead of `::core::os::raw`.
1022     use_core: bool {
1023         methods: {
1024             /// Use `core` instead of `std` in the generated bindings.
1025             ///
1026             /// `std` is used by default.
1027             pub fn use_core(mut self) -> Builder {
1028                 self.options.use_core = true;
1029                 self
1030             }
1031 
1032         },
1033         as_args: "--use-core",
1034     },
1035     /// An optional prefix for the C platform-specific types.
1036     ctypes_prefix: Option<String> {
1037         methods: {
1038             /// Use the given prefix for the C platform-specific types instead of `::std::os::raw`.
1039             ///
1040             /// Alternatively, the [`Builder::use_core`] method can be used to set the prefix to
1041             /// `::core::ffi` or `::core::os::raw`.
1042             pub fn ctypes_prefix<T: Into<String>>(mut self, prefix: T) -> Builder {
1043                 self.options.ctypes_prefix = Some(prefix.into());
1044                 self
1045             }
1046         },
1047         as_args: "--ctypes-prefix",
1048     },
1049     /// The prefix for anonymous fields.
1050     anon_fields_prefix: String {
1051         default: DEFAULT_ANON_FIELDS_PREFIX.into(),
1052         methods: {
1053             /// Use the given prefix for the anonymous fields.
1054             ///
1055             /// An anonymous field, is a field of a C/C++ type that does not have a name. For
1056             /// example, in the following C code:
1057             /// ```c
1058             /// struct integer {
1059             ///   struct {
1060             ///     int inner;
1061             ///   };
1062             /// }
1063             /// ```
1064             ///
1065             /// The only field of the `integer` `struct` is an anonymous field and its Rust
1066             /// representation will be named using this prefix followed by an integer identifier.
1067             ///
1068             /// The default prefix is `__bindgen_anon_`.
1069             pub fn anon_fields_prefix<T: Into<String>>(mut self, prefix: T) -> Builder {
1070                 self.options.anon_fields_prefix = prefix.into();
1071                 self
1072             }
1073         },
1074         as_args: |prefix, args| {
1075             if prefix != DEFAULT_ANON_FIELDS_PREFIX {
1076                 args.push("--anon-fields-prefix".to_owned());
1077                 args.push(prefix.clone());
1078             }
1079         },
1080     },
1081     /// Whether to measure the time for each one of the `bindgen` phases.
1082     time_phases: bool {
1083         methods: {
1084             /// Set whether to measure the elapsed time for each one of the `bindgen` phases. This
1085             /// information is printed to `stderr`.
1086             ///
1087             /// The elapsed time is not measured by default.
1088             pub fn time_phases(mut self, doit: bool) -> Self {
1089                 self.options.time_phases = doit;
1090                 self
1091             }
1092         },
1093         as_args: "--time-phases",
1094     },
1095     /// Whether to convert C float types to `f32` and `f64`.
1096     convert_floats: bool {
1097         default: true,
1098         methods: {
1099             /// Avoid converting C float types to `f32` and `f64`.
1100             pub fn no_convert_floats(mut self) -> Self {
1101                 self.options.convert_floats = false;
1102                 self
1103             }
1104         },
1105         as_args: |value, args| (!value).as_args(args, "--no-convert-floats"),
1106     },
1107     /// The set of raw lines to be prepended to the top-level module of the generated Rust code.
1108     raw_lines: Vec<Box<str>> {
1109         methods: {
1110             /// Add a line of Rust code at the beginning of the generated bindings. The string is
1111             /// passed through without any modification.
1112             pub fn raw_line<T: Into<String>>(mut self, arg: T) -> Self {
1113                 self.options.raw_lines.push(arg.into().into_boxed_str());
1114                 self
1115             }
1116         },
1117         as_args: |raw_lines, args| {
1118             for line in raw_lines {
1119                 args.push("--raw-line".to_owned());
1120                 args.push(line.clone().into());
1121             }
1122         },
1123     },
1124     /// The set of raw lines to prepend to different modules.
1125     module_lines: HashMap<Box<str>, Vec<Box<str>>> {
1126         methods: {
1127             /// Add a given line to the beginning of a given module.
1128             ///
1129             /// This option only comes into effect if the [`Builder::enable_cxx_namespaces`] method
1130             /// is also being called.
1131             pub fn module_raw_line<T, U>(mut self, module: T, line: U) -> Self
1132             where
1133                 T: Into<String>,
1134                 U: Into<String>,
1135             {
1136                 self.options
1137                     .module_lines
1138                     .entry(module.into().into_boxed_str())
1139                     .or_default()
1140                     .push(line.into().into_boxed_str());
1141                 self
1142             }
1143         },
1144         as_args: |module_lines, args| {
1145             for (module, lines) in module_lines {
1146                 for line in lines.iter() {
1147                     args.push("--module-raw-line".to_owned());
1148                     args.push(module.clone().into());
1149                     args.push(line.clone().into());
1150                 }
1151             }
1152         },
1153     },
1154     /// The input header files.
1155     input_headers:  Vec<Box<str>> {
1156         methods: {
1157             /// Add an input C/C++ header to generate bindings for.
1158             ///
1159             /// This can be used to generate bindings for a single header:
1160             ///
1161             /// ```ignore
1162             /// let bindings = bindgen::Builder::default()
1163             ///     .header("input.h")
1164             ///     .generate()
1165             ///     .unwrap();
1166             /// ```
1167             ///
1168             /// Or for multiple headers:
1169             ///
1170             /// ```ignore
1171             /// let bindings = bindgen::Builder::default()
1172             ///     .header("first.h")
1173             ///     .header("second.h")
1174             ///     .header("third.h")
1175             ///     .generate()
1176             ///     .unwrap();
1177             /// ```
1178             pub fn header<T: Into<String>>(mut self, header: T) -> Builder {
1179                 self.options.input_headers.push(header.into().into_boxed_str());
1180                 self
1181             }
1182         },
1183         // This field is handled specially inside the macro.
1184         as_args: ignore,
1185     },
1186     /// The set of arguments to be passed straight through to Clang.
1187     clang_args: Vec<Box<str>> {
1188         methods: {
1189             /// Add an argument to be passed straight through to Clang.
1190             pub fn clang_arg<T: Into<String>>(self, arg: T) -> Builder {
1191                 self.clang_args([arg.into().into_boxed_str()])
1192             }
1193 
1194             /// Add several arguments to be passed straight through to Clang.
1195             pub fn clang_args<I: IntoIterator>(mut self, args: I) -> Builder
1196             where
1197                 I::Item: AsRef<str>,
1198             {
1199                 for arg in args {
1200                     self.options.clang_args.push(arg.as_ref().to_owned().into_boxed_str());
1201                 }
1202                 self
1203             }
1204         },
1205         // This field is handled specially inside the macro.
1206         as_args: ignore,
1207     },
1208     /// Tuples of unsaved file contents of the form (name, contents).
1209     input_header_contents: Vec<(Box<str>, Box<str>)> {
1210         methods: {
1211             /// Add `contents` as an input C/C++ header named `name`.
1212             ///
1213             /// This can be used to inject additional C/C++ code as an input without having to
1214             /// create additional header files.
1215             pub fn header_contents(mut self, name: &str, contents: &str) -> Builder {
1216                 // Apparently clang relies on having virtual FS correspondent to
1217                 // the real one, so we need absolute paths here
1218                 let absolute_path = env::current_dir()
1219                     .expect("Cannot retrieve current directory")
1220                     .join(name)
1221                     .to_str()
1222                     .expect("Cannot convert current directory name to string")
1223                     .into();
1224                 self.options
1225                     .input_header_contents
1226                     .push((absolute_path, contents.into()));
1227                 self
1228             }
1229         },
1230         // Header contents cannot be added from the CLI.
1231         as_args: ignore,
1232     },
1233     /// A user-provided visitor to allow customizing different kinds of situations.
1234     parse_callbacks: Vec<Rc<dyn ParseCallbacks>> {
1235         methods: {
1236             /// Add a new [`ParseCallbacks`] instance to configure types in different situations.
1237             pub fn parse_callbacks(mut self, cb: Box<dyn ParseCallbacks>) -> Self {
1238                 self.options.parse_callbacks.push(Rc::from(cb));
1239                 self
1240             }
1241         },
1242         as_args: |_callbacks, _args| {
1243             #[cfg(feature = "__cli")]
1244             for cb in _callbacks {
1245                 _args.extend(cb.cli_args());
1246             }
1247         },
1248     },
1249     /// Which kind of items should we generate. We generate all of them by default.
1250     codegen_config: CodegenConfig {
1251         default: CodegenConfig::all(),
1252         methods: {
1253             /// Do not generate any functions.
1254             ///
1255             /// Functions are generated by default.
1256             pub fn ignore_functions(mut self) -> Builder {
1257                 self.options.codegen_config.remove(CodegenConfig::FUNCTIONS);
1258                 self
1259             }
1260 
1261             /// Do not generate any methods.
1262             ///
1263             /// Methods are generated by default.
1264             pub fn ignore_methods(mut self) -> Builder {
1265                 self.options.codegen_config.remove(CodegenConfig::METHODS);
1266                 self
1267             }
1268 
1269             /// Choose what to generate using a [`CodegenConfig`].
1270             ///
1271             /// This option overlaps with [`Builder::ignore_functions`] and
1272             /// [`Builder::ignore_methods`].
1273             ///
1274             /// All the items in `CodegenConfig` are generated by default.
1275             pub fn with_codegen_config(mut self, config: CodegenConfig) -> Self {
1276                 self.options.codegen_config = config;
1277                 self
1278             }
1279         },
1280         as_args: |codegen_config, args| {
1281             if !codegen_config.functions() {
1282                 args.push("--ignore-functions".to_owned());
1283             }
1284 
1285             args.push("--generate".to_owned());
1286 
1287             //Temporary placeholder for the 4 options below.
1288             let mut options: Vec<String> = Vec::new();
1289             if codegen_config.functions() {
1290                 options.push("functions".to_owned());
1291             }
1292 
1293             if codegen_config.types() {
1294                 options.push("types".to_owned());
1295             }
1296 
1297             if codegen_config.vars() {
1298                 options.push("vars".to_owned());
1299             }
1300 
1301             if codegen_config.methods() {
1302                 options.push("methods".to_owned());
1303             }
1304 
1305             if codegen_config.constructors() {
1306                 options.push("constructors".to_owned());
1307             }
1308 
1309             if codegen_config.destructors() {
1310                 options.push("destructors".to_owned());
1311             }
1312 
1313             args.push(options.join(","));
1314 
1315             if !codegen_config.methods() {
1316                 args.push("--ignore-methods".to_owned());
1317             }
1318         },
1319     },
1320     /// Whether to treat inline namespaces conservatively.
1321     conservative_inline_namespaces: bool {
1322         methods: {
1323             /// Treat inline namespaces conservatively.
1324             ///
1325             /// This is tricky, because in C++ is technically legal to override an item
1326             /// defined in an inline namespace:
1327             ///
1328             /// ```cpp
1329             /// inline namespace foo {
1330             ///     using Bar = int;
1331             /// }
1332             /// using Bar = long;
1333             /// ```
1334             ///
1335             /// Even though referencing `Bar` is a compiler error.
1336             ///
1337             /// We want to support this (arguably esoteric) use case, but we do not want to make
1338             /// the rest of `bindgen` users pay an usability penalty for that.
1339             ///
1340             /// To support this, we need to keep all the inline namespaces around, but then using
1341             /// `bindgen` becomes a bit more difficult, because you cannot reference paths like
1342             /// `std::string` (you'd need to use the proper inline namespace).
1343             ///
1344             /// We could complicate a lot of the logic to detect name collisions and, in the
1345             /// absence of collisions, generate a `pub use inline_ns::*` or something like that.
1346             ///
1347             /// That is probably something we can do to improve the usability of this option if we
1348             /// realize it is needed way more often. Our guess is that this extra logic is not
1349             /// going to be very useful.
1350             ///
1351             /// This option is disabled by default.
1352             pub fn conservative_inline_namespaces(mut self) -> Builder {
1353                 self.options.conservative_inline_namespaces = true;
1354                 self
1355             }
1356         },
1357         as_args: "--conservative-inline-namespaces",
1358     },
1359     /// Whether to keep documentation comments in the generated output.
1360     generate_comments: bool {
1361         default: true,
1362         methods: {
1363             /// Set whether the generated bindings should contain documentation comments.
1364             ///
1365             /// Documentation comments are included by default.
1366             ///
1367             /// Note that clang excludes comments from system headers by default, pass
1368             /// `"-fretain-comments-from-system-headers"` to the [`Builder::clang_arg`] method to
1369             /// include them.
1370             ///
1371             /// It is also possible to process all comments and not just documentation using the
1372             /// `"-fparse-all-comments"` flag. Check [these slides on clang comment parsing](
1373             /// https://llvm.org/devmtg/2012-11/Gribenko_CommentParsing.pdf) for more information
1374             /// and examples.
1375             pub fn generate_comments(mut self, doit: bool) -> Self {
1376                 self.options.generate_comments = doit;
1377                 self
1378             }
1379         },
1380         as_args: |value, args| (!value).as_args(args, "--no-doc-comments"),
1381     },
1382     /// Whether to generate inline functions.
1383     generate_inline_functions: bool {
1384         methods: {
1385             /// Set whether to generate inline functions.
1386             ///
1387             /// This option is disabled by default.
1388             ///
1389             /// Note that they will usually not work. However you can use `-fkeep-inline-functions`
1390             /// or `-fno-inline-functions` if you are responsible of compiling the library to make
1391             /// them callable.
1392             #[cfg_attr(
1393                 feature = "experimental",
1394                 doc = "\nCheck the [`Builder::wrap_static_fns`] method for an alternative."
1395             )]
1396             pub fn generate_inline_functions(mut self, doit: bool) -> Self {
1397                 self.options.generate_inline_functions = doit;
1398                 self
1399             }
1400         },
1401         as_args: "--generate-inline-functions",
1402     },
1403     /// Whether to allowlist types recursively.
1404     allowlist_recursively: bool {
1405         default: true,
1406         methods: {
1407             /// Set whether to recursively allowlist items.
1408             ///
1409             /// Items are allowlisted recursively by default.
1410             ///
1411             /// Given that we have explicitly allowlisted the `initiate_dance_party` function in
1412             /// this C header:
1413             ///
1414             /// ```c
1415             /// typedef struct MoonBoots {
1416             ///     int bouncy_level;
1417             /// } MoonBoots;
1418             ///
1419             /// void initiate_dance_party(MoonBoots* boots);
1420             /// ```
1421             ///
1422             /// We would normally generate bindings to both the `initiate_dance_party` function and
1423             /// the `MoonBoots` type that it transitively references. If `false` is passed to this
1424             /// method, `bindgen` will not emit bindings for anything except the explicitly
1425             /// allowlisted items, meaning that the definition for `MoonBoots` would not be
1426             /// generated. However, the `initiate_dance_party` function would still reference
1427             /// `MoonBoots`!
1428             ///
1429             /// **Disabling this feature will almost certainly cause `bindgen` to emit bindings
1430             /// that will not compile!** If you disable this feature, then it is *your*
1431             /// responsibility to provide definitions for every type that is referenced from an
1432             /// explicitly allowlisted item. One way to provide the missing definitions is by using
1433             /// the [`Builder::raw_line`] method, another would be to define them in Rust and then
1434             /// `include!(...)` the bindings immediately afterwards.
1435             pub fn allowlist_recursively(mut self, doit: bool) -> Self {
1436                 self.options.allowlist_recursively = doit;
1437                 self
1438             }
1439         },
1440         as_args: |value, args| (!value).as_args(args, "--no-recursive-allowlist"),
1441     },
1442     /// Whether to emit `#[macro_use] extern crate objc;` instead of `use objc;` in the prologue of
1443     /// the files generated from objective-c files.
1444     objc_extern_crate: bool {
1445         methods: {
1446             /// Emit `#[macro_use] extern crate objc;` instead of `use objc;` in the prologue of
1447             /// the files generated from objective-c files.
1448             ///
1449             /// `use objc;` is emitted by default.
1450             pub fn objc_extern_crate(mut self, doit: bool) -> Self {
1451                 self.options.objc_extern_crate = doit;
1452                 self
1453             }
1454         },
1455         as_args: "--objc-extern-crate",
1456     },
1457     /// Whether to generate proper block signatures instead of `void` pointers.
1458     generate_block: bool {
1459         methods: {
1460             /// Generate proper block signatures instead of `void` pointers.
1461             ///
1462             /// `void` pointers are used by default.
1463             pub fn generate_block(mut self, doit: bool) -> Self {
1464                 self.options.generate_block = doit;
1465                 self
1466             }
1467         },
1468         as_args: "--generate-block",
1469     },
1470     /// Whether to generate strings as `CStr`.
1471     generate_cstr: bool {
1472         methods: {
1473             /// Set whether string constants should be generated as `&CStr` instead of `&[u8]`.
1474             ///
1475             /// A minimum Rust target of 1.59 is required for this to have any effect as support
1476             /// for `CStr::from_bytes_with_nul_unchecked` in `const` contexts is needed.
1477             ///
1478             /// This option is disabled by default but will become enabled by default in a future
1479             /// release, so enabling this is recommended.
1480             pub fn generate_cstr(mut self, doit: bool) -> Self {
1481                 self.options.generate_cstr = doit;
1482                 self
1483             }
1484         },
1485         as_args: "--generate-cstr",
1486     },
1487     /// Whether to emit `#[macro_use] extern crate block;` instead of `use block;` in the prologue
1488     /// of the files generated from apple block files.
1489     block_extern_crate: bool {
1490         methods: {
1491             /// Emit `#[macro_use] extern crate block;` instead of `use block;` in the prologue of
1492             /// the files generated from apple block files.
1493             ///
1494             /// `use block;` is emitted by default.
1495             pub fn block_extern_crate(mut self, doit: bool) -> Self {
1496                 self.options.block_extern_crate = doit;
1497                 self
1498             }
1499         },
1500         as_args: "--block-extern-crate",
1501     },
1502     /// Whether to use the clang-provided name mangling.
1503     enable_mangling: bool {
1504         default: true,
1505         methods: {
1506             /// Set whether to use the clang-provided name mangling. This is probably needed for
1507             /// C++ features.
1508             ///
1509             /// The mangling provided by clang is used by default.
1510             ///
1511             /// We allow disabling this option because some old `libclang` versions seem to return
1512             /// incorrect results in some cases for non-mangled functions, check [#528] for more
1513             /// information.
1514             ///
1515             /// [#528]: https://github.com/rust-lang/rust-bindgen/issues/528
1516             pub fn trust_clang_mangling(mut self, doit: bool) -> Self {
1517                 self.options.enable_mangling = doit;
1518                 self
1519             }
1520 
1521         },
1522         as_args: |value, args| (!value).as_args(args, "--distrust-clang-mangling"),
1523     },
1524     /// Whether to detect include paths using `clang_sys`.
1525     detect_include_paths: bool {
1526         default: true,
1527         methods: {
1528             /// Set whether to detect include paths using `clang_sys`.
1529             ///
1530             /// `clang_sys` is used to detect include paths by default.
1531             pub fn detect_include_paths(mut self, doit: bool) -> Self {
1532                 self.options.detect_include_paths = doit;
1533                 self
1534             }
1535         },
1536         as_args: |value, args| (!value).as_args(args, "--no-include-path-detection"),
1537     },
1538     /// Whether we should try to fit macro constants into types smaller than `u32` and `i32`.
1539     fit_macro_constants: bool {
1540         methods: {
1541             /// Set whether `bindgen` should try to fit macro constants into types smaller than `u32`
1542             /// and `i32`.
1543             ///
1544             /// This option is disabled by default.
1545             pub fn fit_macro_constants(mut self, doit: bool) -> Self {
1546                 self.options.fit_macro_constants = doit;
1547                 self
1548             }
1549         },
1550         as_args: "--fit-macro-constant-types",
1551     },
1552     /// Whether to prepend the `enum` name to constant or newtype variants.
1553     prepend_enum_name: bool {
1554         default: true,
1555         methods: {
1556             /// Set whether to prepend the `enum` name to constant or newtype variants.
1557             ///
1558             /// The `enum` name is prepended by default.
1559             pub fn prepend_enum_name(mut self, doit: bool) -> Self {
1560                 self.options.prepend_enum_name = doit;
1561                 self
1562             }
1563         },
1564         as_args: |value, args| (!value).as_args(args, "--no-prepend-enum-name"),
1565     },
1566     /// Version of the Rust compiler to target.
1567     rust_target: RustTarget {
1568         methods: {
1569             /// Specify the Rust target version.
1570             ///
1571             /// The default target is the latest stable Rust version.
1572             pub fn rust_target(mut self, rust_target: RustTarget) -> Self {
1573                 self.options.set_rust_target(rust_target);
1574                 self
1575             }
1576         },
1577         as_args: |rust_target, args| {
1578             args.push("--rust-target".to_owned());
1579             args.push(rust_target.to_string());
1580         },
1581     },
1582     /// Features to be enabled. They are derived from `rust_target`.
1583     rust_features: RustFeatures {
1584         default: RustTarget::default().into(),
1585         methods: {},
1586         // This field cannot be set from the CLI,
1587         as_args: ignore,
1588     },
1589     /// Enable support for native Rust unions if they are supported.
1590     untagged_union: bool {
1591         default: true,
1592         methods: {
1593             /// Disable support for native Rust unions, if supported.
1594             ///
1595             /// The default value of this option is set based on the value passed to
1596             /// [`Builder::rust_target`].
1597             pub fn disable_untagged_union(mut self) -> Self {
1598                 self.options.untagged_union = false;
1599                 self
1600             }
1601         }
1602         as_args: |value, args| (!value).as_args(args, "--disable-untagged-union"),
1603     },
1604     /// Whether we should record which items in the regex sets did match any C items.
1605     record_matches: bool {
1606         default: true,
1607         methods: {
1608             /// Set whether we should record which items in our regex sets did match any C items.
1609             ///
1610             /// Matches are recorded by default.
1611             pub fn record_matches(mut self, doit: bool) -> Self {
1612                 self.options.record_matches = doit;
1613                 self
1614             }
1615 
1616         },
1617         as_args: |value, args| (!value).as_args(args, "--no-record-matches"),
1618     },
1619     /// Whether `size_t` should be translated to `usize` automatically.
1620     size_t_is_usize: bool {
1621         default: true,
1622         methods: {
1623             /// Set whether `size_t` should be translated to `usize`.
1624             ///
1625             /// If `size_t` is translated to `usize`, type definitions for `size_t` will not be
1626             /// emitted.
1627             ///
1628             /// `size_t` is translated to `usize` by default.
1629             pub fn size_t_is_usize(mut self, is: bool) -> Self {
1630                 self.options.size_t_is_usize = is;
1631                 self
1632             }
1633         },
1634         as_args: |value, args| (!value).as_args(args, "--no-size_t-is-usize"),
1635     },
1636     /// The tool that should be used to format the generated bindings.
1637     formatter: Formatter {
1638         methods: {
1639             /// Set whether `rustfmt` should be used to format the generated bindings.
1640             ///
1641             /// `rustfmt` is used by default.
1642             ///
1643             /// This method overlaps in functionality with the more general [`Builder::formatter`].
1644             /// Thus, the latter should be preferred.
1645             #[deprecated]
1646             pub fn rustfmt_bindings(mut self, doit: bool) -> Self {
1647                 self.options.formatter = if doit {
1648                     Formatter::Rustfmt
1649                 } else {
1650                     Formatter::None
1651                 };
1652                 self
1653             }
1654 
1655             /// Set which tool should be used to format the generated bindings.
1656             ///
1657             /// The default formatter is [`Formatter::Rustfmt`].
1658             ///
1659             /// To be able to use `prettyplease` as a formatter, the `"prettyplease"` feature for
1660             /// `bindgen` must be enabled in the Cargo manifest.
1661             pub fn formatter(mut self, formatter: Formatter) -> Self {
1662                 self.options.formatter = formatter;
1663                 self
1664             }
1665         },
1666         as_args: |formatter, args| {
1667             if *formatter != Default::default() {
1668                 args.push("--formatter".to_owned());
1669                 args.push(formatter.to_string());
1670             }
1671         },
1672     },
1673     /// The absolute path to the `rustfmt` configuration file.
1674     rustfmt_configuration_file: Option<PathBuf> {
1675         methods: {
1676             /// Set the absolute path to the `rustfmt` configuration file.
1677             ///
1678             /// The default `rustfmt` options are used if `None` is passed to this method or if
1679             /// this method is not called at all.
1680             ///
1681             /// Calling this method will set the [`Builder::rustfmt_bindings`] option to `true`
1682             /// and the [`Builder::formatter`] option to [`Formatter::Rustfmt`].
1683             pub fn rustfmt_configuration_file(mut self, path: Option<PathBuf>) -> Self {
1684                 self = self.formatter(Formatter::Rustfmt);
1685                 self.options.rustfmt_configuration_file = path;
1686                 self
1687             }
1688         },
1689         as_args: "--rustfmt-configuration-file",
1690     },
1691     /// Types that should not derive `PartialEq`.
1692     no_partialeq_types: RegexSet {
1693         methods: {
1694             regex_option! {
1695                 /// Do not derive `PartialEq` for a given type.
1696                 pub fn no_partialeq<T: Into<String>>(mut self, arg: T) -> Builder {
1697                     self.options.no_partialeq_types.insert(arg.into());
1698                     self
1699                 }
1700             }
1701         },
1702         as_args: "--no-partialeq",
1703     },
1704     /// Types that should not derive `Copy`.
1705     no_copy_types: RegexSet {
1706         methods: {
1707             regex_option! {
1708                 /// Do not derive `Copy` and `Clone` for a given type.
1709                 pub fn no_copy<T: Into<String>>(mut self, arg: T) -> Self {
1710                     self.options.no_copy_types.insert(arg.into());
1711                     self
1712                 }
1713             }
1714         },
1715         as_args: "--no-copy",
1716     },
1717     /// Types that should not derive `Debug`.
1718     no_debug_types: RegexSet {
1719         methods: {
1720             regex_option! {
1721                 /// Do not derive `Debug` for a given type.
1722                 pub fn no_debug<T: Into<String>>(mut self, arg: T) -> Self {
1723                     self.options.no_debug_types.insert(arg.into());
1724                     self
1725                 }
1726             }
1727         },
1728         as_args: "--no-debug",
1729     },
1730     /// Types that should not derive or implement `Default`.
1731     no_default_types: RegexSet {
1732         methods: {
1733             regex_option! {
1734                 /// Do not derive or implement `Default` for a given type.
1735                 pub fn no_default<T: Into<String>>(mut self, arg: T) -> Self {
1736                     self.options.no_default_types.insert(arg.into());
1737                     self
1738                 }
1739             }
1740         },
1741         as_args: "--no-default",
1742     },
1743     /// Types that should not derive `Hash`.
1744     no_hash_types: RegexSet {
1745         methods: {
1746             regex_option! {
1747                 /// Do not derive `Hash` for a given type.
1748                 pub fn no_hash<T: Into<String>>(mut self, arg: T) -> Builder {
1749                     self.options.no_hash_types.insert(arg.into());
1750                     self
1751                 }
1752             }
1753         },
1754         as_args: "--no-hash",
1755     },
1756     /// Types that should be annotated with `#[must_use]`.
1757     must_use_types: RegexSet {
1758         methods: {
1759             regex_option! {
1760                 /// Annotate the given type with the `#[must_use]` attribute.
1761                 pub fn must_use_type<T: Into<String>>(mut self, arg: T) -> Builder {
1762                     self.options.must_use_types.insert(arg.into());
1763                     self
1764                 }
1765             }
1766         },
1767         as_args: "--must-use-type",
1768     },
1769     /// Whether C arrays should be regular pointers in rust or array pointers
1770     array_pointers_in_arguments: bool {
1771         methods: {
1772             /// Translate arrays `T arr[size]` into array pointers `*mut [T; size]` instead of
1773             /// translating them as `*mut T` which is the default.
1774             ///
1775             /// The same is done for `*const` pointers.
1776             pub fn array_pointers_in_arguments(mut self, doit: bool) -> Self {
1777                 self.options.array_pointers_in_arguments = doit;
1778                 self
1779             }
1780 
1781         },
1782         as_args: "--use-array-pointers-in-arguments",
1783     },
1784     /// The name of the `wasm_import_module`.
1785     wasm_import_module_name: Option<String> {
1786         methods: {
1787             /// Adds the `#[link(wasm_import_module = import_name)]` attribute to all the `extern`
1788             /// blocks generated by `bindgen`.
1789             ///
1790             /// This attribute is not added by default.
1791             pub fn wasm_import_module_name<T: Into<String>>(
1792                 mut self,
1793                 import_name: T,
1794             ) -> Self {
1795                 self.options.wasm_import_module_name = Some(import_name.into());
1796                 self
1797             }
1798         },
1799         as_args: "--wasm-import-module-name",
1800     },
1801     /// The name of the dynamic library (if we are generating bindings for a shared library).
1802     dynamic_library_name: Option<String> {
1803         methods: {
1804             /// Generate bindings for a shared library with the given name.
1805             ///
1806             /// This option is disabled by default.
1807             pub fn dynamic_library_name<T: Into<String>>(
1808                 mut self,
1809                 dynamic_library_name: T,
1810             ) -> Self {
1811                 self.options.dynamic_library_name = Some(dynamic_library_name.into());
1812                 self
1813             }
1814         },
1815         as_args: "--dynamic-loading",
1816     },
1817     /// Whether to equire successful linkage for all routines in a shared library.
1818     dynamic_link_require_all: bool {
1819         methods: {
1820             /// Set whether to require successful linkage for all routines in a shared library.
1821             /// This allows us to optimize function calls by being able to safely assume function
1822             /// pointers are valid.
1823             ///
1824             /// This option only comes into effect if the [`Builder::dynamic_library_name`] option
1825             /// is set.
1826             ///
1827             /// This option is disabled by default.
1828             pub fn dynamic_link_require_all(mut self, req: bool) -> Self {
1829                 self.options.dynamic_link_require_all = req;
1830                 self
1831             }
1832         },
1833         as_args: "--dynamic-link-require-all",
1834     },
1835     /// Whether to only make generated bindings `pub` if the items would be publicly accessible by
1836     /// C++.
1837     respect_cxx_access_specs: bool {
1838         methods: {
1839             /// Set whether to respect the C++ access specifications.
1840             ///
1841             /// Passing `true` to this method will set the visibility of the generated Rust items
1842             /// as `pub` only if the corresponding C++ items are publicly accessible instead of
1843             /// marking all the items as public, which is the default.
1844             pub fn respect_cxx_access_specs(mut self, doit: bool) -> Self {
1845                 self.options.respect_cxx_access_specs = doit;
1846                 self
1847             }
1848 
1849         },
1850         as_args: "--respect-cxx-access-specs",
1851     },
1852     /// Whether to translate `enum` integer types to native Rust integer types.
1853     translate_enum_integer_types: bool {
1854         methods: {
1855             /// Set whether to always translate `enum` integer types to native Rust integer types.
1856             ///
1857             /// Passing `true` to this method will result in `enum`s having types such as `u32` and
1858             /// `i16` instead of `c_uint` and `c_short` which is the default. The `#[repr]` types
1859             /// of Rust `enum`s are always translated to Rust integer types.
1860             pub fn translate_enum_integer_types(mut self, doit: bool) -> Self {
1861                 self.options.translate_enum_integer_types = doit;
1862                 self
1863             }
1864         },
1865         as_args: "--translate-enum-integer-types",
1866     },
1867     /// Whether to generate types with C style naming.
1868     c_naming: bool {
1869         methods: {
1870             /// Set whether to generate types with C style naming.
1871             ///
1872             /// Passing `true` to this method will add prefixes to the generated type names. For
1873             /// example, instead of a `struct` with name `A` we will generate a `struct` with
1874             /// `struct_A`. Currently applies to `struct`s, `union`s, and `enum`s.
1875             pub fn c_naming(mut self, doit: bool) -> Self {
1876                 self.options.c_naming = doit;
1877                 self
1878             }
1879         },
1880         as_args: "--c-naming",
1881     },
1882     /// Wether to always emit explicit padding fields.
1883     force_explicit_padding: bool {
1884         methods: {
1885             /// Set whether to always emit explicit padding fields.
1886             ///
1887             /// This option should be enabled if a `struct` needs to be serialized in its native
1888             /// format (padding bytes and all). This could be required if such `struct` will be
1889             /// written to a file or sent over the network, as anything reading the padding bytes
1890             /// of a struct may cause undefined behavior.
1891             ///
1892             /// Padding fields are not emitted by default.
1893             pub fn explicit_padding(mut self, doit: bool) -> Self {
1894                 self.options.force_explicit_padding = doit;
1895                 self
1896             }
1897         },
1898         as_args: "--explicit-padding",
1899     },
1900     /// Whether to emit vtable functions.
1901     vtable_generation: bool {
1902         methods: {
1903             /// Set whether to enable experimental support to generate virtual table functions.
1904             ///
1905             /// This option should mostly work, though some edge cases are likely to be broken.
1906             ///
1907             /// Virtual table generation is disabled by default.
1908             pub fn vtable_generation(mut self, doit: bool) -> Self {
1909                 self.options.vtable_generation = doit;
1910                 self
1911             }
1912         },
1913         as_args: "--vtable-generation",
1914     },
1915     /// Whether to sort the generated Rust items.
1916     sort_semantically: bool {
1917         methods: {
1918             /// Set whether to sort the generated Rust items in a predefined manner.
1919             ///
1920             /// Items are not ordered by default.
1921             pub fn sort_semantically(mut self, doit: bool) -> Self {
1922                 self.options.sort_semantically = doit;
1923                 self
1924             }
1925         },
1926         as_args: "--sort-semantically",
1927     },
1928     /// Whether to deduplicate `extern` blocks.
1929     merge_extern_blocks: bool {
1930         methods: {
1931             /// Merge all extern blocks under the same module into a single one.
1932             ///
1933             /// Extern blocks are not merged by default.
1934             pub fn merge_extern_blocks(mut self, doit: bool) -> Self {
1935                 self.options.merge_extern_blocks = doit;
1936                 self
1937             }
1938         },
1939         as_args: "--merge-extern-blocks",
1940     },
1941     /// Whether to wrap unsafe operations in unsafe blocks.
1942     wrap_unsafe_ops: bool {
1943         methods: {
1944             /// Wrap all unsafe operations in unsafe blocks.
1945             ///
1946             /// Unsafe operations are not wrapped by default.
1947             pub fn wrap_unsafe_ops(mut self, doit: bool) -> Self {
1948                 self.options.wrap_unsafe_ops = doit;
1949                 self
1950             }
1951         },
1952         as_args: "--wrap-unsafe-ops",
1953     },
1954     /// Patterns for functions whose ABI should be overriden.
1955     abi_overrides: HashMap<Abi, RegexSet> {
1956         methods: {
1957             regex_option! {
1958                 /// Override the ABI of a given function.
1959                 pub fn override_abi<T: Into<String>>(mut self, abi: Abi, arg: T) -> Self {
1960                     self.options
1961                         .abi_overrides
1962                         .entry(abi)
1963                         .or_default()
1964                         .insert(arg.into());
1965                     self
1966                 }
1967             }
1968         },
1969         as_args: |overrides, args| {
1970             for (abi, set) in overrides {
1971                 for item in set.get_items() {
1972                     args.push("--override-abi".to_owned());
1973                     args.push(format!("{}={}", item, abi));
1974                 }
1975             }
1976         },
1977     },
1978     /// Whether to generate wrappers for `static` functions.
1979     wrap_static_fns: bool {
1980         methods: {
1981             #[cfg(feature = "experimental")]
1982             /// Set whether to generate wrappers for `static`` functions.
1983             ///
1984             /// Passing `true` to this method will generate a C source file with non-`static`
1985             /// functions that call the `static` functions found in the input headers and can be
1986             /// called from Rust once the source file is compiled.
1987             ///
1988             /// The path of this source file can be set using the [`Builder::wrap_static_fns_path`]
1989             /// method.
1990             pub fn wrap_static_fns(mut self, doit: bool) -> Self {
1991                 self.options.wrap_static_fns = doit;
1992                 self
1993             }
1994         },
1995         as_args: "--wrap-static-fns",
1996     },
1997     /// The suffix to be added to the function wrappers for `static` functions.
1998     wrap_static_fns_suffix: Option<String> {
1999         methods: {
2000             #[cfg(feature = "experimental")]
2001             /// Set the suffix added to the wrappers for `static` functions.
2002             ///
2003             /// This option only comes into effect if `true` is passed to the
2004             /// [`Builder::wrap_static_fns`] method.
2005             ///
2006             /// The default suffix is `__extern`.
2007             pub fn wrap_static_fns_suffix<T: AsRef<str>>(mut self, suffix: T) -> Self {
2008                 self.options.wrap_static_fns_suffix = Some(suffix.as_ref().to_owned());
2009                 self
2010             }
2011         },
2012         as_args: "--wrap-static-fns-suffix",
2013     },
2014     /// The path of the file where the wrappers for `static` functions will be emitted.
2015     wrap_static_fns_path: Option<PathBuf> {
2016         methods: {
2017             #[cfg(feature = "experimental")]
2018             /// Set the path for the source code file that would be created if any wrapper
2019             /// functions must be generated due to the presence of `static` functions.
2020             ///
2021             /// `bindgen` will automatically add the right extension to the header and source code
2022             /// files.
2023             ///
2024             /// This option only comes into effect if `true` is passed to the
2025             /// [`Builder::wrap_static_fns`] method.
2026             ///
2027             /// The default path is `temp_dir/bindgen/extern`, where `temp_dir` is the path
2028             /// returned by [`std::env::temp_dir`] .
2029             pub fn wrap_static_fns_path<T: AsRef<Path>>(mut self, path: T) -> Self {
2030                 self.options.wrap_static_fns_path = Some(path.as_ref().to_owned());
2031                 self
2032             }
2033         },
2034         as_args: "--wrap-static-fns-path",
2035     },
2036     /// Default visibility of fields.
2037     default_visibility: FieldVisibilityKind {
2038         methods: {
2039             /// Set the default visibility of fields, including bitfields and accessor methods for
2040             /// bitfields.
2041             ///
2042             /// This option only comes into effect if the [`Builder::respect_cxx_access_specs`]
2043             /// option is disabled.
2044             pub fn default_visibility(
2045                 mut self,
2046                 visibility: FieldVisibilityKind,
2047             ) -> Self {
2048                 self.options.default_visibility = visibility;
2049                 self
2050             }
2051         },
2052         as_args: |visibility, args| {
2053             if *visibility != Default::default() {
2054                 args.push("--default-visibility".to_owned());
2055                 args.push(visibility.to_string());
2056             }
2057         },
2058     },
2059     /// Whether to emit diagnostics or not.
2060     emit_diagnostics: bool {
2061         methods: {
2062             #[cfg(feature = "experimental")]
2063             /// Emit diagnostics.
2064             ///
2065             /// These diagnostics are emitted to `stderr` if you are using `bindgen-cli` or printed
2066             /// using `cargo:warning=` if you are using `bindgen` as a `build-dependency`.
2067             ///
2068             /// Diagnostics are not emitted by default.
2069             ///
2070             /// The layout and contents of these diagnostic messages are not covered by versioning
2071             /// and can change without notice.
2072             pub fn emit_diagnostics(mut self) -> Self {
2073                 self.options.emit_diagnostics = true;
2074                 self
2075             }
2076         },
2077         as_args: "--emit-diagnostics",
2078     }
2079 }
2080