Skip to content
This repository has been archived by the owner on Dec 29, 2022. It is now read-only.

Commit

Permalink
Read env vars at runtime, not compile time
Browse files Browse the repository at this point in the history
  • Loading branch information
nrc committed Jun 16, 2017
1 parent a704d31 commit c750c66
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,22 +369,23 @@ impl BuildQueue {
}
if self.config.sysroot.is_empty() {
args.push("--sysroot".to_owned());
let home = option_env!("RUSTUP_HOME").or(option_env!("MULTIRUST_HOME"));
let toolchain = option_env!("RUSTUP_TOOLCHAIN").or(option_env!("MULTIRUST_TOOLCHAIN"));
let sys_root = if let (Some(home), Some(toolchain)) = (home, toolchain) {
let home = env::var("RUSTUP_HOME").or(env::var("MULTIRUST_HOME"));
let toolchain = env::var("RUSTUP_TOOLCHAIN").or(env::var("MULTIRUST_TOOLCHAIN"));
let sys_root = if let (Ok(home), Ok(toolchain)) = (home, toolchain) {
format!("{}/toolchains/{}", home, toolchain)
} else {
option_env!("SYSROOT")
env::var("SYSROOT")
.map(|s| s.to_owned())
.or_else(|| Command::new("rustc")
.arg("--print")
.arg("sysroot")
.output()
.ok()
.and_then(|out| String::from_utf8(out.stdout).ok())
.map(|s| s.trim().to_owned()))
.expect("need to specify SYSROOT env var, \
or use rustup or multirust")
.or_else(|| Command::new("rustc")
.arg("--print")
.arg("sysroot")
.output()
.ok()
.and_then(|out| String::from_utf8(out.stdout).ok())
.map(|s| s.trim().to_owned()))
.expect("need to specify SYSROOT env var, \
or use rustup or multirust")
};
args.push(sys_root.to_owned());
}
Expand Down

0 comments on commit c750c66

Please sign in to comment.