]> git.lizzy.rs Git - rust.git/blob - src/bootstrap/build.rs
Rollup merge of #95843 - GuillaumeGomez:improve-new-cyclic-doc, r=m-ou-se
[rust.git] / src / bootstrap / build.rs
1 use env::consts::{EXE_EXTENSION, EXE_SUFFIX};
2 use std::env;
3 use std::ffi::OsString;
4 use std::path::PathBuf;
5
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);
12         name.into()
13     } else {
14         name.clone()
15     }
16 }
17
18 fn main() {
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);
23
24     // This may not be a canonicalized path.
25     let mut rustc = PathBuf::from(env::var_os("RUSTC").unwrap());
26
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() {
32                 rustc = absolute;
33                 break;
34             }
35         }
36     }
37     assert!(rustc.is_absolute());
38
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());
43 }