summaryrefslogtreecommitdiff
path: root/src/options.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/options.rs')
-rw-r--r--src/options.rs187
1 files changed, 116 insertions, 71 deletions
diff --git a/src/options.rs b/src/options.rs
index d15cba81..6ead9241 100644
--- a/src/options.rs
+++ b/src/options.rs
@@ -1,14 +1,12 @@
-use bindgen::{Builder, CodegenConfig, RUST_TARGET_STRINGS, RustTarget, builder, EnumVariation};
+use bindgen::{builder, Builder, CodegenConfig, EnumVariation, RustTarget, RUST_TARGET_STRINGS};
use clap::{App, Arg};
use std::fs::File;
-use std::io::{self, Error, ErrorKind, Write, stderr};
+use std::io::{self, stderr, Error, ErrorKind, Write};
use std::path::PathBuf;
use std::str::FromStr;
/// Construct a new [`Builder`](./struct.Builder.html) from command line flags.
-pub fn builder_from_flags<I>(
- args: I,
-) -> Result<(Builder, Box<dyn io::Write>, bool), io::Error>
+pub fn builder_from_flags<I>(args: I) -> Result<(Builder, Box<dyn io::Write>, bool), io::Error>
where
I: Iterator<Item = String>,
{
@@ -31,12 +29,20 @@ where
.help("The default style of code used to generate enums.")
.value_name("variant")
.default_value("consts")
- .possible_values(&["consts", "moduleconsts", "bitfield", "rust", "rust_non_exhaustive"])
+ .possible_values(&[
+ "consts",
+ "moduleconsts",
+ "bitfield",
+ "rust",
+ "rust_non_exhaustive",
+ ])
.multiple(false),
Arg::with_name("bitfield-enum")
.long("bitfield-enum")
- .help("Mark any enum whose name matches <regex> as a set of \
- bitfield flags.")
+ .help(
+ "Mark any enum whose name matches <regex> as a set of \
+ bitfield flags.",
+ )
.value_name("regex")
.takes_value(true)
.multiple(true)
@@ -50,16 +56,20 @@ where
.number_of_values(1),
Arg::with_name("constified-enum")
.long("constified-enum")
- .help("Mark any enum whose name matches <regex> as a series of \
- constants.")
+ .help(
+ "Mark any enum whose name matches <regex> as a series of \
+ constants.",
+ )
.value_name("regex")
.takes_value(true)
.multiple(true)
.number_of_values(1),
Arg::with_name("constified-enum-module")
.long("constified-enum-module")
- .help("Mark any enum whose name matches <regex> as a module of \
- constants.")
+ .help(
+ "Mark any enum whose name matches <regex> as a module of \
+ constants.",
+ )
.value_name("regex")
.takes_value(true)
.multiple(true)
@@ -98,14 +108,16 @@ where
.long("no-derive-default")
.hidden(true)
.help("Avoid deriving Default on any type."),
- Arg::with_name("impl-debug")
- .long("impl-debug")
- .help("Create Debug implementation, if it can not be derived \
- automatically."),
+ Arg::with_name("impl-debug").long("impl-debug").help(
+ "Create Debug implementation, if it can not be derived \
+ automatically.",
+ ),
Arg::with_name("impl-partialeq")
.long("impl-partialeq")
- .help("Create PartialEq implementation, if it can not be derived \
- automatically."),
+ .help(
+ "Create PartialEq implementation, if it can not be derived \
+ automatically.",
+ ),
Arg::with_name("with-derive-default")
.long("with-derive-default")
.help("Derive Default on any type."),
@@ -120,22 +132,30 @@ where
.help("Derive partialord on any type."),
Arg::with_name("with-derive-eq")
.long("with-derive-eq")
- .help("Derive eq on any type. Enable this option also \
- enables --with-derive-partialeq"),
+ .help(
+ "Derive eq on any type. Enable this option also \
+ enables --with-derive-partialeq",
+ ),
Arg::with_name("with-derive-ord")
.long("with-derive-ord")
- .help("Derive ord on any type. Enable this option also \
- enables --with-derive-partialord"),
+ .help(
+ "Derive ord on any type. Enable this option also \
+ enables --with-derive-partialord",
+ ),
Arg::with_name("no-doc-comments")
.long("no-doc-comments")
- .help("Avoid including doc comments in the output, see: \
- https://github.com/rust-lang/rust-bindgen/issues/426"),
+ .help(
+ "Avoid including doc comments in the output, see: \
+ https://github.com/rust-lang/rust-bindgen/issues/426",
+ ),
Arg::with_name("no-recursive-whitelist")
.long("no-recursive-whitelist")
- .help("Disable whitelisting types recursively. This will cause \
- bindgen to emit Rust code that won't compile! See the \
- `bindgen::Builder::whitelist_recursively` method's \
- documentation for details."),
+ .help(
+ "Disable whitelisting types recursively. This will cause \
+ bindgen to emit Rust code that won't compile! See the \
+ `bindgen::Builder::whitelist_recursively` method's \
+ documentation for details.",
+ ),
Arg::with_name("objc-extern-crate")
.long("objc-extern-crate")
.help("Use extern crate instead of use for objc."),
@@ -148,23 +168,23 @@ where
Arg::with_name("distrust-clang-mangling")
.long("distrust-clang-mangling")
.help("Do not trust the libclang-provided mangling"),
- Arg::with_name("builtins")
- .long("builtins")
- .help("Output bindings for builtin definitions, e.g. \
- __builtin_va_list."),
+ Arg::with_name("builtins").long("builtins").help(
+ "Output bindings for builtin definitions, e.g. \
+ __builtin_va_list.",
+ ),
Arg::with_name("ctypes-prefix")
.long("ctypes-prefix")
- .help("Use the given prefix before raw types instead of \
- ::std::os::raw.")
+ .help(
+ "Use the given prefix before raw types instead of \
+ ::std::os::raw.",
+ )
.value_name("prefix")
.takes_value(true),
Arg::with_name("time-phases")
.long("time-phases")
.help("Time the different bindgen phases and print to stderr"),
// All positional arguments after the end of options marker, `--`
- Arg::with_name("clang-args")
- .last(true)
- .multiple(true),
+ Arg::with_name("clang-args").last(true).multiple(true),
Arg::with_name("emit-clang-ast")
.long("emit-clang-ast")
.help("Output the Clang AST for debugging purposes."),
@@ -181,18 +201,24 @@ where
.help("Enable support for C++ namespaces."),
Arg::with_name("disable-name-namespacing")
.long("disable-name-namespacing")
- .help("Disable namespacing via mangling, causing bindgen to \
- generate names like \"Baz\" instead of \"foo_bar_Baz\" \
- for an input name \"foo::bar::Baz\"."),
+ .help(
+ "Disable namespacing via mangling, causing bindgen to \
+ generate names like \"Baz\" instead of \"foo_bar_Baz\" \
+ for an input name \"foo::bar::Baz\".",
+ ),
Arg::with_name("ignore-functions")
.long("ignore-functions")
- .help("Do not generate bindings for functions or methods. This \
- is useful when you only care about struct layouts."),
+ .help(
+ "Do not generate bindings for functions or methods. This \
+ is useful when you only care about struct layouts.",
+ ),
Arg::with_name("generate")
.long("generate")
- .help("Generate only given items, split by commas. \
- Valid values are \"functions\",\"types\", \"vars\", \
- \"methods\", \"constructors\" and \"destructors\".")
+ .help(
+ "Generate only given items, split by commas. \
+ Valid values are \"functions\",\"types\", \"vars\", \
+ \"methods\", \"constructors\" and \"destructors\".",
+ )
.takes_value(true),
Arg::with_name("ignore-methods")
.long("ignore-methods")
@@ -237,16 +263,20 @@ where
.help("Use types from Rust core instead of std."),
Arg::with_name("conservative-inline-namespaces")
.long("conservative-inline-namespaces")
- .help("Conservatively generate inline namespaces to avoid name \
- conflicts."),
+ .help(
+ "Conservatively generate inline namespaces to avoid name \
+ conflicts.",
+ ),
Arg::with_name("use-msvc-mangling")
.long("use-msvc-mangling")
.help("MSVC C++ ABI mangling. DEPRECATED: Has no effect."),
Arg::with_name("whitelist-function")
.long("whitelist-function")
- .help("Whitelist all the free-standing functions matching \
- <regex>. Other non-whitelisted functions will not be \
- generated.")
+ .help(
+ "Whitelist all the free-standing functions matching \
+ <regex>. Other non-whitelisted functions will not be \
+ generated.",
+ )
.value_name("regex")
.takes_value(true)
.multiple(true)
@@ -256,17 +286,21 @@ where
.help("Generate inline functions."),
Arg::with_name("whitelist-type")
.long("whitelist-type")
- .help("Only generate types matching <regex>. Other non-whitelisted types will \
- not be generated.")
+ .help(
+ "Only generate types matching <regex>. Other non-whitelisted types will \
+ not be generated.",
+ )
.value_name("regex")
.takes_value(true)
.multiple(true)
.number_of_values(1),
Arg::with_name("whitelist-var")
.long("whitelist-var")
- .help("Whitelist all the free-standing variables matching \
- <regex>. Other non-whitelisted variables will not be \
- generated.")
+ .help(
+ "Whitelist all the free-standing variables matching \
+ <regex>. Other non-whitelisted variables will not be \
+ generated.",
+ )
.value_name("regex")
.takes_value(true)
.multiple(true)
@@ -276,27 +310,35 @@ where
.help("Print verbose error messages."),
Arg::with_name("dump-preprocessed-input")
.long("dump-preprocessed-input")
- .help("Preprocess and dump the input header files to disk. \
- Useful when debugging bindgen, using C-Reduce, or when \
- filing issues. The resulting file will be named \
- something like `__bindgen.i` or `__bindgen.ii`."),
+ .help(
+ "Preprocess and dump the input header files to disk. \
+ Useful when debugging bindgen, using C-Reduce, or when \
+ filing issues. The resulting file will be named \
+ something like `__bindgen.i` or `__bindgen.ii`.",
+ ),
Arg::with_name("no-record-matches")
.long("no-record-matches")
- .help("Do not record matching items in the regex sets. \
- This disables reporting of unused items."),
+ .help(
+ "Do not record matching items in the regex sets. \
+ This disables reporting of unused items.",
+ ),
Arg::with_name("no-rustfmt-bindings")
.long("no-rustfmt-bindings")
.help("Do not format the generated bindings with rustfmt."),
Arg::with_name("rustfmt-bindings")
.long("rustfmt-bindings")
- .help("Format the generated bindings with rustfmt. DEPRECATED: \
- --rustfmt-bindings is now enabled by default. Disable \
- with --no-rustfmt-bindings."),
+ .help(
+ "Format the generated bindings with rustfmt. DEPRECATED: \
+ --rustfmt-bindings is now enabled by default. Disable \
+ with --no-rustfmt-bindings.",
+ ),
Arg::with_name("rustfmt-configuration-file")
.long("rustfmt-configuration-file")
- .help("The absolute path to the rustfmt configuration file. \
- The configuration file will be used for formatting the bindings. \
- This parameter is incompatible with --no-rustfmt-bindings.")
+ .help(
+ "The absolute path to the rustfmt configuration file. \
+ The configuration file will be used for formatting the bindings. \
+ This parameter is incompatible with --no-rustfmt-bindings.",
+ )
.value_name("path")
.takes_value(true)
.multiple(false)
@@ -324,8 +366,10 @@ where
.number_of_values(1),
Arg::with_name("enable-function-attribute-detection")
.long("enable-function-attribute-detection")
- .help("Enables detecting unexposed attributes in functions (slow).
- Used to generate #[must_use] annotations."),
+ .help(
+ "Enables detecting unexposed attributes in functions (slow).
+ Used to generate #[must_use] annotations.",
+ ),
Arg::with_name("use-array-pointers-in-arguments")
.long("use-array-pointers-in-arguments")
.help("Use `*const [T; size]` instead of `*const T` for C arrays"),
@@ -345,7 +389,8 @@ where
writeln!(
&mut stderr(),
"warning: the `--unstable-rust` option is deprecated"
- ).expect("Unable to write error message");
+ )
+ .expect("Unable to write error message");
}
if let Some(rust_target) = matches.value_of("rust-target") {
@@ -624,7 +669,7 @@ where
if no_rustfmt_bindings {
return Err(Error::new(
ErrorKind::Other,
- "Cannot supply both --rustfmt-configuration-file and --no-rustfmt-bindings"
+ "Cannot supply both --rustfmt-configuration-file and --no-rustfmt-bindings",
));
}