|
7 | 7 | * [Creating a Package](#creating-a-package)
|
8 | 8 | * [Creating a Library Package](#creating-a-library-package)
|
9 | 9 | * [Creating an Executable Package](#creating-an-executable-package)
|
| 10 | + * [Creating a Macro Package](#creating-a-macro-package) |
10 | 11 | * [Defining Dependencies](#defining-dependencies)
|
11 | 12 | * [Publishing a Package](#publishing-a-package)
|
12 | 13 | * [Requiring System Libraries](#requiring-system-libraries)
|
@@ -68,6 +69,25 @@ can be turned into a executable target if there is a `main.swift` file present i
|
68 | 69 | its sources. The complete reference for layout is
|
69 | 70 | [here](PackageDescription.md#target).
|
70 | 71 |
|
| 72 | +### Creating a Macro Package |
| 73 | + |
| 74 | +SwiftPM can generate boilerplate for custom macros: |
| 75 | + |
| 76 | + $ mkdir MyMacro |
| 77 | + $ cd MyMacro |
| 78 | + $ swift package init --type macro |
| 79 | + $ swift build |
| 80 | + $ swift run |
| 81 | + The value 42 was produced by the code "a + b" |
| 82 | + |
| 83 | +This creates a package with a `.macro` type target with its required dependencies |
| 84 | +on [swift-syntax](https://github.com/apple/swift-syntax), a library `.target` |
| 85 | +containing the macro's code, and an `.executableTarget` and `.testTarget` for |
| 86 | +running the macro. The sample macro, `StringifyMacro`, is documented in the Swift |
| 87 | +Evolution proposal for [Expression Macros](https://github.com/apple/swift-evolution/blob/main/proposals/0382-expression-macros.md) |
| 88 | +and the WWDC [Write Swift macros](https://developer.apple.com/videos/play/wwdc2023/10166) |
| 89 | +video. See further documentation on macros in [The Swift Programming Language](https://docs.swift.org/swift-book/documentation/the-swift-programming-language/macros/) book. |
| 90 | + |
71 | 91 | ## Defining Dependencies
|
72 | 92 |
|
73 | 93 | To depend on a package, define the dependency and the version in the manifest of
|
|
0 commit comments