@@ -252,7 +252,8 @@ impl BuilderDefine for cmake::Config {
252252 self . out_dir ( out_dir)
253253 }
254254
255- fn configure_cpp ( & mut self , _debug : bool ) -> & mut Self {
255+ fn configure_cpp ( & mut self , debug : bool ) -> & mut Self {
256+ self . profile ( if debug { "Debug" } else { "Release" } ) ;
256257 self . define ( "SNMALLOC_RUST_SUPPORT" , "ON" )
257258 . very_verbose ( true )
258259 . define ( "CMAKE_SH" , "CMAKE_SH-NOTFOUND" )
@@ -308,8 +309,29 @@ fn configure_platform(config: &mut BuildConfig) {
308309 for flag in common_flags {
309310 config. builder . flag_if_supported ( flag) ;
310311 }
311-
312- if let Some ( msystem) = & config. msystem {
312+ if config. is_msvc ( ) {
313+ let msvc_flags = vec ! [
314+ "/nologo" , "/W4" , "/WX" , "/wd4127" , "/wd4324" , "/wd4201" ,
315+ "/Ob2" , "/DNDEBUG" , "/EHsc" , "/Gd" , "/TP" , "/Gm-" , "/GS" ,
316+ "/fp:precise" , "/Zc:wchar_t" , "/Zc:forScope" , "/Zc:inline"
317+ ] ;
318+ for flag in msvc_flags {
319+ config. builder . flag_if_supported ( flag) ;
320+ }
321+
322+ if config. features . lto {
323+ config. builder
324+ . flag_if_supported ( "/GL" )
325+ . define ( "CMAKE_INTERPROCEDURAL_OPTIMIZATION" , "TRUE" )
326+ . define ( "SNMALLOC_IPO" , "ON" ) ;
327+ println ! ( "cargo:rustc-link-arg=/LTCG" ) ;
328+ }
329+
330+ config. builder
331+ . define ( "CMAKE_CXX_FLAGS_RELEASE" , "/O2 /Ob2 /DNDEBUG /EHsc" )
332+ . define ( "CMAKE_C_FLAGS_RELEASE" , "/O2 /Ob2 /DNDEBUG /EHsc" ) ;
333+ }
334+ else if let Some ( msystem) = & config. msystem {
313335 match msystem. as_str ( ) {
314336 "CLANG64" | "CLANGARM64" => {
315337 let defines = vec ! [
@@ -339,28 +361,6 @@ fn configure_platform(config: &mut BuildConfig) {
339361 }
340362 }
341363 }
342- _ if config. is_msvc ( ) => {
343- let msvc_flags = vec ! [
344- "/nologo" , "/W4" , "/WX" , "/wd4127" , "/wd4324" , "/wd4201" ,
345- "/Ob2" , "/DNDEBUG" , "/EHsc" , "/Gd" , "/TP" , "/Gm-" , "/GS" ,
346- "/fp:precise" , "/Zc:wchar_t" , "/Zc:forScope" , "/Zc:inline"
347- ] ;
348- for flag in msvc_flags {
349- config. builder . flag_if_supported ( flag) ;
350- }
351-
352- if config. features . lto {
353- config. builder
354- . flag_if_supported ( "/GL" )
355- . define ( "CMAKE_INTERPROCEDURAL_OPTIMIZATION" , "TRUE" )
356- . define ( "SNMALLOC_IPO" , "ON" ) ;
357- println ! ( "cargo:rustc-link-arg=/LTCG" ) ;
358- }
359-
360- config. builder
361- . define ( "CMAKE_CXX_FLAGS_RELEASE" , "/O2 /Ob2 /DNDEBUG /EHsc" )
362- . define ( "CMAKE_C_FLAGS_RELEASE" , "/O2 /Ob2 /DNDEBUG /EHsc" ) ;
363- }
364364 _ if config. is_unix ( ) => {
365365 let unix_flags = vec ! [ "-fPIC" , "-pthread" , "-fno-exceptions" , "-fno-rtti" , "-mcx16" , "-Wno-unused-parameter" ] ;
366366 for flag in unix_flags {
@@ -426,7 +426,11 @@ fn configure_linking(config: &BuildConfig) {
426426 println ! ( "cargo:rustc-link-lib=ws2_32" ) ;
427427 println ! ( "cargo:rustc-link-lib=userenv" ) ;
428428 println ! ( "cargo:rustc-link-lib=bcrypt" ) ;
429- println ! ( "cargo:rustc-link-lib=msvcrt" ) ;
429+ if config. debug {
430+ println ! ( "cargo:rustc-link-lib=msvcrtd" ) ;
431+ } else {
432+ println ! ( "cargo:rustc-link-lib=msvcrt" ) ;
433+ }
430434 }
431435 _ if config. is_windows ( ) && config. is_gnu ( ) => {
432436 println ! ( "cargo:rustc-link-lib=kernel32" ) ;
0 commit comments