Skip to content

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

Merged
merged 2 commits into from
Mar 9, 2023

Conversation

DougGregor
Copy link
Member

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.

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.
@DougGregor
Copy link
Member Author

@swift-ci please test

@tomerd
Copy link
Contributor

tomerd commented Mar 9, 2023

cc @TimTr @bitjammer

@DougGregor
Copy link
Member Author

@swift-ci please smoke test

@DougGregor
Copy link
Member Author

macOS failure looks unrelated?

/Users/ec2-user/jenkins/workspace/swift-package-manager-with-xcode-self-hosted-PR-osx/branch-main/swiftpm: error: package at '/Users/ec2-user/jenkins/workspace/swift-package-manager-with-xcode-self-hosted-PR-osx/branch-main/swiftpm' is using Swift tools version 5.7.0 but the installed version is 5.5.0

@tomerd
Copy link
Contributor

tomerd commented Mar 9, 2023

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"),
Copy link
Contributor

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.

Copy link
Member Author

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
Copy link
Contributor

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.

Copy link
Member Author

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
Copy link
Contributor

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?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, makes sense

@DougGregor
Copy link
Member Author

@swift-ci please smoke test

@DougGregor DougGregor merged commit bbc5538 into swiftlang:main Mar 9, 2023
@DougGregor DougGregor deleted the swift-package-init-type-macro branch March 9, 2023 23:32
@DougGregor DougGregor restored the swift-package-init-type-macro branch March 9, 2023 23:32
@DougGregor DougGregor deleted the swift-package-init-type-macro branch March 9, 2023 23:32
abertelrud added a commit that referenced this pull request Mar 27, 2023
… 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.
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.

3 participants