| 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 | #[cfg (feature = "__cli" )] |
| 8 | pub(crate) mod cli; |
| 9 | |
| 10 | use crate::callbacks::ParseCallbacks; |
| 11 | use crate::codegen::{ |
| 12 | AliasVariation, EnumVariation, MacroTypeVariation, NonCopyUnionStyle, |
| 13 | }; |
| 14 | use crate::deps::DepfileSpec; |
| 15 | use crate::features::{RustEdition, RustFeatures, RustTarget}; |
| 16 | use crate::regex_set::RegexSet; |
| 17 | use crate::Abi; |
| 18 | use crate::Builder; |
| 19 | use crate::CodegenConfig; |
| 20 | use crate::FieldVisibilityKind; |
| 21 | use crate::Formatter; |
| 22 | use crate::HashMap; |
| 23 | use crate::DEFAULT_ANON_FIELDS_PREFIX; |
| 24 | |
| 25 | use std::env; |
| 26 | use std::path::{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 of 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 { |
| 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 | /// Add input C/C++ header(s) to generate bindings for. |
| 1184 | /// |
| 1185 | /// This can be used to generate bindings for a single header: |
| 1186 | /// |
| 1187 | /// ```ignore |
| 1188 | /// let bindings = bindgen::Builder::default() |
| 1189 | /// .headers(["input.h"]) |
| 1190 | /// .generate() |
| 1191 | /// .unwrap(); |
| 1192 | /// ``` |
| 1193 | /// |
| 1194 | /// Or for multiple headers: |
| 1195 | /// |
| 1196 | /// ```ignore |
| 1197 | /// let bindings = bindgen::Builder::default() |
| 1198 | /// .headers(["first.h", "second.h", "third.h"]) |
| 1199 | /// .generate() |
| 1200 | /// .unwrap(); |
| 1201 | /// ``` |
| 1202 | pub fn headers<I: IntoIterator>(mut self, headers: I) -> Builder |
| 1203 | where |
| 1204 | I::Item: Into<String>, |
| 1205 | { |
| 1206 | self.options |
| 1207 | .input_headers |
| 1208 | .extend(headers.into_iter().map(Into::into).map(Into::into)); |
| 1209 | self |
| 1210 | } |
| 1211 | }, |
| 1212 | // This field is handled specially inside the macro. |
| 1213 | as_args: ignore, |
| 1214 | }, |
| 1215 | /// The set of arguments to be passed straight through to Clang. |
| 1216 | clang_args: Vec<Box<str>> { |
| 1217 | methods: { |
| 1218 | /// Add an argument to be passed straight through to Clang. |
| 1219 | pub fn clang_arg<T: Into<String>>(self, arg: T) -> Builder { |
| 1220 | self.clang_args([arg.into().into_boxed_str()]) |
| 1221 | } |
| 1222 | |
| 1223 | /// Add several arguments to be passed straight through to Clang. |
| 1224 | pub fn clang_args<I: IntoIterator>(mut self, args: I) -> Builder |
| 1225 | where |
| 1226 | I::Item: AsRef<str>, |
| 1227 | { |
| 1228 | for arg in args { |
| 1229 | self.options.clang_args.push(arg.as_ref().to_owned().into_boxed_str()); |
| 1230 | } |
| 1231 | self |
| 1232 | } |
| 1233 | }, |
| 1234 | // This field is handled specially inside the macro. |
| 1235 | as_args: ignore, |
| 1236 | }, |
| 1237 | /// Tuples of unsaved file contents of the form (name, contents). |
| 1238 | input_header_contents: Vec<(Box<str>, Box<str>)> { |
| 1239 | methods: { |
| 1240 | /// Add `contents` as an input C/C++ header named `name`. |
| 1241 | /// |
| 1242 | /// This can be used to inject additional C/C++ code as an input without having to |
| 1243 | /// create additional header files. |
| 1244 | pub fn header_contents(mut self, name: &str, contents: &str) -> Builder { |
| 1245 | // Apparently clang relies on having virtual FS correspondent to |
| 1246 | // the real one, so we need absolute paths here |
| 1247 | let absolute_path = env::current_dir() |
| 1248 | .expect("Cannot retrieve current directory" ) |
| 1249 | .join(name) |
| 1250 | .to_str() |
| 1251 | .expect("Cannot convert current directory name to string" ) |
| 1252 | .into(); |
| 1253 | self.options |
| 1254 | .input_header_contents |
| 1255 | .push((absolute_path, contents.into())); |
| 1256 | self |
| 1257 | } |
| 1258 | }, |
| 1259 | // Header contents cannot be added from the CLI. |
| 1260 | as_args: ignore, |
| 1261 | }, |
| 1262 | /// A user-provided visitor to allow customizing different kinds of situations. |
| 1263 | parse_callbacks: Vec<Rc<dyn ParseCallbacks>> { |
| 1264 | methods: { |
| 1265 | /// Add a new [`ParseCallbacks`] instance to configure types in different situations. |
| 1266 | /// |
| 1267 | /// This can also be used with [`CargoCallbacks`](struct@crate::CargoCallbacks) to emit |
| 1268 | /// `cargo:rerun-if-changed=...` for all `#include`d header files. |
| 1269 | pub fn parse_callbacks(mut self, cb: Box<dyn ParseCallbacks>) -> Self { |
| 1270 | self.options.parse_callbacks.push(Rc::from(cb)); |
| 1271 | self |
| 1272 | } |
| 1273 | }, |
| 1274 | as_args: |_callbacks, _args| { |
| 1275 | #[cfg (feature = "__cli" )] |
| 1276 | for cb in _callbacks { |
| 1277 | _args.extend(cb.cli_args()); |
| 1278 | } |
| 1279 | }, |
| 1280 | }, |
| 1281 | /// Which kind of items should we generate. We generate all of them by default. |
| 1282 | codegen_config: CodegenConfig { |
| 1283 | default: CodegenConfig::all(), |
| 1284 | methods: { |
| 1285 | /// Do not generate any functions. |
| 1286 | /// |
| 1287 | /// Functions are generated by default. |
| 1288 | pub fn ignore_functions(mut self) -> Builder { |
| 1289 | self.options.codegen_config.remove(CodegenConfig::FUNCTIONS); |
| 1290 | self |
| 1291 | } |
| 1292 | |
| 1293 | /// Do not generate any methods. |
| 1294 | /// |
| 1295 | /// Methods are generated by default. |
| 1296 | pub fn ignore_methods(mut self) -> Builder { |
| 1297 | self.options.codegen_config.remove(CodegenConfig::METHODS); |
| 1298 | self |
| 1299 | } |
| 1300 | |
| 1301 | /// Choose what to generate using a [`CodegenConfig`]. |
| 1302 | /// |
| 1303 | /// This option overlaps with [`Builder::ignore_functions`] and |
| 1304 | /// [`Builder::ignore_methods`]. |
| 1305 | /// |
| 1306 | /// All the items in `CodegenConfig` are generated by default. |
| 1307 | pub fn with_codegen_config(mut self, config: CodegenConfig) -> Self { |
| 1308 | self.options.codegen_config = config; |
| 1309 | self |
| 1310 | } |
| 1311 | }, |
| 1312 | as_args: |codegen_config, args| { |
| 1313 | if !codegen_config.functions() { |
| 1314 | args.push("--ignore-functions" .to_owned()); |
| 1315 | } |
| 1316 | |
| 1317 | args.push("--generate" .to_owned()); |
| 1318 | |
| 1319 | //Temporary placeholder for the 4 options below. |
| 1320 | let mut options: Vec<String> = Vec::new(); |
| 1321 | if codegen_config.functions() { |
| 1322 | options.push("functions" .to_owned()); |
| 1323 | } |
| 1324 | |
| 1325 | if codegen_config.types() { |
| 1326 | options.push("types" .to_owned()); |
| 1327 | } |
| 1328 | |
| 1329 | if codegen_config.vars() { |
| 1330 | options.push("vars" .to_owned()); |
| 1331 | } |
| 1332 | |
| 1333 | if codegen_config.methods() { |
| 1334 | options.push("methods" .to_owned()); |
| 1335 | } |
| 1336 | |
| 1337 | if codegen_config.constructors() { |
| 1338 | options.push("constructors" .to_owned()); |
| 1339 | } |
| 1340 | |
| 1341 | if codegen_config.destructors() { |
| 1342 | options.push("destructors" .to_owned()); |
| 1343 | } |
| 1344 | |
| 1345 | args.push(options.join("," )); |
| 1346 | |
| 1347 | if !codegen_config.methods() { |
| 1348 | args.push("--ignore-methods" .to_owned()); |
| 1349 | } |
| 1350 | }, |
| 1351 | }, |
| 1352 | /// Whether to treat inline namespaces conservatively. |
| 1353 | conservative_inline_namespaces: bool { |
| 1354 | methods: { |
| 1355 | /// Treat inline namespaces conservatively. |
| 1356 | /// |
| 1357 | /// This is tricky, because in C++ is technically legal to override an item |
| 1358 | /// defined in an inline namespace: |
| 1359 | /// |
| 1360 | /// ```cpp |
| 1361 | /// inline namespace foo { |
| 1362 | /// using Bar = int; |
| 1363 | /// } |
| 1364 | /// using Bar = long; |
| 1365 | /// ``` |
| 1366 | /// |
| 1367 | /// Even though referencing `Bar` is a compiler error. |
| 1368 | /// |
| 1369 | /// We want to support this (arguably esoteric) use case, but we do not want to make |
| 1370 | /// the rest of `bindgen` users pay an usability penalty for that. |
| 1371 | /// |
| 1372 | /// To support this, we need to keep all the inline namespaces around, but then using |
| 1373 | /// `bindgen` becomes a bit more difficult, because you cannot reference paths like |
| 1374 | /// `std::string` (you'd need to use the proper inline namespace). |
| 1375 | /// |
| 1376 | /// We could complicate a lot of the logic to detect name collisions and, in the |
| 1377 | /// absence of collisions, generate a `pub use inline_ns::*` or something like that. |
| 1378 | /// |
| 1379 | /// That is probably something we can do to improve the usability of this option if we |
| 1380 | /// realize it is needed way more often. Our guess is that this extra logic is not |
| 1381 | /// going to be very useful. |
| 1382 | /// |
| 1383 | /// This option is disabled by default. |
| 1384 | pub fn conservative_inline_namespaces(mut self) -> Builder { |
| 1385 | self.options.conservative_inline_namespaces = true; |
| 1386 | self |
| 1387 | } |
| 1388 | }, |
| 1389 | as_args: "--conservative-inline-namespaces" , |
| 1390 | }, |
| 1391 | /// Whether to keep documentation comments in the generated output. |
| 1392 | generate_comments: bool { |
| 1393 | default: true, |
| 1394 | methods: { |
| 1395 | /// Set whether the generated bindings should contain documentation comments. |
| 1396 | /// |
| 1397 | /// Documentation comments are included by default. |
| 1398 | /// |
| 1399 | /// Note that clang excludes comments from system headers by default, pass |
| 1400 | /// `"-fretain-comments-from-system-headers"` to the [`Builder::clang_arg`] method to |
| 1401 | /// include them. |
| 1402 | /// |
| 1403 | /// It is also possible to process all comments and not just documentation using the |
| 1404 | /// `"-fparse-all-comments"` flag. Check [these slides on clang comment parsing]( |
| 1405 | /// https://llvm.org/devmtg/2012-11/Gribenko_CommentParsing.pdf) for more information |
| 1406 | /// and examples. |
| 1407 | pub fn generate_comments(mut self, doit: bool) -> Self { |
| 1408 | self.options.generate_comments = doit; |
| 1409 | self |
| 1410 | } |
| 1411 | }, |
| 1412 | as_args: |value, args| (!value).as_args(args, "--no-doc-comments" ), |
| 1413 | }, |
| 1414 | /// Whether to generate inline functions. |
| 1415 | generate_inline_functions: bool { |
| 1416 | methods: { |
| 1417 | /// Set whether to generate inline functions. |
| 1418 | /// |
| 1419 | /// This option is disabled by default. |
| 1420 | /// |
| 1421 | /// Note that they will usually not work. However you can use `-fkeep-inline-functions` |
| 1422 | /// or `-fno-inline-functions` if you are responsible of compiling the library to make |
| 1423 | /// them callable. |
| 1424 | /// |
| 1425 | /// Check the [`Builder::wrap_static_fns`] method for an alternative. |
| 1426 | pub fn generate_inline_functions(mut self, doit: bool) -> Self { |
| 1427 | self.options.generate_inline_functions = doit; |
| 1428 | self |
| 1429 | } |
| 1430 | }, |
| 1431 | as_args: "--generate-inline-functions" , |
| 1432 | }, |
| 1433 | /// Whether to allowlist types recursively. |
| 1434 | allowlist_recursively: bool { |
| 1435 | default: true, |
| 1436 | methods: { |
| 1437 | /// Set whether to recursively allowlist items. |
| 1438 | /// |
| 1439 | /// Items are allowlisted recursively by default. |
| 1440 | /// |
| 1441 | /// Given that we have explicitly allowlisted the `initiate_dance_party` function in |
| 1442 | /// this C header: |
| 1443 | /// |
| 1444 | /// ```c |
| 1445 | /// typedef struct MoonBoots { |
| 1446 | /// int bouncy_level; |
| 1447 | /// } MoonBoots; |
| 1448 | /// |
| 1449 | /// void initiate_dance_party(MoonBoots* boots); |
| 1450 | /// ``` |
| 1451 | /// |
| 1452 | /// We would normally generate bindings to both the `initiate_dance_party` function and |
| 1453 | /// the `MoonBoots` type that it transitively references. If `false` is passed to this |
| 1454 | /// method, `bindgen` will not emit bindings for anything except the explicitly |
| 1455 | /// allowlisted items, meaning that the definition for `MoonBoots` would not be |
| 1456 | /// generated. However, the `initiate_dance_party` function would still reference |
| 1457 | /// `MoonBoots`! |
| 1458 | /// |
| 1459 | /// **Disabling this feature will almost certainly cause `bindgen` to emit bindings |
| 1460 | /// that will not compile!** If you disable this feature, then it is *your* |
| 1461 | /// responsibility to provide definitions for every type that is referenced from an |
| 1462 | /// explicitly allowlisted item. One way to provide the missing definitions is by using |
| 1463 | /// the [`Builder::raw_line`] method, another would be to define them in Rust and then |
| 1464 | /// `include!(...)` the bindings immediately afterwards. |
| 1465 | pub fn allowlist_recursively(mut self, doit: bool) -> Self { |
| 1466 | self.options.allowlist_recursively = doit; |
| 1467 | self |
| 1468 | } |
| 1469 | }, |
| 1470 | as_args: |value, args| (!value).as_args(args, "--no-recursive-allowlist" ), |
| 1471 | }, |
| 1472 | /// Whether to emit `#[macro_use] extern crate objc;` instead of `use objc;` in the prologue of |
| 1473 | /// the files generated from objective-c files. |
| 1474 | objc_extern_crate: bool { |
| 1475 | methods: { |
| 1476 | /// Emit `#[macro_use] extern crate objc;` instead of `use objc;` in the prologue of |
| 1477 | /// the files generated from objective-c files. |
| 1478 | /// |
| 1479 | /// `use objc;` is emitted by default. |
| 1480 | pub fn objc_extern_crate(mut self, doit: bool) -> Self { |
| 1481 | self.options.objc_extern_crate = doit; |
| 1482 | self |
| 1483 | } |
| 1484 | }, |
| 1485 | as_args: "--objc-extern-crate" , |
| 1486 | }, |
| 1487 | /// Whether to generate proper block signatures instead of `void` pointers. |
| 1488 | generate_block: bool { |
| 1489 | methods: { |
| 1490 | /// Generate proper block signatures instead of `void` pointers. |
| 1491 | /// |
| 1492 | /// `void` pointers are used by default. |
| 1493 | pub fn generate_block(mut self, doit: bool) -> Self { |
| 1494 | self.options.generate_block = doit; |
| 1495 | self |
| 1496 | } |
| 1497 | }, |
| 1498 | as_args: "--generate-block" , |
| 1499 | }, |
| 1500 | /// Whether to generate strings as `CStr`. |
| 1501 | generate_cstr: bool { |
| 1502 | methods: { |
| 1503 | /// Set whether string constants should be generated as `&CStr` instead of `&[u8]`. |
| 1504 | /// |
| 1505 | /// A minimum Rust target of 1.59 is required for this to have any effect as support |
| 1506 | /// for `CStr::from_bytes_with_nul_unchecked` in `const` contexts is needed. |
| 1507 | /// |
| 1508 | /// This option is disabled by default but will become enabled by default in a future |
| 1509 | /// release, so enabling this is recommended. |
| 1510 | pub fn generate_cstr(mut self, doit: bool) -> Self { |
| 1511 | self.options.generate_cstr = doit; |
| 1512 | self |
| 1513 | } |
| 1514 | }, |
| 1515 | as_args: "--generate-cstr" , |
| 1516 | }, |
| 1517 | /// Whether to emit `#[macro_use] extern crate block;` instead of `use block;` in the prologue |
| 1518 | /// of the files generated from apple block files. |
| 1519 | block_extern_crate: bool { |
| 1520 | methods: { |
| 1521 | /// Emit `#[macro_use] extern crate block;` instead of `use block;` in the prologue of |
| 1522 | /// the files generated from apple block files. |
| 1523 | /// |
| 1524 | /// `use block;` is emitted by default. |
| 1525 | pub fn block_extern_crate(mut self, doit: bool) -> Self { |
| 1526 | self.options.block_extern_crate = doit; |
| 1527 | self |
| 1528 | } |
| 1529 | }, |
| 1530 | as_args: "--block-extern-crate" , |
| 1531 | }, |
| 1532 | /// Whether to use the clang-provided name mangling. |
| 1533 | enable_mangling: bool { |
| 1534 | default: true, |
| 1535 | methods: { |
| 1536 | /// Set whether to use the clang-provided name mangling. This is probably needed for |
| 1537 | /// C++ features. |
| 1538 | /// |
| 1539 | /// The mangling provided by clang is used by default. |
| 1540 | /// |
| 1541 | /// We allow disabling this option because some old `libclang` versions seem to return |
| 1542 | /// incorrect results in some cases for non-mangled functions, check [#528] for more |
| 1543 | /// information. |
| 1544 | /// |
| 1545 | /// [#528]: https://github.com/rust-lang/rust-bindgen/issues/528 |
| 1546 | pub fn trust_clang_mangling(mut self, doit: bool) -> Self { |
| 1547 | self.options.enable_mangling = doit; |
| 1548 | self |
| 1549 | } |
| 1550 | |
| 1551 | }, |
| 1552 | as_args: |value, args| (!value).as_args(args, "--distrust-clang-mangling" ), |
| 1553 | }, |
| 1554 | /// Whether to detect include paths using `clang_sys`. |
| 1555 | detect_include_paths: bool { |
| 1556 | default: true, |
| 1557 | methods: { |
| 1558 | /// Set whether to detect include paths using `clang_sys`. |
| 1559 | /// |
| 1560 | /// `clang_sys` is used to detect include paths by default. |
| 1561 | pub fn detect_include_paths(mut self, doit: bool) -> Self { |
| 1562 | self.options.detect_include_paths = doit; |
| 1563 | self |
| 1564 | } |
| 1565 | }, |
| 1566 | as_args: |value, args| (!value).as_args(args, "--no-include-path-detection" ), |
| 1567 | }, |
| 1568 | /// Whether we should try to fit macro constants into types smaller than `u32` and `i32`. |
| 1569 | fit_macro_constants: bool { |
| 1570 | methods: { |
| 1571 | /// Set whether `bindgen` should try to fit macro constants into types smaller than `u32` |
| 1572 | /// and `i32`. |
| 1573 | /// |
| 1574 | /// This option is disabled by default. |
| 1575 | pub fn fit_macro_constants(mut self, doit: bool) -> Self { |
| 1576 | self.options.fit_macro_constants = doit; |
| 1577 | self |
| 1578 | } |
| 1579 | }, |
| 1580 | as_args: "--fit-macro-constant-types" , |
| 1581 | }, |
| 1582 | /// Whether to prepend the `enum` name to constant or newtype variants. |
| 1583 | prepend_enum_name: bool { |
| 1584 | default: true, |
| 1585 | methods: { |
| 1586 | /// Set whether to prepend the `enum` name to constant or newtype variants. |
| 1587 | /// |
| 1588 | /// The `enum` name is prepended by default. |
| 1589 | pub fn prepend_enum_name(mut self, doit: bool) -> Self { |
| 1590 | self.options.prepend_enum_name = doit; |
| 1591 | self |
| 1592 | } |
| 1593 | }, |
| 1594 | as_args: |value, args| (!value).as_args(args, "--no-prepend-enum-name" ), |
| 1595 | }, |
| 1596 | /// Version of the Rust compiler to target. |
| 1597 | rust_target: RustTarget { |
| 1598 | methods: { |
| 1599 | /// Specify the Rust target version. |
| 1600 | /// |
| 1601 | /// The default target is the latest stable Rust version. |
| 1602 | pub fn rust_target(mut self, rust_target: RustTarget) -> Self { |
| 1603 | self.options.set_rust_target(rust_target); |
| 1604 | self |
| 1605 | } |
| 1606 | }, |
| 1607 | as_args: |rust_target, args| { |
| 1608 | args.push("--rust-target" .to_owned()); |
| 1609 | args.push(rust_target.to_string()); |
| 1610 | }, |
| 1611 | }, |
| 1612 | /// The Rust edition to use for code generation. |
| 1613 | rust_edition: Option<RustEdition> { |
| 1614 | methods: { |
| 1615 | /// Specify the Rust target edition. |
| 1616 | /// |
| 1617 | /// The default edition is the latest edition supported by the chosen Rust target. |
| 1618 | pub fn rust_edition(mut self, rust_edition: RustEdition) -> Self { |
| 1619 | self.options.rust_edition = Some(rust_edition); |
| 1620 | self |
| 1621 | } |
| 1622 | } |
| 1623 | as_args: |edition, args| { |
| 1624 | if let Some(edition) = edition { |
| 1625 | args.push("--rust-edition" .to_owned()); |
| 1626 | args.push(edition.to_string()); |
| 1627 | } |
| 1628 | }, |
| 1629 | }, |
| 1630 | /// Features to be enabled. They are derived from `rust_target`. |
| 1631 | rust_features: RustFeatures { |
| 1632 | methods: {}, |
| 1633 | // This field cannot be set from the CLI, |
| 1634 | as_args: ignore, |
| 1635 | }, |
| 1636 | /// Enable support for native Rust unions if they are supported. |
| 1637 | untagged_union: bool { |
| 1638 | default: true, |
| 1639 | methods: { |
| 1640 | /// Disable support for native Rust unions, if supported. |
| 1641 | /// |
| 1642 | /// The default value of this option is set based on the value passed to |
| 1643 | /// [`Builder::rust_target`]. |
| 1644 | pub fn disable_untagged_union(mut self) -> Self { |
| 1645 | self.options.untagged_union = false; |
| 1646 | self |
| 1647 | } |
| 1648 | } |
| 1649 | as_args: |value, args| (!value).as_args(args, "--disable-untagged-union" ), |
| 1650 | }, |
| 1651 | /// Whether we should record which items in the regex sets did match any C items. |
| 1652 | record_matches: bool { |
| 1653 | default: true, |
| 1654 | methods: { |
| 1655 | /// Set whether we should record which items in our regex sets did match any C items. |
| 1656 | /// |
| 1657 | /// Matches are recorded by default. |
| 1658 | pub fn record_matches(mut self, doit: bool) -> Self { |
| 1659 | self.options.record_matches = doit; |
| 1660 | self |
| 1661 | } |
| 1662 | |
| 1663 | }, |
| 1664 | as_args: |value, args| (!value).as_args(args, "--no-record-matches" ), |
| 1665 | }, |
| 1666 | /// Whether `size_t` should be translated to `usize` automatically. |
| 1667 | size_t_is_usize: bool { |
| 1668 | default: true, |
| 1669 | methods: { |
| 1670 | /// Set whether `size_t` should be translated to `usize`. |
| 1671 | /// |
| 1672 | /// If `size_t` is translated to `usize`, type definitions for `size_t` will not be |
| 1673 | /// emitted. |
| 1674 | /// |
| 1675 | /// `size_t` is translated to `usize` by default. |
| 1676 | pub fn size_t_is_usize(mut self, is: bool) -> Self { |
| 1677 | self.options.size_t_is_usize = is; |
| 1678 | self |
| 1679 | } |
| 1680 | }, |
| 1681 | as_args: |value, args| (!value).as_args(args, "--no-size_t-is-usize" ), |
| 1682 | }, |
| 1683 | /// The tool that should be used to format the generated bindings. |
| 1684 | formatter: Formatter { |
| 1685 | methods: { |
| 1686 | /// Set whether `rustfmt` should be used to format the generated bindings. |
| 1687 | /// |
| 1688 | /// `rustfmt` is used by default. |
| 1689 | /// |
| 1690 | /// This method overlaps in functionality with the more general [`Builder::formatter`]. |
| 1691 | /// Thus, the latter should be preferred. |
| 1692 | #[deprecated ] |
| 1693 | pub fn rustfmt_bindings(mut self, doit: bool) -> Self { |
| 1694 | self.options.formatter = if doit { |
| 1695 | Formatter::Rustfmt |
| 1696 | } else { |
| 1697 | Formatter::None |
| 1698 | }; |
| 1699 | self |
| 1700 | } |
| 1701 | |
| 1702 | /// Set which tool should be used to format the generated bindings. |
| 1703 | /// |
| 1704 | /// The default formatter is [`Formatter::Rustfmt`]. |
| 1705 | /// |
| 1706 | /// To be able to use `prettyplease` as a formatter, the `"prettyplease"` feature for |
| 1707 | /// `bindgen` must be enabled in the Cargo manifest. |
| 1708 | pub fn formatter(mut self, formatter: Formatter) -> Self { |
| 1709 | self.options.formatter = formatter; |
| 1710 | self |
| 1711 | } |
| 1712 | }, |
| 1713 | as_args: |formatter, args| { |
| 1714 | if *formatter != Default::default() { |
| 1715 | args.push("--formatter" .to_owned()); |
| 1716 | args.push(formatter.to_string()); |
| 1717 | } |
| 1718 | }, |
| 1719 | }, |
| 1720 | /// The absolute path to the `rustfmt` configuration file. |
| 1721 | rustfmt_configuration_file: Option<PathBuf> { |
| 1722 | methods: { |
| 1723 | /// Set the absolute path to the `rustfmt` configuration file. |
| 1724 | /// |
| 1725 | /// The default `rustfmt` options are used if `None` is passed to this method or if |
| 1726 | /// this method is not called at all. |
| 1727 | /// |
| 1728 | /// Calling this method will set the [`Builder::rustfmt_bindings`] option to `true` |
| 1729 | /// and the [`Builder::formatter`] option to [`Formatter::Rustfmt`]. |
| 1730 | pub fn rustfmt_configuration_file(mut self, path: Option<PathBuf>) -> Self { |
| 1731 | self = self.formatter(Formatter::Rustfmt); |
| 1732 | self.options.rustfmt_configuration_file = path; |
| 1733 | self |
| 1734 | } |
| 1735 | }, |
| 1736 | as_args: "--rustfmt-configuration-file" , |
| 1737 | }, |
| 1738 | /// Types that should not derive `PartialEq`. |
| 1739 | no_partialeq_types: RegexSet { |
| 1740 | methods: { |
| 1741 | regex_option! { |
| 1742 | /// Do not derive `PartialEq` for a given type. |
| 1743 | pub fn no_partialeq<T: Into<String>>(mut self, arg: T) -> Builder { |
| 1744 | self.options.no_partialeq_types.insert(arg.into()); |
| 1745 | self |
| 1746 | } |
| 1747 | } |
| 1748 | }, |
| 1749 | as_args: "--no-partialeq" , |
| 1750 | }, |
| 1751 | /// Types that should not derive `Copy`. |
| 1752 | no_copy_types: RegexSet { |
| 1753 | methods: { |
| 1754 | regex_option! { |
| 1755 | /// Do not derive `Copy` and `Clone` for a given type. |
| 1756 | pub fn no_copy<T: Into<String>>(mut self, arg: T) -> Self { |
| 1757 | self.options.no_copy_types.insert(arg.into()); |
| 1758 | self |
| 1759 | } |
| 1760 | } |
| 1761 | }, |
| 1762 | as_args: "--no-copy" , |
| 1763 | }, |
| 1764 | /// Types that should not derive `Debug`. |
| 1765 | no_debug_types: RegexSet { |
| 1766 | methods: { |
| 1767 | regex_option! { |
| 1768 | /// Do not derive `Debug` for a given type. |
| 1769 | pub fn no_debug<T: Into<String>>(mut self, arg: T) -> Self { |
| 1770 | self.options.no_debug_types.insert(arg.into()); |
| 1771 | self |
| 1772 | } |
| 1773 | } |
| 1774 | }, |
| 1775 | as_args: "--no-debug" , |
| 1776 | }, |
| 1777 | /// Types that should not derive or implement `Default`. |
| 1778 | no_default_types: RegexSet { |
| 1779 | methods: { |
| 1780 | regex_option! { |
| 1781 | /// Do not derive or implement `Default` for a given type. |
| 1782 | pub fn no_default<T: Into<String>>(mut self, arg: T) -> Self { |
| 1783 | self.options.no_default_types.insert(arg.into()); |
| 1784 | self |
| 1785 | } |
| 1786 | } |
| 1787 | }, |
| 1788 | as_args: "--no-default" , |
| 1789 | }, |
| 1790 | /// Types that should not derive `Hash`. |
| 1791 | no_hash_types: RegexSet { |
| 1792 | methods: { |
| 1793 | regex_option! { |
| 1794 | /// Do not derive `Hash` for a given type. |
| 1795 | pub fn no_hash<T: Into<String>>(mut self, arg: T) -> Builder { |
| 1796 | self.options.no_hash_types.insert(arg.into()); |
| 1797 | self |
| 1798 | } |
| 1799 | } |
| 1800 | }, |
| 1801 | as_args: "--no-hash" , |
| 1802 | }, |
| 1803 | /// Types that should be annotated with `#[must_use]`. |
| 1804 | must_use_types: RegexSet { |
| 1805 | methods: { |
| 1806 | regex_option! { |
| 1807 | /// Annotate the given type with the `#[must_use]` attribute. |
| 1808 | pub fn must_use_type<T: Into<String>>(mut self, arg: T) -> Builder { |
| 1809 | self.options.must_use_types.insert(arg.into()); |
| 1810 | self |
| 1811 | } |
| 1812 | } |
| 1813 | }, |
| 1814 | as_args: "--must-use-type" , |
| 1815 | }, |
| 1816 | /// Whether C arrays should be regular pointers in rust or array pointers |
| 1817 | array_pointers_in_arguments: bool { |
| 1818 | methods: { |
| 1819 | /// Translate arrays `T arr[size]` into array pointers `*mut [T; size]` instead of |
| 1820 | /// translating them as `*mut T` which is the default. |
| 1821 | /// |
| 1822 | /// The same is done for `*const` pointers. |
| 1823 | pub fn array_pointers_in_arguments(mut self, doit: bool) -> Self { |
| 1824 | self.options.array_pointers_in_arguments = doit; |
| 1825 | self |
| 1826 | } |
| 1827 | |
| 1828 | }, |
| 1829 | as_args: "--use-array-pointers-in-arguments" , |
| 1830 | }, |
| 1831 | /// The name of the `wasm_import_module`. |
| 1832 | wasm_import_module_name: Option<String> { |
| 1833 | methods: { |
| 1834 | /// Adds the `#[link(wasm_import_module = import_name)]` attribute to all the `extern` |
| 1835 | /// blocks generated by `bindgen`. |
| 1836 | /// |
| 1837 | /// This attribute is not added by default. |
| 1838 | pub fn wasm_import_module_name<T: Into<String>>( |
| 1839 | mut self, |
| 1840 | import_name: T, |
| 1841 | ) -> Self { |
| 1842 | self.options.wasm_import_module_name = Some(import_name.into()); |
| 1843 | self |
| 1844 | } |
| 1845 | }, |
| 1846 | as_args: "--wasm-import-module-name" , |
| 1847 | }, |
| 1848 | /// The name of the dynamic library (if we are generating bindings for a shared library). |
| 1849 | dynamic_library_name: Option<String> { |
| 1850 | methods: { |
| 1851 | /// Generate bindings for a shared library with the given name. |
| 1852 | /// |
| 1853 | /// This option is disabled by default. |
| 1854 | pub fn dynamic_library_name<T: Into<String>>( |
| 1855 | mut self, |
| 1856 | dynamic_library_name: T, |
| 1857 | ) -> Self { |
| 1858 | self.options.dynamic_library_name = Some(dynamic_library_name.into()); |
| 1859 | self |
| 1860 | } |
| 1861 | }, |
| 1862 | as_args: "--dynamic-loading" , |
| 1863 | }, |
| 1864 | /// Whether to require successful linkage for all routines in a shared library. |
| 1865 | dynamic_link_require_all: bool { |
| 1866 | methods: { |
| 1867 | /// Set whether to require successful linkage for all routines in a shared library. |
| 1868 | /// This allows us to optimize function calls by being able to safely assume function |
| 1869 | /// pointers are valid. |
| 1870 | /// |
| 1871 | /// This option only comes into effect if the [`Builder::dynamic_library_name`] option |
| 1872 | /// is set. |
| 1873 | /// |
| 1874 | /// This option is disabled by default. |
| 1875 | pub fn dynamic_link_require_all(mut self, req: bool) -> Self { |
| 1876 | self.options.dynamic_link_require_all = req; |
| 1877 | self |
| 1878 | } |
| 1879 | }, |
| 1880 | as_args: "--dynamic-link-require-all" , |
| 1881 | }, |
| 1882 | /// Whether to only make generated bindings `pub` if the items would be publicly accessible by |
| 1883 | /// C++. |
| 1884 | respect_cxx_access_specs: bool { |
| 1885 | methods: { |
| 1886 | /// Set whether to respect the C++ access specifications. |
| 1887 | /// |
| 1888 | /// Passing `true` to this method will set the visibility of the generated Rust items |
| 1889 | /// as `pub` only if the corresponding C++ items are publicly accessible instead of |
| 1890 | /// marking all the items as public, which is the default. |
| 1891 | pub fn respect_cxx_access_specs(mut self, doit: bool) -> Self { |
| 1892 | self.options.respect_cxx_access_specs = doit; |
| 1893 | self |
| 1894 | } |
| 1895 | |
| 1896 | }, |
| 1897 | as_args: "--respect-cxx-access-specs" , |
| 1898 | }, |
| 1899 | /// Whether to translate `enum` integer types to native Rust integer types. |
| 1900 | translate_enum_integer_types: bool { |
| 1901 | methods: { |
| 1902 | /// Set whether to always translate `enum` integer types to native Rust integer types. |
| 1903 | /// |
| 1904 | /// Passing `true` to this method will result in `enum`s having types such as `u32` and |
| 1905 | /// `i16` instead of `c_uint` and `c_short` which is the default. The `#[repr]` types |
| 1906 | /// of Rust `enum`s are always translated to Rust integer types. |
| 1907 | pub fn translate_enum_integer_types(mut self, doit: bool) -> Self { |
| 1908 | self.options.translate_enum_integer_types = doit; |
| 1909 | self |
| 1910 | } |
| 1911 | }, |
| 1912 | as_args: "--translate-enum-integer-types" , |
| 1913 | }, |
| 1914 | /// Whether to generate types with C style naming. |
| 1915 | c_naming: bool { |
| 1916 | methods: { |
| 1917 | /// Set whether to generate types with C style naming. |
| 1918 | /// |
| 1919 | /// Passing `true` to this method will add prefixes to the generated type names. For |
| 1920 | /// example, instead of a `struct` with name `A` we will generate a `struct` with |
| 1921 | /// `struct_A`. Currently applies to `struct`s, `union`s, and `enum`s. |
| 1922 | pub fn c_naming(mut self, doit: bool) -> Self { |
| 1923 | self.options.c_naming = doit; |
| 1924 | self |
| 1925 | } |
| 1926 | }, |
| 1927 | as_args: "--c-naming" , |
| 1928 | }, |
| 1929 | /// Whether to always emit explicit padding fields. |
| 1930 | force_explicit_padding: bool { |
| 1931 | methods: { |
| 1932 | /// Set whether to always emit explicit padding fields. |
| 1933 | /// |
| 1934 | /// This option should be enabled if a `struct` needs to be serialized in its native |
| 1935 | /// format (padding bytes and all). This could be required if such `struct` will be |
| 1936 | /// written to a file or sent over the network, as anything reading the padding bytes |
| 1937 | /// of a struct may cause undefined behavior. |
| 1938 | /// |
| 1939 | /// Padding fields are not emitted by default. |
| 1940 | pub fn explicit_padding(mut self, doit: bool) -> Self { |
| 1941 | self.options.force_explicit_padding = doit; |
| 1942 | self |
| 1943 | } |
| 1944 | }, |
| 1945 | as_args: "--explicit-padding" , |
| 1946 | }, |
| 1947 | /// Whether to emit vtable functions. |
| 1948 | vtable_generation: bool { |
| 1949 | methods: { |
| 1950 | /// Set whether to enable experimental support to generate virtual table functions. |
| 1951 | /// |
| 1952 | /// This option should mostly work, though some edge cases are likely to be broken. |
| 1953 | /// |
| 1954 | /// Virtual table generation is disabled by default. |
| 1955 | pub fn vtable_generation(mut self, doit: bool) -> Self { |
| 1956 | self.options.vtable_generation = doit; |
| 1957 | self |
| 1958 | } |
| 1959 | }, |
| 1960 | as_args: "--vtable-generation" , |
| 1961 | }, |
| 1962 | /// Whether to sort the generated Rust items. |
| 1963 | sort_semantically: bool { |
| 1964 | methods: { |
| 1965 | /// Set whether to sort the generated Rust items in a predefined manner. |
| 1966 | /// |
| 1967 | /// Items are not ordered by default. |
| 1968 | pub fn sort_semantically(mut self, doit: bool) -> Self { |
| 1969 | self.options.sort_semantically = doit; |
| 1970 | self |
| 1971 | } |
| 1972 | }, |
| 1973 | as_args: "--sort-semantically" , |
| 1974 | }, |
| 1975 | /// Whether to deduplicate `extern` blocks. |
| 1976 | merge_extern_blocks: bool { |
| 1977 | methods: { |
| 1978 | /// Merge all extern blocks under the same module into a single one. |
| 1979 | /// |
| 1980 | /// Extern blocks are not merged by default. |
| 1981 | pub fn merge_extern_blocks(mut self, doit: bool) -> Self { |
| 1982 | self.options.merge_extern_blocks = doit; |
| 1983 | self |
| 1984 | } |
| 1985 | }, |
| 1986 | as_args: "--merge-extern-blocks" , |
| 1987 | }, |
| 1988 | /// Whether to wrap unsafe operations in unsafe blocks. |
| 1989 | wrap_unsafe_ops: bool { |
| 1990 | methods: { |
| 1991 | /// Wrap all unsafe operations in unsafe blocks. |
| 1992 | /// |
| 1993 | /// Unsafe operations are not wrapped by default. |
| 1994 | pub fn wrap_unsafe_ops(mut self, doit: bool) -> Self { |
| 1995 | self.options.wrap_unsafe_ops = doit; |
| 1996 | self |
| 1997 | } |
| 1998 | }, |
| 1999 | as_args: "--wrap-unsafe-ops" , |
| 2000 | }, |
| 2001 | /// Use DSTs to represent structures with flexible array members. |
| 2002 | flexarray_dst: bool { |
| 2003 | methods: { |
| 2004 | /// Use DSTs to represent structures with flexible array members. |
| 2005 | /// |
| 2006 | /// This option is disabled by default. |
| 2007 | pub fn flexarray_dst(mut self, doit: bool) -> Self { |
| 2008 | self.options.flexarray_dst = doit; |
| 2009 | self |
| 2010 | } |
| 2011 | }, |
| 2012 | as_args: "--flexarray-dst" , |
| 2013 | }, |
| 2014 | /// Patterns for functions whose ABI should be overridden. |
| 2015 | abi_overrides: HashMap<Abi, RegexSet> { |
| 2016 | methods: { |
| 2017 | regex_option! { |
| 2018 | /// Override the ABI of a given function. |
| 2019 | pub fn override_abi<T: Into<String>>(mut self, abi: Abi, arg: T) -> Self { |
| 2020 | self.options |
| 2021 | .abi_overrides |
| 2022 | .entry(abi) |
| 2023 | .or_default() |
| 2024 | .insert(arg.into()); |
| 2025 | self |
| 2026 | } |
| 2027 | } |
| 2028 | }, |
| 2029 | as_args: |overrides, args| { |
| 2030 | for (abi, set) in overrides { |
| 2031 | for item in set.get_items() { |
| 2032 | args.push("--override-abi" .to_owned()); |
| 2033 | args.push(format!(" {item}= {abi}" )); |
| 2034 | } |
| 2035 | } |
| 2036 | }, |
| 2037 | }, |
| 2038 | /// Whether to generate wrappers for `static` functions. |
| 2039 | wrap_static_fns: bool { |
| 2040 | methods: { |
| 2041 | /// Set whether to generate wrappers for `static`` functions. |
| 2042 | /// |
| 2043 | /// Passing `true` to this method will generate a C source file with non-`static` |
| 2044 | /// functions that call the `static` functions found in the input headers and can be |
| 2045 | /// called from Rust once the source file is compiled. |
| 2046 | /// |
| 2047 | /// The path of this source file can be set using the [`Builder::wrap_static_fns_path`] |
| 2048 | /// method. |
| 2049 | pub fn wrap_static_fns(mut self, doit: bool) -> Self { |
| 2050 | self.options.wrap_static_fns = doit; |
| 2051 | self |
| 2052 | } |
| 2053 | }, |
| 2054 | as_args: "--wrap-static-fns" , |
| 2055 | }, |
| 2056 | /// The suffix to be added to the function wrappers for `static` functions. |
| 2057 | wrap_static_fns_suffix: Option<String> { |
| 2058 | methods: { |
| 2059 | /// Set the suffix added to the wrappers for `static` functions. |
| 2060 | /// |
| 2061 | /// This option only comes into effect if `true` is passed to the |
| 2062 | /// [`Builder::wrap_static_fns`] method. |
| 2063 | /// |
| 2064 | /// The default suffix is `__extern`. |
| 2065 | pub fn wrap_static_fns_suffix<T: AsRef<str>>(mut self, suffix: T) -> Self { |
| 2066 | self.options.wrap_static_fns_suffix = Some(suffix.as_ref().to_owned()); |
| 2067 | self |
| 2068 | } |
| 2069 | }, |
| 2070 | as_args: "--wrap-static-fns-suffix" , |
| 2071 | }, |
| 2072 | /// The path of the file where the wrappers for `static` functions will be emitted. |
| 2073 | wrap_static_fns_path: Option<PathBuf> { |
| 2074 | methods: { |
| 2075 | /// Set the path for the source code file that would be created if any wrapper |
| 2076 | /// functions must be generated due to the presence of `static` functions. |
| 2077 | /// |
| 2078 | /// `bindgen` will automatically add the right extension to the header and source code |
| 2079 | /// files. |
| 2080 | /// |
| 2081 | /// This option only comes into effect if `true` is passed to the |
| 2082 | /// [`Builder::wrap_static_fns`] method. |
| 2083 | /// |
| 2084 | /// The default path is `temp_dir/bindgen/extern`, where `temp_dir` is the path |
| 2085 | /// returned by [`std::env::temp_dir`] . |
| 2086 | pub fn wrap_static_fns_path<T: AsRef<Path>>(mut self, path: T) -> Self { |
| 2087 | self.options.wrap_static_fns_path = Some(path.as_ref().to_owned()); |
| 2088 | self |
| 2089 | } |
| 2090 | }, |
| 2091 | as_args: "--wrap-static-fns-path" , |
| 2092 | }, |
| 2093 | /// Default visibility of fields. |
| 2094 | default_visibility: FieldVisibilityKind { |
| 2095 | methods: { |
| 2096 | /// Set the default visibility of fields, including bitfields and accessor methods for |
| 2097 | /// bitfields. |
| 2098 | /// |
| 2099 | /// This option only comes into effect if the [`Builder::respect_cxx_access_specs`] |
| 2100 | /// option is disabled. |
| 2101 | pub fn default_visibility( |
| 2102 | mut self, |
| 2103 | visibility: FieldVisibilityKind, |
| 2104 | ) -> Self { |
| 2105 | self.options.default_visibility = visibility; |
| 2106 | self |
| 2107 | } |
| 2108 | }, |
| 2109 | as_args: |visibility, args| { |
| 2110 | if *visibility != Default::default() { |
| 2111 | args.push("--default-visibility" .to_owned()); |
| 2112 | args.push(visibility.to_string()); |
| 2113 | } |
| 2114 | }, |
| 2115 | }, |
| 2116 | /// Whether to emit diagnostics or not. |
| 2117 | emit_diagnostics: bool { |
| 2118 | methods: { |
| 2119 | #[cfg (feature = "experimental" )] |
| 2120 | /// Emit diagnostics. |
| 2121 | /// |
| 2122 | /// These diagnostics are emitted to `stderr` if you are using `bindgen-cli` or printed |
| 2123 | /// using `cargo:warning=` if you are using `bindgen` as a `build-dependency`. |
| 2124 | /// |
| 2125 | /// Diagnostics are not emitted by default. |
| 2126 | /// |
| 2127 | /// The layout and contents of these diagnostic messages are not covered by versioning |
| 2128 | /// and can change without notice. |
| 2129 | pub fn emit_diagnostics(mut self) -> Self { |
| 2130 | self.options.emit_diagnostics = true; |
| 2131 | self |
| 2132 | } |
| 2133 | }, |
| 2134 | as_args: "--emit-diagnostics" , |
| 2135 | }, |
| 2136 | /// Whether to use Clang evaluation on temporary files as a fallback for macros that fail to |
| 2137 | /// parse. |
| 2138 | clang_macro_fallback: bool { |
| 2139 | methods: { |
| 2140 | /// Use Clang as a fallback for macros that fail to parse using `CExpr`. |
| 2141 | /// |
| 2142 | /// This uses a workaround to evaluate each macro in a temporary file. Because this |
| 2143 | /// results in slower compilation, this option is opt-in. |
| 2144 | pub fn clang_macro_fallback(mut self) -> Self { |
| 2145 | self.options.clang_macro_fallback = true; |
| 2146 | self |
| 2147 | } |
| 2148 | }, |
| 2149 | as_args: "--clang-macro-fallback" , |
| 2150 | } |
| 2151 | /// Path to use for temporary files created by clang macro fallback code like precompiled |
| 2152 | /// headers. |
| 2153 | clang_macro_fallback_build_dir: Option<PathBuf> { |
| 2154 | methods: { |
| 2155 | /// Set a path to a directory to which `.c` and `.h.pch` files should be written for the |
| 2156 | /// purpose of using clang to evaluate macros that can't be easily parsed. |
| 2157 | /// |
| 2158 | /// The default location for `.h.pch` files is the directory that the corresponding |
| 2159 | /// `.h` file is located in. The default for the temporary `.c` file used for clang |
| 2160 | /// parsing is the current working directory. Both of these defaults are overridden |
| 2161 | /// by this option. |
| 2162 | pub fn clang_macro_fallback_build_dir<P: AsRef<Path>>(mut self, path: P) -> Self { |
| 2163 | self.options.clang_macro_fallback_build_dir = Some(path.as_ref().to_owned()); |
| 2164 | self |
| 2165 | } |
| 2166 | }, |
| 2167 | as_args: "--clang-macro-fallback-build-dir" , |
| 2168 | } |
| 2169 | } |
| 2170 | |