diff options
author | Pierre-Antoine Rault <par@rigelk.eu> | 2017-06-19 01:09:33 +0200 |
---|---|---|
committer | Pierre-Antoine Rault <par@rigelk.eu> | 2017-06-19 23:35:07 +0200 |
commit | 41db162348a51dc2a06901efc4fa6bc1e7f31b14 (patch) | |
tree | 68302d940f6d0ee89b67b88cbe7dfac31ba16876 | |
parent | d37fe132be5350ed1477b4e578a5d1b70c583666 (diff) |
switch defaults from generating unstable Rust to generating stable Rust
- changing the Builder::no_unstable_rust method to the Builder::unstable_rust method
- changing the --no-unstable-rust flag to a --unstable-rust flag in src/options.rs
- changing bindgen-flags header in the test headers to remove the --no-unstable-rust flag
Fixes #757
-rw-r--r-- | bindgen-integration/build.rs | 1 | ||||
-rw-r--r-- | book/src/tutorial-3.md | 4 | ||||
-rw-r--r-- | book/src/using-unions.md | 10 | ||||
-rw-r--r-- | src/lib.rs | 8 | ||||
-rw-r--r-- | src/options.rs | 10 | ||||
-rw-r--r-- | tests/headers/jsval_layout_opaque.hpp | 2 | ||||
-rw-r--r-- | tests/headers/only_bitfields.hpp | 1 | ||||
-rw-r--r-- | tests/headers/struct_with_bitfields.h | 1 | ||||
-rw-r--r-- | tests/headers/union_with_anon_struct_bitfield.h | 1 | ||||
-rw-r--r-- | tests/headers/weird_bitfields.hpp | 1 | ||||
-rwxr-xr-x | tests/test-one.sh | 2 | ||||
-rw-r--r-- | tests/tests.rs | 3 |
12 files changed, 18 insertions, 26 deletions
diff --git a/bindgen-integration/build.rs b/bindgen-integration/build.rs index b715486c..7107d04b 100644 --- a/bindgen-integration/build.rs +++ b/bindgen-integration/build.rs @@ -28,7 +28,6 @@ fn main() { let macros = Arc::new(RwLock::new(HashSet::new())); let bindings = Builder::default() - .no_unstable_rust() .enable_cxx_namespaces() .raw_line("pub use self::root::*;") .header("cpp/Test.h") diff --git a/book/src/tutorial-3.md b/book/src/tutorial-3.md index a6a7135e..41197aa0 100644 --- a/book/src/tutorial-3.md +++ b/book/src/tutorial-3.md @@ -22,10 +22,6 @@ fn main() { // to bindgen, and lets you build up options for // the resulting bindings. let bindings = bindgen::Builder::default() - // Do not generate unstable Rust code that - // requires a nightly rustc and enabling - // unstable features. - .no_unstable_rust() // The input header we would like to generate // bindings for. .header("wrapper.h") diff --git a/book/src/using-unions.md b/book/src/using-unions.md index 66ba6d13..9ee10a92 100644 --- a/book/src/using-unions.md +++ b/book/src/using-unions.md @@ -1,6 +1,8 @@ # Using the Union Types Generated by Bindgen -**NOTE:** As of Rust version 1.17, Rust does not have a stable `union` type. Issue [#32836](https://github.com/rust-lang/rust/issues/32836) tracks the stabilization of a `union` type in Rust. By default, bindgen will generate the preliminary unstable `union` type, unless the flag `--no-unstable-rust` flag is used. +**NOTE:** As of Rust version 1.17, Rust does not have a stable `union` type. Issue [#32836](https://github.com/rust-lang/rust/issues/32836) tracks the stabilization of a `union` type in Rust. + +By using the flag `--unstable-rust`, bindgen will generate the preliminary unstable `union` type. In general, most interactions with unions (either reading or writing) are unsafe. @@ -29,12 +31,12 @@ typedef union { ### Library -* [`bindgen::Builder::no_unstable_rust()`](https://docs.rs/bindgen/0.25.3/bindgen/struct.Builder.html#method.no_unstable_rust) +* [`bindgen::Builder::unstable_rust()`](https://docs.rs/bindgen/0.25.3/bindgen/struct.Builder.html#method.unstable_rust) * [`bindgen::Builder::derive_default()`](https://docs.rs/bindgen/0.25.3/bindgen/struct.Builder.html#method.derive_default) ### Command Line -* `--no-unstable-rust` +* `--unstable-rust` * `--with-derive-default` ## Using the unstable `union` version @@ -129,4 +131,4 @@ error[E0308]: mismatched types | = note: expected type `bindings::__BindgenUnionField<bindings::alpha_t>` found type `bindings::alpha_t` -```
\ No newline at end of file +``` @@ -333,7 +333,7 @@ impl Builder { } if !self.options.unstable_rust { - output_vector.push("--no-unstable-rust".into()); + output_vector.push("--unstable-rust".into()); } self.options @@ -736,8 +736,8 @@ impl Builder { } /// Avoid generating any unstable Rust, such as Rust unions, in the generated bindings. - pub fn no_unstable_rust(mut self) -> Builder { - self.options.unstable_rust = false; + pub fn unstable_rust(mut self, doit: bool) -> Self { + self.options.unstable_rust = doit; self } @@ -959,7 +959,7 @@ impl Default for BindgenOptions { derive_default: false, enable_cxx_namespaces: false, disable_name_namespacing: false, - unstable_rust: true, + unstable_rust: false, use_core: false, ctypes_prefix: None, namespaced_constants: true, diff --git a/src/options.rs b/src/options.rs index bbf9c0dd..fc0dd247 100644 --- a/src/options.rs +++ b/src/options.rs @@ -135,9 +135,9 @@ pub fn builder_from_flags<I> Arg::with_name("no-prepend-enum-name") .long("no-prepend-enum-name") .help("Do not prepend the enum name to bitfield or constant variants."), - Arg::with_name("no-unstable-rust") - .long("no-unstable-rust") - .help("Do not generate unstable Rust code.") + Arg::with_name("unstable-rust") + .long("unstable-rust") + .help("Generate unstable Rust code.") .multiple(true), // FIXME: Pass legacy test suite Arg::with_name("opaque-type") .long("opaque-type") @@ -325,8 +325,8 @@ pub fn builder_from_flags<I> builder = builder.ignore_methods(); } - if matches.is_present("no-unstable-rust") { - builder = builder.no_unstable_rust(); + if matches.is_present("unstable-rust") { + builder = builder.unstable_rust(true); } if matches.is_present("no-convert-floats") { diff --git a/tests/headers/jsval_layout_opaque.hpp b/tests/headers/jsval_layout_opaque.hpp index 85c5be63..8f36f77d 100644 --- a/tests/headers/jsval_layout_opaque.hpp +++ b/tests/headers/jsval_layout_opaque.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --no-unstable-rust -- -std=c++11 +// bindgen-flags: -- -std=c++11 /** * These typedefs are hacky, but keep our tests consistent across 64-bit diff --git a/tests/headers/only_bitfields.hpp b/tests/headers/only_bitfields.hpp index 84db0586..793bc66b 100644 --- a/tests/headers/only_bitfields.hpp +++ b/tests/headers/only_bitfields.hpp @@ -1,4 +1,3 @@ -// bindgen-flags: --no-unstable-rust class C { bool a: 1; bool b: 7; diff --git a/tests/headers/struct_with_bitfields.h b/tests/headers/struct_with_bitfields.h index 107fb136..ece512cd 100644 --- a/tests/headers/struct_with_bitfields.h +++ b/tests/headers/struct_with_bitfields.h @@ -1,4 +1,3 @@ -// bindgen-flags: --no-unstable-rust struct bitfield { unsigned short a :1, diff --git a/tests/headers/union_with_anon_struct_bitfield.h b/tests/headers/union_with_anon_struct_bitfield.h index 24c7dce8..9668ce40 100644 --- a/tests/headers/union_with_anon_struct_bitfield.h +++ b/tests/headers/union_with_anon_struct_bitfield.h @@ -1,4 +1,3 @@ -// bindgen-flags: --no-unstable-rust union foo { int a; struct { diff --git a/tests/headers/weird_bitfields.hpp b/tests/headers/weird_bitfields.hpp index 755681c1..68cbf4a5 100644 --- a/tests/headers/weird_bitfields.hpp +++ b/tests/headers/weird_bitfields.hpp @@ -1,4 +1,3 @@ -// bindgen-flags: --no-unstable-rust // You can guess where this is taken from... enum nsStyleSVGOpacitySource { eStyleSVGOpacitySource_Normal, diff --git a/tests/test-one.sh b/tests/test-one.sh index ac466164..16fe1f12 100755 --- a/tests/test-one.sh +++ b/tests/test-one.sh @@ -24,7 +24,7 @@ TEST_BINDINGS_BINARY=$(mktemp -t bindings.XXXXXX) FLAGS="$(grep "// bindgen-flags: " "$TEST" || echo)" FLAGS="${FLAGS/\/\/ bindgen\-flags:/}" # Prepend the default flags added in test.rs's `create_bindgen_builder`. -FLAGS="--no-unstable-rust --with-derive-default --raw-line '' --raw-line '#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]' --raw-line '' $FLAGS" +FLAGS="--with-derive-default --raw-line '' --raw-line '#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]' --raw-line '' $FLAGS" eval ./target/debug/bindgen \ diff --git a/tests/tests.rs b/tests/tests.rs index 46f83155..c1d79954 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -146,7 +146,7 @@ fn create_bindgen_builder(header: &PathBuf) -> Result<Option<Builder>, Error> { .chain(flags.into_iter()); builder_from_flags(args) - .map(|(builder, _, _)| Some(builder.no_unstable_rust())) + .map(|(builder, _, _)| Some(builder)) } macro_rules! test_header { @@ -177,7 +177,6 @@ include!(concat!(env!("OUT_DIR"), "/tests.rs")); fn test_header_contents() { let bindings = builder() .header_contents("test.h", "int foo(const char* a);") - .no_unstable_rust() .generate() .unwrap() .to_string(); |