Browse Source

Merge pull request #103 from alexbool/master

Fix build with opt-levels s/z (issue #102)
vs2017
Alex Crichton 8 years ago
committed by GitHub
parent
commit
3419148e2b
  1. 15
      src/lib.rs
  2. 14
      tests/test.rs

15
src/lib.rs

@ -74,7 +74,7 @@ pub struct Config {
target: Option<String>,
host: Option<String>,
out_dir: Option<PathBuf>,
opt_level: Option<u32>,
opt_level: Option<String>,
debug: Option<bool>,
env: Vec<(OsString, OsString)>,
compiler: Option<PathBuf>,
@ -250,7 +250,16 @@ impl Config {
/// This option is automatically scraped from the `OPT_LEVEL` environment
/// variable by build scripts, so it's not required to call this function.
pub fn opt_level(&mut self, opt_level: u32) -> &mut Config {
self.opt_level = Some(opt_level);
self.opt_level = Some(opt_level.to_string());
self
}
/// Configures the optimization level of the generated object files.
///
/// This option is automatically scraped from the `OPT_LEVEL` environment
/// variable by build scripts, so it's not required to call this function.
pub fn opt_level_str(&mut self, opt_level: &str) -> &mut Config {
self.opt_level = Some(opt_level.to_string());
self
}
@ -796,7 +805,7 @@ impl Config {
}
fn get_opt_level(&self) -> String {
self.opt_level.map(|s| s.to_string()).unwrap_or_else(|| {
self.opt_level.as_ref().cloned().unwrap_or_else(|| {
self.getenv_unwrap("OPT_LEVEL")
})
}

14
tests/test.rs

@ -31,6 +31,20 @@ fn gnu_opt_level_1() {
.must_not_have("-O2");
}
#[test]
fn gnu_opt_level_s() {
let test = Test::gnu();
test.gcc()
.opt_level_str("s")
.file("foo.c").compile("libfoo.a");
test.cmd(0).must_have("-Os")
.must_not_have("-O1")
.must_not_have("-O2")
.must_not_have("-O3")
.must_not_have("-Oz");
}
#[test]
fn gnu_debug() {
let test = Test::gnu();

Loading…
Cancel
Save