Skip to content

Commit ebebeab

Browse files
authored
Support macro targets in plugin context (#6484)
This currently prevents the use of plugins in any package graph that happens to include one or more macro targets which seems extremely unfortunate. This fix is slightly ugly because `PackagePlugin` should not concretely know about macros. An alternative could be excluding macros from the project model that plugins see. rdar://108531004 (cherry picked from commit 76744ca)
1 parent 94d42c2 commit ebebeab

File tree

4 files changed

+9
-1
lines changed

4 files changed

+9
-1
lines changed

Sources/PackagePlugin/PackageModel.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,9 @@ public enum ModuleKind {
235235
case snippet
236236
/// A module that contains unit tests.
237237
case test
238+
/// A module that contains code for a macro.
239+
@available(_PackageDescription, introduced: 5.9)
240+
case macro // FIXME: This should really come from `CompilerPluginSupport` somehow, but we lack the infrastructure to allow that currently.
238241
}
239242

240243
/// Represents a target consisting of a source code module compiled using Swift.

Sources/PackagePlugin/PluginContextDeserializer.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,8 @@ fileprivate extension ModuleKind {
261261
self = .snippet
262262
case .test:
263263
self = .test
264+
case .macro:
265+
self = .macro
264266
}
265267
}
266268
}

Sources/PackagePlugin/PluginMessages.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ enum HostToPluginMessage: Codable {
173173
case executable
174174
case snippet
175175
case test
176+
case macro
176177
}
177178

178179
enum BinaryArtifactKind: Codable {

Sources/SPMBuildCore/PluginContextSerializer.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,9 @@ fileprivate extension WireInput.Target.TargetInfo.SourceModuleKind {
278278
self = .snippet
279279
case .test:
280280
self = .test
281-
case .binary, .plugin, .systemModule, .macro:
281+
case .macro:
282+
self = .macro
283+
case .binary, .plugin, .systemModule:
282284
throw StringError("unexpected target kind \(kind) for source module")
283285
}
284286
}

0 commit comments

Comments
 (0)