Skip to content

Commit adeb978

Browse files
authored
remove platform dependent unused stuff from sdl_bindings.rs, update sdl and dependencies (#1506)
* update bindgen and pin version, remove (hopefully all) platform dependent unused stuff from sdl_bindings.rs * update SDL to 2.32.10 release notes: https://github.com/libsdl-org/SDL/releases/tag/release-2.32.10 * take all changes from #1496 except changes to bindings * fmt * update bitflags and lazy_static * give all bitflags types the same useful set of derives mostly adds Default * add changelog entry * remove TODO and unpin bindgen
1 parent 4583b3d commit adeb978

File tree

15 files changed

+8278
-26394
lines changed

15 files changed

+8278
-26394
lines changed

Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ name = "sdl2"
1717
path = "src/sdl2/lib.rs"
1818

1919
[dependencies]
20-
bitflags = "1.2.1"
20+
bitflags = "2.10.0"
2121
libc = "0.2.92"
22-
lazy_static = "1.4.0"
22+
lazy_static = "1.5.0"
2323

2424
[dependencies.sdl2-sys]
2525
path = "sdl2-sys"
@@ -31,9 +31,9 @@ version = ">= 1.0"
3131
optional = true
3232

3333
[dev-dependencies]
34-
rand = "0.7"
35-
wgpu = { version = "0.20", features = ["spirv"] }
36-
pollster = "0.2.4"
34+
rand = "0.9.1"
35+
wgpu = { version = "26.0.1", features = ["spirv"] }
36+
pollster = "0.4.0"
3737
env_logger = "0.11.0"
3838

3939
[dependencies.raw-window-handle]

changelog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
In this file will be listed the changes, especially the breaking ones that one should be careful of
22
when upgrading from a version of rust-sdl2 to another.
33

4+
### v0.39.0
5+
6+
[PR #1506](https://github.com/Rust-SDL2/rust-sdl2/pull/1506) **BREAKING CHANGE** Update crates.io dependencies, update bundled SDL2 to 2.32.10, add whitelist to bindgen to only emit SDL related items, and specifically no platform (or compiler, etc) specific items. Implement the same set of useful derived traits on bitflags types.
7+
48
### v0.38.0
9+
510
[PR #1493](https://github.com/Rust-SDL2/rust-sdl2/pull/1493) Add `Rect::origin` and specifies origin location in `Rect::new`.
611

712
[PR #1472](https://github.com/Rust-SDL2/rust-sdl2/pull/1472) Add `Canvas::render_geometry`, `Canvas::render_geometry_raw` and an example that uses them both. Both these bindings use `SDL_RenderGeometryRaw`.

examples/audio-whitenoise.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ impl AudioCallback for MyCallback {
1111
type Channel = f32;
1212

1313
fn callback(&mut self, out: &mut [f32]) {
14-
use self::rand::{thread_rng, Rng};
15-
let mut rng = thread_rng();
14+
use self::rand::{rng, Rng};
15+
let mut rng = rng();
1616

1717
// Generate white noise
1818
for x in out.iter_mut() {
19-
*x = (rng.gen_range(0.0, 2.0) - 1.0) * self.volume;
19+
*x = (rng.random_range(0.0..2.0) - 1.0) * self.volume;
2020
}
2121
}
2222
}

sdl2-sys/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ path = "src/lib.rs"
2020
libc = "^0.2"
2121

2222
[build-dependencies.bindgen]
23-
version = "^0.69"
23+
version = "0.72.1"
2424
optional = true
2525

2626
[build-dependencies.pkg-config]

sdl2-sys/SDL

Submodule SDL updated 1349 files

sdl2-sys/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,7 @@ fn generate_bindings(target: &str, host: &str, headers_paths: &[String]) {
657657
let mut bindings = bindgen::Builder::default()
658658
// enable no_std-friendly output by only using core definitions
659659
.use_core()
660+
.allowlist_item("(SDL|AUDIO|RW)_.*")
660661
.bitfield_enum("SDL_RendererFlip")
661662
.newtype_enum("SDL_Keymod")
662663
.default_enum_style(bindgen::EnumVariation::Rust {

sdl2-sys/sdl_bindings.rs

Lines changed: 8190 additions & 26380 deletions
Large diffs are not rendered by default.

src/sdl2/event.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ pub enum EventType {
295295
ControllerDeviceAdded = SDL_EventType::SDL_CONTROLLERDEVICEADDED as u32,
296296
ControllerDeviceRemoved = SDL_EventType::SDL_CONTROLLERDEVICEREMOVED as u32,
297297
ControllerDeviceRemapped = SDL_EventType::SDL_CONTROLLERDEVICEREMAPPED as u32,
298+
ControllerSteamHandleUpdate = SDL_EventType::SDL_CONTROLLERSTEAMHANDLEUPDATED as u32,
298299
ControllerTouchpadDown = SDL_EventType::SDL_CONTROLLERTOUCHPADDOWN as u32,
299300
ControllerTouchpadMotion = SDL_EventType::SDL_CONTROLLERTOUCHPADMOTION as u32,
300301
ControllerTouchpadUp = SDL_EventType::SDL_CONTROLLERTOUCHPADUP as u32,
@@ -411,6 +412,7 @@ pub enum DisplayEvent {
411412
Orientation(Orientation),
412413
Connected,
413414
Disconnected,
415+
Moved,
414416
}
415417

416418
impl DisplayEvent {
@@ -433,6 +435,7 @@ impl DisplayEvent {
433435
}
434436
sys::SDL_DisplayEventID::SDL_DISPLAYEVENT_CONNECTED => DisplayEvent::Connected,
435437
sys::SDL_DisplayEventID::SDL_DISPLAYEVENT_DISCONNECTED => DisplayEvent::Disconnected,
438+
sys::SDL_DisplayEventID::SDL_DISPLAYEVENT_MOVED => DisplayEvent::Moved,
436439
}
437440
}
438441

@@ -450,6 +453,7 @@ impl DisplayEvent {
450453
sys::SDL_DisplayEventID::SDL_DISPLAYEVENT_DISCONNECTED as u8,
451454
0,
452455
),
456+
DisplayEvent::Moved => (sys::SDL_DisplayEventID::SDL_DISPLAYEVENT_MOVED as u8, 0),
453457
}
454458
}
455459

@@ -739,6 +743,11 @@ pub enum Event {
739743
/// The controller's joystick `id`
740744
which: u32,
741745
},
746+
ControllerSteamHandleUpdate {
747+
timestamp: u32,
748+
/// The controller's joystick `id`
749+
which: u32,
750+
},
742751

743752
ControllerTouchpadDown {
744753
timestamp: u32,
@@ -1464,6 +1473,22 @@ impl Event {
14641473
}
14651474
}
14661475

1476+
Event::ControllerSteamHandleUpdate { timestamp, which } => {
1477+
let event = sys::SDL_ControllerDeviceEvent {
1478+
type_: SDL_EventType::SDL_CONTROLLERSTEAMHANDLEUPDATED as u32,
1479+
timestamp,
1480+
which: which as i32,
1481+
};
1482+
unsafe {
1483+
ptr::copy(
1484+
&event,
1485+
ret.as_mut_ptr() as *mut sys::SDL_ControllerDeviceEvent,
1486+
1,
1487+
);
1488+
Some(ret.assume_init())
1489+
}
1490+
}
1491+
14671492
Event::FingerDown { .. }
14681493
| Event::FingerUp { .. }
14691494
| Event::FingerMotion { .. }
@@ -1784,6 +1809,13 @@ impl Event {
17841809
which: event.which as u32,
17851810
}
17861811
}
1812+
EventType::ControllerSteamHandleUpdate => {
1813+
let event = raw.cdevice;
1814+
Event::ControllerSteamHandleUpdate {
1815+
timestamp: event.timestamp,
1816+
which: event.which as u32,
1817+
}
1818+
}
17871819
EventType::ControllerTouchpadDown => {
17881820
let event = raw.ctouchpad;
17891821
Event::ControllerTouchpadDown {
@@ -2101,6 +2133,10 @@ impl Event {
21012133
| (Self::ControllerDeviceAdded { .. }, Self::ControllerDeviceAdded { .. })
21022134
| (Self::ControllerDeviceRemoved { .. }, Self::ControllerDeviceRemoved { .. })
21032135
| (Self::ControllerDeviceRemapped { .. }, Self::ControllerDeviceRemapped { .. })
2136+
| (
2137+
Self::ControllerSteamHandleUpdate { .. },
2138+
Self::ControllerSteamHandleUpdate { .. },
2139+
)
21042140
| (Self::FingerDown { .. }, Self::FingerDown { .. })
21052141
| (Self::FingerUp { .. }, Self::FingerUp { .. })
21062142
| (Self::FingerMotion { .. }, Self::FingerMotion { .. })
@@ -2170,6 +2206,7 @@ impl Event {
21702206
Self::ControllerDeviceAdded { timestamp, .. } => timestamp,
21712207
Self::ControllerDeviceRemoved { timestamp, .. } => timestamp,
21722208
Self::ControllerDeviceRemapped { timestamp, .. } => timestamp,
2209+
Self::ControllerSteamHandleUpdate { timestamp, .. } => timestamp,
21732210
Self::ControllerTouchpadDown { timestamp, .. } => timestamp,
21742211
Self::ControllerTouchpadMotion { timestamp, .. } => timestamp,
21752212
Self::ControllerTouchpadUp { timestamp, .. } => timestamp,
@@ -2413,6 +2450,7 @@ impl Event {
24132450
| Self::ControllerDeviceAdded { .. }
24142451
| Self::ControllerDeviceRemoved { .. }
24152452
| Self::ControllerDeviceRemapped { .. }
2453+
| Self::ControllerSteamHandleUpdate { .. }
24162454
)
24172455
}
24182456

src/sdl2/image/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ use version::Version;
3434
bitflags! {
3535
/// InitFlags are passed to init() to control which subsystem
3636
/// functionality to load.
37+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
3738
pub struct InitFlag : u32 {
3839
const JPG = image::IMG_InitFlags_IMG_INIT_JPG;
3940
const PNG = image::IMG_InitFlags_IMG_INIT_PNG;

src/sdl2/keyboard/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ pub use self::keycode::Keycode;
1616
pub use self::scancode::Scancode;
1717

1818
bitflags! {
19+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
1920
pub struct Mod: u16 {
20-
const NOMOD = crate::sys::SDL_Keymod::KMOD_NONE.0 as u16;
21+
const NOMOD = crate::sys::SDL_Keymod::KMOD_NONE.0 as u16;
2122
const LSHIFTMOD = crate::sys::SDL_Keymod::KMOD_LSHIFT.0 as u16;
2223
const RSHIFTMOD = crate::sys::SDL_Keymod::KMOD_RSHIFT.0 as u16;
2324
const LCTRLMOD = crate::sys::SDL_Keymod::KMOD_LCTRL.0 as u16;

0 commit comments

Comments
 (0)