Context: https://forums.swift.org/t/how-to-import-macros-using-methods-other-than-swiftpm/66645/19
Xcode 15
- Open swift-macro-examples-main/MacroExamples.xcodeproj.
- Build the MacroExamples scheme.
- Once the build is completed, go to the build details page and find the compiler invocation for main.swift.
- The compiler invocation will have the plugin executable path after this flag
-load-executable-path
It will look something like this:
-load-plugin-executable
/Users/chirag.ramani/Library/Developer/Xcode/DerivedData/swift-macro-examples-main-csywlwgecxhauhdfxsutsqgbukkc/Build/Products/Debug/MacroExamplesPlugin\#MacroExamplesPlugin
- Find the path to MacroExamplesLib.swiftmodule from the same details page.
It will look something like this:
/Users/chirag.ramani/Library/Developer/Xcode/DerivedData/swift-macro-examples-main-csywlwgecxhauhdfxsutsqgbukkc/Build/Intermediates.noindex/MacroExamples.build/Debug/MacroExamplesLib.build/Objects-normal/arm64/MacroExamplesLib.swiftmodule
- Open MacroClient/MacroClient.xcodeproj.
- Update the OTHER SWIFT FLAGS as follows:
-I<absolute path to MacroExamplesLib.swiftmodule>
-load-plugin-executable
/Users/chirag.ramani/Library/Developer/Xcode/DerivedData/swift-macro-examples-main-csywlwgecxhauhdfxsutsqgbukkc/Build/Products/Debug/MacroExamplesPlugin\#MacroExamplesPlugin
- Build the project. Note: I have seen indexing not picking up the latest modification to OTHER SWIFT FLAGS. So kill XCBuildService, Xcode, and re-open MacroClient project.
Observations:
- Everything builds fine, lldb prints macro results as expected.
- Indexing is successful (as per indexing logs).
- Macro - open definition works all fine as well. It opens the public interface of
MacroExamplesLib
.
Issues:
- Syntax highlight for #stringify is not present.
Expand Macro
option is not shown but theInline Macro
option is shown(and works as expected).