Skip to content

Commit f56b8e1

Browse files
authored
Rollup merge of rust-lang#63155 - mfkl:uwp-msvc, r=alexcrichton
Add UWP MSVC targets Hi, - The README URI change is the correct one for VS2019 community edition, which I suspect most people would use. Doesn't _need_ to be merged though. - This rust-lang@5e6619e fixes the UWP build (msvc or not, doesn't matter). I suspect it broke with recent changes unnoticed because no CI. - Store lib location is found through the VCToolsInstallDir env variable. The end of the path is currently for the VS2019 store lib locations only. - I could not test the aarch64_uwp_windows_msvc target because the rust build script does not currently support arm64 msvc AFAIU.
2 parents 9e9a136 + 1581c43 commit f56b8e1

File tree

9 files changed

+140
-3
lines changed

9 files changed

+140
-3
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ then you may need to force rustbuild to use an older version. This can be done
144144
by manually calling the appropriate vcvars file before running the bootstrap.
145145
146146
```batch
147-
> CALL "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Auxiliary\Build\vcvars64.bat"
147+
> CALL "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat"
148148
> python x.py build
149149
```
150150

src/librustc_codegen_ssa/back/link.rs

+32
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ use std::path::{Path, PathBuf};
3232
use std::process::{Output, Stdio, ExitStatus};
3333
use std::str;
3434
use std::env;
35+
use std::ffi::OsString;
3536

3637
pub use rustc_codegen_utils::link::*;
3738

@@ -158,6 +159,36 @@ pub fn get_linker(sess: &Session, linker: &Path, flavor: LinkerFlavor) -> (PathB
158159
}
159160
};
160161

