@@ -99,6 +99,7 @@ pub struct Build {
99
99
flags : Vec < String > ,
100
100
flags_supported : Vec < String > ,
101
101
known_flag_support_status : Arc < Mutex < HashMap < String , bool > > > ,
102
+ no_default_flags : bool ,
102
103
files : Vec < PathBuf > ,
103
104
cpp : bool ,
104
105
cpp_link_stdlib : Option < Option < String > > ,
@@ -277,6 +278,7 @@ impl Build {
277
278
flags : Vec :: new ( ) ,
278
279
flags_supported : Vec :: new ( ) ,
279
280
known_flag_support_status : Arc :: new ( Mutex :: new ( HashMap :: new ( ) ) ) ,
281
+ no_default_flags : false ,
280
282
files : Vec :: new ( ) ,
281
283
shared_flag : None ,
282
284
static_flag : None ,
@@ -497,6 +499,17 @@ impl Build {
497
499
self
498
500
}
499
501
502
+ /// Disables the generation of default compiler flags. The default compiler
503
+ /// flags may cause conflicts in some cross compiling scenarios.
504
+ ///
505
+ /// Setting the `CRATE_CC_NO_DEFAULTS` environment variable has the same
506
+ /// effect as setting this to `true`. The presence of the environment
507
+ /// variable and the value of `no_default_flags` will be OR'd together.
508
+ pub fn no_default_flags ( & mut self , no_default_flags : bool ) -> & mut Build {
509
+ self . no_default_flags = no_default_flags;
510
+ self
511
+ }
512
+
500
513
/// Add a file which will be compiled
501
514
pub fn file < P : AsRef < Path > > ( & mut self , p : P ) -> & mut Build {
502
515
self . files . push ( p. as_ref ( ) . to_path_buf ( ) ) ;
@@ -1073,11 +1086,10 @@ impl Build {
1073
1086
let mut cmd = self . get_base_compiler ( ) ?;
1074
1087
let envflags = self . envflags ( if self . cpp { "CXXFLAGS" } else { "CFLAGS" } ) ;
1075
1088
1076
- // Disable default flag generation via environment variable or when
1077
- // certain cross compiling arguments are set
1078
- let use_defaults = self . getenv ( "CRATE_CC_NO_DEFAULTS" ) . is_none ( ) ;
1089
+ // Disable default flag generation via `no_default_flags` or environment variable
1090
+ let no_defaults = self . no_default_flags || self . getenv ( "CRATE_CC_NO_DEFAULTS" ) . is_some ( ) ;
1079
1091
1080
- if use_defaults {
1092
+ if !no_defaults {
1081
1093
self . add_default_flags ( & mut cmd, & target, & opt_level) ?;
1082
1094
} else {
1083
1095
println ! ( "Info: default compiler flags are disabled" ) ;
0 commit comments