Skip to content

Commit c05ba8a

Browse files
committed
Append target-specific tools directory ($(RUST)/bin/rustlib/<triple>/bin/) to PATH during linking,
so that rustc can invoke them.
1 parent 76c02af commit c05ba8a

File tree

2 files changed

+35
-7
lines changed

2 files changed

+35
-7
lines changed

src/librustc/driver/driver.rs

+19-3
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ use serialize::{json, Encodable};
3232

3333
use std::io;
3434
use std::io::fs;
35+
use std::os;
3536
use arena::TypedArena;
3637
use syntax::ast;
3738
use syntax::attr;
@@ -258,18 +259,26 @@ pub fn phase_2_configure_and_expand(sess: &Session,
258259
// dependent dlls. Note that this uses cfg!(windows) as opposed to
259260
// targ_cfg because syntax extensions are always loaded for the host
260261
// compiler, not for the target.
262+
let mut _old_path = String::new();
261263
if cfg!(windows) {
262-
sess.host_filesearch().add_dylib_search_paths();
264+
_old_path = os::getenv("PATH").unwrap_or(_old_path);
265+
let mut new_path = sess.host_filesearch().get_dylib_search_paths();
266+
new_path.push_all_move(os::split_paths(_old_path.as_slice()));
267+
os::setenv("PATH", os::join_paths(new_path.as_slice()).unwrap());
263268
}
264269
let cfg = syntax::ext::expand::ExpansionConfig {
265270
deriving_hash_type_parameter: sess.features.default_type_params.get(),
266271
crate_name: crate_name.to_string(),
267272
};
268-
syntax::ext::expand::expand_crate(&sess.parse_sess,
273+
let ret = syntax::ext::expand::expand_crate(&sess.parse_sess,
269274
cfg,
270275
macros,
271276
syntax_exts,
272-
krate)
277+
krate);
278+
if cfg!(windows) {
279+
os::setenv("PATH", _old_path);
280+
}
281+
ret
273282
}
274283
);
275284

@@ -509,11 +518,18 @@ pub fn phase_5_run_llvm_passes(sess: &Session,
509518
pub fn phase_6_link_output(sess: &Session,
510519
trans: &CrateTranslation,
511520
outputs: &OutputFilenames) {
521+
let old_path = os::getenv("PATH").unwrap_or_else(||String::new());
522+
let mut new_path = os::split_paths(old_path.as_slice());
523+
new_path.push_all_move(sess.host_filesearch().get_tools_search_paths());
524+
os::setenv("PATH", os::join_paths(new_path.as_slice()).unwrap());
525+
512526
time(sess.time_passes(), "linking", (), |_|
513527
link::link_binary(sess,
514528
trans,
515529
outputs,
516530
trans.link.crate_name.as_slice()));
531+
532+
os::setenv("PATH", old_path);
517533
}
518534

519535
pub fn stop_after_phase_3(sess: &Session) -> bool {

src/librustc/metadata/filesearch.rs

+16-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
use std::cell::RefCell;
1414
use std::os;
1515
use std::io::fs;
16-
use std::dynamic_lib::DynamicLibrary;
1716
use std::collections::HashSet;
1817

1918
use util::fs as myfs;
@@ -134,11 +133,24 @@ impl<'a> FileSearch<'a> {
134133
}
135134
}
136135

137-
pub fn add_dylib_search_paths(&self) {
136+
// Returns a list of directories where target-specific dylibs might be located.
137+
pub fn get_dylib_search_paths(&self) -> Vec<Path> {
138+
let mut paths = Vec::new();
138139
self.for_each_lib_search_path(|lib_search_path| {
139-
DynamicLibrary::prepend_search_path(lib_search_path);
140+
paths.push(lib_search_path.clone());
140141
FileDoesntMatch
141-
})
142+
});
143+
paths
144+
}
145+
146+
// Returns a list of directories where target-specific tool binaries are located.
147+
pub fn get_tools_search_paths(&self) -> Vec<Path> {
148+
let mut p = Path::new(self.sysroot);
149+
p.push(find_libdir(self.sysroot));
150+
p.push(rustlibdir());
151+
p.push(self.triple);
152+
p.push("bin");
153+
vec![p]
142154
}
143155
}
144156

0 commit comments

Comments
 (0)