Skip to content

Commit 4b240fe

Browse files
committed
Auto merge of #34083 - alexcrichton:dumb-hack, r=nrc
rustc: Try to contain prepends to PATH This commit attempts to bring our prepends to PATH on Windows when loading plugins because we've been seeing quite a few issues with failing to spawn a process on Windows, the leading theory of which is that PATH is too large as a result of this. Currently this is mostly a stab in the dark as it's not confirmed to actually fix the problem, but it's probably not a bad change to have anyway! cc #33844 Closes #17360
2 parents d3e014e + 1564e92 commit 4b240fe

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/librustc_driver/driver.rs

+16-4
Original file line numberDiff line numberDiff line change
@@ -669,12 +669,24 @@ pub fn phase_2_configure_and_expand<'a>(sess: &Session,
669669
// dependent dlls. Note that this uses cfg!(windows) as opposed to
670670
// targ_cfg because syntax extensions are always loaded for the host
671671
// compiler, not for the target.
672-
let mut _old_path = OsString::new();
672+
//
673+
// This is somewhat of an inherently racy operation, however, as
674+
// multiple threads calling this function could possibly continue
675+
// extending PATH far beyond what it should. To solve this for now we
676+
// just don't add any new elements to PATH which are already there
677+
// within PATH. This is basically a targeted fix at #17360 for rustdoc
678+
// which runs rustc in parallel but has been seen (#33844) to cause
679+
// problems with PATH becoming too long.
680+
let mut old_path = OsString::new();
673681
if cfg!(windows) {
674-
_old_path = env::var_os("PATH").unwrap_or(_old_path);
682+
old_path = env::var_os("PATH").unwrap_or(old_path);
675683
let mut new_path = sess.host_filesearch(PathKind::All)
676684
.get_dylib_search_paths();
677-
new_path.extend(env::split_paths(&_old_path));
685+
for path in env::split_paths(&old_path) {
686+
if !new_path.contains(&path) {
687+
new_path.push(path);
688+
}
689+
}
678690
env::set_var("PATH", &env::join_paths(new_path).unwrap());
679691
}
680692
let features = sess.features.borrow();
@@ -694,7 +706,7 @@ pub fn phase_2_configure_and_expand<'a>(sess: &Session,
694706
syntax_exts,
695707
krate);
696708
if cfg!(windows) {
697-
env::set_var("PATH", &_old_path);
709+
env::set_var("PATH", &old_path);
698710
}
699711
*sess.available_macros.borrow_mut() = macro_names;
700712
ret

0 commit comments

Comments
 (0)