diff options
Diffstat (limited to 'src/options.rs')
-rw-r--r-- | src/options.rs | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/src/options.rs b/src/options.rs index 8fce0586..28faea99 100644 --- a/src/options.rs +++ b/src/options.rs @@ -1,7 +1,9 @@ -use bindgen::{builder, Builder, CodegenConfig}; + +use bindgen::{Builder, CodegenConfig, RUST_TARGET_STRINGS, RustTarget, builder}; use clap::{App, Arg}; use std::fs::File; -use std::io::{self, Error, ErrorKind}; +use std::io::{self, Error, ErrorKind, Write, stderr}; +use std::str::FromStr; /// Construct a new [`Builder`](./struct.Builder.html) from command line flags. pub fn builder_from_flags<I>( @@ -10,6 +12,10 @@ pub fn builder_from_flags<I>( where I: Iterator<Item = String>, { + let rust_target_help = format!( + "Version of the Rust compiler to target. Valid options are: {:?}.", + RUST_TARGET_STRINGS); + let matches = App::new("bindgen") .version(env!("CARGO_PKG_VERSION")) .about("Generates Rust bindings from C/C++ headers.") @@ -148,7 +154,7 @@ where .help("Do not prepend the enum name to bitfield or constant variants."), Arg::with_name("unstable-rust") .long("unstable-rust") - .help("Generate unstable Rust code.") + .help("Generate unstable Rust code (deprecated; use --rust-target instead).") .multiple(true), // FIXME: Pass legacy test suite Arg::with_name("opaque-type") .long("opaque-type") @@ -168,6 +174,10 @@ where .takes_value(true) .multiple(true) .number_of_values(1), + Arg::with_name("rust-target") + .long("rust-target") + .help(&rust_target_help) + .takes_value(true), Arg::with_name("static") .long("static-link") .help("Link to static library.") @@ -233,6 +243,16 @@ where return Err(Error::new(ErrorKind::Other, "Header not found")); } + if matches.is_present("unstable-rust") { + builder = builder.rust_target(RustTarget::Nightly); + writeln!(&mut stderr(), "warning: the `--unstable-rust` option is deprecated") + .expect("Unable to write error message"); + } + + if let Some(rust_target) = matches.value_of("rust-target") { + builder = builder.rust_target(RustTarget::from_str(rust_target)?); + } + if let Some(bitfields) = matches.values_of("bitfield-enum") { for regex in bitfields { builder = builder.bitfield_enum(regex); @@ -353,10 +373,6 @@ where builder = builder.ignore_methods(); } - if matches.is_present("unstable-rust") { - builder = builder.unstable_rust(true); - } - if matches.is_present("no-convert-floats") { builder = builder.no_convert_floats(); } |