Skip to content

Conversation

ianks
Copy link
Collaborator

@ianks ianks commented Jul 3, 2025

So we don't recompile all the time when using nix.

ianks and others added 30 commits July 3, 2025 15:24
Refine rubygems_invoked? to ignore Nix environments,
update comments for clarity, and add comprehensive tests
to ensure correct detection in various contexts.
Bump actions/upload-core-dumps and setup-ruby-and-rust to ad2f407 for improved reliability and updates across CI workflows.
Move linting steps (clippy, fmt, Standard.rb) to a new lint job for improved workflow structure and clarity.
Block specific AVX512 types and headers in bindgen to avoid
Clang 20 issues with these intrinsics.
Standardize spacing, blank lines, and indentation across docs and code for improved readability. No functional changes.
Add header guards to prevent AVX512 intrinsics inclusion on Windows,
fixing bindgen errors. Remove related blocklists now unnecessary.
Move header blocking from clang args to bindgen blocklists for better handling of Clang 20 issues with AVX512 types on Windows.
Clean up excess blank line and trailing space in blocklist_item.
Avoid AVX512 intrinsics issues by disabling Clang's builtin headers via -nostdinc. Removes related blocklists for cleaner bindgen config.
Replace -nostdinc hack with targeted blocklists for AVX512
intrinsics and types to avoid bindgen failures on Windows with
Clang 20. Improves maintainability and avoids suppressing all
builtin headers.
Define header guards in clang args to avoid inclusion of problematic AVX512-related headers when building on Windows.
Replace header guard defines with clang flags to disable AVX512,
AVX10.2, and AMX-AVX512 CPU features when generating bindings on
Windows. This prevents problematic intrinsics from being included.
Switch from disabling CPU features to undefining related
macros and adding MinGW include paths to address
intrinsics issues when generating bindings on Windows.
Add target flags, header guards, and blocklists to disable
AVX512 and AVX10 intrinsics/types for Windows builds.
This prevents build failures with Clang 20 and MinGW.
- Add comprehensive header guards for all AVX512/AVX10 intrinsics
- Create wrapper_windows.h to predefine guards before includes
- Add extensive -mno-avx* flags and -U macros for feature detection
- Update bindings.rs to use multi-level defense against intrinsics

This fixes the 'unknown type name __m512h' errors when building
with bindgen on Windows using Clang 20.
- Removed -mno-avx512er and -mno-avx512pf flags that are not recognized by some Clang versions
- These flags were causing 'unknown argument' errors on Windows CI
- MinGW include paths were already added for mm_malloc.h support
- Disable AVX and AVX2 to prevent loading of immintrin.h
- Pre-define __m128h, __m256h, __m512h types before any headers
- Pre-define _Float16 and vector types to avoid conflicts
- Add more header guards for SSE/AVX intrinsics headers
- Disable SSE, SSE2, SSE3, SSSE3, SSE4.1, SSE4.2
- This should prevent loading of emmintrin.h and other intrinsics
- Fix _Float16 typedef guard to prevent redefinition
- Removed problematic typedef struct definitions from wrapper_windows.h
- Added -msoft-float flag to completely avoid floating-point issues
- Keep header guards and macro undefinitions only
- Fixed formatting in bindings.rs line 65
- The -msoft-float flag was causing 'expected square brackets' parse errors
- Windows builds should work with the AVX/SSE disable flags alone
Comment out other Ruby versions and OSes to speed up CI runs or simplify debugging. All non-essential configurations are temporarily disabled.
- The CI environment sets BINDGEN_EXTRA_CLANG_ARGS with invalid target triple
- This was causing "expected square brackets" parse errors in bindgen
- Clear the environment variable on Windows before running bindgen
- Also added header guards for __AVX512FP16INTRIN_H format used by CI

Co-Authored-By: Claude <noreply@anthropic.com>
- The CI sets BINDGEN_EXTRA_CLANG_ARGS with --target=stable-x86_64-pc-windows-gnu
- The "stable" prefix is invalid and causes bindgen parse errors
- Filter out the invalid target flag while keeping other args
- This should fix the "expected square brackets" error on Windows

Co-Authored-By: Claude <noreply@anthropic.com>
- Filter the environment variable at the very beginning of main()
- This ensures it's cleaned before bindgen reads it internally
- Also add sysroot detection for Windows builds
- Remove duplicate filtering logic from bindings.rs

Co-Authored-By: Claude <noreply@anthropic.com>
- Update CI to use debug-windows branch with target triple fix
- Remove now-unnecessary BINDGEN_EXTRA_CLANG_ARGS filtering
- The fix is now upstream in the actions repository

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Parse and fix the invalid --target=stable-x86_64-pc-windows-gnu
- Replace with correct --target=x86_64-pc-windows-gnu
- This is done within the bindings generation code before bindgen runs
- Revert CI to use the main branch of oxidize-rb/actions

The upstream CI sets BINDGEN_EXTRA_CLANG_ARGS with an invalid target
triple that includes "stable-" prefix, which causes bindgen parse errors.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Fix the invalid target triple at the very beginning of main()
- This ensures it's fixed before any bindgen operations read it
- Remove duplicate fix from bindings.rs

The CI sets BINDGEN_EXTRA_CLANG_ARGS with --target=stable-x86_64-pc-windows-gnu
which causes bindgen parse errors. We need to fix it as early as possible.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
ianks and others added 20 commits July 4, 2025 16:47
- Fix the invalid target triple in create_rust_makefile method
- This ensures all rb-sys projects get the fix, not just rb-sys itself
- The CI sets BINDGEN_EXTRA_CLANG_ARGS with --target=stable-x86_64-pc-windows-gnu
- We filter out the invalid target and replace with correct one

