@@ -793,6 +793,10 @@ impl Build {
793
793
/// When enabled on systems that support dynamic linking, this prevents
794
794
/// linking with the shared libraries.
795
795
///
796
+ /// If not specified, this falls back to:
797
+ /// - `-Ctarget-features=+crt-static` when compiling in a build script.
798
+ /// - A target-specific default.
799
+ ///
796
800
/// # Example
797
801
///
798
802
/// ```no_run
@@ -1301,6 +1305,9 @@ impl Build {
1301
1305
/// Configures whether the /MT flag or the /MD flag will be passed to msvc build tools.
1302
1306
///
1303
1307
/// This option defaults to `false`, and affect only msvc targets.
1308
+ ///
1309
+ /// If not specified, this falls back to `-Ctarget-features=+crt-static`
1310
+ /// when compiling in a build script.
1304
1311
pub fn static_crt ( & mut self , static_crt : bool ) -> & mut Build {
1305
1312
self . static_crt = Some ( static_crt) ;
1306
1313
self
@@ -1944,18 +1951,10 @@ impl Build {
1944
1951
ToolFamily :: Msvc { .. } => {
1945
1952
cmd. push_cc_arg ( "-nologo" . into ( ) ) ;
1946
1953
1947
- let crt_flag = match self . static_crt {
1948
- Some ( true ) => "-MT" ,
1949
- Some ( false ) => "-MD" ,
1950
- None => {
1951
- let features = self . getenv ( "CARGO_CFG_TARGET_FEATURE" ) ;
1952
- let features = features. as_deref ( ) . unwrap_or_default ( ) ;
1953
- if features. to_string_lossy ( ) . contains ( "crt-static" ) {
1954
- "-MT"
1955
- } else {
1956
- "-MD"
1957
- }
1958
- }
1954
+ let crt_flag = if self . static_crt . unwrap_or_else ( || target. crt_static ( ) ) {
1955
+ "-MT"
1956
+ } else {
1957
+ "-MD"
1959
1958
} ;
1960
1959
cmd. push_cc_arg ( crt_flag. into ( ) ) ;
1961
1960
@@ -2142,12 +2141,8 @@ impl Build {
2142
2141
cmd. args . push ( "-finput-charset=utf-8" . into ( ) ) ;
2143
2142
}
2144
2143
2145
- if self . static_flag . is_none ( ) {
2146
- let features = self . getenv ( "CARGO_CFG_TARGET_FEATURE" ) ;
2147
- let features = features. as_deref ( ) . unwrap_or_default ( ) ;
2148
- if features. to_string_lossy ( ) . contains ( "crt-static" ) {
2149
- cmd. args . push ( "-static" . into ( ) ) ;
2150
- }
2144
+ if self . static_flag . is_none ( ) && target. crt_static ( ) {
2145
+ cmd. args . push ( "-static" . into ( ) ) ;
2151
2146
}
2152
2147
2153
2148
// armv7 targets get to use armv7 instructions
0 commit comments