about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2017-06-08 06:02:04 +0000
committerbors <bors@rust-lang.org>2017-06-08 06:02:04 +0000
commit76eea743b4b7a1827d921d1dc685f1102c17a1b3 (patch)
tree8e6334e03ba29eeb29a6496561d581abd74a91be
parente1fa8de0fb900026a1a126928940e4eea3b729b5 (diff)
parente8689c7de71f822dca891099a94c9377c36e46b2 (diff)
downloadrust-76eea743b4b7a1827d921d1dc685f1102c17a1b3.tar.gz
rust-76eea743b4b7a1827d921d1dc685f1102c17a1b3.zip
Auto merge of #42481 - brson:wingnu, r=alexcrichton
Fix setting PATH during linkage on windows-gnu

This makes the behavior almost exactly the same as before the VS2017 patch, except that on MSVC builds the host bin path is no longer added to PATH. I am not sure that's actually necessary on any platform.

r? @alexcrichton

Fixes https://github.com/rust-lang/rust/issues/42422
-rw-r--r--src/librustc_trans/back/link.rs20
1 files changed, 11 insertions, 9 deletions
diff --git a/src/librustc_trans/back/link.rs b/src/librustc_trans/back/link.rs
index ee92a4b4a2d..e57cbb1c910 100644
--- a/src/librustc_trans/back/link.rs
+++ b/src/librustc_trans/back/link.rs
@@ -141,17 +141,20 @@ pub fn build_link_meta(incremental_hashes_map: &IncrementalHashesMap) -> LinkMet
     return r;
 }
 
-// The third parameter is for an env vars, used to set up the path for MSVC
-// to find its DLLs
+// The third parameter is for env vars, used on windows to set up the
+// path for MSVC to find its DLLs, and gcc to find its bundled
+// toolchain
 pub fn get_linker(sess: &Session) -> (String, Command, Vec<(OsString, OsString)>) {
+    let envs = vec![("PATH".into(), command_path(sess))];
+
     if let Some(ref linker) = sess.opts.cg.linker {
-        (linker.clone(), Command::new(linker), vec![])
+        (linker.clone(), Command::new(linker), envs)
     } else if sess.target.target.options.is_like_msvc {
         let (cmd, envs) = msvc_link_exe_cmd(sess);
         ("link.exe".to_string(), cmd, envs)
     } else {
-        (sess.target.target.options.linker.clone(),
-         Command::new(&sess.target.target.options.linker), vec![])
+        let linker = &sess.target.target.options.linker;
+        (linker.clone(), Command::new(&linker), envs)
     }
 }
 
@@ -182,7 +185,7 @@ pub fn get_ar_prog(sess: &Session) -> String {
     })
 }
 
-fn command_path(sess: &Session, extra: Option<PathBuf>) -> OsString {
+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)
@@ -190,7 +193,6 @@ fn command_path(sess: &Session, extra: Option<PathBuf>) -> OsString {
     if let Some(path) = env::var_os("PATH") {
         new_path.extend(env::split_paths(&path));
     }
-    new_path.extend(extra);
     env::join_paths(new_path).unwrap()
 }
 
@@ -451,7 +453,7 @@ fn archive_config<'a>(sess: &'a Session,
         src: input.map(|p| p.to_path_buf()),
         lib_search_paths: archive_search_paths(sess),
         ar_prog: get_ar_prog(sess),
-        command_path: command_path(sess, None),
+        command_path: command_path(sess),
     }
 }
 
@@ -727,7 +729,7 @@ fn link_natively(sess: &Session,
 
     // The invocations of cc share some flags across platforms
     let (pname, mut cmd, envs) = get_linker(sess);
-    // This will set PATH on MSVC
+    // This will set PATH on windows
     cmd.envs(envs);
 
     let root = sess.target_filesearch(PathKind::Native).get_lib_path();