Skip to content

Commit e406adb

Browse files
committed
rustc_trans: Append to PATH instead of prepending
Currently we run sub-commands with a different PATH so they can find the bundled `gcc.exe` that we ship with the `*-windows-gnu` host compilers. The current logic, however, *prepends* to `PATH` which means that if the system has a `gcc` installed it will not be used over the bundled `gcc`. This can cause problems, however, if the system gcc is used to compile native code and the Rust compiler then links everything with the bundled gcc. The standard library in both situations can be subtly different (the C standard library), and this can lead to errors such as rust-lang/flate2-rs#27. This commit switches the ordering by appending our own tools to `PATH` instead of prepending, so the system tools will be favored over the bundled ones (which are intended to only be used as a last resort anyway).
1 parent 8f36038 commit e406adb

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/librustc_trans/back/link.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -390,15 +390,16 @@ pub fn get_ar_prog(sess: &Session) -> String {
390390

391391
fn command_path(sess: &Session) -> OsString {
392392
// The compiler's sysroot often has some bundled tools, so add it to the
393-
// PATH for the child.
394-
let mut new_path = sess.host_filesearch(PathKind::All)
395-
.get_tools_search_paths();
396-
if let Some(path) = env::var_os("PATH") {
397-
new_path.extend(env::split_paths(&path));
398-
}
393+
// PATH for the child. Be sure that we *append* to the PATH so we favor the
394+
// system tools if they're configured and otherwise just fall back to the
395+
// bundled versions.
396+
let path = env::var_os("PATH").unwrap_or(OsString::new());
397+
let mut new_path = env::split_paths(&path).collect::<Vec<_>>();
399398
if sess.target.target.options.is_like_msvc {
400399
new_path.extend(msvc::host_dll_path());
401400
}
401+
new_path.extend(sess.host_filesearch(PathKind::All)
402+
.get_tools_search_paths());
402403
env::join_paths(new_path).unwrap()
403404
}
404405

0 commit comments

Comments
 (0)