Skip to content

Commit

Permalink
Allow bundled debug build (Rust-SDL2#1081)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
waych authored Apr 2, 2021
1 parent 870b591 commit a2148d3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ 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`.

[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.

[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.

### v0.34.4
Expand Down
18 changes: 15 additions & 3 deletions sdl2-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
{
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a2148d3

Please sign in to comment.