How to import macros using methods other than SwiftPM

I'm struggling for 2 days to solve a build error in Microsoft Azure's CI using my local machine (MBP M1 Max, Xcode 15) as a run agent for my project that uses MetaCodable macro after adding it as a Swift package, it builds locally without problems, but in the CI I got the error: "External macro implementation couldn't be found"
I've tried the following 4 flags in Other Swift Flags build setting:
-plugin-path
-load-plugin-library
-load-plugin-executable
-external-plugin-path (mentioned here)

with the following value:
$(BUILT_PRODUCTS_DIR)#MetaCodable

as appears in the screenshot:

but I still couldn't get the project to compile on CI due to this error.
Any thoughts on this would be highly appreciated.

P.S. the CI builds without problems if the project doesn't contain the macro, and there are no CocoPods at all in the project.

-load-plugin-executable should be worked @mjamal
you can refer to the example above

as I mentioned above, I tried -load-plugin-executable with the value of:
$(BUILT_PRODUCTS_DIR)#MetaCodable

but the Microsoft Azure's CI log shows the following error and warning:

error: external macro implementation type 'CodableMacroPlugin.CodedAt' could not be found for macro 'CodedAt'

"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

Have you solved this problem? I have the same problem:
":0: warning: compiler plugin not loaded:

I couldn't solve it until now .. I posted SO question here to grab some attention.

1 Like

It may be a sandbox execution problem, You can check the CI log to see if there are "sandbox-exec: sandbox_apply: Operation not permitted"

Perhaps you can confirm if the architecture of the binary file meets the requirements

It turned out to be an XCode 15 problem with CI providers (Microsoft Azure and Fastlane) and it's not related to Swift Macros, a Microsoft engineer pointed that out in this thread that I recently opened on their developer community, he also pointed me to a hot discussion on Apple Developers Forums to keep track of the updates regarding this issue.

Hi, I have written a step-by-step guide on how you can distribute macro libraries with CocoaPods, hope it helps you achieving your goal.

2 Likes

Please note that if you are using xcframeworks (e.g. link with SwiftSyntax that was built as an xcframework), you also need to specify the option "-disable-sandbox"

-load-plugin-executable solution was working as expected on Xcode 15 but is not on Xcode 16 - beta 5, does anyone use it on Xcode 16 ?

I'm unable to get this working on Xcode 16 either.

For context, this is needed because xcodebuild -exportLocalizations does not automatically load macros so builds would fail on Xcode 15 without it.

This was working on Xcode 15:

OTHER_SWIFT_FLAGS="-Xfrontend -load-plugin-executable -Xfrontend .../SourcePackages/checkouts/swift-case-paths/.build/debug/CasePathsMacros#CasePathsMacros -Xfrontend -load-plugin-executable -Xfrontend .../SourcePackages/checkouts/swift-macros/.build/debug/Macros#Macros" xcodebuild -exportLocalizations -exportLanguage en -project X.xcodeproj -localizationPath . -scheme X -sdk macosx ONLY_ACTIVE_ARCH=NO ARCHS="arm64

On Xcode 16 it fails to build:

error: external macro implementation type 'CasePathsMacros.CasePathableMacro' could not be found for macro 'CasePathable()'; No such file or directory

Figured out the difference required:

Xcode 15:

-load-plugin-executable <path>#<modulename>

Xcode 16:

-load-plugin-executable <path>-tool#<modulename>
4 Likes

@Ignacio_Soto thank you for documenting this, saved us a ton of time!

1 Like