Skip to content

Conversation

@antonilol
Copy link
Contributor

@antonilol antonilol commented Dec 10, 2025

fixes #1511

If pregenerated bindings are not available for the target this error is printed (temporarily removed them to test):

  Could not copy pregenerated bindings "sdl_bindings.rs" for target "x86_64-unknown-linux-gnu": No such file or directory (os error 2).
  If pregenerated bindings do not exist for your target, they can be generated by enabling the "bindgen" feature.

Only 2 CI checks fail now instead of the 6 on master currently, those 2 that fail is related to vcpkg and not on linux, so maybe someone else has some insights on how to fix that.

The diff of locally found bindings and generated ones is dumped in the CI logs, from there I git applied it, worked pretty well :).

TODO:

  • Did any of mixer,ttf,gfx,image work on mac or windows without bindgen? That currently doesn't in this PR because I don't have the necessary C header files.
  • Fall back to bindings generated on linux if there are none for the current target?

@antonilol antonilol marked this pull request as ready for review December 10, 2025 22:31
@antonilol antonilol changed the title refactor generate_bindings, clean and update remaining bindings Target specific bindings + refactor generate_bindings, clean, update remaining bindings Dec 10, 2025
extern crate statements are not needed anymore, cfg_if was unused,
remove unused import
@antonilol
Copy link
Contributor Author

For review: please look at the TODO questions (with the checkboxes) too

@Cobrand
Copy link
Member

Cobrand commented Dec 16, 2025

I am not against the idea but what does this specifically solve? Current bindings are generated for linux and 99% of users will never know the difference if it was generated for windows or something else.

The only exception is when using platform-specific stuff such as raw-window-handle, but then the feature flag use-bindgen is here for that, and I assume it's only going to be a problem for a very specific minority, but a lot of complexity added.

@antonilol
Copy link
Contributor Author

I am not against the idea but what does this specifically solve? Current bindings are generated for linux and 99% of users will never know the difference if it was generated for windows or something else.

I dont use windows, but on master currently all windows tests fail because of a layout incompatibility found by bindgen (the generated layout tests) on windows (example). This PR fixes this, but can be overkill. I dont expect a layout incompatibility because primitive types have the same layout on linux as on windows.

The only exception is when using platform-specific stuff such as raw-window-handle, but then the feature flag use-bindgen is here for that, and I assume it's only going to be a problem for a very specific minority, but a lot of complexity added.

Agreed.

Does this crate currently build on windows?

@renski-dev
Copy link
Contributor

renski-dev commented Dec 24, 2025

Does this crate currently build on windows?

It does, but not with default features. I use this in my Cargo.toml:

sdl2 = { git = "https://github.com/Rust-SDL2/rust-sdl2.git", features = [
  "static-link",
  "bundled",
  "use-bindgen",
] }

Without bindgen, all the X11 types and SDL types that include X11 types fail layout checks. As far as I can tell, there is no reasonable way to solve this without target specific bindings or bindgen.

Though, why not use bindgen by default?

Edit
The cause of the mismatch is the size of type XID = libc::c_ulong. From the libc crate:

cfg_if! {
    if #[cfg(all(target_pointer_width = "64", not(windows)))] {
        pub type c_long = i64;
        pub type c_ulong = u64;
    } else {
        // The minimal size of `long` in the C standard is 32 bits
        pub type c_long = i32;
        pub type c_ulong = u32;
    }
}

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.

Idea: target specific sdl_bindings.rs

3 participants