diff --git a/src/bootstrap/build.rs b/src/bootstrap/build.rs index 8a5bf933d56ec..ab34d5c1e5504 100644 --- a/src/bootstrap/build.rs +++ b/src/bootstrap/build.rs @@ -1,10 +1,25 @@ +use env::consts::{EXE_EXTENSION, EXE_SUFFIX}; use std::env; +use std::ffi::OsString; use std::path::PathBuf; +/// Given an executable called `name`, return the filename for the +/// executable for a particular target. +pub fn exe(name: &PathBuf) -> PathBuf { + if EXE_EXTENSION != "" && name.extension() != Some(EXE_EXTENSION.as_ref()) { + let mut name: OsString = name.clone().into(); + name.push(EXE_SUFFIX); + name.into() + } else { + name.clone() + } +} + fn main() { + let host = env::var("HOST").unwrap(); println!("cargo:rerun-if-changed=build.rs"); println!("cargo:rerun-if-env-changed=RUSTC"); - println!("cargo:rustc-env=BUILD_TRIPLE={}", env::var("HOST").unwrap()); + println!("cargo:rustc-env=BUILD_TRIPLE={}", host); // This may not be a canonicalized path. let mut rustc = PathBuf::from(env::var_os("RUSTC").unwrap()); @@ -12,7 +27,7 @@ fn main() { if rustc.is_relative() { println!("cargo:rerun-if-env-changed=PATH"); for dir in env::split_paths(&env::var_os("PATH").unwrap_or_default()) { - let absolute = dir.join(&rustc); + let absolute = dir.join(&exe(&rustc)); if absolute.exists() { rustc = absolute; break;