@@ -293,7 +293,6 @@ fn patch_sdl2(sdl2_source_path: &Path) {
293
293
#[ cfg( feature = "bundled" ) ]
294
294
fn compile_sdl2 ( sdl2_build_path : & Path , target_os : & str ) -> PathBuf {
295
295
let mut cfg = cmake:: Config :: new ( sdl2_build_path) ;
296
- cfg. profile ( "release" ) ;
297
296
298
297
// Override __FLTUSED__ to keep the _fltused symbol from getting defined in the static build.
299
298
// This conflicts and fails to link properly when building statically on Windows, likely due to
@@ -367,6 +366,20 @@ fn compute_include_paths() -> Vec<String> {
367
366
include_paths
368
367
}
369
368
369
+ /// There's no easy way to extract this suffix from `cmake::Config` so we have to emulate their
370
+ /// behaviour here (see the source for `cmake::Config::build`).
371
+ fn debug_postfix ( ) -> & ' static str {
372
+ match (
373
+ & env:: var ( "OPT_LEVEL" ) . unwrap_or_default ( ) [ ..] ,
374
+ & env:: var ( "PROFILE" ) . unwrap_or_default ( ) [ ..] ,
375
+ ) {
376
+ ( "1" , _) | ( "2" , _) | ( "3" , _) | ( "s" , _) | ( "z" , _) => "" ,
377
+ ( "0" , _) => "d" ,
378
+ ( _, "debug" ) => "d" ,
379
+ ( _, _) => "" ,
380
+ }
381
+ }
382
+
370
383
fn link_sdl2 ( target_os : & str ) {
371
384
#[ cfg( all( feature = "use-pkgconfig" , not( feature = "bundled" ) ) ) ]
372
385
{
@@ -403,6 +416,8 @@ fn link_sdl2(target_os: &str) {
403
416
if cfg ! ( feature = "bundled" ) || cfg ! ( not( feature = "use-pkgconfig" ) ) {
404
417
if cfg ! ( feature = "use_mac_framework" ) && target_os == "darwin" {
405
418
println ! ( "cargo:rustc-flags=-l framework=SDL2" ) ;
419
+ } else if target_os. contains ( "windows" ) {
420
+ println ! ( "cargo:rustc-flags=-l SDL2{}" , debug_postfix( ) ) ;
406
421
} else if target_os != "emscripten" {
407
422
println ! ( "cargo:rustc-flags=-l SDL2" ) ;
408
423
}
@@ -414,8 +429,8 @@ fn link_sdl2(target_os: &str) {
414
429
if cfg ! ( feature = "bundled" )
415
430
|| ( cfg ! ( feature = "use-pkgconfig" ) == false && cfg ! ( feature = "use-vcpkg" ) == false )
416
431
{
417
- println ! ( "cargo:rustc-link-lib=static=SDL2main" ) ;
418
- println ! ( "cargo:rustc-link-lib=static=SDL2" ) ;
432
+ println ! ( "cargo:rustc-link-lib=static=SDL2main{}" , debug_postfix ( ) ) ;
433
+ println ! ( "cargo:rustc-link-lib=static=SDL2{}" , debug_postfix ( ) ) ;
419
434
}
420
435
421
436
// Also linked to any required libraries for each supported platform
@@ -552,9 +567,9 @@ fn copy_dynamic_libraries(sdl2_compiled_path: &PathBuf, target_os: &str) {
552
567
// copy sdl2.dll out of its build tree and down to the top level cargo
553
568
// binary output directory.
554
569
if target_os. contains ( "windows" ) {
555
- let sdl2_dll_name = "SDL2.dll" ;
570
+ let sdl2_dll_name = format ! ( "SDL2{} .dll" , debug_postfix ( ) ) ;
556
571
let sdl2_bin_path = sdl2_compiled_path. join ( "bin" ) ;
557
- let src_dll_path = sdl2_bin_path. join ( sdl2_dll_name) ;
572
+ let src_dll_path = sdl2_bin_path. join ( & sdl2_dll_name) ;
558
573
559
574
// Copy the dll to:
560
575
// * target dir: as a product ship product of the build,
0 commit comments