Skip to content

Conversation

@lorentey
Copy link
Member

@lorentey lorentey commented Dec 21, 2021

Instead of spelling out availability incantations, contributors can now specify availability annotations using special comments that mention the swift-system version that will introduce the entry point:

/*System 0.0.2*/
public func greeting() -> String {
  "Hello"
}

The new script Utilities/expand-availability.py can then be used to augment these comments with the ABI-stable OS versions that introduced these:

/*System 0.0.2, @available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)*/
public func greeting() -> String {
  "Hello"
}

(The script updates these expansions every time it runs.)

When the script is run with the option --attributes, it instead adds the availability incantation as an actual availability attribute:

/*System 0.0.2*/@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
public func greeting() -> String {
  "Hello"
}

This can be used by package maintainers to generate the ABI stable variant of swift-system that ships in Apple's OS distributions.

The script recognizes all three forms of these annotations and updates them on every run, so we can run the script to enable/disable attributes as needed.

…OS 15

Availability annotations now follow a rigid syntax that mentions the swift-system version that introduced the entry point:

```
/*System 0.0.2, @available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)*/
public func greeting() -> String {
  "Hello"
}
```

This is designed to be processed by automated source generation tools.
By running this script, we can expand comments of the form

```
/*System 0.0.1*/
```

Into either a longer comment that includes the associated OS versions numbers,

```
/*System 0.0.1, @available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *)*/
```

or, when the `--attribute` option is used, into an actual `@available` attribute:

```
/*System 0.0.1*/@available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *)
```

The script can be run repeatedly to switch between these two forms, as needed.
@lorentey
Copy link
Member Author

@swift-ci test

@lorentey lorentey requested a review from milseman December 21, 2021 01:25
Copy link
Contributor

@milseman milseman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

I mean it's kinda crazy you have to do this, but keep doing it!

@lorentey
Copy link
Member Author

@swift-ci test

@lorentey lorentey merged commit 1d5e35a into apple:main Dec 21, 2021
@lorentey lorentey deleted the introduce-availability-macros branch December 21, 2021 21:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants