File tree 5 files changed +55
-1
lines changed
5 files changed +55
-1
lines changed Original file line number Diff line number Diff line change @@ -219,7 +219,7 @@ impl CanDeriveDebug for Item {
219
219
type Extra = ( ) ;
220
220
221
221
fn can_derive_debug ( & self , ctx : & BindgenContext , _: ( ) ) -> bool {
222
- match self . kind {
222
+ ctx . options ( ) . derive_debug && match self . kind {
223
223
ItemKind :: Type ( ref ty) => {
224
224
if self . is_opaque ( ctx) {
225
225
ty. layout ( ctx)
Original file line number Diff line number Diff line change @@ -268,6 +268,12 @@ impl Builder {
268
268
self
269
269
}
270
270
271
+ /// Set whether `Debug` should be derived by default.
272
+ pub fn derive_debug ( mut self , doit : bool ) -> Self {
273
+ self . options . derive_debug = doit;
274
+ self
275
+ }
276
+
271
277
/// Emit Clang AST.
272
278
pub fn emit_clang_ast ( mut self ) -> Builder {
273
279
self . options . emit_ast = true ;
Original file line number Diff line number Diff line change @@ -31,6 +31,9 @@ pub fn builder_from_flags<I>(args: I)
31
31
. takes_value ( true )
32
32
. multiple ( true )
33
33
. number_of_values ( 1 ) ,
34
+ Arg :: with_name ( "no-derive-debug" )
35
+ . long ( "no-derive-debug" )
36
+ . help ( "Avoid deriving Debug on any type." ) ,
34
37
Arg :: with_name ( "builtins" )
35
38
. long ( "builtins" )
36
39
. help ( "Output bindings for builtin definitions, e.g. \
@@ -181,6 +184,10 @@ pub fn builder_from_flags<I>(args: I)
181
184
builder = builder. emit_builtins ( ) ;
182
185
}
183
186
187
+ if matches. is_present ( "no-derive-debug" ) {
188
+ builder = builder. derive_debug ( false ) ;
189
+ }
190
+
184
191
if let Some ( prefix) = matches. value_of ( "ctypes-prefix" ) {
185
192
builder = builder. ctypes_prefix ( prefix) ;
186
193
}
Original file line number Diff line number Diff line change
1
+ /* automatically generated by rust-bindgen */
2
+
3
+
4
+ #![ allow( non_snake_case) ]
5
+
6
+ #[ repr( C ) ] #[ derive( Copy , Clone ) ] pub struct foo { bar : :: std:: os:: raw:: c_int , }
7
+
8
+ /**
9
+ * bar should compile. It will normally derive debug, but our blacklist of foo
10
+ * and replacement for another type that doesn't implement it would prevent it
11
+ * from building if --no-derive-debug didn't work.
12
+ */
13
+ #[ repr( C ) ]
14
+ #[ derive( Copy ) ]
15
+ pub struct bar {
16
+ pub foo : foo ,
17
+ pub baz : :: std:: os:: raw:: c_int ,
18
+ }
19
+ #[ test]
20
+ fn bindgen_test_layout_bar ( ) {
21
+ assert_eq ! ( :: std:: mem:: size_of:: <bar>( ) , 8usize ) ;
22
+ assert_eq ! ( :: std:: mem:: align_of:: <bar>( ) , 4usize ) ;
23
+ }
24
+ impl Clone for bar {
25
+ fn clone ( & self ) -> Self { * self }
26
+ }
Original file line number Diff line number Diff line change
1
+ // bindgen-flags: --no-derive-debug --blacklist-type foo --raw-line "#[repr(C)] #[derive(Copy, Clone)] pub struct foo { bar: ::std::os::raw::c_int, }"
2
+
3
+ struct foo {
4
+ int bar;
5
+ };
6
+
7
+ /* *
8
+ * bar should compile. It will normally derive debug, but our blacklist of foo
9
+ * and replacement for another type that doesn't implement it would prevent it
10
+ * from building if --no-derive-debug didn't work.
11
+ */
12
+ struct bar {
13
+ struct foo foo;
14
+ int baz;
15
+ };
You can’t perform that action at this time.
0 commit comments