-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Windows subsystem support #1665
Conversation
cc @retep998 |
I haven't tried to do this myself, but the RFC is implying that it requires special compiler flags. If this is a use case we want to support, then perhaps Cargo should also gain something for it. There might be a similar concern with mac. I'm not sure what the difference between a console app and a nonconsole app is over there, or even what the proper names are. But it might be worth covering them both at the same time and with the same Cargo option. If this is also a concern, designing it to hit both with as few changes as possible could be helpful. Even if we need a separate RFC to finish it. One of the things I want to do with Rust is Windows desktop apps. I had assumed this was trivially possible and that I could just kill the console at any time, but I guess I should have checked. |
Right now you can change the subsystem by passing |
@camlorn AFAIK, there's no equivalent for OSX or linux, all executables are the same there, the only difference between a GUI app and a console app are code differences. |
@Diggsey @retep998 I would personally vote for defaulting such an option to Windows 7, with Vista and XP requiring you to explicitly set it. |
@camlorn Right, but the executable does not need to be linked specially - it is sufficient to simply place it in the correct location in the application bundle. I see this as being a problem for one of the various packaging plugins for cargo to solve. |
Thanks for the PR @Diggsey! I've got a few questions, but mostly along the lines of clarification. Could you provide a detailed explanation of what Also, this would in theory be a breaking change for anyone who explicitly has a Being relatively unfamiliar with this space as well, I wouldn't mind expanding the alternatives a bit more in detail. For example I'm not sure what a Also, how would a |
extern "system" WinMain(_: HINSTANCE, _: HINSTANCE, _: LPSTR, _: c_int) -> c_int {
// call Rust's std::rt entry point
return exit_code;
} None of the arguments matter and can all be obtained via other means.
https://github.com/search?q=WinMain+language%3Arust&type=Code&utf8=%E2%9C%93
Nope, the only thing that matters is choosing the subsystem at link time. Since any non-console app can still be run from within a console, it is up to the application to determine whether stdout/stderr are valid at runtime and redirect logging appropriately. |
@alexcrichton Hopefully these changes address your comments.
No, the aim is for the entire compilation process to be completely identical up until link time. If libraries want to have different code-gen, they should do so via the existing feature or cfg systems. It's not all that different from other linker options such as what icon to use for the produced executable: it greatly simplifies things if it's independent of the compilation process. |
- Emit either `WinMain` or `main` from `libstd` based on `cfg` options. | ||
|
||
This has the advantage of not requiring changes to `rustc`, but is something | ||
of a non-starter since it requires a version of `libstd` for each subsystem. |
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.
To clarify here, the compiler generates a main
symbol as the very last thing when an executable is generated. This main symbol is then wired up to libstd's #[start]
function. In that sense, I don't think that this would require multiple versions of libstd?
Also, are you thinking that this alternative is basically rustc --cfg subsystem=windows foo.rs
or something like that?
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 is considering the hypothetical that the main
symbol generation is moved out of the compiler and into libstd
- libstd would then conditionally export a main
or WinMain
function depending on cfg
options.
I've seen similar approaches in C++ libraries which attempt to abstract over platform differences.
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.
Right now that's not actually possible with the compiler, something like a --cfg
flag can't conditionally export different symbols when we're shipping a precompiled artifact, so maybe that's why I'm finding this confusing? Are you assuming here that we're compiling std from source on demand or something like that?
One major difference is that console programs need to use |
@DemiMarie It's trivial to figure out whether the handle you get via |
Naive question: why does passing |
@CryZe That problem is probably due to the fact that you have the console subsystem. One has to pass the |
@tomaka It doesn't, either something is exporting |
All the startup information like |
I've removed some of the "hypothetical" alternatives at @alexcrichton's suggestion, and I've fleshed out a possible design for the "command-line configurable" alternative. I initially went with the "dual symbol" solution as the main proposal because I thought it would be a quick way to get this support into rustc, with room for later improvement. That may still be the case, but if there's no objection to the specific design I went with for the alternative, it may be better to jump straight to that. The main problem I see is that it adds extra command-line surface for everyone, but it's only going to be relevant when targeting windows, and I can imagine there may be some objection to that. |
@tomaka Ah, you may have been using the GNU toolchain. This is more of a problem for MSVC. I've updated the RFC accordingly. |
@Diggsey The |
The duplicate symbol solution which this RFC proposes does not affect linker flags at all, and the version numbers specified for the subsystem do not affect which entry point is used, so I don't think there's any overlap at all there. The alternative which adds a subsystem config to rustc and cargo does have some overlap: as proposed, rustc would not understand a version number, and so would not pass it through to the linker, but it would still be possible to manually pass in the option as we do now. I don't believe it restricts us in future: we could backwards compatibly extend the set of possible values for |
并没有理解如何隐藏后台窗体。 |
Help!How can I hide the DOS form? |
@3442853561 This repository is for RFCs, proposals for the Rust programmer language. This is not the right place to ask questions. Secondly, your question is vague and cannot be answer as is. Please be specific, and ask it at either https://reddit.com/r/rust or https://stackoverflow.com. |
This wouldn't involve libstd support, but for the benefit of applications using libcore, could this support the "NATIVE" subsystem as well? |
@joshtriplett the |
@retep998 I wasn't suggesting that the RFC needed to define how that would work. I just wondered if a Rust crate producing a Windows driver could use this mechanism to declare the correct target subsystem, assuming it doesn't use std and otherwise meets the assumptions of a Windows driver, or if such a crate would still have to use linker options directly. |
@joshtriplett At the moment this RFC doesn't specify any subsystems other than windows or console. To make a driver you have to pass other linker args anyway such as |
@rfcbot fcp merge Discussion I think has reached a close at this point on the RFC, and having discussed it in a tools team meeting I believe our concerns are addressed as well. I propose we merge! |
Team member alexcrichton has proposed to merge this. The next step is review by the rest of the tagged teams: No concerns currently listed. See this document for info about what commands tagged team members can give me. |
@rfcbot reviewed |
1 similar comment
@rfcbot reviewed |
🔔 This RFC is now entering its week-long final comment period for merging 🔔 |
All relevant subteam members have reviewed. No concerns remain. |
The final comment period is now complete. |
Ok, looks like nothing new came up during FCP, so merging! Thanks again for the RFC @Diggsey! Tracking issue: rust-lang/rust#37499 |
I find it strange that What would be the next steps to address such an issue? Issue in the https://github.com/rust-lang/rust repository? |
@pravic Panic behavior is probably better handled with custom panic hooks. |
Rendered
[mbrubeck: edited to link to final rendered version]