-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Add support for creating a macro package #6250
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 support for creating a macro package #6250
Conversation
Introduce `swift package init --type macro` to create a new package that defines a macro. It contains: * A macro implementation target * A library that provides the macro declaration for use by clients * A "client" executable that imports the library and uses the macro * A test target for debugging the macro implementation Note that the test target runs into linking issues because the macro implementation target is an executable, not a library. I believe this is a known issue. Tracked by rdar://106468626.
@swift-ci please test |
cc @TimTr @bitjammer |
@swift-ci please smoke test |
macOS failure looks unrelated?
|
yes the macOS self hosted job is defunct due to old Xcode cc @shahmishal |
} else if packageType == .macro { | ||
pkgParams.append(""" | ||
dependencies: [ | ||
.package(url: "https://github.com/apple/swift-syntax.git", branch: "main"), |
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.
We should make sure to have a follow-up task to change this from main
once we have a concrete version that people should be using.
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.
Right. We should get that once we branch for Swift 5.9.
@@ -239,7 +318,8 @@ public final class InitPackage { | |||
// Create a tools version with current version but with patch set to zero. | |||
// We do this to avoid adding unnecessary constraints to patch versions, if | |||
// the package really needs it, they should add it manually. | |||
let version = InitPackage.newPackageToolsVersion.zeroedPatch | |||
let version = packageType == .macro ? ToolsVersion.vNext |
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.
Also something to keep in mind to update later.
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.
Right, we'll update this when the macro
target gets a proper Swift version instead of 999.
case .macro: | ||
content = """ | ||
// The Swift Programming Language | ||
// https://docs.swift.org/swift-book |
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.
Maybe a more concrete reference to macros once we have it?
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.
Yes, makes sense
@swift-ci please smoke test |
… in #6250 The loss of this newline seems to have been unintentional and changed the behaviour from what it was in SwiftPM 5.8. This commit restores it.
Introduce
swift package init --type macro
to create a new package that defines a macro. It contains:Note that the test target runs into linking issues because the macro implementation target is an executable, not a library. I believe this is a known issue.
Tracked by rdar://106468626.