Skip to content

Commit 64484b8

Browse files
authored
Fix build, tests, examples for SDL3 as of 2023-07-31 (#5)
* Check /usr/local/lib for libSDL on Linux * Fix build, tests, examples for SDL3 as of 2023-07-30 This commit fixes numerous build and test failures that pop up when linking against an updated SDL3-sys that uses recent a recent SDL3 git version (fb68e8464638976e13c6a31eb8d3a7884e4b833e used here). Note that this version depends on an open PR to sdl3-sys-rs (to allow for testing). New feature: - Feature `test-mode` allows running the integration tests without failing the Sdl::init() sanity check; the documentation reflects this now. Missing: - examples/audio-wav.rs is currently disabled; it needs to be ported from AudioCVT (which has been retired) to AudioStream. - The examples need testing. - The docs still refer to sdl2 all over the place.
1 parent 2d8218e commit 64484b8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+492
-552
lines changed

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ image = ["sdl3-sys/image"]
4848
ttf = ["sdl3-sys/ttf"]
4949
# Use hidapi support in SDL. Only 2.0.12 and after
5050
hidapi = []
51+
# test_mode allows SDL to be initialised from a thread that is not the main thread
52+
test-mode = []
5153

5254
use-bindgen = ["sdl3-sys/use-bindgen"]
5355
use-pkgconfig = ["sdl3-sys/use-pkgconfig"]

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,14 @@ the latest version of both Rust and Cargo, check that you've updated sdl3-rs
725725
to the latest version, and run `cargo clean`. If that fails, please let us know
726726
on the issue tracker.
727727

728+
# Testing
729+
730+
You can run the test suite via:
731+
```
732+
cargo test --features=test-mode
733+
```
734+
The `test-mode` feature allows running `Sdl::new()` from a thread other than the main thread, which is necessary for running the integration tests (`test/*.rs`).
735+
728736
# Contributing
729737

730738
We're looking for people to help get SDL3 support in Rust built, tested, and completed. You can help out!

build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
fn main() {
2-
#[cfg(any(target_os = "openbsd", target_os = "freebsd"))]
2+
#[cfg(any(target_os = "linux", target_os = "openbsd", target_os = "freebsd"))]
33
println!(r"cargo:rustc-link-search=/usr/local/lib");
44
}

examples/animation.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,14 @@ fn main() -> Result<(), String> {
7575
let ticks = timer.ticks() as i32;
7676

7777
// set the current frame for time
78-
source_rect_0.set_x(32 * ((ticks / 100) % frames_per_anim));
79-
dest_rect_0.set_x(1 * ((ticks / 14) % 768) - 128);
78+
source_rect_0.set_x((32 * ((ticks / 100) % frames_per_anim)) as f32);
79+
dest_rect_0.set_x((1 * ((ticks / 14) % 768) - 128) as f32);
8080

81-
source_rect_1.set_x(32 * ((ticks / 100) % frames_per_anim));
82-
dest_rect_1.set_x((1 * ((ticks / 12) % 768) - 672) * -1);
81+
source_rect_1.set_x((32 * ((ticks / 100) % frames_per_anim)) as f32);
82+
dest_rect_1.set_x(((1 * ((ticks / 12) % 768) - 672) * -1) as f32);
8383

84-
source_rect_2.set_x(32 * ((ticks / 100) % frames_per_anim));
85-
dest_rect_2.set_x(1 * ((ticks / 10) % 768) - 128);
84+
source_rect_2.set_x((32 * ((ticks / 100) % frames_per_anim)) as f32);
85+
dest_rect_2.set_x((1 * ((ticks / 10) % 768) - 128) as f32);
8686

8787
canvas.clear();
8888
// copy the frame to the canvas

examples/audio-capture-and-replay.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
extern crate sdl2;
1+
extern crate sdl3;
22

3-
use sdl2::audio::{AudioCallback, AudioSpecDesired};
4-
use sdl2::AudioSubsystem;
3+
use sdl3::audio::{AudioCallback, AudioSpecDesired};
4+
use sdl3::AudioSubsystem;
55
use std::i16;
66
use std::sync::mpsc;
77
use std::time::Duration;
@@ -140,7 +140,7 @@ fn replay_recorded_vec(
140140
}
141141

142142
fn main() -> Result<(), String> {
143-
let sdl_context = sdl2::init()?;
143+
let sdl_context = sdl3::init()?;
144144
let audio_subsystem = sdl_context.audio()?;
145145

146146
let desired_spec = AudioSpecDesired {

examples/audio-queue-squarewave.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
extern crate sdl2;
1+
extern crate sdl3;
22

3-
use sdl2::audio::AudioSpecDesired;
3+
use sdl3::audio::AudioSpecDesired;
44

55
use std::time::Duration;
66

@@ -22,7 +22,7 @@ fn gen_wave(bytes_to_write: i32) -> Vec<i16> {
2222
}
2323

2424
fn main() -> Result<(), String> {
25-
let sdl_context = sdl2::init()?;
25+
let sdl_context = sdl3::init()?;
2626
let audio_subsystem = sdl_context.audio()?;
2727

2828
let desired_spec = AudioSpecDesired {

examples/audio-squarewave.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
extern crate sdl2;
1+
extern crate sdl3;
22

3-
use sdl2::audio::{AudioCallback, AudioSpecDesired};
3+
use sdl3::audio::{AudioCallback, AudioSpecDesired};
44
use std::time::Duration;
55

66
struct SquareWave {
@@ -26,7 +26,7 @@ impl AudioCallback for SquareWave {
2626
}
2727

2828
fn main() -> Result<(), String> {
29-
let sdl_context = sdl2::init()?;
29+
let sdl_context = sdl3::init()?;
3030
let audio_subsystem = sdl_context.audio()?;
3131

3232
let desired_spec = AudioSpecDesired {

examples/audio-wav.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
extern crate sdl2;
1+
extern crate sdl3;
22

3-
use sdl2::audio::{AudioCVT, AudioCallback, AudioSpecDesired, AudioSpecWAV};
3+
use sdl3::audio::{AudioCallback, AudioSpecDesired, AudioSpecWAV};
44
use std::borrow::Cow;
55
use std::path::{Path, PathBuf};
66
use std::time::Duration;
@@ -38,12 +38,15 @@ impl AudioCallback for Sound {
3838
}
3939
}
4040

41+
// FIXME: Convert to AudioStream library
42+
fn main() -> () {}
43+
#[cfg(feature = "")]
4144
fn main() -> Result<(), String> {
4245
let wav_file: Cow<'static, Path> = match std::env::args().nth(1) {
4346
None => Cow::from(Path::new("./assets/sine.wav")),
4447
Some(s) => Cow::from(PathBuf::from(s)),
4548
};
46-
let sdl_context = sdl2::init()?;
49+
let sdl_context = sdl3::init()?;
4750
let audio_subsystem = sdl_context.audio()?;
4851

4952
let desired_spec = AudioSpecDesired {
@@ -85,3 +88,4 @@ fn main() -> Result<(), String> {
8588

8689
Ok(())
8790
}
91+

examples/audio-whitenoise.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
extern crate rand;
2-
extern crate sdl2;
2+
extern crate sdl3;
33

4-
use sdl2::audio::{AudioCallback, AudioSpecDesired};
4+
use sdl3::audio::{AudioCallback, AudioSpecDesired};
55
use std::time::Duration;
66

77
struct MyCallback {
@@ -22,7 +22,7 @@ impl AudioCallback for MyCallback {
2222
}
2323

2424
fn main() -> Result<(), String> {
25-
let sdl_context = sdl2::init()?;
25+
let sdl_context = sdl3::init()?;
2626
let audio_subsystem = sdl_context.audio()?;
2727

2828
let desired_spec = AudioSpecDesired {

examples/cursor.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
extern crate sdl2;
1+
extern crate sdl3;
22

3-
use sdl2::event::Event;
4-
use sdl2::image::{InitFlag, LoadSurface};
5-
use sdl2::keyboard::Keycode;
6-
use sdl2::mouse::Cursor;
7-
use sdl2::pixels::Color;
8-
use sdl2::rect::Rect;
9-
use sdl2::surface::Surface;
3+
use sdl3::event::Event;
4+
use sdl3::image::{InitFlag, LoadSurface};
5+
use sdl3::keyboard::Keycode;
6+
use sdl3::mouse::Cursor;
7+
use sdl3::pixels::Color;
8+
use sdl3::rect::Rect;
9+
use sdl3::surface::Surface;
1010
use std::env;
1111
use std::path::Path;
1212

1313
pub fn run(png: &Path) -> Result<(), String> {
14-
let sdl_context = sdl2::init()?;
14+
let sdl_context = sdl3::init()?;
1515
let video_subsystem = sdl_context.video()?;
16-
let _image_context = sdl2::image::init(InitFlag::PNG | InitFlag::JPG)?;
16+
let _image_context = sdl3::image::init(InitFlag::PNG | InitFlag::JPG)?;
1717
let window = video_subsystem
18-
.window("rust-sdl2 demo: Cursor", 800, 600)
18+
.window("rust-sdl3 demo: Cursor", 800, 600)
1919
.position_centered()
2020
.build()
2121
.map_err(|e| e.to_string())?;

0 commit comments

Comments
 (0)