summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2017-01-24 13:31:53 -0800
committerGitHub <noreply@github.com>2017-01-24 13:31:53 -0800
commit0c07e9e70d924806a1f3c05491444c6564b866a0 (patch)
tree6b9b692ed3b7ebf09fbddc962341b32f1d192f9e
parent0318b741087d45396618eca163274b916e17ccab (diff)
parent5d8019b7dc2f0581fc560fbc12d504c516a8476d (diff)
Auto merge of #434 - emilio:no-derive-debug, r=fitzgen
Honor and expose the derive_debug option. Fixes #432 r? @fitzgen
-rw-r--r--src/ir/item.rs2
-rw-r--r--src/lib.rs6
-rw-r--r--src/options.rs7
-rw-r--r--tests/expectations/tests/no-derive-debug.rs26
-rw-r--r--tests/headers/no-derive-debug.h15
5 files changed, 55 insertions, 1 deletions
diff --git a/src/ir/item.rs b/src/ir/item.rs
index ac2d122e..7b18b331 100644
--- a/src/ir/item.rs
+++ b/src/ir/item.rs
@@ -219,7 +219,7 @@ impl CanDeriveDebug for Item {
type Extra = ();
fn can_derive_debug(&self, ctx: &BindgenContext, _: ()) -> bool {
- match self.kind {
+ ctx.options().derive_debug && match self.kind {
ItemKind::Type(ref ty) => {
if self.is_opaque(ctx) {
ty.layout(ctx)
diff --git a/src/lib.rs b/src/lib.rs
index 88da1a48..bb621718 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -268,6 +268,12 @@ impl Builder {
self
}
+ /// Set whether `Debug` should be derived by default.
+ pub fn derive_debug(mut self, doit: bool) -> Self {
+ self.options.derive_debug = doit;
+ self
+ }
+
/// Emit Clang AST.
pub fn emit_clang_ast(mut self) -> Builder {
self.options.emit_ast = true;
diff --git a/src/options.rs b/src/options.rs
index 3456bfea..c5c80d63 100644
--- a/src/options.rs
+++ b/src/options.rs
@@ -31,6 +31,9 @@ pub fn builder_from_flags<I>(args: I)
.takes_value(true)
.multiple(true)
.number_of_values(1),
+ Arg::with_name("no-derive-debug")
+ .long("no-derive-debug")
+ .help("Avoid deriving Debug on any type."),
Arg::with_name("builtins")
.long("builtins")
.help("Output bindings for builtin definitions, e.g. \
@@ -181,6 +184,10 @@ pub fn builder_from_flags<I>(args: I)
builder = builder.emit_builtins();
}
+ if matches.is_present("no-derive-debug") {
+ builder = builder.derive_debug(false);
+ }
+
if let Some(prefix) = matches.value_of("ctypes-prefix") {
builder = builder.ctypes_prefix(prefix);
}
diff --git a/tests/expectations/tests/no-derive-debug.rs b/tests/expectations/tests/no-derive-debug.rs
new file mode 100644
index 00000000..e45b2678
--- /dev/null
+++ b/tests/expectations/tests/no-derive-debug.rs
@@ -0,0 +1,26 @@
+/* automatically generated by rust-bindgen */
+
+
+#![allow(non_snake_case)]
+
+#[repr(C)] #[derive(Copy, Clone)] pub struct foo { bar: ::std::os::raw::c_int, }
+
+/**
+ * bar should compile. It will normally derive debug, but our blacklist of foo
+ * and replacement for another type that doesn't implement it would prevent it
+ * from building if --no-derive-debug didn't work.
+ */
+#[repr(C)]
+#[derive(Copy)]
+pub struct bar {
+ pub foo: foo,
+ pub baz: ::std::os::raw::c_int,
+}
+#[test]
+fn bindgen_test_layout_bar() {
+ assert_eq!(::std::mem::size_of::<bar>() , 8usize);
+ assert_eq!(::std::mem::align_of::<bar>() , 4usize);
+}
+impl Clone for bar {
+ fn clone(&self) -> Self { *self }
+}
diff --git a/tests/headers/no-derive-debug.h b/tests/headers/no-derive-debug.h
new file mode 100644
index 00000000..4a49e404
--- /dev/null
+++ b/tests/headers/no-derive-debug.h
@@ -0,0 +1,15 @@
+// bindgen-flags: --no-derive-debug --blacklist-type foo --raw-line "#[repr(C)] #[derive(Copy, Clone)] pub struct foo { bar: ::std::os::raw::c_int, }"
+
+struct foo {
+ int bar;
+};
+
+/**
+ * bar should compile. It will normally derive debug, but our blacklist of foo
+ * and replacement for another type that doesn't implement it would prevent it
+ * from building if --no-derive-debug didn't work.
+ */
+struct bar {
+ struct foo foo;
+ int baz;
+};