Skip to content

Commit 76eea74

Browse files
committed
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 #42422
2 parents e1fa8de + e8689c7 commit 76eea74

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/librustc_trans/back/link.rs

+11-9
Original file line numberDiff line numberDiff line change
@@ -141,17 +141,20 @@ pub fn build_link_meta(incremental_hashes_map: &IncrementalHashesMap) -> LinkMet
141141
return r;
142142
}
143143

144-
// The third parameter is for an env vars, used to set up the path for MSVC
145-
// to find its DLLs
144+
// The third parameter is for env vars, used on windows to set up the
145+
// path for MSVC to find its DLLs, and gcc to find its bundled
146+
// toolchain
146147
pub fn get_linker(sess: &Session) -> (String, Command, Vec<(OsString, OsString)>) {
148+
let envs = vec![("PATH".into(), command_path(sess))];
149+
147150
if let Some(ref linker) = sess.opts.cg.linker {
148-
(linker.clone(), Command::new(linker), vec![])
151+
(linker.clone(), Command::new(linker), envs)
149152
} else if sess.target.target.options.is_like_msvc {
150153
let (cmd, envs) = msvc_link_exe_cmd(sess);
151154
("link.exe".to_string(), cmd, envs)
152155
} else {
153-
(sess.target.target.options.linker.clone(),
154-
Command::new(&sess.target.target.options.linker), vec![])
156+
let linker = &sess.target.target.options.linker;
157+
(linker.clone(), Command::new(&linker), envs)
155158
}
156159
}
157160

@@ -182,15 +185,14 @@ pub fn get_ar_prog(sess: &Session) -> String {
182185
})
183186
}
184187

185-
fn command_path(sess: &Session, extra: Option<PathBuf>) -> OsString {
188+
fn command_path(sess: &Session) -> OsString {
186189
// The compiler's sysroot often has some bundled tools, so add it to the
187190
// PATH for the child.
188191
let mut new_path = sess.host_filesearch(PathKind::All)
189192
.get_tools_search_paths();
190193
if let Some(path) = env::var_os("PATH") {
191194
new_path.extend(env::split_paths(&path));
192195
}
193-
new_path.extend(extra);
194196
env::join_paths(new_path).unwrap()
195197
}
196198

@@ -451,7 +453,7 @@ fn archive_config<'a>(sess: &'a Session,
451453
src: input.map(|p| p.to_path_buf()),
452454
lib_search_paths: archive_search_paths(sess),
453455
ar_prog: get_ar_prog(sess),
454-
command_path: command_path(sess, None),
456+
command_path: command_path(sess),
455457
}
456458
}
457459

@@ -727,7 +729,7 @@ fn link_natively(sess: &Session,
727729

728730
// The invocations of cc share some flags across platforms
729731
let (pname, mut cmd, envs) = get_linker(sess);
730-
// This will set PATH on MSVC
732+
// This will set PATH on windows
731733
cmd.envs(envs);
732734

733735
let root = sess.target_filesearch(PathKind::Native).get_lib_path();

0 commit comments

Comments
 (0)