Skip to content

Commit 2ad26e8

Browse files
committed
Auto merge of #26490 - alexcrichton:fix-msvc-again, r=brson
This commit ensures that the modifications made in #26382 also apply to the archive commands run in addition to the linker commands.
2 parents 27ecbba + db5b463 commit 2ad26e8

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

src/librustc_back/archive.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//! A helper class for dealing with static archives
1212
1313
use std::env;
14+
use std::ffi::OsString;
1415
use std::fs::{self, File};
1516
use std::io::prelude::*;
1617
use std::io;
@@ -30,7 +31,8 @@ pub struct ArchiveConfig<'a> {
3031
pub lib_search_paths: Vec<PathBuf>,
3132
pub slib_prefix: String,
3233
pub slib_suffix: String,
33-
pub ar_prog: String
34+
pub ar_prog: String,
35+
pub command_path: OsString,
3436
}
3537

3638
pub struct Archive<'a> {
@@ -114,6 +116,7 @@ impl<'a> Archive<'a> {
114116
let abs_dst = env::current_dir().unwrap().join(&self.config.dst);
115117
let ar = &self.config.ar_prog;
116118
let mut cmd = Command::new(ar);
119+
cmd.env("PATH", &self.config.command_path);
117120
cmd.stdout(Stdio::piped()).stderr(Stdio::piped());
118121
self.prepare_ar_action(&mut cmd, &abs_dst, action);
119122
info!("{:?}", cmd);

src/librustc_trans/back/link.rs

+15-9
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ use util::fs::fix_windows_verbatim_for_gcc;
3030
use rustc_back::tempdir::TempDir;
3131

3232
use std::env;
33+
use std::ffi::OsString;
3334
use std::fs::{self, PathExt};
3435
use std::io::{self, Read, Write};
3536
use std::mem;
@@ -370,6 +371,17 @@ pub fn get_ar_prog(sess: &Session) -> String {
370371
})
371372
}
372373

374+
fn command_path(sess: &Session) -> OsString {
375+
// The compiler's sysroot often has some bundled tools, so add it to the
376+
// PATH for the child.
377+
let mut new_path = sess.host_filesearch(PathKind::All)
378+
.get_tools_search_paths();
379+
if let Some(path) = env::var_os("PATH") {
380+
new_path.extend(env::split_paths(&path));
381+
}
382+
env::join_paths(new_path).unwrap()
383+
}
384+
373385
pub fn remove(sess: &Session, path: &Path) {
374386
match fs::remove_file(path) {
375387
Ok(..) => {}
@@ -554,6 +566,7 @@ fn link_rlib<'a>(sess: &'a Session,
554566
slib_prefix: sess.target.target.options.staticlib_prefix.clone(),
555567
slib_suffix: sess.target.target.options.staticlib_suffix.clone(),
556568
ar_prog: get_ar_prog(sess),
569+
command_path: command_path(sess),
557570
};
558571
let mut ab = ArchiveBuilder::create(config);
559572
ab.add_file(obj_filename).unwrap();
@@ -796,15 +809,7 @@ fn link_natively(sess: &Session, trans: &CrateTranslation, dylib: bool,
796809
// The invocations of cc share some flags across platforms
797810
let pname = get_cc_prog(sess);
798811
let mut cmd = Command::new(&pname);
799-
800-
// The compiler's sysroot often has some bundled tools, so add it to the
801-
// PATH for the child.
802-
let mut new_path = sess.host_filesearch(PathKind::All)
803-
.get_tools_search_paths();
804-
if let Some(path) = env::var_os("PATH") {
805-
new_path.extend(env::split_paths(&path));
806-
}
807-
cmd.env("PATH", env::join_paths(new_path).unwrap());
812+
cmd.env("PATH", command_path(sess));
808813

809814
let root = sess.target_filesearch(PathKind::Native).get_lib_path();
810815
cmd.args(&sess.target.target.options.pre_link_args);
@@ -1187,6 +1192,7 @@ fn add_upstream_rust_crates(cmd: &mut Linker, sess: &Session,
11871192
slib_prefix: sess.target.target.options.staticlib_prefix.clone(),
11881193
slib_suffix: sess.target.target.options.staticlib_suffix.clone(),
11891194
ar_prog: get_ar_prog(sess),
1195+
command_path: command_path(sess),
11901196
};
11911197
let mut archive = Archive::open(config);
11921198
archive.remove_file(&format!("{}.o", name));

0 commit comments

Comments
 (0)