XCode 15 beta - No such module error with SwiftPM and Macro

Hello everyone,

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).

Has anyone experienced the same problem?

Thank you.

EDIT: It seems to be possible to use iOS only if you import the macro as dependency into a separate project

1 Like

We have a bit of a confusing situation here because macros only build for the host, but tests will always use the run destination in Xcode. I am improving the template here to skip the tests when an unsupported destination is used: [5.9] Improve macros test template by neonichu · Pull Request #6654 · apple/swift-package-manager · GitHub

1 Like

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) :skull:

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...)

I also disabled macros validation with

defaults write com.apple.dt.Xcode IDESkipMacroFingerprintValidation -bool YES

just in case xcode simply forgot to ask me to enable macros from swift-cocoa-extensions...

Same error for me, this time happening in the test target of my macro, and happened in 15.1 and 15.2 release versions.

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 :clown_face:

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 :new_moon_with_face::new_moon_with_face::new_moon_with_face:)

And btw it looks like I get the error when running tests, but it occurs on the compilation of the module itself before tests :thinking:

1 Like

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.

1 Like

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.

Essentially this, asked once for each macro target depended on: How do I trust a swift macro targe… | Apple Developer Forums

If you've never seen the dialog, I assume you may have disabled macro validation locally xcodebuild -skipMacroValidation [...] or globally:

$ defaults write com.apple.dt.Xcode IDESkipMacroFingerprintValidation -bool YES

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.

In my case I'm able to build the package locally with Xcode, but not from the terminal with the xcodebuild, so there is no button to spam :D

Spamming commands and building multiple times didn't help (and it shouldn't work like this anyway I assume...) :sweat:

Facing the same issue. Xcode 15.2 (15C500b)

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 :white_check_mark: feel free to take a look at sources (Package.swift and _InterceptionMacros target)