From c9da160aadf115314809c653449f355d268e8e2a Mon Sep 17 00:00:00 2001 From: Martin Finkel Date: Fri, 9 Aug 2019 15:51:16 +0200 Subject: [PATCH] review feedback: move uwp link code to get_linker --- src/librustc_codegen_ssa/back/link.rs | 41 ++++++++++++++++++--------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/src/librustc_codegen_ssa/back/link.rs b/src/librustc_codegen_ssa/back/link.rs index ea8e55145fa6..076283d521ff 100644 --- a/src/librustc_codegen_ssa/back/link.rs +++ b/src/librustc_codegen_ssa/back/link.rs @@ -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); }