diff --git a/src/header/wchar/cbindgen.toml b/src/header/wchar/cbindgen.toml index a31881baad..77b888b105 100644 --- a/src/header/wchar/cbindgen.toml +++ b/src/header/wchar/cbindgen.toml @@ -1,8 +1,4 @@ -sys_includes = [ - "stdio.h", - "time.h", - "features.h", -] +sys_includes = ["features.h"] after_includes = """ // int32_t, uint32_t, WCHAR_MIN, WCHAR_MAX #include @@ -25,6 +21,21 @@ after_includes = """ typedef __WINT_TYPE__ wint_t; #endif // _WINT_T +// Define mbstate_t before headers that may transitively re-include wchar.h. +// The circular chain wchar.h → stdio.h → inttypes.h → wchar.h (and also +// stdlib.h → wchar.h) would otherwise cause wint_t and mbstate_t to be +// undefined in gnulib's wchar.h wrapper, breaking m4, bison, and other +// gnulib-based packages. +#ifndef _RELIBC_MBSTATE_T +#define _RELIBC_MBSTATE_T +typedef struct {} mbstate_t; +#endif + +// Now include headers that depend on wchar_t/wint_t/mbstate_t. +// These must come after the type definitions to break circular includes. +#include +#include + // NULL, size_t, must come after wchar_t and wint_t #define __need_size_t #define __need_NULL @@ -38,6 +49,9 @@ style = "Type" no_includes = true cpp_compat = true +[export] +exclude = ["mbstate_t"] + [export.rename] "tm" = "struct tm"