Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add UWP MSVC targets #63155

Merged
merged 8 commits into from
Aug 15, 2019
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
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
1 change: 1 addition & 0 deletions src/librustc_target/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ path = "lib.rs"
[dependencies]
bitflags = "1.0"
log = "0.4"
cc = "1.0.1"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh sorry I meant moreso that cc is laready linked elsewhere and it's already handled in probing for it, so we should reuse that location to add paths to link as opposed to doing so in the target spec directory here. (as this is how MSVC is handled in general)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I'm still not clear on what to do.

You want me to patch cc-rs or librustc_codegen_ssa or both?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry so what I mean is that librustc_codegen_ssa already (AFAIK) has tons of logic for dealing with MSVC and leverages the cc crate to find compilers and add paths to link against. The logic for handling UWP paths should all happen around there rather than being duplicated here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code is not pretty... but it seems to work. Let me know what you think

rustc_data_structures = { path = "../librustc_data_structures" }
rustc_serialize = { path = "../libserialize", package = "serialize" }
syntax_pos = { path = "../libsyntax_pos" }
37 changes: 37 additions & 0 deletions src/librustc_target/spec/aarch64_uwp_windows_msvc.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use crate::spec::{LinkerFlavor, Target, TargetResult, PanicStrategy};
use cc::windows_registry;

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the background on this FIXME that causes it to exist? Does that belong in a comment or an issue?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The AArch64 Windows backend didn't implement SEH unwinding when the aarch64-pc-windows-msvc target was first added, so I suspect this is the same as that. I haven't checked the LLVM backend recently to see if this works.

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(),
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,
})
}
35 changes: 35 additions & 0 deletions src/librustc_target/spec/i686_uwp_windows_msvc.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use crate::spec::{LinkerFlavor, Target, TargetResult};
use cc::windows_registry;

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 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(),
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
Original file line number Diff line number Diff line change
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 @@ -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),

Expand Down
33 changes: 33 additions & 0 deletions src/librustc_target/spec/windows_uwp_msvc_base.rs
Original file line number Diff line number Diff line change
@@ -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()
}
}
35 changes: 35 additions & 0 deletions src/librustc_target/spec/x86_64_uwp_windows_msvc.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use crate::spec::{LinkerFlavor, Target, TargetResult};
use cc::windows_registry;

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 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(),
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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