Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
sys:
os: macos-latest
rust_toolchain: stable
- ruby_version: mswin

Check warning on line 58 in .github/workflows/ci.yml

View workflow job for this annotation

GitHub Actions / 🧪 Test (mswin, windows-2022, stable-x86_64-pc-windows-msvc)

mswin builds use ruby-master, and which is unstable and may break your build at any time (see https://github.com/MSP-Greg/ruby-loco/issues/12)
sys:
os: windows-2022
rust_toolchain: stable-x86_64-pc-windows-msvc
Expand All @@ -82,7 +82,7 @@
shell: bash
run: script/ci/set-debug-env.sh

- uses: oxidize-rb/actions/setup-ruby-and-rust@d4731ac609739be0920f0faf5569b58b8eb1a262 # v1
- uses: oxidize-rb/actions/setup-ruby-and-rust@4c939d516bd77ec5806f382c9bb574f4634098a7 # v1
if: matrix.ruby_version != 'skip'
with:
cache-version: v2
Expand Down Expand Up @@ -115,7 +115,7 @@

- name: 🧪 Cargo test
shell: bash
if: matrix.ruby_version != 'mswin'

Check warning on line 118 in .github/workflows/ci.yml

View workflow job for this annotation

GitHub Actions / 🧪 Test (mswin, windows-2022, stable-x86_64-pc-windows-msvc)

mswin builds use ruby-master, and which is unstable and may break your build at any time (see https://github.com/MSP-Greg/ruby-loco/issues/12)
run: |
ulimit -c unlimited
bundle exec rake test:cargo
Expand Down Expand Up @@ -177,7 +177,7 @@

- uses: oxidize-rb/actions/upload-core-dumps@d4731ac609739be0920f0faf5569b58b8eb1a262 # v1

- uses: oxidize-rb/actions/setup-ruby-and-rust@d4731ac609739be0920f0faf5569b58b8eb1a262 # v1
- uses: oxidize-rb/actions/setup-ruby-and-rust@4c939d516bd77ec5806f382c9bb574f4634098a7 # v1
with:
ruby-version: none
rustup-toolchain: ${{ matrix.sys.rust_toolchain }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
with:
path: rb-sys
- uses: oxidize-rb/actions/setup-ruby-and-rust@d4731ac609739be0920f0faf5569b58b8eb1a262 # v1
- uses: oxidize-rb/actions/setup-ruby-and-rust@4c939d516bd77ec5806f382c9bb574f4634098a7 # v1
id: setup
with:
cache-version: v2
Expand Down
40 changes: 35 additions & 5 deletions crates/rb-sys-build/src/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ pub fn generate(
clang_args.extend(rbconfig.cflags.clone());
clang_args.extend(rbconfig.cppflags());

// On Windows x86_64, we need to handle AVX512 FP16 compatibility issues
// Clang 20+ includes types like __m512h that aren't compatible with bindgen
if cfg!(target_os = "windows") && cfg!(target_arch = "x86_64") {
// For MinGW toolchain, disable SSE/AVX only for bindgen
// This prevents intrinsics headers from loading but doesn't affect the final binary
if !is_msvc() {
clang_args.push("-mno-sse".to_string());
clang_args.push("-mno-avx".to_string());
}
}

debug_log!("INFO: using bindgen with clang args: {:?}", clang_args);

let mut wrapper_h = WRAPPER_H_CONTENT.to_string();
Expand All @@ -48,7 +59,7 @@ pub fn generate(
clang_args.push("-DHAVE_RUBY_IO_BUFFER_H".to_string());
}

let bindings = default_bindgen(clang_args)
let bindings = default_bindgen(clang_args, rbconfig)
.allowlist_file(".*ruby.*")
.blocklist_item("ruby_abi_version")
.blocklist_function("rb_tr_abi_version")
Expand Down Expand Up @@ -129,14 +140,28 @@ fn clean_docs(rbconfig: &RbConfig, syntax: &mut syn::File) {
})
}

fn default_bindgen(clang_args: Vec<String>) -> bindgen::Builder {
let bindings = bindgen::Builder::default()
fn default_bindgen(clang_args: Vec<String>, rbconfig: &RbConfig) -> bindgen::Builder {
// Disable layout tests and Debug impl for Ruby 2.7 and 3.0 on Windows MinGW due to type incompatibilities
let is_old_ruby_windows_mingw = if cfg!(target_os = "windows") && !is_msvc() {
if let Some((major, minor)) = rbconfig.major_minor() {
(major == 2 && minor == 7) || (major == 3 && minor == 0)
} else {
false
}
} else {
false
};

let enable_layout_tests = !is_old_ruby_windows_mingw && cfg!(feature = "bindgen-layout-tests");
let impl_debug = !is_old_ruby_windows_mingw && cfg!(feature = "bindgen-impl-debug");

let mut bindings = bindgen::Builder::default()
.rustified_enum(".*")
.no_copy("rb_data_type_struct")
.derive_eq(true)
.derive_debug(true)
.clang_args(clang_args)
.layout_tests(cfg!(feature = "bindgen-layout-tests"))
.layout_tests(enable_layout_tests)
.blocklist_item("^__darwin_pthread.*")
.blocklist_item("^_opaque_pthread.*")
.blocklist_item("^pthread_.*")
Expand All @@ -145,9 +170,14 @@ fn default_bindgen(clang_args: Vec<String>) -> bindgen::Builder {
.merge_extern_blocks(true)
.generate_comments(true)
.size_t_is_usize(env::var("CARGO_FEATURE_BINDGEN_SIZE_T_IS_USIZE").is_ok())
.impl_debug(cfg!(feature = "bindgen-impl-debug"))
.impl_debug(impl_debug)
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()));

// Make __mingw_ldbl_type_t opaque on Windows MinGW to avoid conflicting packed/align representation
if cfg!(target_os = "windows") && !is_msvc() {
bindings = bindings.opaque_type("__mingw_ldbl_type_t");
}

if env::var("CARGO_FEATURE_BINDGEN_ENABLE_FUNCTION_ATTRIBUTE_DETECTION").is_ok() {
bindings.enable_function_attribute_detection()
} else {
Expand Down
Loading