Navigation Menu

Skip to content

Commit

Permalink
Rollup merge of rust-lang#63155 - mfkl:uwp-msvc, r=alexcrichton
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Centril committed Aug 15, 2019
2 parents 9e9a136 + 1581c43 commit f56b8e1
Show file tree
Hide file tree
Showing 9 changed files with 140 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -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
```

Expand Down
32 changes: 32 additions & 0 deletions src/librustc_codegen_ssa/back/link.rs
Expand Up @@ -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::*;

Expand Down Expand Up @@ -158,6 +159,36 @@ 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 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)
Expand Down Expand Up @@ -1027,6 +1058,7 @@ 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));

for obj in codegen_results.modules.iter().filter_map(|m| m.object.as_ref()) {
cmd.add_object(obj);
}
Expand Down
24 changes: 24 additions & 0 deletions src/librustc_target/spec/aarch64_uwp_windows_msvc.rs
@@ -0,0 +1,24 @@
use crate::spec::{LinkerFlavor, Target, TargetResult, PanicStrategy};

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;

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,
})
}
22 changes: 22 additions & 0 deletions src/librustc_target/spec/i686_uwp_windows_msvc.rs
@@ -0,0 +1,22 @@
use crate::spec::{LinkerFlavor, Target, TargetResult};

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;

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,
})
}
4 changes: 4 additions & 0 deletions src/librustc_target/spec/mod.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -442,8 +443,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),

Expand Down
33 changes: 33 additions & 0 deletions 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()
}
}
22 changes: 22 additions & 0 deletions src/librustc_target/spec/x86_64_uwp_windows_msvc.rs
@@ -0,0 +1,22 @@
use crate::spec::{LinkerFlavor, Target, TargetResult};

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;

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,
})
}
2 changes: 1 addition & 1 deletion src/libstd/sys/windows/c.rs
Expand Up @@ -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,
}
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/sys/windows/fs.rs
Expand Up @@ -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;
Expand Down

0 comments on commit f56b8e1

Please sign in to comment.