Skip to content

Commit a27c3c6

Browse files
committed
Convert SDL_mixer bindings into autogenerated bindings
Progresses on #647
1 parent f2a7b7f commit a27c3c6

File tree

6 files changed

+544
-194
lines changed

6 files changed

+544
-194
lines changed

examples/mixer-demo.rs

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

55
use std::env;
66
use std::path::Path;
7-
use sdl2::mixer::{DEFAULT_CHANNELS, INIT_MP3, INIT_FLAC, INIT_MOD, INIT_FLUIDSYNTH, INIT_MODPLUG,
7+
use sdl2::mixer::{DEFAULT_CHANNELS, INIT_MP3, INIT_FLAC, INIT_MOD,
88
INIT_OGG, AUDIO_S16LSB};
99

1010
fn main() {
@@ -33,7 +33,7 @@ fn demo(music_file: &Path, sound_file: Option<&Path>) {
3333
let chunk_size = 1_024;
3434
sdl2::mixer::open_audio(frequency, format, channels, chunk_size).unwrap();
3535
let _mixer_context = sdl2::mixer::init(
36-
INIT_MP3 | INIT_FLAC | INIT_MOD | INIT_FLUIDSYNTH | INIT_MODPLUG | INIT_OGG
36+
INIT_MP3 | INIT_FLAC | INIT_MOD | INIT_OGG
3737
).unwrap();
3838

3939
// Number of mixing channels available for sound effect `Chunk`s to play

sdl2-sys/build.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,9 @@ fn copy_pregenerated_bindings() {
287287

288288
fs::copy(crate_path.join("sdl_ttf_bindings.rs"), out_path.join("ttf_bindings.rs"))
289289
.expect("Couldn't find pregenerated SDL_ttf bindings!");
290+
291+
fs::copy(crate_path.join("sdl_mixer_bindings.rs"), out_path.join("mixer_bindings.rs"))
292+
.expect("Couldn't find pregenerated SDL_mixer bindings!");
290293
}
291294

292295
#[cfg(feature = "bindgen")]
@@ -297,6 +300,7 @@ fn generate_bindings<S: AsRef<str> + ::std::fmt::Debug>(target: &str, host: &str
297300
let mut bindings = bindgen::Builder::default();
298301
let mut image_bindings = bindgen::Builder::default();
299302
let mut ttf_bindings = bindgen::Builder::default();
303+
let mut mixer_bindings = bindgen::Builder::default();
300304

301305
// Set correct target triple for bindgen when cross-compiling
302306
if target != host {
@@ -308,6 +312,9 @@ fn generate_bindings<S: AsRef<str> + ::std::fmt::Debug>(target: &str, host: &str
308312

309313
ttf_bindings = ttf_bindings.clang_arg("-target");
310314
ttf_bindings = ttf_bindings.clang_arg(target.clone());
315+
316+
mixer_bindings = mixer_bindings.clang_arg("-target");
317+
mixer_bindings = mixer_bindings.clang_arg(target.clone());
311318
}
312319

313320
if headers_paths.len() == 0 {
@@ -318,12 +325,14 @@ fn generate_bindings<S: AsRef<str> + ::std::fmt::Debug>(target: &str, host: &str
318325
bindings = bindings.clang_arg(format!("-I{}", include_path.display()));
319326
image_bindings = image_bindings.clang_arg(format!("-I{}", include_path.display()));
320327
ttf_bindings = ttf_bindings.clang_arg(format!("-I{}", include_path.display()));
328+
mixer_bindings = mixer_bindings.clang_arg(format!("-I{}", include_path.display()));
321329
} else {
322330
// if paths are included, use them for bindgen. Bindgen should use the first one.
323331
for headers_path in headers_paths {
324332
bindings = bindings.clang_arg(format!("-I{}", headers_path.as_ref()));
325333
image_bindings = image_bindings.clang_arg(format!("-I{}", headers_path.as_ref()));
326334
ttf_bindings = ttf_bindings.clang_arg(format!("-I{}", headers_path.as_ref()));
335+
mixer_bindings = mixer_bindings.clang_arg(format!("-I{}", headers_path.as_ref()));
327336
}
328337
}
329338

@@ -345,6 +354,12 @@ fn generate_bindings<S: AsRef<str> + ::std::fmt::Debug>(target: &str, host: &str
345354
ttf_bindings = ttf_bindings.clang_arg(format!("-IC:/Program Files (x86)/Windows Kits/10/Include/10.0.10240.0/ucrt"));
346355
ttf_bindings = ttf_bindings.clang_arg(format!("-IC:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/include"));
347356
ttf_bindings = ttf_bindings.clang_arg(format!("-IC:/Program Files (x86)/Windows Kits/8.1/Include/um"));
357+
358+
mixer_bindings = mixer_bindings.clang_arg(format!("-IC:/Program Files (x86)/Windows Kits/8.1/Include/shared"));
359+
mixer_bindings = mixer_bindings.clang_arg(format!("-IC:/Program Files/LLVM/lib/clang/5.0.0/include"));
360+
mixer_bindings = mixer_bindings.clang_arg(format!("-IC:/Program Files (x86)/Windows Kits/10/Include/10.0.10240.0/ucrt"));
361+
mixer_bindings = mixer_bindings.clang_arg(format!("-IC:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/include"));
362+
mixer_bindings = mixer_bindings.clang_arg(format!("-IC:/Program Files (x86)/Windows Kits/8.1/Include/um"));
348363
};
349364

350365
// SDL2 hasn't a default configuration for Linux
@@ -355,6 +370,8 @@ fn generate_bindings<S: AsRef<str> + ::std::fmt::Debug>(target: &str, host: &str
355370
image_bindings = image_bindings.clang_arg("-DSDL_VIDEO_DRIVER_WAYLAND");
356371
ttf_bindings = ttf_bindings.clang_arg("-DSDL_VIDEO_DRIVER_X11");
357372
ttf_bindings = ttf_bindings.clang_arg("-DSDL_VIDEO_DRIVER_WAYLAND");
373+
mixer_bindings = mixer_bindings.clang_arg("-DSDL_VIDEO_DRIVER_X11");
374+
mixer_bindings = mixer_bindings.clang_arg("-DSDL_VIDEO_DRIVER_WAYLAND");
358375
}
359376

360377
let bindings = bindings
@@ -403,6 +420,24 @@ fn generate_bindings<S: AsRef<str> + ::std::fmt::Debug>(target: &str, host: &str
403420
.write_to_file(out_path.join("ttf_bindings.rs"))
404421
.expect("Couldn't write ttf_bindings!");
405422

423+
let mixer_bindings = mixer_bindings
424+
.header("wrapper_mixer.h")
425+
.whitelist_type("MIX.*")
426+
.whitelist_type("Mix.*")
427+
.whitelist_type("MUS.*")
428+
.whitelist_function("Mix.*")
429+
.whitelist_var("MIX.*")
430+
.whitelist_var("MUS.*")
431+
.blacklist_type("SDL_.*")
432+
.blacklist_type("_IO.*|FILE")
433+
.generate()
434+
.expect("Unable to generate mixer_bindings!");
435+
436+
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
437+
438+
mixer_bindings
439+
.write_to_file(out_path.join("mixer_bindings.rs"))
440+
.expect("Couldn't write mixer_bindings!");
406441
}
407442

408443
fn get_os_from_triple(triple: &str) -> Option<&str>

0 commit comments

Comments
 (0)