@@ -72,6 +72,7 @@ pub struct Config {
72
72
build_args : Vec < OsString > ,
73
73
cmake_target : Option < String > ,
74
74
env : Vec < ( OsString , OsString ) > ,
75
+ static_crt : Option < bool > ,
75
76
}
76
77
77
78
/// Builds the native library rooted at `path` with the default cmake options.
@@ -112,6 +113,7 @@ impl Config {
112
113
build_args : Vec :: new ( ) ,
113
114
cmake_target : None ,
114
115
env : Vec :: new ( ) ,
116
+ static_crt : None ,
115
117
}
116
118
}
117
119
@@ -191,6 +193,14 @@ impl Config {
191
193
self
192
194
}
193
195
196
+ /// Configures whether the /MT flag or the /MD flag will be passed to msvc build tools.
197
+ ///
198
+ /// This option defaults to `false`, and affect only msvc targets.
199
+ pub fn static_crt ( & mut self , static_crt : bool ) -> & mut Config {
200
+ self . static_crt = Some ( static_crt) ;
201
+ self
202
+ }
203
+
194
204
/// Add an argument to the final `cmake` build step
195
205
pub fn build_arg < A : AsRef < OsStr > > ( & mut self , arg : A ) -> & mut Config {
196
206
self . build_args . push ( arg. as_ref ( ) . to_owned ( ) ) ;
@@ -227,19 +237,25 @@ impl Config {
227
237
getenv_unwrap ( "HOST" )
228
238
} ) ;
229
239
let msvc = target. contains ( "msvc" ) ;
230
- let c_compiler = gcc:: Config :: new ( ) . cargo_metadata ( false )
231
- . opt_level ( 0 )
232
- . debug ( false )
233
- . target ( & target)
234
- . host ( & host)
235
- . get_compiler ( ) ;
236
- let cxx_compiler = gcc:: Config :: new ( ) . cargo_metadata ( false )
237
- . cpp ( true )
238
- . opt_level ( 0 )
239
- . debug ( false )
240
- . target ( & target)
241
- . host ( & host)
242
- . get_compiler ( ) ;
240
+ let mut c_cfg = gcc:: Config :: new ( ) ;
241
+ c_cfg. cargo_metadata ( false )
242
+ . opt_level ( 0 )
243
+ . debug ( false )
244
+ . target ( & target)
245
+ . host ( & host) ;
246
+ let mut cxx_cfg = gcc:: Config :: new ( ) ;
247
+ cxx_cfg. cargo_metadata ( false )
248
+ . cpp ( true )
249
+ . opt_level ( 0 )
250
+ . debug ( false )
251
+ . target ( & target)
252
+ . host ( & host) ;
253
+ if let Some ( static_crt) = self . static_crt {
254
+ c_cfg. static_crt ( static_crt) ;
255
+ cxx_cfg. static_crt ( static_crt) ;
256
+ }
257
+ let c_compiler = c_cfg. get_compiler ( ) ;
258
+ let cxx_compiler = cxx_cfg. get_compiler ( ) ;
243
259
244
260
let dst = self . out_dir . clone ( ) . unwrap_or_else ( || {
245
261
PathBuf :: from ( getenv_unwrap ( "OUT_DIR" ) )
0 commit comments