Skip to content

Commit 66a01c8

Browse files
authored
fix: use consistent u32 type for enum constants on Windows (#4)
bindgen generates enum constants as i32 on Windows MSVC (C standard: enum underlying type is int) but u32 on GCC/Clang when all values are non-negative. This causes type mismatch errors when using the constants. Add .default_enum_style(bindgen::EnumVariation::Consts) combined with .translate_enum_integer_types(true) to force consistent unsigned types across all platforms. Co-authored-by: kaju <kajukitli@users.noreply.github.com>
1 parent 72ea8e6 commit 66a01c8

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

build.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,11 @@ fn generate_bindings(out_dir: &Path, include_dir: &Path) {
266266
.allowlist_function("nghttp2_.*")
267267
.allowlist_type("nghttp2_.*")
268268
.allowlist_var("NGHTTP2_.*")
269+
// Generate enum constants with consistent types across platforms.
270+
// Without this, C enums become i32 on MSVC (C standard: enum is int)
271+
// but u32 on GCC/Clang (where the underlying type matches the values).
272+
.default_enum_style(bindgen::EnumVariation::Consts)
273+
.translate_enum_integer_types(true)
269274
// Opaque types that should not derive Copy
270275
.opaque_type("nghttp2_session")
271276
.opaque_type("nghttp2_rcbuf")

0 commit comments

Comments
 (0)