@@ -95,8 +95,8 @@ fn main() {
95
95
Ok ( CMakeBuildType :: MinSizeRel ) => ( false , "MinSizeRel" ) ,
96
96
Err ( e) => panic ! ( "Cannot determine CMake build type: {}" , e) ,
97
97
} ;
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" {
100
100
cfg = cfg. define ( "CMAKE_SH" , "CMAKE_SH-NOTFOUND" ) ;
101
101
102
102
// cc::get_compiler have /nologo /MD default flags that are cmake::Config
@@ -109,47 +109,50 @@ fn main() {
109
109
// CMAKE_C_FLAGS + CMAKE_C_FLAGS_RELEASE
110
110
cfg = cfg. cflag ( "/DWIN32 /D_WINDOWS /W3 /MD /O2 /Ob2 /DNDEBUG" ) ;
111
111
}
112
- }
112
+ } else if target_env == "gnu" {
113
+ cfg = cfg. define ( "CMAKE_SH" , "CMAKE_SH-NOTFOUND" ) ;
114
+ // Those flags prevents mimalloc from building on windows
115
+ if is_debug {
116
+ // CMAKE_C_FLAGS + CMAKE_C_FLAGS_DEBUG
117
+ cfg = cfg. cflag ( "-static -ffunction-sections -fdata-sections -m64 -O2 -fpic" ) ;
118
+ } else {
119
+ // CMAKE_C_FLAGS + CMAKE_C_FLAGS_RELEASE
120
+ cfg = cfg. cflag ( "-static -ffunction-sections -fdata-sections -m64 -O3 -fpic" ) ;
121
+ }
122
+ } ;
113
123
114
124
let mut out_dir = "./build" . to_string ( ) ;
115
- if cfg ! ( all( windows, target_env = "msvc" ) ) {
125
+ if cfg ! ( all( windows) ) {
116
126
out_dir. push ( '/' ) ;
117
127
out_dir. push_str ( win_folder) ;
118
128
}
119
- let out_name = if cfg ! ( all( windows, target_env = "msvc" ) ) {
129
+ let out_name = if cfg ! ( all( windows) ) {
120
130
if is_debug {
121
131
if cfg ! ( feature = "secure" ) {
122
132
"mimalloc-static-secure-debug"
123
133
} else {
124
134
"mimalloc-static-debug"
125
135
}
136
+ } else if cfg ! ( feature = "secure" ) {
137
+ "mimalloc-static-secure"
126
138
} else {
127
- if cfg ! ( feature = "secure" ) {
128
- "mimalloc-static-secure"
129
- } else {
130
- "mimalloc-static"
131
- }
139
+ "mimalloc-static"
132
140
}
133
- } else {
134
- if is_debug {
135
- if cfg ! ( feature = "secure" ) {
136
- "mimalloc-secure-debug"
137
- } else {
138
- "mimalloc-debug"
139
- }
141
+ } else if is_debug {
142
+ if cfg ! ( feature = "secure" ) {
143
+ "mimalloc-secure-debug"
140
144
} else {
141
- if cfg ! ( feature = "secure" ) {
142
- "mimalloc-secure"
143
- } else {
144
- "mimalloc"
145
- }
145
+ "mimalloc-debug"
146
146
}
147
+ } else if cfg ! ( feature = "secure" ) {
148
+ "mimalloc-secure"
149
+ } else {
150
+ "mimalloc"
147
151
} ;
148
152
149
153
// Build mimalloc-static
150
154
let mut dst = cfg. build_target ( "mimalloc-static" ) . build ( ) ;
151
155
dst. push ( out_dir) ;
152
-
153
156
println ! ( "cargo:rustc-link-search=native={}" , dst. display( ) ) ;
154
157
println ! ( "cargo:rustc-link-lib={}" , out_name) ;
155
158
}
0 commit comments