Swift Macros: external macro implementation type could not be found

1.9k views Asked by At

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.

2

There are 2 answers

1
Trumpfi On

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.

1
Archdoog On

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