Skip to content

Commit

Permalink
Add custom flags
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcrichton committed Mar 25, 2016
1 parent a2cf6be commit 965d657
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ macro_rules! t {
pub struct TestGenerator {
headers: Vec<String>,
includes: Vec<PathBuf>,
flags: Vec<String>,
target: Option<String>,
out_dir: Option<PathBuf>,
defines: Vec<(String, Option<String>)>,
Expand Down Expand Up @@ -90,6 +91,7 @@ impl TestGenerator {
TestGenerator {
headers: Vec::new(),
includes: Vec::new(),
flags: Vec::new(),
target: None,
out_dir: None,
defines: Vec::new(),
Expand Down Expand Up @@ -155,6 +157,32 @@ impl TestGenerator {
self
}

/// Add a flag to the C compiler invocation.
///
/// This can be useful for tweaking the warning settings of the underlying
/// compiler.
///
/// # Examples
///
/// ```no_run
/// use std::env;
/// use std::path::PathBuf;
///
/// use ctest::TestGenerator;
///
/// let mut cfg = TestGenerator::new();
///
/// // if msvc
/// cfg.flag("/wd4820");
///
/// // if gnu
/// cfg.flag("-Wno-type-limits");
/// ```
pub fn flag(&mut self, flag: &str) -> &mut TestGenerator {
self.flags.push(flag.to_string());
self
}

/// Configures the output directory of the generated Rust and C code.
///
/// Note that for Cargo builds this defaults to `$OUT_DIR` and it's not
Expand Down Expand Up @@ -531,6 +559,9 @@ impl TestGenerator {
// Compile our C shim to be linked into tests
let mut cfg = gcc::Config::new();
cfg.file(&out.with_extension("c"));
for flag in self.flags.iter() {
cfg.flag(flag);
}

if target.contains("msvc") {
cfg.flag("/W3").flag("/Wall").flag("/WX")
Expand Down

0 comments on commit 965d657

Please sign in to comment.