Skip to content

Commit c8d22b7

Browse files
committed
Roll-forward "Allow bundled debug build (Rust-SDL2#1081)"
Roll this forward again to make merge easier.
1 parent c5d8f5c commit c8d22b7

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

changelog.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ when upgrading from a version of rust-sdl2 to another.
33

44
### Unreleased
55

6-
* Rollback PR #1081: Broke dynamic linking on Windows #1088
6+
Nothing for now
77

88
### v0.34.4
99

sdl2-sys/build.rs

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

298297
// Override __FLTUSED__ to keep the _fltused symbol from getting defined in the static build.
299298
// This conflicts and fails to link properly when building statically on Windows, likely due to
@@ -411,11 +410,24 @@ fn link_sdl2(target_os: &str) {
411410

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

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

0 commit comments

Comments
 (0)