Browse Source

Add the option to specify a compiler

add-rc-path
Alex Crichton 10 years ago
parent
commit
06a863da11
  1. 16
      src/lib.rs
  2. 3
      tests/test.rs

16
src/lib.rs

@ -73,6 +73,7 @@ pub struct Config {
opt_level: Option<u32>,
debug: Option<bool>,
env: Vec<(OsString, OsString)>,
compiler: Option<PathBuf>,
}
fn getenv(v: &str) -> Option<String> {
@ -129,6 +130,7 @@ impl Config {
opt_level: None,
debug: None,
env: Vec::new(),
compiler: None,
}
}
@ -263,6 +265,16 @@ impl Config {
self
}
/// Configures the compiler to be used to produce output.
///
/// This option is automatically determined from the target platform or a
/// number of environment variables, so it's not required to call this
/// function.
pub fn compiler<P: AsRef<Path>>(&mut self, compiler: P) -> &mut Config {
self.compiler = Some(compiler.as_ref().to_owned());
self
}
#[doc(hidden)]
pub fn __set_env<A, B>(&mut self, a: A, b: B) -> &mut Config
where A: AsRef<OsStr>, B: AsRef<OsStr>
@ -492,6 +504,10 @@ impl Config {
}
fn get_compiler(&self) -> (Command, String) {
if let Some(ref c) = self.compiler {
return (self.cmd(c), c.file_name().unwrap()
.to_string_lossy().into_owned())
}
let target = self.get_target();
let (env, msvc, gnu, default) = if self.cpp {
("CXX", "cl", "g++", "c++")

3
tests/test.rs

@ -67,6 +67,9 @@ impl Test {
.out_dir(self.td.path())
.__set_env("PATH", env::join_paths(path).unwrap())
.__set_env("GCCTEST_OUT_DIR", self.td.path());
if self.msvc {
cfg.compiler(self.td.path().join("cl"));
}
return cfg
}

Loading…
Cancel
Save