Skip to content

Commit

Permalink
Roll-forward "Allow bundled debug build (Rust-SDL2#1081)"
Browse files Browse the repository at this point in the history
Roll this forward again to make merge easier.
  • Loading branch information
waych committed Apr 19, 2021
1 parent c5d8f5c commit c8d22b7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ when upgrading from a version of rust-sdl2 to another.

### Unreleased

* Rollback PR #1081: Broke dynamic linking on Windows #1088
Nothing for now

### 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 @@ -293,7 +293,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");

// Override __FLTUSED__ to keep the _fltused symbol from getting defined in the static build.
// This conflicts and fails to link properly when building statically on Windows, likely due to
Expand Down Expand Up @@ -411,11 +410,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 c8d22b7

Please sign in to comment.