about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMartin Finkel <finkel2804@gmail.com>2019-08-09 15:51:16 +0200
committerMartin Finkel <finkel2804@gmail.com>2019-08-12 15:07:23 +0200
commitc9da160aadf115314809c653449f355d268e8e2a (patch)
tree6fecc9e0b12fcef11ac255e563f4c6dd74d70859
parent89044a908ed602ae3dee74905866cffd63c164b3 (diff)
downloadrust-c9da160aadf115314809c653449f355d268e8e2a.tar.gz
rust-c9da160aadf115314809c653449f355d268e8e2a.zip
review feedback: move uwp link code to get_linker
-rw-r--r--src/librustc_codegen_ssa/back/link.rs41
1 files changed, 28 insertions, 13 deletions
diff --git a/src/librustc_codegen_ssa/back/link.rs b/src/librustc_codegen_ssa/back/link.rs
index ea8e55145fa..076283d521f 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);
     }