You can add flag -load-plugin-executable <path>#<modulename> to OTHER_SWIFT_FLAGS via the post_install hook in the Podfile.
The executable file you can find in the build folder of your swift package with the target macro
I tried this method, but it doesn't seem to work. Did I misunderstand something?
I have currently created a new target that depends on SwiftSyntax through CocoaPods. Within this target, I've defined macros that compile successfully. However, unlike SPM, it cannot be used externally
Even though macro expansion has been achieved, compilation still results in errors
Note that, currently, the only supported way of using macros is using SwiftPM's .macro target. Compiler options related to macro plugins are not guaranteed to be stable, nor officially documented. It is possible to make macro plugin manually and use it if really want, but again it's not guaranteed to be stable.
Does your macro work in SwiftPM? If not, or you haven't tried it, I'd recommend to make it work in SwiftPM first, then port it using CocoaPods.
When making macro plugin manually (not using SwiftPM), check these things:
Macro plugin target must be an executable target.
Macro plugin target must be built for "host" platform, not the application "target". I.e. macOS not iOS.
Macro plugin target must import SwiftCompilerPlugin and declare @main type conforming to CompilerPlugin, and define providingMacros listing the providing macro types. E.g.
Specify -load-plugin-executable <path>#<modulename> to the user targets. i.e. the module that declares macro icarusCodable = #externalMacro(...), and the actual users of @icarusCodable. Where <path> is the built plugin target executable and <modulename> is the Swift module name of the plugin target.
Are there any blockers to publicizing and documenting the driver flags for passing in macros?
IMO, there should not be any public-facing officially supported language features that are only accessible through SwiftPM or through an -Xfrontend backdoor flag; the swiftc driver interface for this should be stabilized at the same time as the rest of the feature set.
I hope this can be of help to you.
MacrosDemo/LFCMacroMacros is the binary product after macro compilation. You can execute 'swift build -c release' in the root directory of the macros, and then find it in the 'build' directory @songwei@jjrscott
@chiragramani Do you have a sample project and steps to reproduce the issue? How do you pre-compile the macro? Do you set any specific compiler arguments in the client project so that it finds the pre-compiled macro?
Thank you for the reproducer. I confirmed the symptom, and it turned out that this is a Xcode issue but not a Swift (or SourceKit) issue. Could you file a feedback (https://feedbackassistant.apple.com/)?
(As a workaround, Refactor > Inline Macro still should work)