Skip to content

Commit e3c0658

Browse files
authored
Allow bundled debug build (#1081)
sdl2-sys was hardcoding the bundled build as a release build, unconditionally for a long time. This can cause problems however if an upstream link of a binary is mixing C++ libraries that mix debug and non debug builds, or so at least I'm led to believe for static builds.
1 parent 706d608 commit e3c0658

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ when upgrading from a version of rust-sdl2 to another.
55

66
* Add patch to fix metal detection (https://bugzilla.libsdl.org/show_bug.cgi?id=4988)
77
* Changed signature of TimerSubsystem::ticks to accept `&self`.
8+
9+
[PR #1081](https://github.com/Rust-SDL2/rust-sdl2/pull/1081): Allow bundled build to be built in debug mode. Fixes issue when linking binary with mixed debug+release CRT dependencies.
10+
811
[PR #1080](https://github.com/Rust-SDL2/rust-sdl2/pull/1080): Fix line endings of patches to lf so patching of sources works on Windows.
912

1013
### v0.34.4

sdl2-sys/build.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,6 @@ fn patch_sdl2(sdl2_source_path: &Path) {
304304
#[cfg(feature = "bundled")]
305305
fn compile_sdl2(sdl2_build_path: &Path, target_os: &str) -> PathBuf {
306306
let mut cfg = cmake::Config::new(sdl2_build_path);
307-
cfg.profile("release");
308307

309308
#[cfg(target_os = "linux")]
310309
{
@@ -416,11 +415,24 @@ fn link_sdl2(target_os: &str) {
416415

417416
#[cfg(feature = "static-link")]
418417
{
418+
// There's no way to extract this from `cmake::Config` so we have to emulate their
419+
// behaviour here (see the source for `cmake::Config::build`).
420+
let debug_postfix = match (
421+
&env::var("OPT_LEVEL").unwrap_or_default()[..],
422+
&env::var("PROFILE").unwrap_or_default()[..],
423+
) {
424+
("1", _) | ("2", _) | ("3", _) | ("s", _) | ("z", _) => "",
425+
("0", _) => "d",
426+
(_, "debug") => "d",
427+
// ("0", _) => "",
428+
// (_, "debug") => "",
429+
(_, _) => "",
430+
};
419431
if cfg!(feature = "bundled")
420432
|| (cfg!(feature = "use-pkgconfig") == false && cfg!(feature = "use-vcpkg") == false)
421433
{
422-
println!("cargo:rustc-link-lib=static=SDL2main");
423-
println!("cargo:rustc-link-lib=static=SDL2");
434+
println!("cargo:rustc-link-lib=static=SDL2main{}", debug_postfix);
435+
println!("cargo:rustc-link-lib=static=SDL2{}", debug_postfix);
424436
}
425437

426438
// Also linked to any required libraries for each supported platform

0 commit comments

Comments
 (0)