-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Add Games MSVC targets #67745
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 Games MSVC targets #67745
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use crate::spec::{LinkerFlavor, PanicStrategy, Target, TargetResult}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Copied from |
||
|
||
pub fn target() -> TargetResult { | ||
let mut base = super::windows_games_msvc_base::opts(); | ||
base.max_atomic_width = Some(64); | ||
base.has_elf_tls = true; | ||
base.features = "+neon,+fp-armv8".to_string(); | ||
|
||
// FIXME: this shouldn't be panic=abort, it should be panic=unwind | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See prior discussion here: https://github.com/rust-lang/rust/pull/63155/files#r312060124 |
||
base.panic_strategy = PanicStrategy::Abort; | ||
|
||
Ok(Target { | ||
llvm_target: "aarch64-games-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: "games".to_string(), | ||
linker_flavor: LinkerFlavor::Msvc, | ||
options: base, | ||
}) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use crate::spec::{LinkerFlavor, Target, TargetResult}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Like above, copied from |
||
|
||
pub fn target() -> TargetResult { | ||
let mut base = super::windows_games_msvc_base::opts(); | ||
base.cpu = "pentium4".to_string(); | ||
base.max_atomic_width = Some(64); | ||
base.has_elf_tls = true; | ||
|
||
// Mark all dynamic libraries and executables as compatible with the larger 4GiB address | ||
// space available to x86 Windows binaries on x86_64. | ||
base.pre_link_args.get_mut(&LinkerFlavor::Msvc).unwrap().push("/LARGEADDRESSAWARE".to_string()); | ||
|
||
// Ensure the linker will only produce an image if it can also produce a table of | ||
// the image's safe exception handlers. | ||
// https://docs.microsoft.com/en-us/cpp/build/reference/safeseh-image-has-safe-exception-handlers | ||
base.pre_link_args.get_mut(&LinkerFlavor::Msvc).unwrap().push("/SAFESEH".to_string()); | ||
|
||
Ok(Target { | ||
llvm_target: "i686-games-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: "games".to_string(), | ||
linker_flavor: LinkerFlavor::Msvc, | ||
options: base, | ||
}) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use crate::spec::{LinkArgs, LinkerFlavor, TargetOptions}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to
See here for more info on umbrella libraries: https://docs.microsoft.com/en-us/windows/win32/apiindex/windows-umbrella-libraries There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can add the above as a comment in code if it would be useful. |
||
use std::default::Default; | ||
|
||
pub fn opts() -> TargetOptions { | ||
let mut args = LinkArgs::new(); | ||
args.insert( | ||
LinkerFlavor::Msvc, | ||
vec!["/NOLOGO".to_string(), "/NXCOMPAT".to_string(), "onecore.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, | ||
// set VSLANG to 1033 can prevent link.exe from using | ||
// language packs, and avoid generating Non-UTF-8 error | ||
// messages if a link error occurred. | ||
link_env: vec![("VSLANG".to_string(), "1033".to_string())], | ||
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() | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use crate::spec::{LinkerFlavor, Target, TargetResult}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Copied from |
||
|
||
pub fn target() -> TargetResult { | ||
let mut base = super::windows_games_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-games-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: "games".to_string(), | ||
linker_flavor: LinkerFlavor::Msvc, | ||
options: base, | ||
}) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -151,9 +151,6 @@ pub const IO_REPARSE_TAG_MOUNT_POINT: DWORD = 0xa0000003; | |
pub const SYMLINK_FLAG_RELATIVE: DWORD = 0x00000001; | ||
pub const FSCTL_SET_REPARSE_POINT: DWORD = 0x900a4; | ||
|
||
pub const SYMBOLIC_LINK_FLAG_DIRECTORY: DWORD = 0x1; | ||
pub const SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE: DWORD = 0x2; | ||
|
||
// Note that these are not actually HANDLEs, just values to pass to GetStdHandle | ||
pub const STD_INPUT_HANDLE: DWORD = -10i32 as DWORD; | ||
pub const STD_OUTPUT_HANDLE: DWORD = -11i32 as DWORD; | ||
|
@@ -638,6 +635,34 @@ if #[cfg(not(target_vendor = "uwp"))] { | |
pub type PVECTORED_EXCEPTION_HANDLER = extern "system" | ||
fn(ExceptionInfo: *mut EXCEPTION_POINTERS) -> LONG; | ||
|
||
pub const HANDLE_FLAG_INHERIT: DWORD = 0x00000001; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These 4 items simply moved up a little bit in the file because other items moved out. These are still forbidden when targeting UWP, but are available for Games. |
||
|
||
extern "system" { | ||
pub fn SetHandleInformation(hObject: HANDLE, | ||
dwMask: DWORD, | ||
dwFlags: DWORD) -> BOOL; | ||
pub fn AddVectoredExceptionHandler(FirstHandler: ULONG, | ||
VectoredHandler: PVECTORED_EXCEPTION_HANDLER) | ||
-> LPVOID; | ||
pub fn CreateHardLinkW(lpSymlinkFileName: LPCWSTR, | ||
lpTargetFileName: LPCWSTR, | ||
lpSecurityAttributes: LPSECURITY_ATTRIBUTES) | ||
-> BOOL; | ||
} | ||
} | ||
} | ||
|
||
// Functions forbidden when targeting the Games API partition | ||
cfg_if::cfg_if! { | ||
if #[cfg(not(target_vendor = "games"))] { | ||
pub const SYMBOLIC_LINK_FLAG_DIRECTORY: DWORD = 0x1; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to the Windows SDK headers, symbolic links are only supported on desktop apps and drivers (not UWP or games):
The MSDN docs agree (they say So I think these should be also compiled out for |
||
pub const SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE: DWORD = 0x2; | ||
} | ||
} | ||
|
||
// Functions forbidden when targeting UWP or the Games API partition | ||
cfg_if::cfg_if! { | ||
if #[cfg(not(any(target_vendor = "uwp", target_vendor = "games")))] { | ||
#[repr(C)] | ||
#[derive(Copy, Clone)] | ||
pub struct CONSOLE_READCONSOLE_CONTROL { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Console stuff is also unavailable in Games (a little ironic...) |
||
|
@@ -666,8 +691,6 @@ if #[cfg(not(target_vendor = "uwp"))] { | |
pub type LPBY_HANDLE_FILE_INFORMATION = *mut BY_HANDLE_FILE_INFORMATION; | ||
pub type LPCVOID = *const c_void; | ||
|
||
pub const HANDLE_FLAG_INHERIT: DWORD = 0x00000001; | ||
|
||
pub const TOKEN_READ: DWORD = 0x20008; | ||
|
||
extern "system" { | ||
|
@@ -688,33 +711,24 @@ if #[cfg(not(target_vendor = "uwp"))] { | |
|
||
pub fn GetConsoleMode(hConsoleHandle: HANDLE, | ||
lpMode: LPDWORD) -> BOOL; | ||
// Allowed but unused by UWP | ||
// Allowed but unused by UWP and Games | ||
pub fn OpenProcessToken(ProcessHandle: HANDLE, | ||
DesiredAccess: DWORD, | ||
TokenHandle: *mut HANDLE) -> BOOL; | ||
pub fn GetUserProfileDirectoryW(hToken: HANDLE, | ||
lpProfileDir: LPWSTR, | ||
lpcchSize: *mut DWORD) -> BOOL; | ||
// Allowed but unused by Games | ||
pub fn GetFileInformationByHandle(hFile: HANDLE, | ||
lpFileInformation: LPBY_HANDLE_FILE_INFORMATION) | ||
-> BOOL; | ||
pub fn SetHandleInformation(hObject: HANDLE, | ||
dwMask: DWORD, | ||
dwFlags: DWORD) -> BOOL; | ||
pub fn AddVectoredExceptionHandler(FirstHandler: ULONG, | ||
VectoredHandler: PVECTORED_EXCEPTION_HANDLER) | ||
-> LPVOID; | ||
pub fn CreateHardLinkW(lpSymlinkFileName: LPCWSTR, | ||
lpTargetFileName: LPCWSTR, | ||
lpSecurityAttributes: LPSECURITY_ATTRIBUTES) | ||
-> BOOL; | ||
} | ||
} | ||
} | ||
|
||
// UWP specific functions & types | ||
// UWP and Games specific functions & types | ||
cfg_if::cfg_if! { | ||
if #[cfg(target_vendor = "uwp")] { | ||
if #[cfg(any(target_vendor = "uwp", target_vendor = "games"))] { | ||
pub const BCRYPT_USE_SYSTEM_PREFERRED_RNG: DWORD = 0x00000002; | ||
|
||
#[repr(C)] | ||
|
@@ -732,7 +746,7 @@ if #[cfg(target_vendor = "uwp")] { | |
lpFileInformation: LPVOID, | ||
dwBufferSize: DWORD) -> BOOL; | ||
pub fn BCryptGenRandom(hAlgorithm: LPVOID, pBuffer: *mut u8, | ||
cbBuffer: ULONG, dwFlags: ULONG) -> LONG; | ||
cbBuffer: ULONG, dwFlags: ULONG) -> LONG; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure what happened here with whitespace but tidy didn't complain. I can fix on a later commit. |
||
} | ||
} | ||
} | ||
|
@@ -1019,6 +1033,7 @@ extern "system" { | |
compat_fn! { | ||
kernel32: | ||
|
||
#[cfg(not(target_vendor = "games"))] | ||
pub fn CreateSymbolicLinkW(_lpSymlinkFileName: LPCWSTR, | ||
_lpTargetFileName: LPCWSTR, | ||
_dwFlags: DWORD) -> BOOLEAN { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,14 +38,18 @@ pub mod thread; | |
pub mod thread_local; | ||
pub mod time; | ||
cfg_if::cfg_if! { | ||
if #[cfg(not(target_vendor = "uwp"))] { | ||
pub mod stdio; | ||
pub mod stack_overflow; | ||
} else { | ||
if #[cfg(target_vendor = "uwp")] { | ||
pub mod stdio_uwp; | ||
pub mod stack_overflow_uwp; | ||
pub use self::stdio_uwp as stdio; | ||
pub use self::stack_overflow_uwp as stack_overflow; | ||
} else if #[cfg(target_vendor = "games")] { | ||
pub mod stdio_uwp; | ||
pub mod stack_overflow; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Vectored exception handling is available in Games (but not UWP). |
||
pub use self::stdio_uwp as stdio; | ||
} else { | ||
pub mod stdio; | ||
pub mod stack_overflow; | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See second-to-last paragraph under Where to find the Universal CRT files here: https://docs.microsoft.com/en-us/cpp/porting/upgrade-your-code-to-the-universal-crt?view=vs-2019#where-to-find-the-universal-crt-files
For more background on OneCore: https://docs.microsoft.com/en-us/windows/win32/apiindex/windows-umbrella-libraries