Add flag to ignore type blocklist when computing derive information

Fixes #1454
This commit is contained in:
Jethro Beekman 2021-03-09 23:03:29 +01:00 committed by Emilio Cobos Álvarez
parent af87a859ac
commit 7286c815f8
5 changed files with 117 additions and 2 deletions

View File

@ -138,8 +138,9 @@ impl<'ctx> CannotDerive<'ctx> {
}
fn constrain_type(&mut self, item: &Item, ty: &Type) -> CanDerive {
if !self.ctx.allowlisted_items().contains(&item.id()) {
trace!(
if !self.ctx.options().derive_ignore_blocklist &&
!self.ctx.allowlisted_items().contains(&item.id())
{ trace!(
" cannot derive {} for blocklisted type",
self.derive_trait
);

View File

@ -549,6 +549,10 @@ impl Builder {
output_vector.push("--respect-cxx-access-specs".into());
}
if self.options.derive_ignore_blocklist {
output_vector.push("--derive-ignore-blocklist".into());
}
// Add clang arguments
output_vector.push("--".into());
@ -1568,6 +1572,12 @@ impl Builder {
self.options.respect_cxx_access_specs = doit;
self
}
/// Ignore the type blocklist when computing type derive information
pub fn derive_ignore_blocklist(mut self, doit: bool) -> Self {
self.options.derive_ignore_blocklist = doit;
self
}
}
/// Configuration options for generated bindings.
@ -1859,6 +1869,9 @@ struct BindgenOptions {
/// Only make generated bindings `pub` if the items would be publically accessible
/// by C++.
respect_cxx_access_specs: bool,
/// Ignore the type blocklist when computing type derive information
derive_ignore_blocklist: bool,
}
/// TODO(emilio): This is sort of a lie (see the error message that results from
@ -1996,6 +2009,7 @@ impl Default for BindgenOptions {
wasm_import_module_name: None,
dynamic_library_name: None,
respect_cxx_access_specs: false,
derive_ignore_blocklist: false,
}
}
}

View File

@ -503,6 +503,9 @@ where
Arg::with_name("respect-cxx-access-specs")
.long("respect-cxx-access-specs")
.help("Makes generated bindings `pub` only for items if the items are publically accessible in C++."),
Arg::with_name("derive-ignore-blocklist")
.long("derive-ignore-blocklist")
.help("Ignore the type blocklist when computing type derive information"),
]) // .args()
.get_matches_from(args);
@ -929,6 +932,10 @@ where
builder = builder.respect_cxx_access_specs(true);
}
if matches.is_present("derive-ignore-blocklist") {
builder = builder.derive_ignore_blocklist(true);
}
let verbose = matches.is_present("verbose");
Ok((builder, output, verbose))

View File

@ -0,0 +1,81 @@
#![allow(
dead_code,
non_snake_case,
non_camel_case_types,
non_upper_case_globals
)]
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct rlimit;
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct my_rlimit_conf {
pub core: rlimit,
pub cpu: rlimit,
pub data: rlimit,
pub fsize: rlimit,
}
#[test]
fn bindgen_test_layout_my_rlimit_conf() {
assert_eq!(
::std::mem::size_of::<my_rlimit_conf>(),
0usize,
concat!("Size of: ", stringify!(my_rlimit_conf))
);
assert_eq!(
::std::mem::align_of::<my_rlimit_conf>(),
1usize,
concat!("Alignment of ", stringify!(my_rlimit_conf))
);
assert_eq!(
unsafe {
&(*(::std::ptr::null::<my_rlimit_conf>())).core as *const _ as usize
},
0usize,
concat!(
"Offset of field: ",
stringify!(my_rlimit_conf),
"::",
stringify!(core)
)
);
assert_eq!(
unsafe {
&(*(::std::ptr::null::<my_rlimit_conf>())).cpu as *const _ as usize
},
0usize,
concat!(
"Offset of field: ",
stringify!(my_rlimit_conf),
"::",
stringify!(cpu)
)
);
assert_eq!(
unsafe {
&(*(::std::ptr::null::<my_rlimit_conf>())).data as *const _ as usize
},
0usize,
concat!(
"Offset of field: ",
stringify!(my_rlimit_conf),
"::",
stringify!(data)
)
);
assert_eq!(
unsafe {
&(*(::std::ptr::null::<my_rlimit_conf>())).fsize as *const _
as usize
},
0usize,
concat!(
"Offset of field: ",
stringify!(my_rlimit_conf),
"::",
stringify!(fsize)
)
);
}

View File

@ -0,0 +1,12 @@
// bindgen-flags: --no-recursive-allowlist --allowlist-type "my_rlimit_conf" --derive-ignore-blocklist --raw-line "#[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct rlimit;"
struct rlimit {};
typedef struct
{
struct rlimit core;
struct rlimit cpu;
struct rlimit data;
struct rlimit fsize;
}
my_rlimit_conf;