Skip to content

Commit 0416eef

Browse files
authored
Add info about macro entry point
When trying to add a macro to an existing project, I ran into some inscrutable errors without the macro entry point type. This type is added when you create a new macro project, but I didn't find any documentation about this requirement elsewhere.
1 parent 40dee84 commit 0416eef

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

TSPL.docc/LanguageGuide/Macros.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,19 @@ private func fourCharacterCode(for characters: String) -> UInt32? {
552552
enum CustomError: Error { case message(String) }
553553
```
554554

555+
If you're adding this macro to an existing Swift Package Manager project,
556+
add a type that acts as the entry point for the macro target
557+
and lists the macros that the target defines:
558+
559+
```swift
560+
import SwiftCompilerPlugin
561+
562+
@main
563+
struct MyProjectMacros: CompilerPlugin {
564+
var providingMacros: [Macro.Type] = [FourCharacterCode.self]
565+
}
566+
```
567+
555568
The `#fourCharacterCode` macro
556569
is a freestanding macro that produces an expression,
557570
so the `FourCharacterCode` type that implements it

0 commit comments

Comments
 (0)