Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

defines is not applied for impl const #955

Open
youknowone opened this issue May 17, 2024 · 1 comment · May be fixed by #956 or #989
Open

defines is not applied for impl const #955

youknowone opened this issue May 17, 2024 · 1 comment · May be fixed by #956 or #989

Comments

@youknowone
Copy link
Contributor

youknowone commented May 17, 2024

source (x.rs):

#[repr(C)]
pub struct Foo {
    a: i32,
    #[cfg(feature = "feat")]
    b: i32,
}

impl Foo {
    pub const ZEROED: Self = Self {
        a: 0,
        #[cfg(feature = "feat")]
        b: 0,
    };
}

cbindgen.toml:

[export]
include=["Foo"]

[defines]
"feature = feat" = "FEAT"

command:

cbindgen --config cbindgen.toml x.rs

actual result:

#include <cstdarg>
#include <cstdint>
#include <cstdlib>
#include <ostream>
#include <new>

struct Foo {
  int32_t a;
#if defined(FEAT)
  int32_t b
#endif
  ;
};
constexpr static const Foo Foo_ZEROED = Foo{ /* .a = */ 0, /* .b = */ 0 };

expected result:

#include <cstdarg>
#include <cstdint>
#include <cstdlib>
#include <ostream>
#include <new>

struct Foo {
  int32_t a;
#if defined(FEAT)
  int32_t b
#endif
  ;
};
constexpr static const Foo Foo_ZEROED = Foo{
  /* .a = */ 0,
#if defined(FEAT)
  /* .b = */ 0
#endif
};
@youknowone
Copy link
Contributor Author

maybe related to #937

@youknowone youknowone linked a pull request May 17, 2024 that will close this issue
@youknowone youknowone linked a pull request Aug 10, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant