Macro plugins suffering from module name collisions

i suppose it is natural if a project does not have too many macros, to have one plugin target, likely named _Macros, that contains the various macro implementations.

.macro(name: "_Macros",
        .product(name: "SwiftCompilerPlugin", package: "swift-syntax"),
        .product(name: "SwiftSyntaxMacros", package: "swift-syntax"),
    path: "Sources/Macros"),

and you might consider the macro declaration targets to be normal “libraries” with carefully-chosen names, but not the macro implementations target itself.

and this model will work just fine until someone has the same idea and also writes a macro with an implementation named _Macros, and then you wind up with:

error: multiple targets named '_Macros' in: 'swift-macro-test-a', 'swift-macro-test-b'; consider using the `moduleAliases` parameter in manifest to provide unique names

but the macro plugins are supposed to be package-local. why do they even experience name collisions in the first place?

1 Like