diff --git a/src/cargo/ops/cargo_rustc/context.rs b/src/cargo/ops/cargo_rustc/context.rs index 1310ae189f8..865d4bbc078 100644 --- a/src/cargo/ops/cargo_rustc/context.rs +++ b/src/cargo/ops/cargo_rustc/context.rs @@ -196,11 +196,12 @@ impl<'a, 'cfg> Context<'a, 'cfg> { } let mut with_cfg = process.clone(); + with_cfg.arg("--print=sysroot"); with_cfg.arg("--print=cfg"); - let mut has_cfg = true; + let mut has_cfg_and_sysroot = true; let output = with_cfg.exec_with_output().or_else(|_| { - has_cfg = false; + has_cfg_and_sysroot = false; process.exec_with_output() }).chain_error(|| { human(format!("failed to run `rustc` to learn about \ @@ -237,14 +238,13 @@ impl<'a, 'cfg> Context<'a, 'cfg> { map.insert(crate_type.to_string(), Some((prefix.to_string(), suffix.to_string()))); } - let cfg = if has_cfg { - Some(try!(lines.map(Cfg::from_str).collect())) - } else { - None - }; - - if let Some(ref sysroot) = self.config.rustc()?.sysroot { - let mut rustlib = sysroot.clone(); + if has_cfg_and_sysroot { + let line = match lines.next() { + Some(line) => line, + None => bail!("output of --print=sysroot missing when learning about \ + target-specific information from rustc"), + }; + let mut rustlib = PathBuf::from(line); if kind == Kind::Host { if cfg!(windows) { rustlib.push("bin"); @@ -259,6 +259,12 @@ impl<'a, 'cfg> Context<'a, 'cfg> { rustlib.push("lib"); self.compilation.target_dylib_path = Some(rustlib); } + } + + let cfg = if has_cfg_and_sysroot { + Some(try!(lines.map(Cfg::from_str).collect())) + } else { + None }; let info = match kind { diff --git a/src/cargo/util/rustc.rs b/src/cargo/util/rustc.rs index cd2c5510430..d401452d712 100644 --- a/src/cargo/util/rustc.rs +++ b/src/cargo/util/rustc.rs @@ -7,7 +7,6 @@ pub struct Rustc { pub wrapper: Option, pub verbose_version: String, pub host: String, - pub sysroot: Option, } impl Rustc { @@ -36,20 +35,11 @@ impl Rustc { triple.to_string() }; - let sysroot = { - let mut cmd = util::process(&path); - cmd.arg("--print=sysroot"); - cmd.exec_with_output().ok() - .and_then(|output| String::from_utf8(output.stdout).ok() ) - .map(|s| PathBuf::from(s.trim())) - }; - Ok(Rustc { path: path, wrapper: wrapper, verbose_version: verbose_version, host: host, - sysroot: sysroot }) }