about summary refs log tree commit diff
path: root/src/bootstrap/build.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/bootstrap/build.rs')
-rw-r--r--src/bootstrap/build.rs25
1 files changed, 24 insertions, 1 deletions
diff --git a/src/bootstrap/build.rs b/src/bootstrap/build.rs
index 5e5c31de5b6..d40b924e0ff 100644
--- a/src/bootstrap/build.rs
+++ b/src/bootstrap/build.rs
@@ -1,3 +1,26 @@
+use std::env;
+use std::path::PathBuf;
+
 fn main() {
-    println!("cargo:rustc-env=BUILD_TRIPLE={}", std::env::var("HOST").unwrap());
+    println!("cargo:rerun-if-changed=build.rs");
+    println!("cargo:rustc-env=BUILD_TRIPLE={}", env::var("HOST").unwrap());
+
+    // This may not be a canonicalized path.
+    let mut rustc = PathBuf::from(env::var_os("RUSTC").unwrap());
+
+    if rustc.is_relative() {
+        for dir in env::split_paths(&env::var_os("PATH").unwrap_or_default()) {
+            let absolute = dir.join(&rustc);
+            if absolute.exists() {
+                rustc = absolute;
+                break;
+            }
+        }
+    }
+    assert!(rustc.is_absolute());
+
+    // FIXME: if the path is not utf-8, this is going to break. Unfortunately
+    // Cargo doesn't have a way for us to specify non-utf-8 paths easily, so
+    // we'll need to invent some encoding scheme if this becomes a problem.
+    println!("cargo:rustc-env=RUSTC={}", rustc.to_str().unwrap());
 }