Skip to content

Commit d5f6b45

Browse files
Add "Creating a Macro Package" to Usage.md (#6944)
* Add "Creating a Macro Package" to `Usage.md` * Fix documentation link * Add link to The Swift Programming Language book Co-authored-by: Max Desiatov <[email protected]>
1 parent 8e811d7 commit d5f6b45

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

Documentation/Usage.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* [Creating a Package](#creating-a-package)
88
* [Creating a Library Package](#creating-a-library-package)
99
* [Creating an Executable Package](#creating-an-executable-package)
10+
* [Creating a Macro Package](#creating-a-macro-package)
1011
* [Defining Dependencies](#defining-dependencies)
1112
* [Publishing a Package](#publishing-a-package)
1213
* [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
6869
its sources. The complete reference for layout is
6970
[here](PackageDescription.md#target).
7071

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+
7191
## Defining Dependencies
7292

7393
To depend on a package, define the dependency and the version in the manifest of

0 commit comments

Comments
 (0)