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