@@ -95,8 +95,8 @@ fn main() {
9595 Ok ( CMakeBuildType :: MinSizeRel ) => ( false , "MinSizeRel" ) ,
9696 Err ( e) => panic ! ( "Cannot determine CMake build type: {}" , e) ,
9797 } ;
98-
99- if cfg ! ( all ( windows , target_env = "msvc" ) ) {
98+ let target_env = env :: var ( "CARGO_CFG_TARGET_ENV" ) . unwrap ( ) ;
99+ if target_env == "msvc" {
100100 cfg = cfg. define ( "CMAKE_SH" , "CMAKE_SH-NOTFOUND" ) ;
101101
102102 // cc::get_compiler have /nologo /MD default flags that are cmake::Config
@@ -109,14 +109,31 @@ fn main() {
109109 // CMAKE_C_FLAGS + CMAKE_C_FLAGS_RELEASE
110110 cfg = cfg. cflag ( "/DWIN32 /D_WINDOWS /W3 /MD /O2 /Ob2 /DNDEBUG" ) ;
111111 }
112- }
112+ } else if target_env == "gnu" {
113+ cfg = cfg. define ( "CMAKE_SH" , "CMAKE_SH-NOTFOUND" ) ;
114+ // cc::get_compiler have /nologo /MD default flags that are cmake::Config
115+ // defaults to. Those flags prevents mimalloc from building on windows
116+ // extracted from default cmake configuration on windows
117+ if is_debug {
118+ // CMAKE_C_FLAGS + CMAKE_C_FLAGS_DEBUG
119+ cfg = cfg. cflag ( "-static -ffunction-sections -fdata-sections -m64 -O3 -fpic" ) ;
120+ } else {
121+ // CMAKE_C_FLAGS + CMAKE_C_FLAGS_RELEASE
122+ cfg = cfg. cflag ( "-static -ffunction-sections -fdata-sections -m64 -O3 -fpic" ) ;
123+ }
124+ } ;
113125
114126 let mut out_dir = "./build" . to_string ( ) ;
115127 if cfg ! ( all( windows, target_env = "msvc" ) ) {
116- out_dir. push ( '/' ) ;
117- out_dir. push_str ( win_folder) ;
128+ if target_env == "msvc" {
129+ out_dir. push ( '/' ) ;
130+ out_dir. push_str ( win_folder) ;
131+ } else if target_env == "gnu" {
132+ out_dir. push ( '/' ) ;
133+ out_dir. push_str ( win_folder) ;
134+ }
118135 }
119- let out_name = if cfg ! ( all( windows, target_env = "msvc" ) ) {
136+ let out_name = if cfg ! ( all( windows) ) {
120137 if is_debug {
121138 if cfg ! ( feature = "secure" ) {
122139 "mimalloc-static-secure-debug"
@@ -149,7 +166,6 @@ fn main() {
149166 // Build mimalloc-static
150167 let mut dst = cfg. build_target ( "mimalloc-static" ) . build ( ) ;
151168 dst. push ( out_dir) ;
152-
153169 println ! ( "cargo:rustc-link-search=native={}" , dst. display( ) ) ;
154170 println ! ( "cargo:rustc-link-lib={}" , out_name) ;
155171}
0 commit comments