This fix is applied when any rb-sys project calls create_rust_makefile,
ensuring the environment variable is corrected before the build starts.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add windows_bindgen_fix method to mkmf.rb
- Uses sed to replace invalid --target=stable-* with correct target
- Applied in generated Makefile before cargo is run
- Only runs on Windows platforms (mingw/mswin)

This ensures the environment variable is fixed before cargo/bindgen
sees it, avoiding the "expected square brackets" parse error.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Replace sed-based approach with Ruby gsub
- Fix lint issue: use match? instead of =~
- Fix environment variable at Ruby level before Makefile generation
- Export corrected value to Makefile

Sed doesn't work reliably in Windows MSYS environments, so we
fix the invalid target triple using Ruby string manipulation instead.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add debug logging in both build/main.rs and bindings.rs
- Fix the invalid target triple at both locations to ensure it's caught
- This will help us see if the fix is being applied and why it might not work

The CI sets BINDGEN_EXTRA_CLANG_ARGS with --target=stable-x86_64-pc-windows-gnu
which is invalid and causes bindgen parse errors.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add a step after setup-ruby-and-rust to fix the invalid target triple
- The upstream action sets --target=stable-x86_64-pc-windows-gnu
- Replace it with correct --target=x86_64-pc-windows-gnu
- Export the fixed value to GITHUB_ENV for subsequent steps

This fixes the issue at the CI level rather than trying to fix it
in multiple places within rb-sys itself.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Remove debug output from build/main.rs and bindings.rs
- The fix is now handled in the CI workflow instead
- Keep the codebase clean by removing temporary debug code

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Use safe navigation operator (&.) for ENV variable check
- Replace single quotes with double quotes per Ruby style guide
- Auto-fixed by standardrb tool for consistency

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Log Ruby's CPPFLAGS before passing them to bindgen
- This will help diagnose the 'expected square brackets' parse error
- The error might be coming from malformed flags or shell substitution

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Remove extra blank line in main.rs
- Keep code formatting consistent with rustfmt rules

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- The upstream setup-ruby-and-rust action adds -D__AVX512VLFP16INTRIN_H -D__AVX512FP16INTRIN_H
- These defines interfere with our header guard approach
- Remove them in the CI workflow after the action runs
- This should finally resolve the "expected square brackets" parse error

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Enable RUST_BACKTRACE=1 in CI for better error diagnostics
- Add RUST_LOG=bindgen=debug to get verbose bindgen output
- Improve error handling in bindings.rs to log full clang args
- This will help identify the source of 'expected square brackets' error

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Fix 'borrow of moved value' error by cloning clang_args
- The vector is moved into default_bindgen() but we need it for debug logging
- This allows the error handler to print the full clang args on failure

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
…rors

- Remove -mno-sse* flags that might be incompatible with MinGW
- Remove -march=x86-64 that might conflict with the target
- Fix cargo fmt issues with proper blank lines
- The 'expected square brackets' error might be related to these flags

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add comprehensive blocklist_file patterns to prevent loading any intrinsics headers
- Remove AVX disable flags that might trigger header inclusion
- Remove -U macros that might cause issues
- Add explicit -target flag to ensure correct target
- Clang is still loading its built-in headers despite our guards

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
…headers

The blocklist_file approach didn't work because Clang's built-in headers
are loaded internally and cannot be blocked with bindgen's blocklist_file.

Using -nostdinc prevents Clang from loading any system headers at all,
which should finally prevent the AVX512 intrinsics headers from being
loaded. We then manually add back the necessary include paths for MinGW.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
The -nostdinc approach was too aggressive and prevented Clang from finding
basic headers like stdarg.h. Instead, try undefining all the CPU feature
macros (__AVX512F__, __AVX__, etc.) to prevent the intrinsics headers
from being conditionally included.

Also set -march=x86-64 and -mtune=generic to target a basic x86_64
without vector extensions.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Restored the full test matrix for all Ruby versions and platforms
- Kept the lint job as a separate step for better CI organization
- Removed duplicate lint steps from the test job
- Kept only the changes necessary for the Windows AVX512 fix
This adds detection for NIX_STORE environment variable to prevent
rb-sys from treating nix environments as rubygems installations.
This avoids unnecessary recompilation in development when using nix.

Includes tests to verify the behavior in various scenarios.
🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Simplify Windows AVX512/FP16 workaround: use -mno-sse/-mno-avx for MinGW x86_64
- Remove custom wrapper_windows.h and related header guard logic
- Improve layout/debug impl gating for old Ruby on MinGW
- Switch to action version tags in CI workflows
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4

- uses: oxidize-rb/actions/setup-ruby-and-rust@v1

Check warning

Code scanning / CodeQL

Unpinned tag for a non-immutable Action in workflow Medium

Unpinned 3rd party Action 'CI' step
Uses Step
uses 'oxidize-rb/actions/setup-ruby-and-rust' with ref 'v1', not a pinned commit hash
@@ -18,7 +18,7 @@
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4

- uses: oxidize-rb/actions/setup-ruby-and-rust@d4731ac609739be0920f0faf5569b58b8eb1a262 # v1
- uses: oxidize-rb/actions/setup-ruby-and-rust@v1

Check warning

Code scanning / CodeQL

Unpinned tag for a non-immutable Action in workflow Medium

Unpinned 3rd party Action 'Publish book' step
Uses Step
uses 'oxidize-rb/actions/setup-ruby-and-rust' with ref 'v1', not a pinned commit hash
ianks and others added 2 commits July 7, 2025 13:16
- Move rubygems_invoked? to public method in CargoBuilder
- Clean up whitespace and formatting in documentation files
@ianks ianks merged commit bfb8d5e into main Jul 7, 2025
61 checks passed
@ianks ianks deleted the nix-detect branch July 7, 2025 18:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant