Macros: Xcode 15 and SwiftPM difference of opinions

I have published a library for third parties to use that includes some macros.

My users are struggling to use it because there are two different sets of results between Xcode and SwiftPM.

The sample here:

The above will compile and run if you use "swift build", but if you open that package with Xcode, and try to build it, you will get instead this error:

error: Swift package target 'SwiftGodot' is linked as a static library by 'a' and 'SwiftGodot', but cannot be built dynamically because there is a package product with the same name.

The fix for Xcode is to replace the dependencies line from this:

dependencies: ["SwiftGodot", .product (name: "SwiftGodotMacros", package: "SwiftGodot")],

to this:

dependencies: ["SwiftGodot"],

But if you do this, then SwiftPM produces the following error:

Sources/a/a.swift:8:7: error: external macro implementation type 'SwiftGodotMacroLibrary.GodotMacro' could not be found for macro 'Godot()'
Sources/SwiftGodotMacros/MacroDefs.swift:20:14: note: 'Godot()' declared here
public macro Godot() = #externalMacro(module: "SwiftGodotMacroLibrary", type: "GodotMacro")


I think you were able to solve this in Move macro definitions into SwiftGodot target by tishin · Pull Request #150 · migueldeicaza/SwiftGodot · GitHub, is that correct?

I'm experiencing a similar problem, where Xcode fails to compile yet SPM CLI works fine.

This issue was amongst others that I discussed with an Apple Engineer via a DTS incident and I was asked to file bug report, which I have done under FB13597963.

I included an extremely minimal package setup that triggers the problem, so fingers crossed :crossed_fingers:t2:

1 Like