162+
// UWP apps have API restrictions enforced during Store submissions.
163+
// To comply with the Windows App Certification Kit,
164+
// MSVC needs to link with the Store versions of the runtime libraries (vcruntime, msvcrt, etc).
165+
let t = &sess.target.target;
166+
if flavor == LinkerFlavor::Msvc && t.target_vendor == "uwp" {
167+
if let Some(ref tool) = msvc_tool {
168+
let original_path = tool.path();
169+
if let Some(ref root_lib_path) = original_path.ancestors().skip(4).next() {
170+
let arch = match t.arch.as_str() {
171+
"x86_64" => Some("x64".to_string()),
172+
"x86" => Some("x86".to_string()),
173+
"aarch64" => Some("arm64".to_string()),
174+
_ => None,
175+
};
176+
if let Some(ref a) = arch {
177+
let mut arg = OsString::from("/LIBPATH:");
178+
arg.push(format!("{}\\lib\\{}\\store", root_lib_path.display(), a.to_string()));
179+
cmd.arg(&arg);
180+
}
181+
else {
182+
warn!("arch is not supported");
183+
}
184+
} else {
185+
warn!("MSVC root path lib location not found");
186+
}
187+
} else {
188+
warn!("link.exe not found");
189+
}
190+
}
191+
161192
// The compiler's sysroot often has some bundled tools, so add it to the
162193
// PATH for the child.
163194
let mut new_path = sess.host_filesearch(PathKind::All)
@@ -1027,6 +1058,7 @@ fn link_args<'a, B: ArchiveBuilder<'a>>(cmd: &mut dyn Linker,
10271058
let t = &sess.target.target;
10281059

10291060
cmd.include_path(&fix_windows_verbatim_for_gcc(&lib_path));
1061+
10301062
for obj in codegen_results.modules.iter().filter_map(|m| m.object.as_ref()) {
10311063
cmd.add_object(obj);
10321064
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
use crate::spec::{LinkerFlavor, Target, TargetResult, PanicStrategy};
2+
3+
pub fn target() -> TargetResult {
4+
let mut base = super::windows_uwp_msvc_base::opts();
5+
base.max_atomic_width = Some(64);
6+
base.has_elf_tls = true;
7+
8+
// FIXME: this shouldn't be panic=abort, it should be panic=unwind
9+
base.panic_strategy = PanicStrategy::Abort;
10+
11+
Ok(Target {
12+
llvm_target: "aarch64-pc-windows-msvc".to_string(),
13+
target_endian: "little".to_string(),
14+
target_pointer_width: "64".to_string(),
15+
target_c_int_width: "32".to_string(),
16+
data_layout: "e-m:w-p:64:64-i32:32-i64:64-i128:128-n32:64-S128".to_string(),
17+
arch: "aarch64".to_string(),
18+
target_os: "windows".to_string(),
19+
target_env: "msvc".to_string(),
20+
target_vendor: "uwp".to_string(),
21+
linker_flavor: LinkerFlavor::Msvc,
22+
options: base,
23+
})
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
use crate::spec::{LinkerFlavor, Target, TargetResult};
2+
3+
pub fn target() -> TargetResult {
4+
let mut base = super::windows_uwp_msvc_base::opts();
5+
base.cpu = "pentium4".to_string();
6+
base.max_atomic_width = Some(64);
7+
base.has_elf_tls = true;
8+
9+
Ok(Target {
10+
llvm_target: "i686-pc-windows-msvc".to_string(),
11+
target_endian: "little".to_string(),
12+
target_pointer_width: "32".to_string(),
13+
target_c_int_width: "32".to_string(),
14+
data_layout: "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32".to_string(),
15+
arch: "x86".to_string(),
16+
target_os: "windows".to_string(),
17+
target_env: "msvc".to_string(),
18+
target_vendor: "uwp".to_string(),
19+
linker_flavor: LinkerFlavor::Msvc,
20+
options: base,
21+
})
22+
}

src/librustc_target/spec/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ mod uefi_base;
6161
mod windows_base;
6262
mod windows_msvc_base;
6363
mod windows_uwp_base;
64+
mod windows_uwp_msvc_base;
6465
mod thumb_base;
6566
mod l4re_base;
6667
mod fuchsia_base;
@@ -442,8 +443,11 @@ supported_targets! {
442443
("x86_64-uwp-windows-gnu", x86_64_uwp_windows_gnu),
443444

444445
("aarch64-pc-windows-msvc", aarch64_pc_windows_msvc),
446+
("aarch64-uwp-windows-msvc", aarch64_uwp_windows_msvc),
445447
("x86_64-pc-windows-msvc", x86_64_pc_windows_msvc),
448+
("x86_64-uwp-windows-msvc", x86_64_uwp_windows_msvc),
446449
("i686-pc-windows-msvc", i686_pc_windows_msvc),
450+
("i686-uwp-windows-msvc", i686_uwp_windows_msvc),
447451
("i586-pc-windows-msvc", i586_pc_windows_msvc),
448452
("thumbv7a-pc-windows-msvc", thumbv7a_pc_windows_msvc),
449453

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
use crate::spec::{LinkArgs, LinkerFlavor, TargetOptions};
2+
use std::default::Default;
3+
4+
pub fn opts() -> TargetOptions {
5+
let mut args = LinkArgs::new();
6+
args.insert(LinkerFlavor::Msvc,
7+
vec!["/NOLOGO".to_string(),
8+
"/NXCOMPAT".to_string(),
9+
"/APPCONTAINER".to_string(),
10+
"mincore.lib".to_string()]);
11+
12+
TargetOptions {
13+
function_sections: true,
14+
dynamic_linking: true,
15+
executables: true,
16+
dll_prefix: String::new(),
17+
dll_suffix: ".dll".to_string(),
18+
exe_suffix: ".exe".to_string(),
19+
staticlib_prefix: String::new(),
20+
staticlib_suffix: ".lib".to_string(),
21+
target_family: Some("windows".to_string()),
22+
is_like_windows: true,
23+
is_like_msvc: true,
24+
pre_link_args: args,
25+
crt_static_allows_dylibs: true,
26+
crt_static_respected: true,
27+
abi_return_struct_as_int: true,
28+
emit_debug_gdb_scripts: false,
29+
requires_uwtable: true,
30+
31+
.. Default::default()
32+
}
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
use crate::spec::{LinkerFlavor, Target, TargetResult};
2+
3+
pub fn target() -> TargetResult {
4+
let mut base = super::windows_uwp_msvc_base::opts();
5+
base.cpu = "x86-64".to_string();
6+
base.max_atomic_width = Some(64);
7+
base.has_elf_tls = true;
8+
9+
Ok(Target {
10+
llvm_target: "x86_64-pc-windows-msvc".to_string(),
11+
target_endian: "little".to_string(),
12+
target_pointer_width: "64".to_string(),
13+
target_c_int_width: "32".to_string(),
14+
data_layout: "e-m:w-i64:64-f80:128-n8:16:32:64-S128".to_string(),
15+
arch: "x86_64".to_string(),
16+
target_os: "windows".to_string(),
17+
target_env: "msvc".to_string(),
18+
target_vendor: "uwp".to_string(),
19+
linker_flavor: LinkerFlavor::Msvc,
20+
options: base,
21+
})
22+
}

src/libstd/sys/windows/c.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ if #[cfg(target_vendor = "uwp")] {
714714
pub struct FILE_STANDARD_INFO {
715715
pub AllocationSize: LARGE_INTEGER,
716716
pub EndOfFile: LARGE_INTEGER,
717-
pub NumberOfLink: DWORD,
717+
pub NumberOfLinks: DWORD,
718718
pub DeletePending: BOOLEAN,
719719
pub Directory: BOOLEAN,
720720
}

src/libstd/sys/windows/fs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ impl File {
357357
size as c::DWORD))?;
358358
attr.file_size = info.AllocationSize as u64;
359359
attr.number_of_links = Some(info.NumberOfLinks);
360-
if attr.is_reparse_point() {
360+
if attr.file_type().is_reparse_point() {
361361
let mut b = [0; c::MAXIMUM_REPARSE_DATA_BUFFER_SIZE];
362362
if let Ok((_, buf)) = self.reparse_point(&mut b) {
363363
attr.reparse_tag = buf.ReparseTag;

0 commit comments

Comments
 (0)