From d9808cb12710b80b1a94fa0090df740331b74a68 Mon Sep 17 00:00:00 2001 From: Mike Waychison Date: Fri, 9 Oct 2020 00:24:54 -0400 Subject: [PATCH 1/3] sdl2-sys: Allow bundled debug build 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. --- sdl2-sys/build.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/sdl2-sys/build.rs b/sdl2-sys/build.rs index 3dba6cbd7f0..4cfda7a6834 100644 --- a/sdl2-sys/build.rs +++ b/sdl2-sys/build.rs @@ -304,7 +304,6 @@ fn patch_sdl2(sdl2_source_path: &Path) { #[cfg(feature = "bundled")] fn compile_sdl2(sdl2_build_path: &Path, target_os: &str) -> PathBuf { let mut cfg = cmake::Config::new(sdl2_build_path); - cfg.profile("release"); #[cfg(target_os = "linux")] { @@ -416,11 +415,24 @@ fn link_sdl2(target_os: &str) { #[cfg(feature = "static-link")] { + // There's no way to extract this from `cmake::Config` so we have to emulate their + // behaviour here (see the source for `cmake::Config::build`). + let debug_postfix = match ( + &env::var("OPT_LEVEL").unwrap_or_default()[..], + &env::var("PROFILE").unwrap_or_default()[..], + ) { + ("1", _) | ("2", _) | ("3", _) | ("s", _) | ("z", _) => "", + ("0", _) => "d", + (_, "debug") => "d", + // ("0", _) => "", + // (_, "debug") => "", + (_, _) => "", + }; if cfg!(feature = "bundled") || (cfg!(feature = "use-pkgconfig") == false && cfg!(feature = "use-vcpkg") == false) { - println!("cargo:rustc-link-lib=static=SDL2main"); - println!("cargo:rustc-link-lib=static=SDL2"); + println!("cargo:rustc-link-lib=static=SDL2main{}", debug_postfix); + println!("cargo:rustc-link-lib=static=SDL2{}", debug_postfix); } // Also linked to any required libraries for each supported platform From 5f1766bb120260735ad04753a4d918ed8cc73111 Mon Sep 17 00:00:00 2001 From: Mike Waychison Date: Fri, 26 Mar 2021 15:23:13 -0700 Subject: [PATCH 2/3] Update changelog for debug build. --- changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/changelog.md b/changelog.md index 696a450f648..e3a8228fc97 100644 --- a/changelog.md +++ b/changelog.md @@ -5,6 +5,7 @@ when upgrading from a version of rust-sdl2 to another. * Add patch to fix metal detection (https://bugzilla.libsdl.org/show_bug.cgi?id=4988) * Changed signature of TimerSubsystem::ticks to accept `&self`. + * Allow bundled build to be built in debug mode. Fixes issue when linking binary with mixed debug+release CRT dependencies. ### v0.34.4 From c0e7b590969339aba02bc02008efcd8f628bd977 Mon Sep 17 00:00:00 2001 From: Mike Waychison Date: Fri, 26 Mar 2021 15:33:00 -0700 Subject: [PATCH 3/3] Update with PR --- changelog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index e3a8228fc97..3322507a65f 100644 --- a/changelog.md +++ b/changelog.md @@ -5,7 +5,7 @@ when upgrading from a version of rust-sdl2 to another. * Add patch to fix metal detection (https://bugzilla.libsdl.org/show_bug.cgi?id=4988) * Changed signature of TimerSubsystem::ticks to accept `&self`. - * Allow bundled build to be built in debug mode. Fixes issue when linking binary with mixed debug+release CRT dependencies. +[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. ### v0.34.4