mirror of https://github.com/rust-lang/rust.git
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.
This commit is contained in:
commit
2ad26e850e
|
@ -11,6 +11,7 @@
|
|||
//! A helper class for dealing with static archives
|
||||
|
||||
use std::env;
|
||||
use std::ffi::OsString;
|
||||
use std::fs::{self, File};
|
||||
use std::io::prelude::*;
|
||||
use std::io;
|
||||
|
@ -30,7 +31,8 @@ pub struct ArchiveConfig<'a> {
|
|||
pub lib_search_paths: Vec<PathBuf>,
|
||||
pub slib_prefix: String,
|
||||
pub slib_suffix: String,
|
||||
pub ar_prog: String
|
||||
pub ar_prog: String,
|
||||
pub command_path: OsString,
|
||||
}
|
||||
|
||||
pub struct Archive<'a> {
|
||||
|
@ -114,6 +116,7 @@ impl<'a> Archive<'a> {
|
|||
let abs_dst = env::current_dir().unwrap().join(&self.config.dst);
|
||||
let ar = &self.config.ar_prog;
|
||||
let mut cmd = Command::new(ar);
|
||||
cmd.env("PATH", &self.config.command_path);
|
||||
cmd.stdout(Stdio::piped()).stderr(Stdio::piped());
|
||||
self.prepare_ar_action(&mut cmd, &abs_dst, action);
|
||||
info!("{:?}", cmd);
|
||||
|
|
|
@ -30,6 +30,7 @@ use util::fs::fix_windows_verbatim_for_gcc;
|
|||
use rustc_back::tempdir::TempDir;
|
||||
|
||||
use std::env;
|
||||
use std::ffi::OsString;
|
||||
use std::fs::{self, PathExt};
|
||||
use std::io::{self, Read, Write};
|
||||
use std::mem;
|
||||
|
@ -370,6 +371,17 @@ 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));
|
||||
}
|
||||
env::join_paths(new_path).unwrap()
|
||||
}
|
||||
|
||||
pub fn remove(sess: &Session, path: &Path) {
|
||||
match fs::remove_file(path) {
|
||||
Ok(..) => {}
|
||||
|
@ -554,6 +566,7 @@ fn link_rlib<'a>(sess: &'a Session,
|
|||
slib_prefix: sess.target.target.options.staticlib_prefix.clone(),
|
||||
slib_suffix: sess.target.target.options.staticlib_suffix.clone(),
|
||||
ar_prog: get_ar_prog(sess),
|
||||
command_path: command_path(sess),
|
||||
};
|
||||
let mut ab = ArchiveBuilder::create(config);
|
||||
ab.add_file(obj_filename).unwrap();
|
||||
|
@ -796,15 +809,7 @@ fn link_natively(sess: &Session, trans: &CrateTranslation, dylib: bool,
|
|||
// The invocations of cc share some flags across platforms
|
||||
let pname = get_cc_prog(sess);
|
||||
let mut cmd = Command::new(&pname);
|
||||
|
||||
// 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));
|
||||
}
|
||||
cmd.env("PATH", env::join_paths(new_path).unwrap());
|
||||
cmd.env("PATH", command_path(sess));
|
||||
|
||||
let root = sess.target_filesearch(PathKind::Native).get_lib_path();
|
||||
cmd.args(&sess.target.target.options.pre_link_args);
|
||||
|
@ -1187,6 +1192,7 @@ fn add_upstream_rust_crates(cmd: &mut Linker, sess: &Session,
|
|||
slib_prefix: sess.target.target.options.staticlib_prefix.clone(),
|
||||
slib_suffix: sess.target.target.options.staticlib_suffix.clone(),
|
||||
ar_prog: get_ar_prog(sess),
|
||||
command_path: command_path(sess),
|
||||
};
|
||||
let mut archive = Archive::open(config);
|
||||
archive.remove_file(&format!("{}.o", name));
|
||||
|
|
Loading…
Reference in New Issue