review feedback: move uwp link code to get_linker

This commit is contained in:
Martin Finkel 2019-08-09 15:51:16 +02:00
parent 89044a908e
commit c9da160aad

View file

@ -32,6 +32,7 @@ use std::path::{Path, PathBuf};
use std::process::{Output, Stdio, ExitStatus};
use std::str;
use std::env;
use std::ffi::OsString;
pub use rustc_codegen_utils::link::*;
@ -158,6 +159,33 @@ pub fn get_linker(sess: &Session, linker: &Path, flavor: LinkerFlavor) -> (PathB
}
};
let t = &sess.target.target;
if t.linker_flavor == LinkerFlavor::Msvc && t.target_vendor == "uwp" {
if let Some(ref tool) = msvc_tool {
let original_path = tool.path();
if let Some(ref root_lib_path) = original_path.ancestors().skip(4).next() {
let arch = match t.arch.as_str() {
"x86_64" => Some("x64".to_string()),
"x86" => Some("x86".to_string()),
"aarch64" => Some("arm64".to_string()),
_ => None,
};
if let Some(ref a) = arch {
let mut arg = OsString::from("/LIBPATH:");
arg.push(format!("{}\\lib\\{}\\store", root_lib_path.display(), a.to_string()));
cmd.arg(&arg);
}
else {
warn!("arch is not supported");
}
} else {
warn!("MSVC root path lib location not found");
}
} else {
warn!("link.exe not found");
}
}
// 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)
@ -1028,19 +1056,6 @@ fn link_args<'a, B: ArchiveBuilder<'a>>(cmd: &mut dyn Linker,
cmd.include_path(&fix_windows_verbatim_for_gcc(&lib_path));
if t.linker_flavor == LinkerFlavor::Msvc && t.target_vendor == "uwp" {
let link_tool = windows_registry::find_tool("x86_64-pc-windows-msvc", "link.exe")
.expect("no path found for link.exe");
let original_path = link_tool.path();
let root_lib_path = original_path.ancestors().skip(4).next().unwrap();
if t.arch == "aarch64".to_string() {
cmd.include_path(&root_lib_path.join(format!("lib\\arm64\\store")));
} else {
cmd.include_path(&root_lib_path.join(format!("lib\\{}\\store", t.arch)));
}
}
for obj in codegen_results.modules.iter().filter_map(|m| m.object.as_ref()) {
cmd.add_object(obj);
}