Skip to content

Commit b785f09

Browse files
committed
fix: ensure consistent enum constant types across platforms
On Windows MSVC, C enums are always `int` (i32), while on other platforms bindgen may generate them as u32 for non-negative enums. This causes type mismatches when code using the bindings expects u32. Add `.default_enum_style(bindgen::EnumVariation::Consts)` and `.translate_enum_integer_types(true)` to ensure consistent types regardless of platform.
1 parent 72ea8e6 commit b785f09

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 as consts with consistent types across platforms.
270+
// Without this, MSVC generates i32 (C int) while other platforms may use u32,
271+
// causing type mismatches when consuming code expects u32.
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)