-
Notifications
You must be signed in to change notification settings - Fork 13k
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 support for UWP targets #60260
Merged
+529
−117
Merged
Add support for UWP targets #60260
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
5af318b
rustc: codegen: Build import library for all windows targets
chouquette e34bcdb
libstd: windows: compat: Allow use of attributes
chouquette ce315cd
bootstrap: Build startup object for all windows-gnu target
chouquette 3becaf4
std: Link UWP with allowed libraries only
chouquette 642f8cd
libunwind: Use libunwind when targeting UWP
chouquette 9407ed7
std: rand: Use BCrypt on UWP
chouquette a713a03
std: win: Don't use SetHandleInformation on UWP
chouquette ef26728
std: win: Don't expose link() on UWP
chouquette a24be59
std: win: Don't use GetUserProfileDirectoryW on UWP
chouquette 4c05073
std: win: Don't use GetFileInformationByHandle on UWP
chouquette 668f0d3
std: win: Don't use console APIs on UWP
chouquette e88a4ce
std: win: Disable stack overflow handling on UWP
chouquette 7ed5c36
Add UWP mingw targets
chouquette File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
use crate::spec::{LinkerFlavor, Target, TargetResult}; | ||
|
||
pub fn target() -> TargetResult { | ||
let mut base = super::windows_uwp_base::opts(); | ||
base.cpu = "pentium4".to_string(); | ||
base.max_atomic_width = Some(64); | ||
base.eliminate_frame_pointer = false; // Required for backtraces | ||
|
||
// 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::Gcc).unwrap().push("-Wl,--large-address-aware".to_string()); | ||
|
||
Ok(Target { | ||
llvm_target: "i686-pc-windows-gnu".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: "gnu".to_string(), | ||
target_vendor: "uwp".to_string(), | ||
linker_flavor: LinkerFlavor::Gcc, | ||
options: base, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
use crate::spec::{LinkArgs, LinkerFlavor, TargetOptions}; | ||
use std::default::Default; | ||
|
||
pub fn opts() -> TargetOptions { | ||
let mut pre_link_args = LinkArgs::new(); | ||
pre_link_args.insert(LinkerFlavor::Gcc, vec![ | ||
// Tell GCC to avoid linker plugins, because we are not bundling | ||
// them with Windows installer, and Rust does its own LTO anyways. | ||
"-fno-use-linker-plugin".to_string(), | ||
|
||
// Always enable DEP (NX bit) when it is available | ||
"-Wl,--nxcompat".to_string(), | ||
]); | ||
|
||
let mut late_link_args = LinkArgs::new(); | ||
late_link_args.insert(LinkerFlavor::Gcc, vec![ | ||
//"-lwinstorecompat".to_string(), | ||
//"-lmingwex".to_string(), | ||
//"-lwinstorecompat".to_string(), | ||
"-lwinstorecompat".to_string(), | ||
"-lruntimeobject".to_string(), | ||
"-lsynchronization".to_string(), | ||
"-lvcruntime140_app".to_string(), | ||
"-lucrt".to_string(), | ||
"-lwindowsapp".to_string(), | ||
"-lmingwex".to_string(), | ||
"-lmingw32".to_string(), | ||
]); | ||
|
||
TargetOptions { | ||
// FIXME(#13846) this should be enabled for windows | ||
function_sections: false, | ||
linker: Some("gcc".to_string()), | ||
dynamic_linking: true, | ||
executables: false, | ||
dll_prefix: String::new(), | ||
dll_suffix: ".dll".to_string(), | ||
exe_suffix: ".exe".to_string(), | ||
staticlib_prefix: "lib".to_string(), | ||
staticlib_suffix: ".a".to_string(), | ||
no_default_libraries: true, | ||
target_family: Some("windows".to_string()), | ||
is_like_windows: true, | ||
allows_weak_linkage: false, | ||
pre_link_args, | ||
pre_link_objects_exe: vec![ | ||
"rsbegin.o".to_string(), // Rust compiler runtime initialization, see rsbegin.rs | ||
], | ||
pre_link_objects_dll: vec![ | ||
"rsbegin.o".to_string(), | ||
], | ||
late_link_args, | ||
post_link_objects: vec![ | ||
"rsend.o".to_string(), | ||
], | ||
custom_unwind_resume: true, | ||
abi_return_struct_as_int: true, | ||
emit_debug_gdb_scripts: false, | ||
requires_uwtable: true, | ||
limit_rdylib_exports: false, | ||
|
||
.. Default::default() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use crate::spec::{LinkerFlavor, Target, TargetResult}; | ||
|
||
pub fn target() -> TargetResult { | ||
let mut base = super::windows_uwp_base::opts(); | ||
base.cpu = "x86-64".to_string(); | ||
base.pre_link_args.get_mut(&LinkerFlavor::Gcc).unwrap().push("-m64".to_string()); | ||
base.max_atomic_width = Some(64); | ||
|
||
Ok(Target { | ||
llvm_target: "x86_64-pc-windows-gnu".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: "gnu".to_string(), | ||
target_vendor: "uwp".to_string(), | ||
linker_flavor: LinkerFlavor::Gcc, | ||
options: base, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This looks like it's generating a file called
libfoo.a
, but is it intended that this is generatinglibfoo.dll.a
?Also does this already happen on the existing MinGW target implicitly without this argument being generated? Or otherwise?
If it's not already happening on MinGW, can this be gated to only happen for UWP?
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.
It kind of happens implicitly with GCC/mingw as it can link directly with a DLL, while Clang can't
To be fair I'm not sure how the GNU linker handles it. My understanding is that MSVC doesn't support directly linking to a DLL and requires an import library, and clang is aiming at a feature parity with MSVC more than GCC when it comes to building for Windows.
Though that really is my sole understanding only.
In any case, it already works as is with GCC, but it also works with the implib being explicitly generated. If you prefer so, I can gate it for UWP.
Regarding the naming convention, I can definitely make it more like
libfoo.dll.a
, I'm not sure there's a clear and definite convention, all the import libraries from mingw are in the form libfoo.a to link with foo.dll, I think MSVC aims at foo.lib, and I've indeed seen some .dll.aThere 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.
I think it's probably best to just go ahead and align with what MSVC is doing. I don't really understand why the MinGW UWP toolchain uses LLVM and departs from MinGW idioms, or why a MSVC-based UWP toolchain doesn't work, but we may as well try to keep things at least a little consistent on Windows as we can try...
And yes I think this block should be UWP specific because it's not needed on the MinGW toolchain.
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.
According to #29520 we emit
foo.dll.lib
as the import library for-msvc
so to emitlibfoo.dll.a
for-gnu
makes perfect sense for me. While MinGW is odd in that it can to some extent link to dlls without an import library, I'm in favor of always emitting import libraries on Windows regardless of the toolchain.