From 4bfc138f1d27dd4588a4ffee812f57bf6ab2a6e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Tue, 7 Oct 2025 09:50:02 +0200 Subject: [PATCH 1/2] tests: Add a test for bitflags + disjoint cfg. Came up in https://phabricator.services.mozilla.com/D267702. Seems to provide the right behavior? --- tests/expectations/cfg.c | 22 ++++++++++ tests/expectations/cfg.compat.c | 22 ++++++++++ tests/expectations/cfg.cpp | 66 ++++++++++++++++++++++++++++ tests/expectations/cfg.pyx | 15 +++++++ tests/expectations/cfg_both.c | 22 ++++++++++ tests/expectations/cfg_both.compat.c | 22 ++++++++++ tests/expectations/cfg_tag.c | 22 ++++++++++ tests/expectations/cfg_tag.compat.c | 22 ++++++++++ tests/expectations/cfg_tag.pyx | 15 +++++++ tests/rust/cfg.rs | 20 +++++++++ tests/rust/cfg.toml | 4 ++ 11 files changed, 252 insertions(+) diff --git a/tests/expectations/cfg.c b/tests/expectations/cfg.c index 800b518f6..8d79e5c0e 100644 --- a/tests/expectations/cfg.c +++ b/tests/expectations/cfg.c @@ -4,6 +4,7 @@ DEF PLATFORM_WIN = 0 DEF X11 = 0 DEF M_32 = 0 #endif +#define PLATFORM_UNIX 1 #include @@ -29,9 +30,30 @@ enum FooType { typedef uint32_t FooType; #endif +typedef struct { + uint8_t _0; +} Flags; +/** + * none + */ +#define Flags_NONE (Flags){ ._0 = (uint8_t)0 } +#if defined(PLATFORM_WIN) +#define Flags_A (Flags){ ._0 = (uint8_t)(1 << 0) } +#endif +#if defined(PLATFORM_UNIX) +#define Flags_A (Flags){ ._0 = (uint8_t)(1 << 1) } +#endif +#if defined(PLATFORM_WIN) +#define Flags_B (Flags){ ._0 = (uint8_t)((Flags_A)._0 | (1 << 3)) } +#endif +#if defined(PLATFORM_UNIX) +#define Flags_B (Flags){ ._0 = (uint8_t)((Flags_A)._0 | (1 << 4)) } +#endif + #if (defined(PLATFORM_UNIX) && defined(X11)) typedef struct { FooType ty; + Flags flags; int32_t x; float y; } FooHandle; diff --git a/tests/expectations/cfg.compat.c b/tests/expectations/cfg.compat.c index 6a4574357..741ec0894 100644 --- a/tests/expectations/cfg.compat.c +++ b/tests/expectations/cfg.compat.c @@ -4,6 +4,7 @@ DEF PLATFORM_WIN = 0 DEF X11 = 0 DEF M_32 = 0 #endif +#define PLATFORM_UNIX 1 #include @@ -41,9 +42,30 @@ typedef uint32_t FooType; #endif // __cplusplus #endif +typedef struct { + uint8_t _0; +} Flags; +/** + * none + */ +#define Flags_NONE (Flags){ ._0 = (uint8_t)0 } +#if defined(PLATFORM_WIN) +#define Flags_A (Flags){ ._0 = (uint8_t)(1 << 0) } +#endif +#if defined(PLATFORM_UNIX) +#define Flags_A (Flags){ ._0 = (uint8_t)(1 << 1) } +#endif +#if defined(PLATFORM_WIN) +#define Flags_B (Flags){ ._0 = (uint8_t)((Flags_A)._0 | (1 << 3)) } +#endif +#if defined(PLATFORM_UNIX) +#define Flags_B (Flags){ ._0 = (uint8_t)((Flags_A)._0 | (1 << 4)) } +#endif + #if (defined(PLATFORM_UNIX) && defined(X11)) typedef struct { FooType ty; + Flags flags; int32_t x; float y; } FooHandle; diff --git a/tests/expectations/cfg.cpp b/tests/expectations/cfg.cpp index 1eed9afd2..c9038c637 100644 --- a/tests/expectations/cfg.cpp +++ b/tests/expectations/cfg.cpp @@ -4,6 +4,7 @@ DEF PLATFORM_WIN = 0 DEF X11 = 0 DEF M_32 = 0 #endif +#define PLATFORM_UNIX 1 #include @@ -28,19 +29,84 @@ enum class FooType : uint32_t { }; #endif +struct Flags { + uint8_t _0; + + constexpr explicit operator bool() const { + return !!_0; + } + constexpr Flags operator~() const { + return Flags { static_cast(~_0) }; + } + constexpr Flags operator|(const Flags& other) const { + return Flags { static_cast(this->_0 | other._0) }; + } + Flags& operator|=(const Flags& other) { + *this = (*this | other); + return *this; + } + constexpr Flags operator&(const Flags& other) const { + return Flags { static_cast(this->_0 & other._0) }; + } + Flags& operator&=(const Flags& other) { + *this = (*this & other); + return *this; + } + constexpr Flags operator^(const Flags& other) const { + return Flags { static_cast(this->_0 ^ other._0) }; + } + Flags& operator^=(const Flags& other) { + *this = (*this ^ other); + return *this; + } + bool operator==(const Flags& other) const { + return _0 == other._0; + } + bool operator!=(const Flags& other) const { + return _0 != other._0; + } +}; +/// none +constexpr static const Flags Flags_NONE = Flags{ + /* ._0 = */ (uint8_t)0 +}; +#if defined(PLATFORM_WIN) +constexpr static const Flags Flags_A = Flags{ + /* ._0 = */ (uint8_t)(1 << 0) +}; +#endif +#if defined(PLATFORM_UNIX) +constexpr static const Flags Flags_A = Flags{ + /* ._0 = */ (uint8_t)(1 << 1) +}; +#endif +#if defined(PLATFORM_WIN) +constexpr static const Flags Flags_B = Flags{ + /* ._0 = */ (uint8_t)((Flags_A)._0 | (1 << 3)) +}; +#endif +#if defined(PLATFORM_UNIX) +constexpr static const Flags Flags_B = Flags{ + /* ._0 = */ (uint8_t)((Flags_A)._0 | (1 << 4)) +}; +#endif + #if (defined(PLATFORM_UNIX) && defined(X11)) struct FooHandle { FooType ty; + Flags flags; int32_t x; float y; bool operator==(const FooHandle& other) const { return ty == other.ty && + flags == other.flags && x == other.x && y == other.y; } bool operator!=(const FooHandle& other) const { return ty != other.ty || + flags != other.flags || x != other.x || y != other.y; } diff --git a/tests/expectations/cfg.pyx b/tests/expectations/cfg.pyx index 803fd7a79..d551d182a 100644 --- a/tests/expectations/cfg.pyx +++ b/tests/expectations/cfg.pyx @@ -4,6 +4,7 @@ DEF PLATFORM_WIN = 0 DEF X11 = 0 DEF M_32 = 0 #endif +#define PLATFORM_UNIX 1 from libc.stdint cimport int8_t, int16_t, int32_t, int64_t, intptr_t @@ -28,9 +29,23 @@ cdef extern from *: C, ctypedef uint32_t FooType; + ctypedef struct Flags: + uint8_t _0; + # none + const Flags Flags_NONE # = { 0 } + IF PLATFORM_WIN: + const Flags Flags_A # = { (1 << 0) } + IF PLATFORM_UNIX: + const Flags Flags_A # = { (1 << 1) } + IF PLATFORM_WIN: + const Flags Flags_B # = { ((Flags_A)._0 | (1 << 3)) } + IF PLATFORM_UNIX: + const Flags Flags_B # = { ((Flags_A)._0 | (1 << 4)) } + IF (PLATFORM_UNIX and X11): ctypedef struct FooHandle: FooType ty; + Flags flags; int32_t x; float y; diff --git a/tests/expectations/cfg_both.c b/tests/expectations/cfg_both.c index 55fcc894b..afd2abadc 100644 --- a/tests/expectations/cfg_both.c +++ b/tests/expectations/cfg_both.c @@ -4,6 +4,7 @@ DEF PLATFORM_WIN = 0 DEF X11 = 0 DEF M_32 = 0 #endif +#define PLATFORM_UNIX 1 #include @@ -29,9 +30,30 @@ enum FooType { typedef uint32_t FooType; #endif +typedef struct Flags { + uint8_t _0; +} Flags; +/** + * none + */ +#define Flags_NONE (Flags){ ._0 = (uint8_t)0 } +#if defined(PLATFORM_WIN) +#define Flags_A (Flags){ ._0 = (uint8_t)(1 << 0) } +#endif +#if defined(PLATFORM_UNIX) +#define Flags_A (Flags){ ._0 = (uint8_t)(1 << 1) } +#endif +#if defined(PLATFORM_WIN) +#define Flags_B (Flags){ ._0 = (uint8_t)((Flags_A)._0 | (1 << 3)) } +#endif +#if defined(PLATFORM_UNIX) +#define Flags_B (Flags){ ._0 = (uint8_t)((Flags_A)._0 | (1 << 4)) } +#endif + #if (defined(PLATFORM_UNIX) && defined(X11)) typedef struct FooHandle { FooType ty; + struct Flags flags; int32_t x; float y; } FooHandle; diff --git a/tests/expectations/cfg_both.compat.c b/tests/expectations/cfg_both.compat.c index 000b03d41..84fdb0b25 100644 --- a/tests/expectations/cfg_both.compat.c +++ b/tests/expectations/cfg_both.compat.c @@ -4,6 +4,7 @@ DEF PLATFORM_WIN = 0 DEF X11 = 0 DEF M_32 = 0 #endif +#define PLATFORM_UNIX 1 #include @@ -41,9 +42,30 @@ typedef uint32_t FooType; #endif // __cplusplus #endif +typedef struct Flags { + uint8_t _0; +} Flags; +/** + * none + */ +#define Flags_NONE (Flags){ ._0 = (uint8_t)0 } +#if defined(PLATFORM_WIN) +#define Flags_A (Flags){ ._0 = (uint8_t)(1 << 0) } +#endif +#if defined(PLATFORM_UNIX) +#define Flags_A (Flags){ ._0 = (uint8_t)(1 << 1) } +#endif +#if defined(PLATFORM_WIN) +#define Flags_B (Flags){ ._0 = (uint8_t)((Flags_A)._0 | (1 << 3)) } +#endif +#if defined(PLATFORM_UNIX) +#define Flags_B (Flags){ ._0 = (uint8_t)((Flags_A)._0 | (1 << 4)) } +#endif + #if (defined(PLATFORM_UNIX) && defined(X11)) typedef struct FooHandle { FooType ty; + struct Flags flags; int32_t x; float y; } FooHandle; diff --git a/tests/expectations/cfg_tag.c b/tests/expectations/cfg_tag.c index f9cad7b5e..3a5a54a41 100644 --- a/tests/expectations/cfg_tag.c +++ b/tests/expectations/cfg_tag.c @@ -4,6 +4,7 @@ DEF PLATFORM_WIN = 0 DEF X11 = 0 DEF M_32 = 0 #endif +#define PLATFORM_UNIX 1 #include @@ -29,9 +30,30 @@ enum FooType { typedef uint32_t FooType; #endif +struct Flags { + uint8_t _0; +}; +/** + * none + */ +#define Flags_NONE (Flags){ ._0 = (uint8_t)0 } +#if defined(PLATFORM_WIN) +#define Flags_A (Flags){ ._0 = (uint8_t)(1 << 0) } +#endif +#if defined(PLATFORM_UNIX) +#define Flags_A (Flags){ ._0 = (uint8_t)(1 << 1) } +#endif +#if defined(PLATFORM_WIN) +#define Flags_B (Flags){ ._0 = (uint8_t)((Flags_A)._0 | (1 << 3)) } +#endif +#if defined(PLATFORM_UNIX) +#define Flags_B (Flags){ ._0 = (uint8_t)((Flags_A)._0 | (1 << 4)) } +#endif + #if (defined(PLATFORM_UNIX) && defined(X11)) struct FooHandle { FooType ty; + struct Flags flags; int32_t x; float y; }; diff --git a/tests/expectations/cfg_tag.compat.c b/tests/expectations/cfg_tag.compat.c index cfe66ffd3..e9098b4f5 100644 --- a/tests/expectations/cfg_tag.compat.c +++ b/tests/expectations/cfg_tag.compat.c @@ -4,6 +4,7 @@ DEF PLATFORM_WIN = 0 DEF X11 = 0 DEF M_32 = 0 #endif +#define PLATFORM_UNIX 1 #include @@ -41,9 +42,30 @@ typedef uint32_t FooType; #endif // __cplusplus #endif +struct Flags { + uint8_t _0; +}; +/** + * none + */ +#define Flags_NONE (Flags){ ._0 = (uint8_t)0 } +#if defined(PLATFORM_WIN) +#define Flags_A (Flags){ ._0 = (uint8_t)(1 << 0) } +#endif +#if defined(PLATFORM_UNIX) +#define Flags_A (Flags){ ._0 = (uint8_t)(1 << 1) } +#endif +#if defined(PLATFORM_WIN) +#define Flags_B (Flags){ ._0 = (uint8_t)((Flags_A)._0 | (1 << 3)) } +#endif +#if defined(PLATFORM_UNIX) +#define Flags_B (Flags){ ._0 = (uint8_t)((Flags_A)._0 | (1 << 4)) } +#endif + #if (defined(PLATFORM_UNIX) && defined(X11)) struct FooHandle { FooType ty; + struct Flags flags; int32_t x; float y; }; diff --git a/tests/expectations/cfg_tag.pyx b/tests/expectations/cfg_tag.pyx index 6a0d44d78..e8e31594e 100644 --- a/tests/expectations/cfg_tag.pyx +++ b/tests/expectations/cfg_tag.pyx @@ -4,6 +4,7 @@ DEF PLATFORM_WIN = 0 DEF X11 = 0 DEF M_32 = 0 #endif +#define PLATFORM_UNIX 1 from libc.stdint cimport int8_t, int16_t, int32_t, int64_t, intptr_t @@ -28,9 +29,23 @@ cdef extern from *: C, ctypedef uint32_t FooType; + cdef struct Flags: + uint8_t _0; + # none + const Flags Flags_NONE # = { 0 } + IF PLATFORM_WIN: + const Flags Flags_A # = { (1 << 0) } + IF PLATFORM_UNIX: + const Flags Flags_A # = { (1 << 1) } + IF PLATFORM_WIN: + const Flags Flags_B # = { ((Flags_A)._0 | (1 << 3)) } + IF PLATFORM_UNIX: + const Flags Flags_B # = { ((Flags_A)._0 | (1 << 4)) } + IF (PLATFORM_UNIX and X11): cdef struct FooHandle: FooType ty; + Flags flags; int32_t x; float y; diff --git a/tests/rust/cfg.rs b/tests/rust/cfg.rs index 0efe3546e..b42c1d1a7 100644 --- a/tests/rust/cfg.rs +++ b/tests/rust/cfg.rs @@ -6,10 +6,30 @@ enum FooType { C, } + +#[repr(C)] +pub struct Flags(u8); +bitflags! { + impl Flags: u8 { + /// none + const NONE = 0; + #[cfg(windows)] + const A = 1 << 0; + #[cfg(unix)] + const A = 1 << 1; + + #[cfg(windows)] + const B = Self::A.bits() | (1 << 3); + #[cfg(unix)] + const B = Self::A.bits() | (1 << 4); + } +} + #[cfg(all(unix, x11))] #[repr(C)] struct FooHandle { ty: FooType, + flags: Flags, x: i32, y: f32, } diff --git a/tests/rust/cfg.toml b/tests/rust/cfg.toml index 4d6c4caa6..5359645e1 100644 --- a/tests/rust/cfg.toml +++ b/tests/rust/cfg.toml @@ -5,6 +5,7 @@ DEF PLATFORM_WIN = 0 DEF X11 = 0 DEF M_32 = 0 #endif +#define PLATFORM_UNIX 1 """ [defines] @@ -23,3 +24,6 @@ private_default_tagged_enum_constructor = true [struct] derive_eq = true derive_neq = true + +[macro_expansion] +bitflags = true From 0f39a0488a48ef35f96e263833e076acd4d36b85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Tue, 7 Oct 2025 15:59:35 +0200 Subject: [PATCH 2/2] constant: Handle cfg in associated constants. Fixes https://bugzilla.mozilla.org/show_bug.cgi?id=1992968 --- src/bindgen/ir/constant.rs | 5 +++- tests/expectations/associated_in_body.c | 13 +++++++++++ .../expectations/associated_in_body.compat.c | 13 +++++++++++ tests/expectations/associated_in_body.cpp | 23 +++++++++++++++++++ tests/expectations/associated_in_body.pyx | 11 +++++++++ tests/expectations/associated_in_body_both.c | 13 +++++++++++ .../associated_in_body_both.compat.c | 13 +++++++++++ tests/expectations/associated_in_body_tag.c | 13 +++++++++++ .../associated_in_body_tag.compat.c | 13 +++++++++++ tests/expectations/associated_in_body_tag.pyx | 11 +++++++++ tests/rust/associated_in_body.rs | 4 ++++ tests/rust/associated_in_body.toml | 12 ++++++++++ 12 files changed, 143 insertions(+), 1 deletion(-) diff --git a/src/bindgen/ir/constant.rs b/src/bindgen/ir/constant.rs index 50bee8292..283d66d7f 100644 --- a/src/bindgen/ir/constant.rs +++ b/src/bindgen/ir/constant.rs @@ -636,13 +636,16 @@ impl Constant { debug_assert!(config.structure.associated_constants_in_body); debug_assert!(config.constant.allow_static_const); + let condition = self.cfg.to_condition(config); + condition.write_before(config, out); if let Type::Ptr { is_const: true, .. } = self.ty { out.write("static "); } else { out.write("static const "); } language_backend.write_type(out, &self.ty); - write!(out, " {};", self.export_name()) + write!(out, " {};", self.export_name()); + condition.write_after(config, out); } pub fn write( diff --git a/tests/expectations/associated_in_body.c b/tests/expectations/associated_in_body.c index e41971a77..cf09b172e 100644 --- a/tests/expectations/associated_in_body.c +++ b/tests/expectations/associated_in_body.c @@ -1,3 +1,10 @@ +#if 0 +DEF PLATFORM_UNIX = 0 +DEF PLATFORM_WIN = 0 +#endif +#define PLATFORM_UNIX 1 + + #include #include #include @@ -34,6 +41,12 @@ typedef struct { #define StyleAlignFlags_FLEX_START (StyleAlignFlags){ .bits = (uint8_t)(1 << 3) } #define StyleAlignFlags_MIXED (StyleAlignFlags){ .bits = (uint8_t)(((1 << 4) | (StyleAlignFlags_FLEX_START).bits) | (StyleAlignFlags_END).bits) } #define StyleAlignFlags_MIXED_SELF (StyleAlignFlags){ .bits = (uint8_t)(((1 << 5) | (StyleAlignFlags_FLEX_START).bits) | (StyleAlignFlags_END).bits) } +#if defined(PLATFORM_WIN) +#define StyleAlignFlags_PLATFORM_BIT (StyleAlignFlags){ .bits = (uint8_t)(1 << 6) } +#endif +#if defined(PLATFORM_UNIX) +#define StyleAlignFlags_PLATFORM_BIT (StyleAlignFlags){ .bits = (uint8_t)(1 << 7) } +#endif /** * An arbitrary identifier for a native (OS compositor) surface diff --git a/tests/expectations/associated_in_body.compat.c b/tests/expectations/associated_in_body.compat.c index 095ed2169..26b11bb1a 100644 --- a/tests/expectations/associated_in_body.compat.c +++ b/tests/expectations/associated_in_body.compat.c @@ -1,3 +1,10 @@ +#if 0 +DEF PLATFORM_UNIX = 0 +DEF PLATFORM_WIN = 0 +#endif +#define PLATFORM_UNIX 1 + + #include #include #include @@ -34,6 +41,12 @@ typedef struct { #define StyleAlignFlags_FLEX_START (StyleAlignFlags){ .bits = (uint8_t)(1 << 3) } #define StyleAlignFlags_MIXED (StyleAlignFlags){ .bits = (uint8_t)(((1 << 4) | (StyleAlignFlags_FLEX_START).bits) | (StyleAlignFlags_END).bits) } #define StyleAlignFlags_MIXED_SELF (StyleAlignFlags){ .bits = (uint8_t)(((1 << 5) | (StyleAlignFlags_FLEX_START).bits) | (StyleAlignFlags_END).bits) } +#if defined(PLATFORM_WIN) +#define StyleAlignFlags_PLATFORM_BIT (StyleAlignFlags){ .bits = (uint8_t)(1 << 6) } +#endif +#if defined(PLATFORM_UNIX) +#define StyleAlignFlags_PLATFORM_BIT (StyleAlignFlags){ .bits = (uint8_t)(1 << 7) } +#endif /** * An arbitrary identifier for a native (OS compositor) surface diff --git a/tests/expectations/associated_in_body.cpp b/tests/expectations/associated_in_body.cpp index 29f6bd682..363be0130 100644 --- a/tests/expectations/associated_in_body.cpp +++ b/tests/expectations/associated_in_body.cpp @@ -1,3 +1,10 @@ +#if 0 +DEF PLATFORM_UNIX = 0 +DEF PLATFORM_WIN = 0 +#endif +#define PLATFORM_UNIX 1 + + #include #include #include @@ -45,6 +52,12 @@ struct StyleAlignFlags { static const StyleAlignFlags FLEX_START; static const StyleAlignFlags MIXED; static const StyleAlignFlags MIXED_SELF; +#if defined(PLATFORM_WIN) + static const StyleAlignFlags PLATFORM_BIT; +#endif +#if defined(PLATFORM_UNIX) + static const StyleAlignFlags PLATFORM_BIT; +#endif }; /// 'auto' constexpr inline const StyleAlignFlags StyleAlignFlags::AUTO = StyleAlignFlags{ @@ -75,6 +88,16 @@ constexpr inline const StyleAlignFlags StyleAlignFlags::MIXED = StyleAlignFlags{ constexpr inline const StyleAlignFlags StyleAlignFlags::MIXED_SELF = StyleAlignFlags{ /* .bits = */ (uint8_t)(((1 << 5) | (StyleAlignFlags::FLEX_START).bits) | (StyleAlignFlags::END).bits) }; +#if defined(PLATFORM_WIN) +constexpr inline const StyleAlignFlags StyleAlignFlags::PLATFORM_BIT = StyleAlignFlags{ + /* .bits = */ (uint8_t)(1 << 6) +}; +#endif +#if defined(PLATFORM_UNIX) +constexpr inline const StyleAlignFlags StyleAlignFlags::PLATFORM_BIT = StyleAlignFlags{ + /* .bits = */ (uint8_t)(1 << 7) +}; +#endif /// An arbitrary identifier for a native (OS compositor) surface struct StyleNativeSurfaceId { diff --git a/tests/expectations/associated_in_body.pyx b/tests/expectations/associated_in_body.pyx index f6b20bcd7..ae48cb543 100644 --- a/tests/expectations/associated_in_body.pyx +++ b/tests/expectations/associated_in_body.pyx @@ -1,3 +1,10 @@ +#if 0 +DEF PLATFORM_UNIX = 0 +DEF PLATFORM_WIN = 0 +#endif +#define PLATFORM_UNIX 1 + + from libc.stdint cimport int8_t, int16_t, int32_t, int64_t, intptr_t from libc.stdint cimport uint8_t, uint16_t, uint32_t, uint64_t, uintptr_t cdef extern from *: @@ -24,6 +31,10 @@ cdef extern from *: const StyleAlignFlags StyleAlignFlags_FLEX_START # = { (1 << 3) } const StyleAlignFlags StyleAlignFlags_MIXED # = { (((1 << 4) | (StyleAlignFlags_FLEX_START).bits) | (StyleAlignFlags_END).bits) } const StyleAlignFlags StyleAlignFlags_MIXED_SELF # = { (((1 << 5) | (StyleAlignFlags_FLEX_START).bits) | (StyleAlignFlags_END).bits) } + IF PLATFORM_WIN: + const StyleAlignFlags StyleAlignFlags_PLATFORM_BIT # = { (1 << 6) } + IF PLATFORM_UNIX: + const StyleAlignFlags StyleAlignFlags_PLATFORM_BIT # = { (1 << 7) } # An arbitrary identifier for a native (OS compositor) surface ctypedef struct StyleNativeSurfaceId: diff --git a/tests/expectations/associated_in_body_both.c b/tests/expectations/associated_in_body_both.c index c06a066a6..c32c956eb 100644 --- a/tests/expectations/associated_in_body_both.c +++ b/tests/expectations/associated_in_body_both.c @@ -1,3 +1,10 @@ +#if 0 +DEF PLATFORM_UNIX = 0 +DEF PLATFORM_WIN = 0 +#endif +#define PLATFORM_UNIX 1 + + #include #include #include @@ -34,6 +41,12 @@ typedef struct StyleAlignFlags { #define StyleAlignFlags_FLEX_START (StyleAlignFlags){ .bits = (uint8_t)(1 << 3) } #define StyleAlignFlags_MIXED (StyleAlignFlags){ .bits = (uint8_t)(((1 << 4) | (StyleAlignFlags_FLEX_START).bits) | (StyleAlignFlags_END).bits) } #define StyleAlignFlags_MIXED_SELF (StyleAlignFlags){ .bits = (uint8_t)(((1 << 5) | (StyleAlignFlags_FLEX_START).bits) | (StyleAlignFlags_END).bits) } +#if defined(PLATFORM_WIN) +#define StyleAlignFlags_PLATFORM_BIT (StyleAlignFlags){ .bits = (uint8_t)(1 << 6) } +#endif +#if defined(PLATFORM_UNIX) +#define StyleAlignFlags_PLATFORM_BIT (StyleAlignFlags){ .bits = (uint8_t)(1 << 7) } +#endif /** * An arbitrary identifier for a native (OS compositor) surface diff --git a/tests/expectations/associated_in_body_both.compat.c b/tests/expectations/associated_in_body_both.compat.c index 3187ea3fa..488946837 100644 --- a/tests/expectations/associated_in_body_both.compat.c +++ b/tests/expectations/associated_in_body_both.compat.c @@ -1,3 +1,10 @@ +#if 0 +DEF PLATFORM_UNIX = 0 +DEF PLATFORM_WIN = 0 +#endif +#define PLATFORM_UNIX 1 + + #include #include #include @@ -34,6 +41,12 @@ typedef struct StyleAlignFlags { #define StyleAlignFlags_FLEX_START (StyleAlignFlags){ .bits = (uint8_t)(1 << 3) } #define StyleAlignFlags_MIXED (StyleAlignFlags){ .bits = (uint8_t)(((1 << 4) | (StyleAlignFlags_FLEX_START).bits) | (StyleAlignFlags_END).bits) } #define StyleAlignFlags_MIXED_SELF (StyleAlignFlags){ .bits = (uint8_t)(((1 << 5) | (StyleAlignFlags_FLEX_START).bits) | (StyleAlignFlags_END).bits) } +#if defined(PLATFORM_WIN) +#define StyleAlignFlags_PLATFORM_BIT (StyleAlignFlags){ .bits = (uint8_t)(1 << 6) } +#endif +#if defined(PLATFORM_UNIX) +#define StyleAlignFlags_PLATFORM_BIT (StyleAlignFlags){ .bits = (uint8_t)(1 << 7) } +#endif /** * An arbitrary identifier for a native (OS compositor) surface diff --git a/tests/expectations/associated_in_body_tag.c b/tests/expectations/associated_in_body_tag.c index f0bc16f95..4068cdd49 100644 --- a/tests/expectations/associated_in_body_tag.c +++ b/tests/expectations/associated_in_body_tag.c @@ -1,3 +1,10 @@ +#if 0 +DEF PLATFORM_UNIX = 0 +DEF PLATFORM_WIN = 0 +#endif +#define PLATFORM_UNIX 1 + + #include #include #include @@ -34,6 +41,12 @@ struct StyleAlignFlags { #define StyleAlignFlags_FLEX_START (StyleAlignFlags){ .bits = (uint8_t)(1 << 3) } #define StyleAlignFlags_MIXED (StyleAlignFlags){ .bits = (uint8_t)(((1 << 4) | (StyleAlignFlags_FLEX_START).bits) | (StyleAlignFlags_END).bits) } #define StyleAlignFlags_MIXED_SELF (StyleAlignFlags){ .bits = (uint8_t)(((1 << 5) | (StyleAlignFlags_FLEX_START).bits) | (StyleAlignFlags_END).bits) } +#if defined(PLATFORM_WIN) +#define StyleAlignFlags_PLATFORM_BIT (StyleAlignFlags){ .bits = (uint8_t)(1 << 6) } +#endif +#if defined(PLATFORM_UNIX) +#define StyleAlignFlags_PLATFORM_BIT (StyleAlignFlags){ .bits = (uint8_t)(1 << 7) } +#endif /** * An arbitrary identifier for a native (OS compositor) surface diff --git a/tests/expectations/associated_in_body_tag.compat.c b/tests/expectations/associated_in_body_tag.compat.c index 7f4c486d1..7e8944522 100644 --- a/tests/expectations/associated_in_body_tag.compat.c +++ b/tests/expectations/associated_in_body_tag.compat.c @@ -1,3 +1,10 @@ +#if 0 +DEF PLATFORM_UNIX = 0 +DEF PLATFORM_WIN = 0 +#endif +#define PLATFORM_UNIX 1 + + #include #include #include @@ -34,6 +41,12 @@ struct StyleAlignFlags { #define StyleAlignFlags_FLEX_START (StyleAlignFlags){ .bits = (uint8_t)(1 << 3) } #define StyleAlignFlags_MIXED (StyleAlignFlags){ .bits = (uint8_t)(((1 << 4) | (StyleAlignFlags_FLEX_START).bits) | (StyleAlignFlags_END).bits) } #define StyleAlignFlags_MIXED_SELF (StyleAlignFlags){ .bits = (uint8_t)(((1 << 5) | (StyleAlignFlags_FLEX_START).bits) | (StyleAlignFlags_END).bits) } +#if defined(PLATFORM_WIN) +#define StyleAlignFlags_PLATFORM_BIT (StyleAlignFlags){ .bits = (uint8_t)(1 << 6) } +#endif +#if defined(PLATFORM_UNIX) +#define StyleAlignFlags_PLATFORM_BIT (StyleAlignFlags){ .bits = (uint8_t)(1 << 7) } +#endif /** * An arbitrary identifier for a native (OS compositor) surface diff --git a/tests/expectations/associated_in_body_tag.pyx b/tests/expectations/associated_in_body_tag.pyx index 86697bdf8..93ff71555 100644 --- a/tests/expectations/associated_in_body_tag.pyx +++ b/tests/expectations/associated_in_body_tag.pyx @@ -1,3 +1,10 @@ +#if 0 +DEF PLATFORM_UNIX = 0 +DEF PLATFORM_WIN = 0 +#endif +#define PLATFORM_UNIX 1 + + from libc.stdint cimport int8_t, int16_t, int32_t, int64_t, intptr_t from libc.stdint cimport uint8_t, uint16_t, uint32_t, uint64_t, uintptr_t cdef extern from *: @@ -24,6 +31,10 @@ cdef extern from *: const StyleAlignFlags StyleAlignFlags_FLEX_START # = { (1 << 3) } const StyleAlignFlags StyleAlignFlags_MIXED # = { (((1 << 4) | (StyleAlignFlags_FLEX_START).bits) | (StyleAlignFlags_END).bits) } const StyleAlignFlags StyleAlignFlags_MIXED_SELF # = { (((1 << 5) | (StyleAlignFlags_FLEX_START).bits) | (StyleAlignFlags_END).bits) } + IF PLATFORM_WIN: + const StyleAlignFlags StyleAlignFlags_PLATFORM_BIT # = { (1 << 6) } + IF PLATFORM_UNIX: + const StyleAlignFlags StyleAlignFlags_PLATFORM_BIT # = { (1 << 7) } # An arbitrary identifier for a native (OS compositor) surface cdef struct StyleNativeSurfaceId: diff --git a/tests/rust/associated_in_body.rs b/tests/rust/associated_in_body.rs index 8c76a13ce..b17312fd5 100644 --- a/tests/rust/associated_in_body.rs +++ b/tests/rust/associated_in_body.rs @@ -18,6 +18,10 @@ bitflags! { const FLEX_START = 1 << 3; const MIXED = 1 << 4 | AlignFlags::FLEX_START.bits | AlignFlags::END.bits; const MIXED_SELF = 1 << 5 | AlignFlags::FLEX_START.bits | AlignFlags::END.bits; + #[cfg(windows)] + const PLATFORM_BIT = 1 << 6; + #[cfg(unix)] + const PLATFORM_BIT = 1 << 7; } } diff --git a/tests/rust/associated_in_body.toml b/tests/rust/associated_in_body.toml index a52609b5e..03d191e27 100644 --- a/tests/rust/associated_in_body.toml +++ b/tests/rust/associated_in_body.toml @@ -1,3 +1,11 @@ +header = """ +#if 0 +DEF PLATFORM_UNIX = 0 +DEF PLATFORM_WIN = 0 +#endif +#define PLATFORM_UNIX 1 +""" + [struct] associated_constants_in_body = true @@ -9,3 +17,7 @@ prefix = "Style" # Just ensuring they play well together :) [const] allow_constexpr = true + +[defines] +"unix" = "PLATFORM_UNIX" +"windows" = "PLATFORM_WIN"