Skip to content

Commit

Permalink
fix: only emit cfg attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
oberrich committed Feb 5, 2025
1 parent 0920eee commit e48a074
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion bindgen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ readme = "../README.md"
repository = "https://github.com/rust-lang/rust-bindgen"
documentation = "https://docs.rs/bindgen"
homepage = "https://rust-lang.github.io/rust-bindgen/"
version = "0.71.1"
version = "0.69.5"
build = "build.rs"
rust-version.workspace = true
edition.workspace = true
Expand Down
25 changes: 19 additions & 6 deletions bindgen/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1119,7 +1119,8 @@ impl CodeGenerator for Type {
attrs.extend(
parse_tokens(inner_attrs)
.into_iter()
.map(|attr| parse_quote! { #attr })
.filter(|t| !t.is_empty())
.map(|t| parse_quote! {#t})
.filter_map(|attr: Attribute| {
if attr.path().is_ident("cfg") ||
attr.path().is_ident("link")
Expand Down Expand Up @@ -2663,6 +2664,17 @@ impl CodeGenerator for CompInfo {
},
);

// TODO: Make `cfg_attrs`
let cfg_attrs = attrs
.iter()
.filter(|t| !t.is_empty())
.map(|t| parse_quote! {#t})
.filter(|attr: &Attribute| {
let path = attr.path();
path.is_ident("cfg") || path.is_ident("link")
})
.collect::<Vec<_>>();

let mut tokens = if is_rust_union {
quote! {
#( #attrs )*
Expand Down Expand Up @@ -2869,14 +2881,15 @@ impl CodeGenerator for CompInfo {

if needs_clone_impl {
result.push(quote! {
#( #attrs )*
#( #cfg_attrs )*
impl #impl_generics_labels Clone for #ty_for_impl {
fn clone(&self) -> Self { *self }
}
});
}

if needs_flexarray_impl {
// TODO: Potentially add cfg_attrs
result.push(self.generate_flexarray(
ctx,
&canonical_ident,
Expand Down Expand Up @@ -2910,7 +2923,7 @@ impl CodeGenerator for CompInfo {
// non-zero padding bytes, especially when forwards/backwards compatibility is
// involved.
result.push(quote! {
#( #attrs )*
#( #cfg_attrs )*
impl #impl_generics_labels Default for #ty_for_impl {
fn default() -> Self {
#body
Expand All @@ -2930,7 +2943,7 @@ impl CodeGenerator for CompInfo {
let prefix = ctx.trait_prefix();

result.push(quote! {
#( #attrs )*
#( #cfg_attrs )*
impl #impl_generics_labels ::#prefix::fmt::Debug for #ty_for_impl {
#impl_
}
Expand All @@ -2955,7 +2968,7 @@ impl CodeGenerator for CompInfo {

let prefix = ctx.trait_prefix();
result.push(quote! {
#( #attrs )*
#( #cfg_attrs )*
impl #impl_generics_labels ::#prefix::cmp::PartialEq for #ty_for_impl #partialeq_bounds {
#impl_
}
Expand All @@ -2965,7 +2978,7 @@ impl CodeGenerator for CompInfo {

if !methods.is_empty() {
result.push(quote! {
#( #attrs )*
#( #cfg_attrs )*
impl #impl_generics_labels #ty_for_impl {
#( #methods )*
}
Expand Down

0 comments on commit e48a074

Please sign in to comment.