Skip to content
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

Closed
briansmith opened this issue Nov 7, 2016 · 11 comments
Closed

Need a way to detect Windows XP support in build.rs script #37638

briansmith opened this issue Nov 7, 2016 · 11 comments
Labels
C-feature-request Category: A feature request, i.e: not implemented / a PR. O-windows Operating system: Windows

Comments

@briansmith
Copy link
Contributor

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 on std::fs to read from /dev/urandom. Similar considerations apply to some Mac OS X APIs.

@TimNN
Copy link
Contributor

TimNN commented Nov 7, 2016

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.

@briansmith
Copy link
Contributor Author

That will detect whether the host is running on Windows XP, but I need to know whether Windows XP is being targetted.

@TimNN
Copy link
Contributor

TimNN commented Nov 7, 2016

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.

@alexcrichton
Copy link
Member

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:

  • A Cargo crate feature
  • An environment variable
  • Perhaps we can expose this through cfg(target-feature) like we did for static CRT libs.

@retep998
Copy link
Member

retep998 commented Nov 8, 2016

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.

@briansmith
Copy link
Contributor Author

There are two issues: #37553 is the issue about specifying the target version (IIUC), and this issue (#37638) is about being able to detect the target version in a build.rs.

@retep998
Copy link
Member

retep998 commented Nov 9, 2016

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.

@sanxiyn sanxiyn added the O-windows Operating system: Windows label Nov 15, 2016
@lygstate
Copy link
Contributor

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.

@Mark-Simulacrum Mark-Simulacrum added the C-feature-request Category: A feature request, i.e: not implemented / a PR. label Jul 26, 2017
@steveklabnik
Copy link
Member

Triage: we barely support XP at all anymore, I doubt this will be implemented.

@retep998
Copy link
Member

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.

@briansmith
Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature-request Category: A feature request, i.e: not implemented / a PR. O-windows Operating system: Windows
Projects
None yet
Development

No branches or pull requests

8 participants