Reputation: 7902
I'm using MetaCodable macro in my project, installed via SwiftPM, when I try to build the project using Microsoft Azure's Pipeline using my local machine as a run agent (MBP M1 Max - Sonoma - XCode 15), I get this error message:
error: external macro implementation type 'CodableMacroPlugin.CodedAt' could not be found for macro 'CodedAt'
Some folks here suggest to add -external-plugin-path
to other Swift flags
in build settings, but that doesn't solve the issue.
And in this thread some also suggests to add -load-plugin-library
, or -plugin-path
, or -load-plugin-executable
to other Swift flags
, I tried every option of these using the value: $(BUILT_PRODUCTS_DIR)#MetaCodable
but I got the same error with every CI build.
I also get this warning in the Azure's Pipeline build log:
"output": "<unknown>:0: warning: compiler plugin not loaded: '/Users/my_user_name/Library/Developer/Xcode/DerivedData/MyProject/Build/Products/Release/CodableMacroPlugin; failed to initialize /Users/my_user_name/vsts-agent-osx-x64-2.183.1/_work/9/MyProject/Data/Models/SomeModel.swift
Any thoughts about this are appreciated.
Upvotes: 9
Views: 5660
Reputation: 1651
I ran into this issue while using a Macro I had built into a local SPM package, which I was making use of inside of other local SPM packages. For my app, I use multiple build configurations to control environment (Dev
, QA
, Prod
) which leverage custom names, different from the default Debug
and Release
(Debug-Dev
, Debug-QA
, Debug-Prod
, Release-Dev
, Release-QA
, Release-Prod
)
It appears that Xcode encounters issues with these custom named configurations when expanding Macros used inside of SPM targets as SPM does not know about these custom names, only Debug
and Release
. I discovered this by opening the Package.swift
file as a workspace and building there to realize that I was able to expand when working exclusively with SPM.
I resolved this by splitting my environments into different app targets (one for Dev
, QA
, Prod
), with each now making use of the default Debug
and Release
configurations. This allows me to have each target depend on those local SPM packages and fixed the expansion issues I was having.
It did, however, come with the tradeoff of now needing to attribute Compile Sources to multiple targets instead of one, and necessitated the use of XCConfig files to more easily align build settings across the 3 targets. This is hopefully just an Xcode bug (I'm currently on 16.2) that they will maybe resolve eventually, but I've seen enough other issues in the past with custom named configurations to accept the tradeoffs of moving off of them entirely.
If you're looking for a quicker way to confirm whether or not this change would fix your issue, simply rename your custom named configuration to Debug in project settings and select it in your Scheme. Build the app, then attempt to expand macro again, and you should see that it is now able to if this fix applies to your situation. Hope it helps someone!
Upvotes: 2
Reputation: 890
If your project works fine in Xcode, but you're seeing this issue only from an xcodebuild
command or other CI pipeline tool. This can be caused by the -sdk
flag you've specified (e.g. -sdk iphonesimulator
).
Simply REMOVE:
-sdk iphonesimulator
From your xcodebuild
command
Upvotes: 6
Reputation: 41
I had the same issue and after hours found the solution on my side.
For our library we had to define a macOS support version besides iOS for SwiftSyntaxMacros. Locally we used MacOS 14 and set it to 14. On the Server we were running 13.X. We did not get a error for the MacOS support version only "error: external macro implementation type 'foo' could not be found for macro 'foo'".
After setting it to MacOS 12 the issue was gone:
platforms: [.macOS(.v12), .iOS(.v15)],
I hope this is useful for you. Online I found no solutions for this issue.
Upvotes: 4