-
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
Need a way to detect Windows XP support in build.rs script #37638
Comments
It should already be easily possible to do that: #[cfg(windows)]
fn get_windows_version() -> u32 {
extern crate kernel32;
kernel32::GetVersion() as u32 // probably want to parse that instead
}
#[cfg(not(windows))]
fn get_windows_version() -> u32 {
panic!();
} Edit: And apart from that, this issue should probably be filed agains rust-lang/cargo. |
That will detect whether the host is running on Windows XP, but I need to know whether Windows XP is being targetted. |
Ah, thanks for the clarification! I think in that case you could use cargo feature flags? This would require the user to explicitly request Windows XP support, however I don't know how you would otherwise detect if Windows XP is being targeted. |
We unfortunately don't even really have a way of telling the compiler that you'd like to target XP today. The tests performed in the past were always done with a "pass this random linker arg at the last step". That's far from being an "official" mechanism for targeting XP, and Cargo much less the compiler don't really know what's going on. In the absence of any form of convention here I'd recommend either one of or a combination of:
|
Well, whatever solution we end up choosing, it needs to do more than just support XP. It needs to be able to choose any arbitrary version of Windows as the minimum version. |
Ideally we'd have some sort of unified system so someone just specifies their desired version of Windows once and Rust will figure out the correct subsystem and build scripts will be informed as well. |
I think we can do it in the easy we, we only need to setting the subsystem's version to be 5.01, then windows XP would be supported. |
Triage: we barely support XP at all anymore, I doubt this will be implemented. |
The need for a way to specify the minimum version of the OS that is being targeted is still useful in general, and will remain so even as XP fades out of existence. |
I'm going to close this because, although we do need a general mechanism for determining the minimum operating system version to support, that's quite different than what this issue was about. |
Let's add a way to detect whether Windows XP is being targetted in -msvc builds.
According to https://doc.rust-lang.org/book/getting-started.html#tier-3, The target name for Windows-XP-compatible MSVC targets is the same as for non-Windows-XP-compatible targets.
In particular, when building C code it is necessary to use a different "XP compatible" toolchain with MSVC when XP support is required. However, that toolchain is optional and some developers do not have it installed. Currently we have to choose between breaking XP compatibility unnecessarily and having the build be broken when the XP-compatible toolchain isn't installed. If the build.rs script could detect whether or not XP compatibility was being requested, then it could default to the standard toolchain and then switch to the XP-compatible toolchain only when XP compatibility is specifically requested.
Generalizing this idea, it would be useful to know the minimum version of Windows being targetted in the build. There are various features that only work on Windows 8 or later or Windows 10 or later. If we know that the developer is targetting only later versions of Windows then we can sometimes enable additional functionality and/or we can drop shims to support older versions.
Generalizing this idea even further, this also applies to the Linux kernel. For example, if we know that Linux 3.17 or later is being targetted then we can always rely on the
getrandom
syscall being available and avoid needing dependencies onstd::fs
to read from/dev/urandom
. Similar considerations apply to some Mac OS X APIs.The text was updated successfully, but these errors were encountered: