-
Notifications
You must be signed in to change notification settings - Fork 439
Add a version indicator macro to indicate the swift-syntax version a client is building against #2050
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
Add a version indicator macro to indicate the swift-syntax version a client is building against #2050
Conversation
|
||
## Detailed Explanation | ||
|
||
All the ideas described in the following apply to all packages that depend on swift-syntax, not only macros. | ||
|
||
For simplicity, this article assumes that `509` is the current swift-syntax version and `510` the next, but everything applies to any other major swift-syntax version update, including version jumps to `600`. | ||
For simplicity, this article assumes that 509 is the current swift-syntax version and `510` the next, but everything applies to any other major swift-syntax version update, including version jumps to e.g. 600. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inconsistent with wrapping version in `` and not. I think it's just the one 510
that is wrapped now.
|
||
Any client package that depends on the macro using an `from: "1.0"` and doesn’t have any other transitive dependencies on swift-syntax will automatically receive version `1.3` of the macro when updating the package dependencies using `swift package update` or Xcode’s *Update to Latest Package Versions* command. | ||
Since swift-syntax 510 might have introduced source-breaking changes. If the macro uses any of the APIs that have changes it needs to use conditional compilation clauses that check the version of swift-syntax it is building against. For that purpose, swift-syntax contains marker modules. All versions of swift-syntax ≥ 509 include a `SwiftSyntax509` module. Similarly, swift-syntax ≥ 510 includes a `SwiftSyntax510` and `SwiftSyntax509` module. This allows clients to write |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since swift-syntax 510 might have introduced source-breaking changes. If the macro uses any of the APIs that have changes it needs to use conditional compilation clauses that check the version of swift-syntax it is building against. For that purpose, swift-syntax contains marker modules. All versions of swift-syntax ≥ 509 include a `SwiftSyntax509` module. Similarly, swift-syntax ≥ 510 includes a `SwiftSyntax510` and `SwiftSyntax509` module. This allows clients to write | |
In order to handle breaking API changes, clients can wrap uses of such APIs in conditional compilation clauses that check the version of swift-syntax it is building against. Empty version modules will be used to allow such a check. All versions of swift-syntax ≥ 509 will include an empty `SwiftSyntaxVersion509` module, swift-syntax ≥ 510 will include both a `SwiftSyntaxVersion510` and `SwiftSyntaxVersion509` module, and so on for any new releases. This allows clients to write |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed the Empty version modules will be used to allow such a check
from your suggestion and added the following at the end instead:
The `SwiftSyntax<version>` modules are empty and don’t contain any code. Their only purpose is to serve as targets for the `canImport` checks.
78209c1
to
38f9b2b
Compare
@swift-ci Please test |
|
||
When starting to write a macro, no special considerations need to be made with regard to versioning. Depending on swift-syntax as with `from: "509.0.0"` will make sure that the macro receives any bug fix updates to swift-syntax 509. For example, a macro depending on swift-syntax 509 might be released as version 1.0, 1.2, 2.0, … | ||
Any given version macro can depend on multiple major swift-syntax versions at once. For example, if a macro supports both swift-syntax 509 and swift-syntax 510 may declare its dependency on swift-syntax as |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any given version macro can depend on multiple major swift-syntax versions at once. For example, if a macro supports both swift-syntax 509 and swift-syntax 510 may declare its dependency on swift-syntax as | |
Any given version macro can depend on multiple major swift-syntax versions at once. For example, if a macro supports both swift-syntax 509 and swift-syntax 510, it may declare its dependency on swift-syntax as |
…client is building against All swift-syntax versions ≥ 509 will include a module `SwiftSyntax509` and all swift-syntax versions ≥ 510 will include both `SwiftSyntax509` and `SwiftSyntax510`. This way clients can check which version of swift-syntax they are building against using e.g. ```swift #if canImport(SwiftSyntax510) // code specific to swift-syntax version >= 510 #else // code for swift-syntax < 510 #endif ```
38f9b2b
to
002bbbd
Compare
@swift-ci Please test |
@swift-ci Please test Windows |
All swift-syntax versions ≥ 509 will include a module
SwiftSyntax509
and all swift-syntax versions ≥ 510 will include bothSwiftSyntax509
andSwiftSyntax510
. This way clients can check which version of swift-syntax they are building against using e.g.