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

Windows version number support for the @available attribute #73655

Open
tristanlabelle opened this issue May 15, 2024 · 0 comments
Open

Windows version number support for the @available attribute #73655

tristanlabelle opened this issue May 15, 2024 · 0 comments
Labels
availability The @available attribute and availability checking in general compiler The Swift compiler in itself feature A feature request or implementation Frontend Area → compiler: Frontend Windows Platform: Windows

Comments

@tristanlabelle
Copy link
Contributor

Motivation

The @available enables warnings and deprecation of functionality based on OS version. This is currently not implemented on Windows:

@available(Windows, introduced: 10.0.17763)
func foo() {}

foo()
main.swift:4:1: error: 'foo()' is only available in * 10.0.17763 or newer
2 │ func foo() {}
3 │
4 │ foo()
  │ ├─ error: 'foo()' is only available in * 10.0.17763 or newer
  │ ╰─ note: add 'if #available' version check

(I am building against a version of windows greater than this number. The issue also happens when specifying version 1.0.0 or any other value)

Proposed solution

Windows has well defined version numbers of the form 10.0.<buildnumber> as described on Wikipedia: https://en.wikipedia.org/wiki/Windows_10_version_history . This scheme also supports version numbers prior and subsequent to Windows 10.

On Windows, @available should test whether the Windows version we're building for is greater or equal to the specified version number. As a first approximation, this could use the version number of the Windows SDK we're building for (-windows-sdk-version), but ideally we could also specify a target version number separately. The if #available syntax should also be supported on Windows.

Alternatives considered

As a workaround, it's possible to do runtime checks.

Additional information

No response

@tristanlabelle tristanlabelle added feature A feature request or implementation triage needed This issue needs more specific labels labels May 15, 2024
@compnerd compnerd added Windows Platform: Windows availability The @available attribute and availability checking in general Frontend Area → compiler: Frontend and removed triage needed This issue needs more specific labels labels May 16, 2024
@AnthonyLatsis AnthonyLatsis added the compiler The Swift compiler in itself label May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
availability The @available attribute and availability checking in general compiler The Swift compiler in itself feature A feature request or implementation Frontend Area → compiler: Frontend Windows Platform: Windows
Projects
None yet
Development

No branches or pull requests

3 participants