From 5e6619edd1a3b5c3f85438166d4d32af49f800fd Mon Sep 17 00:00:00 2001 From: Martin Finkel Date: Wed, 31 Jul 2019 10:56:56 +0700 Subject: [PATCH 1/8] Fix UWP build --- src/libstd/sys/windows/c.rs | 2 +- src/libstd/sys/windows/fs.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libstd/sys/windows/c.rs b/src/libstd/sys/windows/c.rs index f706709c9ccf4..b1f9d9766f705 100644 --- a/src/libstd/sys/windows/c.rs +++ b/src/libstd/sys/windows/c.rs @@ -714,7 +714,7 @@ if #[cfg(target_vendor = "uwp")] { pub struct FILE_STANDARD_INFO { pub AllocationSize: LARGE_INTEGER, pub EndOfFile: LARGE_INTEGER, - pub NumberOfLink: DWORD, + pub NumberOfLinks: DWORD, pub DeletePending: BOOLEAN, pub Directory: BOOLEAN, } diff --git a/src/libstd/sys/windows/fs.rs b/src/libstd/sys/windows/fs.rs index 5bae6ba4749bd..204f6af5fc1a0 100644 --- a/src/libstd/sys/windows/fs.rs +++ b/src/libstd/sys/windows/fs.rs @@ -357,7 +357,7 @@ impl File { size as c::DWORD))?; attr.file_size = info.AllocationSize as u64; attr.number_of_links = Some(info.NumberOfLinks); - if attr.is_reparse_point() { + if attr.file_type().is_reparse_point() { let mut b = [0; c::MAXIMUM_REPARSE_DATA_BUFFER_SIZE]; if let Ok((_, buf)) = self.reparse_point(&mut b) { attr.reparse_tag = buf.ReparseTag; From 54e268cf5532362ced32329a9327eaee22353829 Mon Sep 17 00:00:00 2001 From: Martin Finkel Date: Wed, 31 Jul 2019 10:58:17 +0700 Subject: [PATCH 2/8] Fix README MSVC URI --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 40df6a4737871..724bc36ecc6fb 100644 --- a/README.md +++ b/README.md @@ -144,7 +144,7 @@ then you may need to force rustbuild to use an older version. This can be done by manually calling the appropriate vcvars file before running the bootstrap. ```batch -> CALL "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Auxiliary\Build\vcvars64.bat" +> CALL "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat" > python x.py build ``` From 6e4d02369ab30872bf4fa86ed2d2e6f897d0cbd8 Mon Sep 17 00:00:00 2001 From: Martin Finkel Date: Wed, 31 Jul 2019 15:00:34 +0700 Subject: [PATCH 3/8] Add UWP MSVC targets --- .../spec/aarch64_uwp_windows_msvc.rs | 29 ++++++++++++++++ .../spec/i686_uwp_windows_msvc.rs | 27 +++++++++++++++ src/librustc_target/spec/mod.rs | 4 +++ .../spec/windows_uwp_msvc_base.rs | 33 +++++++++++++++++++ .../spec/x86_64_uwp_windows_msvc.rs | 27 +++++++++++++++ 5 files changed, 120 insertions(+) create mode 100644 src/librustc_target/spec/aarch64_uwp_windows_msvc.rs create mode 100644 src/librustc_target/spec/i686_uwp_windows_msvc.rs create mode 100644 src/librustc_target/spec/windows_uwp_msvc_base.rs create mode 100644 src/librustc_target/spec/x86_64_uwp_windows_msvc.rs diff --git a/src/librustc_target/spec/aarch64_uwp_windows_msvc.rs b/src/librustc_target/spec/aarch64_uwp_windows_msvc.rs new file mode 100644 index 0000000000000..cb1e710ed1872 --- /dev/null +++ b/src/librustc_target/spec/aarch64_uwp_windows_msvc.rs @@ -0,0 +1,29 @@ +use crate::spec::{LinkerFlavor, Target, TargetResult, PanicStrategy}; +use std::env; + +pub fn target() -> TargetResult { + let mut base = super::windows_uwp_msvc_base::opts(); + base.max_atomic_width = Some(64); + base.has_elf_tls = true; + + // FIXME: this shouldn't be panic=abort, it should be panic=unwind + base.panic_strategy = PanicStrategy::Abort; + + let lib_root_path = env::var("VCToolsInstallDir").expect("VCToolsInstallDir not found in env"); + base.pre_link_args.get_mut(&LinkerFlavor::Msvc).unwrap() + .push(format!("{}{}{}", "/LIBPATH:".to_string(), lib_root_path, "lib\\arm64\\store".to_string())); + + Ok(Target { + llvm_target: "aarch64-pc-windows-msvc".to_string(), + target_endian: "little".to_string(), + target_pointer_width: "64".to_string(), + target_c_int_width: "32".to_string(), + data_layout: "e-m:w-p:64:64-i32:32-i64:64-i128:128-n32:64-S128".to_string(), + arch: "aarch64".to_string(), + target_os: "windows".to_string(), + target_env: "msvc".to_string(), + target_vendor: "uwp".to_string(), + linker_flavor: LinkerFlavor::Msvc, + options: base, + }) +} diff --git a/src/librustc_target/spec/i686_uwp_windows_msvc.rs b/src/librustc_target/spec/i686_uwp_windows_msvc.rs new file mode 100644 index 0000000000000..d09c9d5d2dbbf --- /dev/null +++ b/src/librustc_target/spec/i686_uwp_windows_msvc.rs @@ -0,0 +1,27 @@ +use crate::spec::{LinkerFlavor, Target, TargetResult}; +use std::env; + +pub fn target() -> TargetResult { + let mut base = super::windows_uwp_msvc_base::opts(); + base.cpu = "pentium4".to_string(); + base.max_atomic_width = Some(64); + base.has_elf_tls = true; + + let lib_root_path = env::var("VCToolsInstallDir").expect("VCToolsInstallDir not found in env"); + base.pre_link_args.get_mut(&LinkerFlavor::Msvc).unwrap() + .push(format!("{}{}{}", "/LIBPATH:".to_string(), lib_root_path, "lib\\x86\\store".to_string())); + + Ok(Target { + llvm_target: "i686-pc-windows-msvc".to_string(), + target_endian: "little".to_string(), + target_pointer_width: "32".to_string(), + target_c_int_width: "32".to_string(), + data_layout: "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32".to_string(), + arch: "x86".to_string(), + target_os: "windows".to_string(), + target_env: "msvc".to_string(), + target_vendor: "uwp".to_string(), + linker_flavor: LinkerFlavor::Msvc, + options: base, + }) +} \ No newline at end of file diff --git a/src/librustc_target/spec/mod.rs b/src/librustc_target/spec/mod.rs index 54e3cad6a6149..dbb29c595038a 100644 --- a/src/librustc_target/spec/mod.rs +++ b/src/librustc_target/spec/mod.rs @@ -61,6 +61,7 @@ mod uefi_base; mod windows_base; mod windows_msvc_base; mod windows_uwp_base; +mod windows_uwp_msvc_base; mod thumb_base; mod l4re_base; mod fuchsia_base; @@ -439,8 +440,11 @@ supported_targets! { ("x86_64-uwp-windows-gnu", x86_64_uwp_windows_gnu), ("aarch64-pc-windows-msvc", aarch64_pc_windows_msvc), + ("aarch64-uwp-windows-msvc", aarch64_uwp_windows_msvc), ("x86_64-pc-windows-msvc", x86_64_pc_windows_msvc), + ("x86_64-uwp-windows-msvc", x86_64_uwp_windows_msvc), ("i686-pc-windows-msvc", i686_pc_windows_msvc), + ("i686-uwp-windows-msvc", i686_uwp_windows_msvc), ("i586-pc-windows-msvc", i586_pc_windows_msvc), ("thumbv7a-pc-windows-msvc", thumbv7a_pc_windows_msvc), diff --git a/src/librustc_target/spec/windows_uwp_msvc_base.rs b/src/librustc_target/spec/windows_uwp_msvc_base.rs new file mode 100644 index 0000000000000..e643513a1a7fe --- /dev/null +++ b/src/librustc_target/spec/windows_uwp_msvc_base.rs @@ -0,0 +1,33 @@ +use crate::spec::{LinkArgs, LinkerFlavor, TargetOptions}; +use std::default::Default; + +pub fn opts() -> TargetOptions { + let mut args = LinkArgs::new(); + args.insert(LinkerFlavor::Msvc, + vec!["/NOLOGO".to_string(), + "/NXCOMPAT".to_string(), + "/APPCONTAINER".to_string(), + "mincore.lib".to_string()]); + + TargetOptions { + function_sections: true, + dynamic_linking: true, + executables: true, + dll_prefix: String::new(), + dll_suffix: ".dll".to_string(), + exe_suffix: ".exe".to_string(), + staticlib_prefix: String::new(), + staticlib_suffix: ".lib".to_string(), + target_family: Some("windows".to_string()), + is_like_windows: true, + is_like_msvc: true, + pre_link_args: args, + crt_static_allows_dylibs: true, + crt_static_respected: true, + abi_return_struct_as_int: true, + emit_debug_gdb_scripts: false, + requires_uwtable: true, + + .. Default::default() + } +} \ No newline at end of file diff --git a/src/librustc_target/spec/x86_64_uwp_windows_msvc.rs b/src/librustc_target/spec/x86_64_uwp_windows_msvc.rs new file mode 100644 index 0000000000000..7d89c73a0e234 --- /dev/null +++ b/src/librustc_target/spec/x86_64_uwp_windows_msvc.rs @@ -0,0 +1,27 @@ +use crate::spec::{LinkerFlavor, Target, TargetResult}; +use std::env; + +pub fn target() -> TargetResult { + let mut base = super::windows_uwp_msvc_base::opts(); + base.cpu = "x86-64".to_string(); + base.max_atomic_width = Some(64); + base.has_elf_tls = true; + + let lib_root_path = env::var("VCToolsInstallDir").expect("VCToolsInstallDir not found in env"); + base.pre_link_args.get_mut(&LinkerFlavor::Msvc).unwrap() + .push(format!("{}{}{}", "/LIBPATH:".to_string(), lib_root_path, "lib\\x64\\store".to_string())); + + Ok(Target { + llvm_target: "x86_64-pc-windows-msvc".to_string(), + target_endian: "little".to_string(), + target_pointer_width: "64".to_string(), + target_c_int_width: "32".to_string(), + data_layout: "e-m:w-i64:64-f80:128-n8:16:32:64-S128".to_string(), + arch: "x86_64".to_string(), + target_os: "windows".to_string(), + target_env: "msvc".to_string(), + target_vendor: "uwp".to_string(), + linker_flavor: LinkerFlavor::Msvc, + options: base, + }) +} \ No newline at end of file From 3c6f6f031600dce97d2fd61a51afb17ff7f453ec Mon Sep 17 00:00:00 2001 From: Martin Finkel Date: Wed, 31 Jul 2019 17:15:26 +0700 Subject: [PATCH 4/8] Fix tidy checks --- src/librustc_target/spec/aarch64_uwp_windows_msvc.rs | 9 +++++++-- src/librustc_target/spec/i686_uwp_windows_msvc.rs | 11 ++++++++--- src/librustc_target/spec/windows_uwp_msvc_base.rs | 2 +- src/librustc_target/spec/x86_64_uwp_windows_msvc.rs | 11 ++++++++--- 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/librustc_target/spec/aarch64_uwp_windows_msvc.rs b/src/librustc_target/spec/aarch64_uwp_windows_msvc.rs index cb1e710ed1872..9309f287dc714 100644 --- a/src/librustc_target/spec/aarch64_uwp_windows_msvc.rs +++ b/src/librustc_target/spec/aarch64_uwp_windows_msvc.rs @@ -9,9 +9,14 @@ pub fn target() -> TargetResult { // FIXME: this shouldn't be panic=abort, it should be panic=unwind base.panic_strategy = PanicStrategy::Abort; - let lib_root_path = env::var("VCToolsInstallDir").expect("VCToolsInstallDir not found in env"); + let lib_root_path = env::var("VCToolsInstallDir") + .expect("VCToolsInstallDir not found in env"); + base.pre_link_args.get_mut(&LinkerFlavor::Msvc).unwrap() - .push(format!("{}{}{}", "/LIBPATH:".to_string(), lib_root_path, "lib\\arm64\\store".to_string())); + .push(format!("{}{}{}", + "/LIBPATH:".to_string(), + lib_root_path, + "lib\\arm64\\store".to_string())); Ok(Target { llvm_target: "aarch64-pc-windows-msvc".to_string(), diff --git a/src/librustc_target/spec/i686_uwp_windows_msvc.rs b/src/librustc_target/spec/i686_uwp_windows_msvc.rs index d09c9d5d2dbbf..d05aee547591f 100644 --- a/src/librustc_target/spec/i686_uwp_windows_msvc.rs +++ b/src/librustc_target/spec/i686_uwp_windows_msvc.rs @@ -7,9 +7,14 @@ pub fn target() -> TargetResult { base.max_atomic_width = Some(64); base.has_elf_tls = true; - let lib_root_path = env::var("VCToolsInstallDir").expect("VCToolsInstallDir not found in env"); + let lib_root_path = env::var("VCToolsInstallDir") + .expect("VCToolsInstallDir not found in env"); + base.pre_link_args.get_mut(&LinkerFlavor::Msvc).unwrap() - .push(format!("{}{}{}", "/LIBPATH:".to_string(), lib_root_path, "lib\\x86\\store".to_string())); + .push(format!("{}{}{}", + "/LIBPATH:".to_string(), + lib_root_path, + "lib\\x86\\store".to_string())); Ok(Target { llvm_target: "i686-pc-windows-msvc".to_string(), @@ -24,4 +29,4 @@ pub fn target() -> TargetResult { linker_flavor: LinkerFlavor::Msvc, options: base, }) -} \ No newline at end of file +} diff --git a/src/librustc_target/spec/windows_uwp_msvc_base.rs b/src/librustc_target/spec/windows_uwp_msvc_base.rs index e643513a1a7fe..1121916e68f51 100644 --- a/src/librustc_target/spec/windows_uwp_msvc_base.rs +++ b/src/librustc_target/spec/windows_uwp_msvc_base.rs @@ -30,4 +30,4 @@ pub fn opts() -> TargetOptions { .. Default::default() } -} \ No newline at end of file +} diff --git a/src/librustc_target/spec/x86_64_uwp_windows_msvc.rs b/src/librustc_target/spec/x86_64_uwp_windows_msvc.rs index 7d89c73a0e234..174d13327eb16 100644 --- a/src/librustc_target/spec/x86_64_uwp_windows_msvc.rs +++ b/src/librustc_target/spec/x86_64_uwp_windows_msvc.rs @@ -7,9 +7,14 @@ pub fn target() -> TargetResult { base.max_atomic_width = Some(64); base.has_elf_tls = true; - let lib_root_path = env::var("VCToolsInstallDir").expect("VCToolsInstallDir not found in env"); + let lib_root_path = env::var("VCToolsInstallDir") + .expect("VCToolsInstallDir not found in env"); + base.pre_link_args.get_mut(&LinkerFlavor::Msvc).unwrap() - .push(format!("{}{}{}", "/LIBPATH:".to_string(), lib_root_path, "lib\\x64\\store".to_string())); + .push(format!("{}{}{}", + "/LIBPATH:".to_string(), + lib_root_path, + "lib\\x64\\store".to_string())); Ok(Target { llvm_target: "x86_64-pc-windows-msvc".to_string(), @@ -24,4 +29,4 @@ pub fn target() -> TargetResult { linker_flavor: LinkerFlavor::Msvc, options: base, }) -} \ No newline at end of file +} From e3d8b6817ef0369915fb0dc5f2f519e942f8d67f Mon Sep 17 00:00:00 2001 From: Martin Finkel Date: Mon, 5 Aug 2019 16:24:20 +0200 Subject: [PATCH 5/8] review feedback: find lib root path from registry --- Cargo.lock | 1 + src/librustc_target/Cargo.toml | 1 + src/librustc_target/spec/aarch64_uwp_windows_msvc.rs | 9 ++++++--- src/librustc_target/spec/i686_uwp_windows_msvc.rs | 9 ++++++--- src/librustc_target/spec/x86_64_uwp_windows_msvc.rs | 9 ++++++--- 5 files changed, 20 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c08d7444d14ea..f2356a2615248 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3126,6 +3126,7 @@ name = "rustc_target" version = "0.0.0" dependencies = [ "bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_data_structures 0.0.0", "serialize 0.0.0", diff --git a/src/librustc_target/Cargo.toml b/src/librustc_target/Cargo.toml index cab1e0e01371d..940acf232ad13 100644 --- a/src/librustc_target/Cargo.toml +++ b/src/librustc_target/Cargo.toml @@ -11,6 +11,7 @@ path = "lib.rs" [dependencies] bitflags = "1.0" log = "0.4" +cc = "1.0.1" rustc_data_structures = { path = "../librustc_data_structures" } rustc_serialize = { path = "../libserialize", package = "serialize" } syntax_pos = { path = "../libsyntax_pos" } diff --git a/src/librustc_target/spec/aarch64_uwp_windows_msvc.rs b/src/librustc_target/spec/aarch64_uwp_windows_msvc.rs index 9309f287dc714..ab1b6705a1da1 100644 --- a/src/librustc_target/spec/aarch64_uwp_windows_msvc.rs +++ b/src/librustc_target/spec/aarch64_uwp_windows_msvc.rs @@ -1,5 +1,5 @@ use crate::spec::{LinkerFlavor, Target, TargetResult, PanicStrategy}; -use std::env; +use cc::windows_registry; pub fn target() -> TargetResult { let mut base = super::windows_uwp_msvc_base::opts(); @@ -9,8 +9,11 @@ pub fn target() -> TargetResult { // FIXME: this shouldn't be panic=abort, it should be panic=unwind base.panic_strategy = PanicStrategy::Abort; - let lib_root_path = env::var("VCToolsInstallDir") - .expect("VCToolsInstallDir not found in env"); + 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 lib_root_path = original_path.ancestors().skip(4).next().unwrap().display(); base.pre_link_args.get_mut(&LinkerFlavor::Msvc).unwrap() .push(format!("{}{}{}", diff --git a/src/librustc_target/spec/i686_uwp_windows_msvc.rs b/src/librustc_target/spec/i686_uwp_windows_msvc.rs index d05aee547591f..bc5631439d19e 100644 --- a/src/librustc_target/spec/i686_uwp_windows_msvc.rs +++ b/src/librustc_target/spec/i686_uwp_windows_msvc.rs @@ -1,5 +1,5 @@ use crate::spec::{LinkerFlavor, Target, TargetResult}; -use std::env; +use cc::windows_registry; pub fn target() -> TargetResult { let mut base = super::windows_uwp_msvc_base::opts(); @@ -7,8 +7,11 @@ pub fn target() -> TargetResult { base.max_atomic_width = Some(64); base.has_elf_tls = true; - let lib_root_path = env::var("VCToolsInstallDir") - .expect("VCToolsInstallDir not found in env"); + 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 lib_root_path = original_path.ancestors().skip(4).next().unwrap().display(); base.pre_link_args.get_mut(&LinkerFlavor::Msvc).unwrap() .push(format!("{}{}{}", diff --git a/src/librustc_target/spec/x86_64_uwp_windows_msvc.rs b/src/librustc_target/spec/x86_64_uwp_windows_msvc.rs index 174d13327eb16..8c15c7c22fcff 100644 --- a/src/librustc_target/spec/x86_64_uwp_windows_msvc.rs +++ b/src/librustc_target/spec/x86_64_uwp_windows_msvc.rs @@ -1,5 +1,5 @@ use crate::spec::{LinkerFlavor, Target, TargetResult}; -use std::env; +use cc::windows_registry; pub fn target() -> TargetResult { let mut base = super::windows_uwp_msvc_base::opts(); @@ -7,8 +7,11 @@ pub fn target() -> TargetResult { base.max_atomic_width = Some(64); base.has_elf_tls = true; - let lib_root_path = env::var("VCToolsInstallDir") - .expect("VCToolsInstallDir not found in env"); + 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 lib_root_path = original_path.ancestors().skip(4).next().unwrap().display(); base.pre_link_args.get_mut(&LinkerFlavor::Msvc).unwrap() .push(format!("{}{}{}", From 89044a908ed602ae3dee74905866cffd63c164b3 Mon Sep 17 00:00:00 2001 From: Martin Finkel Date: Wed, 7 Aug 2019 17:49:15 +0200 Subject: [PATCH 6/8] move store lib probing code to librustc_codegen_ssa --- Cargo.lock | 1 - src/librustc_codegen_ssa/back/link.rs | 14 ++++++++++++++ src/librustc_target/Cargo.toml | 1 - .../spec/aarch64_uwp_windows_msvc.rs | 13 ------------- src/librustc_target/spec/i686_uwp_windows_msvc.rs | 13 ------------- .../spec/x86_64_uwp_windows_msvc.rs | 13 ------------- 6 files changed, 14 insertions(+), 41 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f2356a2615248..c08d7444d14ea 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3126,7 +3126,6 @@ name = "rustc_target" version = "0.0.0" dependencies = [ "bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "cc 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_data_structures 0.0.0", "serialize 0.0.0", diff --git a/src/librustc_codegen_ssa/back/link.rs b/src/librustc_codegen_ssa/back/link.rs index 3f6a1a72ea61e..ea8e55145fa62 100644 --- a/src/librustc_codegen_ssa/back/link.rs +++ b/src/librustc_codegen_ssa/back/link.rs @@ -1027,6 +1027,20 @@ fn link_args<'a, B: ArchiveBuilder<'a>>(cmd: &mut dyn Linker, let t = &sess.target.target; 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); } diff --git a/src/librustc_target/Cargo.toml b/src/librustc_target/Cargo.toml index 940acf232ad13..cab1e0e01371d 100644 --- a/src/librustc_target/Cargo.toml +++ b/src/librustc_target/Cargo.toml @@ -11,7 +11,6 @@ path = "lib.rs" [dependencies] bitflags = "1.0" log = "0.4" -cc = "1.0.1" rustc_data_structures = { path = "../librustc_data_structures" } rustc_serialize = { path = "../libserialize", package = "serialize" } syntax_pos = { path = "../libsyntax_pos" } diff --git a/src/librustc_target/spec/aarch64_uwp_windows_msvc.rs b/src/librustc_target/spec/aarch64_uwp_windows_msvc.rs index ab1b6705a1da1..5d8b829f2ab71 100644 --- a/src/librustc_target/spec/aarch64_uwp_windows_msvc.rs +++ b/src/librustc_target/spec/aarch64_uwp_windows_msvc.rs @@ -1,5 +1,4 @@ use crate::spec::{LinkerFlavor, Target, TargetResult, PanicStrategy}; -use cc::windows_registry; pub fn target() -> TargetResult { let mut base = super::windows_uwp_msvc_base::opts(); @@ -9,18 +8,6 @@ pub fn target() -> TargetResult { // FIXME: this shouldn't be panic=abort, it should be panic=unwind base.panic_strategy = PanicStrategy::Abort; - 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 lib_root_path = original_path.ancestors().skip(4).next().unwrap().display(); - - base.pre_link_args.get_mut(&LinkerFlavor::Msvc).unwrap() - .push(format!("{}{}{}", - "/LIBPATH:".to_string(), - lib_root_path, - "lib\\arm64\\store".to_string())); - Ok(Target { llvm_target: "aarch64-pc-windows-msvc".to_string(), target_endian: "little".to_string(), diff --git a/src/librustc_target/spec/i686_uwp_windows_msvc.rs b/src/librustc_target/spec/i686_uwp_windows_msvc.rs index bc5631439d19e..5e8e8c2a4149c 100644 --- a/src/librustc_target/spec/i686_uwp_windows_msvc.rs +++ b/src/librustc_target/spec/i686_uwp_windows_msvc.rs @@ -1,5 +1,4 @@ use crate::spec::{LinkerFlavor, Target, TargetResult}; -use cc::windows_registry; pub fn target() -> TargetResult { let mut base = super::windows_uwp_msvc_base::opts(); @@ -7,18 +6,6 @@ pub fn target() -> TargetResult { base.max_atomic_width = Some(64); base.has_elf_tls = true; - 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 lib_root_path = original_path.ancestors().skip(4).next().unwrap().display(); - - base.pre_link_args.get_mut(&LinkerFlavor::Msvc).unwrap() - .push(format!("{}{}{}", - "/LIBPATH:".to_string(), - lib_root_path, - "lib\\x86\\store".to_string())); - Ok(Target { llvm_target: "i686-pc-windows-msvc".to_string(), target_endian: "little".to_string(), diff --git a/src/librustc_target/spec/x86_64_uwp_windows_msvc.rs b/src/librustc_target/spec/x86_64_uwp_windows_msvc.rs index 8c15c7c22fcff..40dd52c159151 100644 --- a/src/librustc_target/spec/x86_64_uwp_windows_msvc.rs +++ b/src/librustc_target/spec/x86_64_uwp_windows_msvc.rs @@ -1,5 +1,4 @@ use crate::spec::{LinkerFlavor, Target, TargetResult}; -use cc::windows_registry; pub fn target() -> TargetResult { let mut base = super::windows_uwp_msvc_base::opts(); @@ -7,18 +6,6 @@ pub fn target() -> TargetResult { base.max_atomic_width = Some(64); base.has_elf_tls = true; - 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 lib_root_path = original_path.ancestors().skip(4).next().unwrap().display(); - - base.pre_link_args.get_mut(&LinkerFlavor::Msvc).unwrap() - .push(format!("{}{}{}", - "/LIBPATH:".to_string(), - lib_root_path, - "lib\\x64\\store".to_string())); - Ok(Target { llvm_target: "x86_64-pc-windows-msvc".to_string(), target_endian: "little".to_string(), From c9da160aadf115314809c653449f355d268e8e2a Mon Sep 17 00:00:00 2001 From: Martin Finkel Date: Fri, 9 Aug 2019 15:51:16 +0200 Subject: [PATCH 7/8] 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 ea8e55145fa62..076283d521ffb 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); } From 1581c43be0dd7ac529e85f0a88f7447a315cb787 Mon Sep 17 00:00:00 2001 From: Martin Finkel Date: Tue, 13 Aug 2019 11:11:35 +0200 Subject: [PATCH 8/8] review feedback: add comments and use local flavor variable --- src/librustc_codegen_ssa/back/link.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/librustc_codegen_ssa/back/link.rs b/src/librustc_codegen_ssa/back/link.rs index 076283d521ffb..3a0d5261d0c86 100644 --- a/src/librustc_codegen_ssa/back/link.rs +++ b/src/librustc_codegen_ssa/back/link.rs @@ -159,8 +159,11 @@ pub fn get_linker(sess: &Session, linker: &Path, flavor: LinkerFlavor) -> (PathB } }; + // UWP apps have API restrictions enforced during Store submissions. + // To comply with the Windows App Certification Kit, + // MSVC needs to link with the Store versions of the runtime libraries (vcruntime, msvcrt, etc). let t = &sess.target.target; - if t.linker_flavor == LinkerFlavor::Msvc && t.target_vendor == "uwp" { + if 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() {