Skip to content

Commit d2bd9ed

Browse files
committed
Move linker flags of the mixer module into build script
Progresses on Rust-SDL2#647
1 parent cdd0fad commit d2bd9ed

File tree

2 files changed

+16
-21
lines changed

2 files changed

+16
-21
lines changed

sdl2-sys/build.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,22 @@ fn link_sdl2(target_os: &str) {
196196
// TODO: Add other platform linker options here.
197197
}
198198
}
199+
// SDL libraries seem to not be packed with pkgconfig file on all distros,
200+
// and in the same distros (fedora at least) a symlink is also missing.
201+
//
202+
// Linking directly with file is not possible with cargo since the
203+
// ':filename' syntax is used for renaming of libraries, which basically
204+
// leaves it up to the user to make a symlink to the shared object so
205+
// -lSDL2_mixer can find it.
206+
#[cfg(all(not(feature = "use-pkgconfig"), not(feature = "static-link")))] {
207+
if cfg!(all(any(target_os="linux", target_os="freebsd"), feature = "mixer")) {
208+
println!("cargo:rustc-flags=-l SDL2_mixer");
209+
} else if cfg!(all(target_os="windows", feature = "mixer")) {
210+
println!("cargo:rustc-flags=-l SDL2_mixer");
211+
} else if cfg!(all(any(target_os="macos", feature="use_mac_framework"), feature = "mixer")) {
212+
println!("cargo:rustc-flags=-l framework=SDL2_mixer");
213+
}
214+
}
199215
}
200216

201217
fn main() {

src/sdl2/mixer/mod.rs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -34,27 +34,6 @@ use ::rwops::RWops;
3434
use ::version::Version;
3535
use sys;
3636

37-
// Setup linking for all targets.
38-
#[cfg(target_os="macos")]
39-
mod mac {
40-
#[cfg(any(mac_framework, feature="use_mac_framework"))]
41-
#[link(kind="framework", name="SDL2_mixer")]
42-
extern "C" {
43-
}
44-
45-
#[cfg(not(any(mac_framework, feature="use_mac_framework")))]
46-
#[link(name="SDL2_mixer")]
47-
extern "C" {
48-
}
49-
}
50-
51-
#[cfg(any(target_os="windows", target_os="linux", target_os="freebsd"))]
52-
mod others {
53-
#[link(name="SDL2_mixer")]
54-
extern "C" {
55-
}
56-
}
57-
5837
// This comes from SDL_audio.h
5938
#[allow(non_camel_case_types)]
6039
mod ll {

0 commit comments

Comments
 (0)