I recently downloaded the latest beta version of Xcode 15 and decided to explore its new Macro feature. After creating a new "Swift Macro" I encountered an error when attempting to run the example tests on iOS. The error message is shown in the attached screenshot.
Interestingly, everything functions properly when I choose Mac as the destination for running the tests.
For this project, I'm utilizing swift tools version 15.0 (15a5160n).
I'm getting a similar error in GitHub - CaptureContext/swift-cocoa-extensions, actually I managed to compile it successfully a few times, but as a separate package. Couldn't compile it even a single time as a dependency... And at some point it stopped compiling even in isolation (Xcode 15 & Xcode 15.2 beta)
UPD:
After cleaning everything and rebooting the laptop I managed to compile the package in isolation again, but compilation still fails when it's imported as local or remote dependency (If I comment captured file everything compiles, feels like some linker bug, but I use macros in GitHub - CaptureContext/swift-foundation-extensions: Standard extensions for Foundation framework and have no issues...)
More and more I start to see "no such module" errors when compiling macros
Currently I use Xcode 15.2 beta (15C5500c) and in Xcode everything compiles fine and tests pass. But in terminal or CI I'm getting no such module error
Here is an action, had to make repo public earlier than expected just to show this so maybe someone will be able to figure out how to fix it (CI passed with errors, don't look at the green checkmark )
And btw it looks like I get the error when running tests, but it occurs on the compilation of the module itself before tests
This same issue happened to me just yesterday. I think it had to do with working on a project (TCA) and switching from a pre-macros branch to one which uses them.
Rebuild after rebuild, package cache reset after another, the compiler always complained it could find no such module ComposableArchitecture (was trying to build one of the examples).
Ultimately I restarted Xcode and, having once more reset the package cache and then attempted building the project, it finally asked for permission to run macros from 3 depended Swift modules. Then the project started building.
To me it seems like this could be a bug in the handling (and invalidation) of incremental builds in SwiftPM or its Xcode integration.
Just curious, what was the permission? I have used macro for quite a while but Xcode never asked me for permission to run it.
BTW, I saw those "no such module" error a lot. It typically occurs when I do a fresh build after cleaning build folder. I didn't think much of it because I knew it was because the build system got confused somehow. The error is usually gone after I waited for a while or clicked build button a few times.
I don't remember I saw it, not did I modify Xcode setting. The macros I use are all local packages (they are written by myself) and I import these macros to swift packages (not a Xcode project). Not sure if it makes a difference. Thanks anyway.
Update:
I'm not sure about your project structure, but generally you need smth like this
MyPackageMacroPlugin target with macro implementations
MyPackageMacro target with #externalMacro declarations
Second one should depend on the first one, but you should not import MyPackageMacroPlugin in MyPackageMacro sources, simply declare #externalMacros without additional imports and it'll work just fine
Now CI passes feel free to take a look at sources (Package.swift and _InterceptionMacros target)
True, thats kinda important for tests, but I had this issue even while building the library
Btw here is a link to the Makefile I use to run both library and macros tests (I took TCA as a reference and simplified it a bit)
However it requires copying .xcworkspace from .swiftpm to .github, whoever needs this may copy .xcworkspace from the repo, open it's contents and replace Package.resolved + schemes folder with your contents and you should be good to use the Makefile