From 6a7ae658a67ee0446384bfab7c0588b5e30eef9e Mon Sep 17 00:00:00 2001 From: kaju Date: Wed, 4 Mar 2026 09:25:34 +0000 Subject: [PATCH] fix: use consistent u32 type for enum constants on Windows 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. --- build.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/build.rs b/build.rs index 2dcfe45..8810dd5 100644 --- a/build.rs +++ b/build.rs @@ -266,6 +266,11 @@ fn generate_bindings(out_dir: &Path, include_dir: &Path) { .allowlist_function("nghttp2_.*") .allowlist_type("nghttp2_.*") .allowlist_var("NGHTTP2_.*") + // Generate enum constants with consistent types across platforms. + // Without this, C enums become i32 on MSVC (C standard: enum is int) + // but u32 on GCC/Clang (where the underlying type matches the values). + .default_enum_style(bindgen::EnumVariation::Consts) + .translate_enum_integer_types(true) // Opaque types that should not derive Copy .opaque_type("nghttp2_session") .opaque_type("nghttp2_rcbuf")