Skip to content
This repository was archived by the owner on Oct 8, 2025. It is now read-only.

Commit 76f8f41

Browse files
committed
rust: Change how bindgen creates enums
Previously bindgen was picking the 'constified_enum'. E.g it would turn the luw_srb_flags_t enum typedef enum { LUW_SRB_NONE = 0x00, LUW_SRB_APPEND = 0x01, LUW_SRB_ALLOC = 0x02, LUW_SRB_FULL_SIZE = 0x04, LUW_SRB_FLAGS_ALL = (LUW_SRB_NONE|LUW_SRB_APPEND|LUW_SRB_ALLOC| LUW_SRB_FULL_SIZE) } luw_srb_flags_t; into pub const luw_srb_flags_t_LUW_SRB_NONE: luw_srb_flags_t = 0; pub const luw_srb_flags_t_LUW_SRB_APPEND: luw_srb_flags_t = 1; pub const luw_srb_flags_t_LUW_SRB_ALLOC: luw_srb_flags_t = 2; pub const luw_srb_flags_t_LUW_SRB_FULL_SIZE: luw_srb_flags_t = 4; pub const luw_srb_flags_t_LUW_SRB_FLAGS_ALL: luw_srb_flags_t = 7; But then this requires some further changes to make the names nicer without the type prefixed. This will only be exasperated when adding an enum containing the HTTP status codes... So instead, tell bindgen to use the 'rustified_enum' method which produces this pub enum luw_srb_flags_t { LUW_SRB_NONE = 0, LUW_SRB_APPEND = 1, LUW_SRB_ALLOC = 2, LUW_SRB_FULL_SIZE = 4, LUW_SRB_FLAGS_ALL = 7, } which in theory requires no extra changes (it doesn't with the http status codes enum), however in this specific case, because these are actually bitflags we still need to cast them to u32 so they can be OR'd. Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
1 parent 6764e6e commit 76f8f41

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/rust/unit-wasm-sys/build.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ fn generate_bindings() {
3636
.allowlist_function("^luw_.*")
3737
.allowlist_var("^luw_.*")
3838
.allowlist_type("^luw_.*")
39+
.default_enum_style(bindgen::EnumVariation::Rust {
40+
non_exhaustive: false,
41+
})
3942
.generate()
4043
.expect("Unable to generate bindings");
4144

src/rust/unit-wasm-sys/macros.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub const LUW_VERSION_NUMBER: i32 =
1414
(LUW_VERSION_MINOR << 16) |
1515
(LUW_VERSION_PATCH << 8);
1616

17-
pub const LUW_SRB_NONE: u32 = luw_srb_flags_t_LUW_SRB_NONE;
18-
pub const LUW_SRB_APPEND: u32 = luw_srb_flags_t_LUW_SRB_APPEND;
19-
pub const LUW_SRB_ALLOC: u32 = luw_srb_flags_t_LUW_SRB_ALLOC;
20-
pub const LUW_SRB_FULL_SIZE: u32 = luw_srb_flags_t_LUW_SRB_FLAGS_ALL;
17+
pub const LUW_SRB_NONE: u32 = luw_srb_flags_t::LUW_SRB_NONE as u32;
18+
pub const LUW_SRB_APPEND: u32 = luw_srb_flags_t::LUW_SRB_APPEND as u32;
19+
pub const LUW_SRB_ALLOC: u32 = luw_srb_flags_t::LUW_SRB_ALLOC as u32;
20+
pub const LUW_SRB_FULL_SIZE: u32 = luw_srb_flags_t::LUW_SRB_FLAGS_ALL as u32;

0 commit comments

Comments
 (0)