1 use env::consts::{EXE_EXTENSION, EXE_SUFFIX};
3 use std::ffi::OsString;
4 use std::path::PathBuf;
6 /// Given an executable called `name`, return the filename for the
7 /// executable for a particular target.
8 pub fn exe(name: &PathBuf) -> PathBuf {
9 if EXE_EXTENSION != "" && name.extension() != Some(EXE_EXTENSION.as_ref()) {
10 let mut name: OsString = name.clone().into();
11 name.push(EXE_SUFFIX);
19 let host = env::var("HOST").unwrap();
20 println!("cargo:rerun-if-changed=build.rs");
21 println!("cargo:rerun-if-env-changed=RUSTC");
22 println!("cargo:rustc-env=BUILD_TRIPLE={}", host);
24 // This may not be a canonicalized path.
25 let mut rustc = PathBuf::from(env::var_os("RUSTC").unwrap());
27 if rustc.is_relative() {
28 println!("cargo:rerun-if-env-changed=PATH");
29 for dir in env::split_paths(&env::var_os("PATH").unwrap_or_default()) {
30 let absolute = dir.join(&exe(&rustc));
31 if absolute.exists() {
37 assert!(rustc.is_absolute());
39 // FIXME: if the path is not utf-8, this is going to break. Unfortunately
40 // Cargo doesn't have a way for us to specify non-utf-8 paths easily, so
41 // we'll need to invent some encoding scheme if this becomes a problem.
42 println!("cargo:rustc-env=RUSTC={}", rustc.to_str().unwrap());