Skip to content

defines is not applied for impl const #955

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

Closed
youknowone opened this issue May 17, 2024 · 3 comments · Fixed by #989 · May be fixed by #956
Closed

defines is not applied for impl const #955

youknowone opened this issue May 17, 2024 · 3 comments · Fixed by #989 · May be fixed by #956

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

@nicoburns
Copy link

I'm also running into this trying to conditionally compile an associated const for servo/gecko. cbindgen generates both and then the build fails because there is a duplicate constant.

@youknowone
Copy link
Contributor Author

@nicoburns if you can use constexpr, applying #989 will work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants