Xcodebuild attempts to build macro package with wrong arch

Hello, 3 days ago I made post on apple forum about my problem with building SPM package which contains macros (link Xcodebuild command compiles macro … | Apple Developer Forums). Unfortunately I didn't get any response, so I decided to try my luck here. Has anyone encountered something similar?

Yes, it's been an issue since macro release. Literally doubles the swift-syntax build time. Maybe we'll get a fix when the precompiled swift-syntax solution ships, but that seems only likely for summer at the earliest. :frowning_face:

Edit: Reported this back in January, probably just one among many reports: FB13561794

Is there any way to bypass this behavior? For now, this package has to remain as a local package in the application repo, but since it breaks compilation on the CICD machine, this is quite problematic. In the past, I got around this by adding -arch arm64 parameter to the swift build command for Cocoapods libraries with marcos, but I haven't found a solution for this case.

Not that I've found, none of the arch controls seem to affect what Xcode does to macros. However, I'm not sure how that would break your CI, as superfluous archs should just be a performance issue. Sounds like you may have other arch issues.

It seems so, I just checked the log again. Xcodebuild tried to build only the “LibMacros” target with the wrong arch, all other libraries from swift dependencies (since Wrapper lib only wraps them) have arm64 as the selected arch. The compilation of “LibMacors” ends with the following error: "Wrapper/Sources/LibMacros/DummyMacro.swift:9:8: error: module 'SwiftCompilerPlugin' was created for incompatible target arm64-apple-macos10.15: /Users/REDACTED/Library/Developer/Xcode/DerivedData/ModuleCache.noindex/SwiftCompilerPlugin-1PTTVFAZVZCW9.swiftmodule
import SwiftCompilerPlugin".

Thanks for sharing info. It helps me a lot.

I may have a solution:

command line: defaults write com.apple.dt.Xcode IDEPackageEnablePrebuilts NO

Nuke DerivedData

Resolve Packages. Optionally, Update Packages (both worked for me).

Check that ~/Library/Developer/Xcode/DerivedData/YourProjectName-<gobbledeegook>/SourcePackages does NOT have a prebuilt directory in it.

There seems to be an SPM bug where SPM is downloading only the mac arm prebuilt and not the ios prebuilt even if the Package.swift is correct in including ios as a potential target. I didn't see any github issues about it in the swift-syntax github issues though.

So just disabling prebuilt with this hidden setting appears to do the trick.

That doesn't really make sense, as the macro prebuilt is only ever run on the host, not the target. So there's no need for a special iOS build in the first place. In addition, this issue predates prebuilts, and in fact, prebuilts largely address the issue by avoiding SPM's bug where building swift-syntax from source builds it for both architectures. (Which still occurs in Xcode 26.2.) I don't know what the root cause might be (probably an Xcode issue), but disabling prebuilts doesn't fix it. Unless you're using swift-syntax directly in your app?

No, it wasn’t solution for my problem. Cause of problem was CICD agent changing arch for whole job, so I had to add arch arm64 before build command.