From e406adbcbc6672fa27a5ed5da12880968b89db91 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 22 Jan 2016 12:23:11 -0800 Subject: [PATCH] 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 alexcrichton/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). --- src/librustc_trans/back/link.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/librustc_trans/back/link.rs b/src/librustc_trans/back/link.rs index 0f327d5c84cfd..8b69f2b1d627b 100644 --- a/src/librustc_trans/back/link.rs +++ b/src/librustc_trans/back/link.rs @@ -390,15 +390,16 @@ pub fn get_ar_prog(sess: &Session) -> String { fn command_path(sess: &Session) -> OsString { // The compiler's sysroot often has some bundled tools, so add it to the - // PATH for the child. - let mut new_path = sess.host_filesearch(PathKind::All) - .get_tools_search_paths(); - if let Some(path) = env::var_os("PATH") { - new_path.extend(env::split_paths(&path)); - } + // PATH for the child. Be sure that we *append* to the PATH so we favor the + // system tools if they're configured and otherwise just fall back to the + // bundled versions. + let path = env::var_os("PATH").unwrap_or(OsString::new()); + let mut new_path = env::split_paths(&path).collect::>(); if sess.target.target.options.is_like_msvc { new_path.extend(msvc::host_dll_path()); } + new_path.extend(sess.host_filesearch(PathKind::All) + .get_tools_search_paths()); env::join_paths(new_path).unwrap() }