Auto merge of #31064 - retep998:msvc-host-dlls, r=alexcrichton
Fixes https://github.com/rust-lang/rust/issues/31063 r? @alexcrichton
This commit is contained in:
commit
5c1d5fcd87
@ -396,6 +396,9 @@ fn command_path(sess: &Session) -> OsString {
|
||||
if let Some(path) = env::var_os("PATH") {
|
||||
new_path.extend(env::split_paths(&path));
|
||||
}
|
||||
if sess.target.target.options.is_like_msvc {
|
||||
new_path.extend(msvc::host_dll_path());
|
||||
}
|
||||
env::join_paths(new_path).unwrap()
|
||||
}
|
||||
|
||||
|
@ -31,20 +31,31 @@
|
||||
//! paths/files is based on Microsoft's logic in their vcvars bat files, but
|
||||
//! comments can also be found below leading through the various code paths.
|
||||
|
||||
use std::process::Command;
|
||||
use session::Session;
|
||||
|
||||
#[cfg(windows)]
|
||||
mod registry;
|
||||
|
||||
#[cfg(windows)]
|
||||
pub fn link_exe_cmd(sess: &Session) -> Command {
|
||||
mod platform {
|
||||
use std::env;
|
||||
use std::ffi::OsString;
|
||||
use std::fs;
|
||||
use std::path::{Path, PathBuf};
|
||||
use self::registry::{LOCAL_MACHINE};
|
||||
use std::process::Command;
|
||||
use session::Session;
|
||||
use super::registry::{LOCAL_MACHINE};
|
||||
|
||||
// Cross toolchains depend on dlls from the host toolchain
|
||||
// We can't just add it to the Command's PATH in `link_exe_cmd` because it
|
||||
// is later overridden so we publicly expose it here instead
|
||||
pub fn host_dll_path() -> Option<PathBuf> {
|
||||
get_vc_dir().and_then(|(_, vcdir)| {
|
||||
host_dll_subdir().map(|sub| {
|
||||
vcdir.join("bin").join(sub)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
pub fn link_exe_cmd(sess: &Session) -> Command {
|
||||
let arch = &sess.target.target.arch;
|
||||
let (binsub, libsub, vclibsub) =
|
||||
match (bin_subdir(arch), lib_subdir(arch), vc_lib_subdir(arch)) {
|
||||
@ -86,10 +97,7 @@ pub fn link_exe_cmd(sess: &Session) -> Command {
|
||||
}).or_else(|| {
|
||||
get_vc_dir().and_then(|(ver, vcdir)| {
|
||||
debug!("Found VC installation directory {:?}", vcdir);
|
||||
let mut linker = vcdir.clone();
|
||||
linker.push("bin");
|
||||
linker.push(binsub);
|
||||
linker.push("link.exe");
|
||||
let linker = vcdir.clone().join("bin").join(binsub).join("link.exe");
|
||||
if !linker.is_file() { return None }
|
||||
let mut cmd = Command::new(linker);
|
||||
add_lib(&mut cmd, &vcdir.join("lib").join(vclibsub));
|
||||
@ -122,7 +130,7 @@ pub fn link_exe_cmd(sess: &Session) -> Command {
|
||||
debug!("Failed to locate linker.");
|
||||
Command::new("link.exe")
|
||||
});
|
||||
|
||||
}
|
||||
// A convenience function to make the above code simpler
|
||||
fn add_lib(cmd: &mut Command, lib: &Path) {
|
||||
let mut arg: OsString = "/LIBPATH:".into();
|
||||
@ -257,11 +265,23 @@ fn vc_lib_subdir(arch: &str) -> Option<&'static str> {
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
fn host_dll_subdir() -> Option<&'static str> {
|
||||
if cfg!(target_arch = "x86_64") { Some("amd64") }
|
||||
else if cfg!(target_arch = "x86") { Some("") }
|
||||
else { None }
|
||||
}
|
||||
}
|
||||
|
||||
// If we're not on Windows, then there's no registry to search through and MSVC
|
||||
// wouldn't be able to run, so we just call `link.exe` and hope for the best.
|
||||
#[cfg(not(windows))]
|
||||
mod platform {
|
||||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
use session::Session;
|
||||
pub fn link_exe_cmd(_sess: &Session) -> Command {
|
||||
Command::new("link.exe")
|
||||
}
|
||||
pub fn host_dll_path() -> Option<PathBuf> { None }
|
||||
}
|
||||
pub use self::platform::*;
|
||||
|
Loading…
Reference in New Issue
Block a user