Skip to content

Commit af5db8b

Browse files
francesca64alexcrichton
authored andcommitted
Add no_default_flags method (#435)
1 parent af9f170 commit af5db8b

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/lib.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ pub struct Build {
9999
flags: Vec<String>,
100100
flags_supported: Vec<String>,
101101
known_flag_support_status: Arc<Mutex<HashMap<String, bool>>>,
102+
no_default_flags: bool,
102103
files: Vec<PathBuf>,
103104
cpp: bool,
104105
cpp_link_stdlib: Option<Option<String>>,
@@ -277,6 +278,7 @@ impl Build {
277278
flags: Vec::new(),
278279
flags_supported: Vec::new(),
279280
known_flag_support_status: Arc::new(Mutex::new(HashMap::new())),
281+
no_default_flags: false,
280282
files: Vec::new(),
281283
shared_flag: None,
282284
static_flag: None,
@@ -497,6 +499,17 @@ impl Build {
497499
self
498500
}
499501

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+
500513
/// Add a file which will be compiled
501514
pub fn file<P: AsRef<Path>>(&mut self, p: P) -> &mut Build {
502515
self.files.push(p.as_ref().to_path_buf());
@@ -1073,11 +1086,10 @@ impl Build {
10731086
let mut cmd = self.get_base_compiler()?;
10741087
let envflags = self.envflags(if self.cpp { "CXXFLAGS" } else { "CFLAGS" });
10751088

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();
10791091

1080-
if use_defaults {
1092+
if !no_defaults {
10811093
self.add_default_flags(&mut cmd, &target, &opt_level)?;
10821094
} else {
10831095
println!("Info: default compiler flags are disabled");

0 commit comments

Comments
 (0)