about summary refs log tree commit diff
diff options
context:
space:
mode:
authorVadim Chugunov <vadimcn@gmail.com>2014-09-03 00:46:23 -0700
committerVadim Chugunov <vadimcn@gmail.com>2014-09-11 09:40:20 -0700
commitc05ba8a298e904cabcaa1d96367b058537f541e4 (patch)
tree80900fdc7dabcbd2d728ac3956fe33272dfe0efc
parent76c02af434a7447824b3c0c105c4af57d3d6c50e (diff)
downloadrust-c05ba8a298e904cabcaa1d96367b058537f541e4.tar.gz
rust-c05ba8a298e904cabcaa1d96367b058537f541e4.zip
Append target-specific tools directory ($(RUST)/bin/rustlib/<triple>/bin/) to PATH during linking,
so that rustc can invoke them.
-rw-r--r--src/librustc/driver/driver.rs22
-rw-r--r--src/librustc/metadata/filesearch.rs20
2 files changed, 35 insertions, 7 deletions
diff --git a/src/librustc/driver/driver.rs b/src/librustc/driver/driver.rs
index 4c71c2df44d..018bfecd369 100644
--- a/src/librustc/driver/driver.rs
+++ b/src/librustc/driver/driver.rs
@@ -32,6 +32,7 @@ use serialize::{json, Encodable};
 
 use std::io;
 use std::io::fs;
+use std::os;
 use arena::TypedArena;
 use syntax::ast;
 use syntax::attr;
@@ -258,18 +259,26 @@ pub fn phase_2_configure_and_expand(sess: &Session,
             // dependent dlls. Note that this uses cfg!(windows) as opposed to
             // targ_cfg because syntax extensions are always loaded for the host
             // compiler, not for the target.
+            let mut _old_path = String::new();
             if cfg!(windows) {
-                sess.host_filesearch().add_dylib_search_paths();
+                _old_path = os::getenv("PATH").unwrap_or(_old_path);
+                let mut new_path = sess.host_filesearch().get_dylib_search_paths();
+                new_path.push_all_move(os::split_paths(_old_path.as_slice()));
+                os::setenv("PATH", os::join_paths(new_path.as_slice()).unwrap());
             }
             let cfg = syntax::ext::expand::ExpansionConfig {
                 deriving_hash_type_parameter: sess.features.default_type_params.get(),
                 crate_name: crate_name.to_string(),
             };
-            syntax::ext::expand::expand_crate(&sess.parse_sess,
+            let ret = syntax::ext::expand::expand_crate(&sess.parse_sess,
                                               cfg,
                                               macros,
                                               syntax_exts,
-                                              krate)
+                                              krate);
+            if cfg!(windows) {
+                os::setenv("PATH", _old_path);
+            }
+            ret
         }
     );
 
@@ -509,11 +518,18 @@ pub fn phase_5_run_llvm_passes(sess: &Session,
 pub fn phase_6_link_output(sess: &Session,
                            trans: &CrateTranslation,
                            outputs: &OutputFilenames) {
+    let old_path = os::getenv("PATH").unwrap_or_else(||String::new());
+    let mut new_path = os::split_paths(old_path.as_slice());
+    new_path.push_all_move(sess.host_filesearch().get_tools_search_paths());
+    os::setenv("PATH", os::join_paths(new_path.as_slice()).unwrap());
+
     time(sess.time_passes(), "linking", (), |_|
          link::link_binary(sess,
                            trans,
                            outputs,
                            trans.link.crate_name.as_slice()));
+
+    os::setenv("PATH", old_path);
 }
 
 pub fn stop_after_phase_3(sess: &Session) -> bool {
diff --git a/src/librustc/metadata/filesearch.rs b/src/librustc/metadata/filesearch.rs
index 49c24b190b2..bdabb3efb98 100644
--- a/src/librustc/metadata/filesearch.rs
+++ b/src/librustc/metadata/filesearch.rs
@@ -13,7 +13,6 @@
 use std::cell::RefCell;
 use std::os;
 use std::io::fs;
-use std::dynamic_lib::DynamicLibrary;
 use std::collections::HashSet;
 
 use util::fs as myfs;
@@ -134,11 +133,24 @@ impl<'a> FileSearch<'a> {
         }
     }
 
-    pub fn add_dylib_search_paths(&self) {
+    // Returns a list of directories where target-specific dylibs might be located.
+    pub fn get_dylib_search_paths(&self) -> Vec<Path> {
+        let mut paths = Vec::new();
         self.for_each_lib_search_path(|lib_search_path| {
-            DynamicLibrary::prepend_search_path(lib_search_path);
+            paths.push(lib_search_path.clone());
             FileDoesntMatch
-        })
+        });
+        paths
+    }
+
+    // Returns a list of directories where target-specific tool binaries are located.
+    pub fn get_tools_search_paths(&self) -> Vec<Path> {
+        let mut p = Path::new(self.sysroot);
+        p.push(find_libdir(self.sysroot));
+        p.push(rustlibdir());
+        p.push(self.triple);
+        p.push("bin");
+        vec![p]
     }
 }