Skip to content

Windows version number support for the @available attribute #73655

Open
@tristanlabelle

Description

@tristanlabelle

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrontendArea → compiler: FrontendWindowsPlatform: WindowsavailabilityThe @available attribute and availability checking in generalcompilerThe Swift compiler itselffeatureA feature request or implementation

    Type

    No type

    Projects

    Status

    TODO

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions