@@ -34,6 +34,17 @@ pub fn generate(
3434 clang_args. extend ( rbconfig. cflags . clone ( ) ) ;
3535 clang_args. extend ( rbconfig. cppflags ( ) ) ;
3636
37+ // On Windows x86_64, we need to handle AVX512 FP16 compatibility issues
38+ // Clang 20+ includes types like __m512h that aren't compatible with bindgen
39+ if cfg ! ( target_os = "windows" ) && cfg ! ( target_arch = "x86_64" ) {
40+ // For MinGW toolchain, disable SSE/AVX only for bindgen
41+ // This prevents intrinsics headers from loading but doesn't affect the final binary
42+ if !is_msvc ( ) {
43+ clang_args. push ( "-mno-sse" . to_string ( ) ) ;
44+ clang_args. push ( "-mno-avx" . to_string ( ) ) ;
45+ }
46+ }
47+
3748 debug_log ! ( "INFO: using bindgen with clang args: {:?}" , clang_args) ;
3849
3950 let mut wrapper_h = WRAPPER_H_CONTENT . to_string ( ) ;
@@ -48,7 +59,7 @@ pub fn generate(
4859 clang_args. push ( "-DHAVE_RUBY_IO_BUFFER_H" . to_string ( ) ) ;
4960 }
5061
51- let bindings = default_bindgen ( clang_args)
62+ let bindings = default_bindgen ( clang_args, rbconfig )
5263 . allowlist_file ( ".*ruby.*" )
5364 . blocklist_item ( "ruby_abi_version" )
5465 . blocklist_function ( "rb_tr_abi_version" )
@@ -129,14 +140,28 @@ fn clean_docs(rbconfig: &RbConfig, syntax: &mut syn::File) {
129140 } )
130141}
131142
132- fn default_bindgen ( clang_args : Vec < String > ) -> bindgen:: Builder {
133- let bindings = bindgen:: Builder :: default ( )
143+ fn default_bindgen ( clang_args : Vec < String > , rbconfig : & RbConfig ) -> bindgen:: Builder {
144+ // Disable layout tests and Debug impl for Ruby 2.7 and 3.0 on Windows MinGW due to type incompatibilities
145+ let is_old_ruby_windows_mingw = if cfg ! ( target_os = "windows" ) && !is_msvc ( ) {
146+ if let Some ( ( major, minor) ) = rbconfig. major_minor ( ) {
147+ ( major == 2 && minor == 7 ) || ( major == 3 && minor == 0 )
148+ } else {
149+ false
150+ }
151+ } else {
152+ false
153+ } ;
154+
155+ let enable_layout_tests = !is_old_ruby_windows_mingw && cfg ! ( feature = "bindgen-layout-tests" ) ;
156+ let impl_debug = !is_old_ruby_windows_mingw && cfg ! ( feature = "bindgen-impl-debug" ) ;
157+
158+ let mut bindings = bindgen:: Builder :: default ( )
134159 . rustified_enum ( ".*" )
135160 . no_copy ( "rb_data_type_struct" )
136161 . derive_eq ( true )
137162 . derive_debug ( true )
138163 . clang_args ( clang_args)
139- . layout_tests ( cfg ! ( feature = "bindgen-layout-tests" ) )
164+ . layout_tests ( enable_layout_tests )
140165 . blocklist_item ( "^__darwin_pthread.*" )
141166 . blocklist_item ( "^_opaque_pthread.*" )
142167 . blocklist_item ( "^pthread_.*" )
@@ -145,9 +170,14 @@ fn default_bindgen(clang_args: Vec<String>) -> bindgen::Builder {
145170 . merge_extern_blocks ( true )
146171 . generate_comments ( true )
147172 . size_t_is_usize ( env:: var ( "CARGO_FEATURE_BINDGEN_SIZE_T_IS_USIZE" ) . is_ok ( ) )
148- . impl_debug ( cfg ! ( feature = "bindgen-impl-debug" ) )
173+ . impl_debug ( impl_debug )
149174 . parse_callbacks ( Box :: new ( bindgen:: CargoCallbacks :: new ( ) ) ) ;
150175
176+ // Make __mingw_ldbl_type_t opaque on Windows MinGW to avoid conflicting packed/align representation
177+ if cfg ! ( target_os = "windows" ) && !is_msvc ( ) {
178+ bindings = bindings. opaque_type ( "__mingw_ldbl_type_t" ) ;
179+ }
180+
151181 if env:: var ( "CARGO_FEATURE_BINDGEN_ENABLE_FUNCTION_ATTRIBUTE_DETECTION" ) . is_ok ( ) {
152182 bindings. enable_function_attribute_detection ( )
153183 } else {
0 commit comments