-
Notifications
You must be signed in to change notification settings - Fork 472
Remove X11 and Wayland specific items in pregenerated bindings, refactor build.rs, clean and update bindings #1516
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
For review: please look at the TODO questions (with the checkboxes) too |
|
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 |
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.
Agreed. Does this crate currently build on windows? |
It does, but not with default features. I use this in my 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 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;
}
} |
I saw exactly this in the CI too on windows.
Using git blame to see which PR added the pregenerated bindings, I found this: #695 (comment), dependencies for bindgen are hard to install on windows, but (ironically) the pregenerated bindings only work on linux (on master currently). |
|
So it looks like we might want target specific pregenerated bindings but only for the target specific items (functions, structs, etc). We could also remove that target specific stuff from the pregenerated bindings and ask people to use bindgen when they want to interact with things like the windows manager directly. This would technically be breaking for the few people using this on linux, but given that bindgen runs pretty much out of the box on linux this does not sound too bad. |
|
Ok so this issue comes from commit adeb978 which was from #1506 . I manually bisected it myself on my windows machine. It was probably merged a bit hastily, as the CI fails but with a different error than previously. The issue seems to come from the new EDIT: I think it's probably fixed by doing this: fn generate_bindings(target: &str, host: &str, headers_paths: &[String]) {
let target_os = get_os_from_triple(target).unwrap();
let mut bindings = bindgen::Builder::default()
// enable no_std-friendly output by only using core definitions
.use_core()
.allowlist_item("(SDL|AUDIO|RW)_.*")
.opaque_type("XEvent") // <- this
// ....in sdl2-sys/build.rs XEvent is in the bindings when it has no place to be there, which is a cascade for all the other issues in the CI. It only affects SysWM bindings, which are all platform-specific anyway and you would need bindgen for that. |
The instructions from the bindgen docs have worked every time for me, and it's basically the same as running |
Bindgen has layout checks that were "test functions" (
I was just paraphrasing there, I have never installed bindgen on windows. |
3394fcb to
76fabbc
Compare
It did not work, there were SDL structs that have fields for x11 and wayland that used types like XEvent. |
other less impactful changes: - Remove unused aliases to integer types from bindings - Update bindings - Refactor sdl2-sys/build.rs - Add `update_pregenerated_bindings` now that pregenerated bindings are different. (include no X11 and Wayland specific items anymore)
generate to OUT_DIR as usual, copy from there to the crate root to update the pregenerated bindings also remove `fs::create_dir(&out_path)`, this was left over from target-specific bindings
| not(feature = "bindgen"), | ||
| not(feature = "bundled"), | ||
| ))] | ||
| compile_error!("Enable 'bindgen' and 'bundled' features when using update_pregenerated_bindings"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought it would be fixed after I mentioned it once but apparently not, but maybe this feature of Cargo.toml is not very obvious. In Cargo.toml you can add:
[features]
update_pregenerated_bindings = ["bindgen"]
And enabling update_pregenerated_bindings will auto enable the feature bindgen, saving you from a lot of branching of features or this compile_error message. 2nd point is, bindgen does not have to work with only bundled, but can also work with use-pkgconfig for instance (also I haven't tested it recently), so you shouldn't require bundled to be always on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I at first tried a feature flag, but later realized that a feature is part of the public API, can be enabled from the outside and is listed in the documentation. update_pregenerated_bindings is really for internal use.
bundled is here because I think the bindings should be generated from the bundled SDL2 headers so the versions of the SDL2 submodule and bindings are in sync. (Bindings for the other libs are generated using system headers still because they are not bundled (yet).)
fixes #1511
Remove X11 and Wayland specific items in pregenerated bindings: these bindings cause compile errors on windows, where they are not even usable. SysWM functions are pretty niche, so people using them should use bindgen