-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Add UWP MSVC targets #63155
Conversation
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @zackmdavis (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
// FIXME: this shouldn't be panic=abort, it should be panic=unwind | ||
base.panic_strategy = PanicStrategy::Abort; | ||
|
||
let lib_root_path = env::var("VCToolsInstallDir") |
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.
Note that we already have a good deal of support for this via the cc::windows_registry
probing that we do in the backend. I think it'd be best to do this there instead of here to not require that the VCToolsInstallDir
env var is set. Current MSVC targets don't set this env var and I think that with the probing logic we have you should be able to find the root path anyway?
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.
Done
src/librustc_target/Cargo.toml
Outdated
@@ -11,6 +11,7 @@ path = "lib.rs" | |||
[dependencies] | |||
bitflags = "1.0" | |||
log = "0.4" | |||
cc = "1.0.1" |
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.
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)
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.
Sorry I'm still not clear on what to do.
You want me to patch cc-rs or librustc_codegen_ssa or both?
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.
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.
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.
Code is not pretty... but it seems to work. Let me know what you think
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
base.max_atomic_width = Some(64); | ||
base.has_elf_tls = true; | ||
|
||
// 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 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?
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.
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.
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
@@ -1027,6 +1027,20 @@ 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)); | |||
|
|||
if t.linker_flavor == LinkerFlavor::Msvc && t.target_vendor == "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.
Can this happen inside get_linker
where we're already executing find_tool
?
|
||
if t.linker_flavor == LinkerFlavor::Msvc && t.target_vendor == "uwp" { | ||
let link_tool = windows_registry::find_tool("x86_64-pc-windows-msvc", "link.exe") | ||
.expect("no path found for link.exe"); |
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 should report errors as first-class errors instead of panics, but for this case I think that all errors should be swallowed and this logic ignored. This could perhaps warn!
on errors but it's probably not worthwhile to halt compilation if this fails.
.expect("no path found for link.exe"); | ||
|
||
let original_path = link_tool.path(); | ||
let root_lib_path = original_path.ancestors().skip(4).next().unwrap(); |
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.
Like above this'll want to have error handling to avoid the unwrap
base.max_atomic_width = Some(64); | ||
base.has_elf_tls = true; | ||
|
||
// 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 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.
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.
Looking good to me, thanks!
@@ -158,6 +159,33 @@ pub fn get_linker(sess: &Session, linker: &Path, flavor: LinkerFlavor) -> (PathB | |||
} | |||
}; | |||
|
|||
let t = &sess.target.target; | |||
if t.linker_flavor == LinkerFlavor::Msvc && t.target_vendor == "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.
This should read the flavor
local variable instead of looking this up again
@bors: r+ |
📌 Commit 1581c43 has been approved by |
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.
⌛ Testing commit 1581c43 with merge d321c2ffd8513b4084e3fa20d2c19931985dc450... |
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.
@bors retry rolled up. |
⌛ Testing commit 1581c43 with merge 3f1dd30b59a482e205175bae45d411643bd226b8... |
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.
@bors retry rolled up. |
Rollup of 9 pull requests Successful merges: - #63155 (Add UWP MSVC targets) - #63165 (Add builtin targets for mips64(el)-unknown-linux-muslabi64) - #63306 (Adapt AddRetag for shallow retagging) - #63467 (Add Catalyst (iOS apps running on macOS) target) - #63546 (Remove uses of `mem::uninitialized()` from cloudabi) - #63572 (remove unused Level::PhaseFatal) - #63577 (Test HRTB issue accepted by compiler) - #63582 (Fix ICE #63226) - #63586 (cleanup: Remove `Spanned` where possible) Failed merges: r? @ghost
Woo! Thanks for the work to enable this target, and the work to review it everyone! |
…excrichton Fix dynamic linking for Windows UWP MSVC targets When creating a dynamic library, the MSVC linker generates an import library (.lib) next to the .dll file. Cargo has explicit knowledge of this and includes those generated .dll.lib on the list of files generated by a Cargo invocation. However, the check to see if those import libraries must be included is too strict and doesn't match any Windows targets that don't end in `pc-windows-msvc`. For example, rust-lang/rust#63155 added several new Windows targets for targeting UWP called `*-uwp-windows-msvc`. The end result is that the sysroot for these UWP toolchains don't contain a `std-XXX.dll.lib` file and thus any executable that uses `-C prefer-dynamic` will fail to link because the `std` library is not linked at all. This change relaxes the test and makes Cargo know about those import libraries for all Windows MSVC targets.
Hi,