If you like my article: Buy Me A Coffee!

Trusting Swift macros on Xcode Cloud

2026-10-12 12:15:00 Trusting Swift macros on Xcode Cloud: A Swift macro you trusted on your Mac is a different decision on Xcode Cloud. Commit the fingerprint instead of skipping the check.

A macro builds on my machine. I enabled it once, Xcode remembered, and I stopped thinking about it. The same project on Xcode Cloud stops with this:

Target 'DependenciesMacrosPlugin' must be enabled before it can be used.

The clone hook on the iOS app I ship at Dawn Technology already contained the line that skips package-plugin checks. I described that line in Swift scripts for Xcode and Xcode Cloud. The build still stopped. A macro is a different trust decision, stored in a different file, and the cloud image has never been asked.

The check the plugin line does not touch

ci_post_clone.sh on this app still starts with the plugin workaround:

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

That key is misspelled on purpose. Validatation is the string Xcode reads. It tells Xcode to skip fingerprint checks for package plugins, which is how SwiftGen runs on the cloud image. It has nothing to say about macros.

A macro is a compiler plugin. SwiftPM will not load one from a remote package until that package revision is on an allowlist for the user running the build. On my Mac that happened when I enabled DependenciesMacrosPlugin from swift-dependencies. Xcode wrote one entry into ~/Library/org.swift.swiftpm/security/macros.json. That path is in my home directory. Xcode Cloud builds as a user who has never enabled anything, so the directory is missing and the file is missing with it.

There is a switch that skips the macro check for every package:

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

This key is spelled correctly. The plugin key is not. Copying one and "fixing" the other is how both lines end up doing nothing. -skipMacroValidation on xcodebuild is the same switch, and an Xcode Cloud workflow does not hand you the xcodebuild invocation to attach it to.

I did not use the switch. It trusts every macro in every dependency, including the next one a pull request adds. The file trusts the revisions I have already enabled.

What goes in the file

After enabling the macro locally, the entry looked like this:

[
  {
    "fingerprint" : "411297072220a96f1501211afebd3715316907d2",
    "packageIdentity" : "swift-dependencies",
    "targetName" : "DependenciesMacrosPlugin"
  }
]

packageIdentity is the last path component of the repository URL, in lowercase. targetName is the macro target. In that package the macro target is DependenciesMacrosPlugin. The library that ships the macros is DependenciesMacros. The error names the plugin target, and the allowlist has to name it too.

fingerprint is the resolved Git commit. Both hashes this project trusted are commits on pointfreeco/swift-dependencies. The first was 411297072220a96f1501211afebd3715316907d2. I committed that file, the cloud build went green, and later the same day I updated the package. The fingerprint in the local allowlist became c79f72b3e67a1eb64f66f76704c22ed6a5c1ed84. Cloud failed again, with the same "must be enabled" error, because the commit SwiftPM had checked out was no longer the commit the allowlist named.

That second failure is the useful one. A package update that only changes Package.resolved can look unrelated to signing and plugins. The allowlist makes it fail until someone puts the new fingerprint in the same change. I copied the new entry from my Mac and committed it next to the dependency bump.

Take the entries this repository needs. Leave the rest of your local macros.json where it is. That file is every macro your user has enabled, including experiments in other projects. The cloud build should trust the plugins this app resolves, and a review should be able to see that list.

Put it in place before the build

Xcode Cloud runs ci_scripts/ci_post_clone.sh after the clone and before dependency resolution. The working directory is ci_scripts. I kept macros.json next to the hook and copied it into the location SwiftPM reads:

#!/bin/zsh
set -euo pipefail

mkdir -p ~/Library/org.swift.swiftpm/security/
cp macros.json ~/Library/org.swift.swiftpm/security/

mkdir matters on a clean home directory. cp into a missing security folder fails, and without that folder the macro check fails later with the error you were already staring at. set -euo pipefail has to come first. In the first version of this hook the copy sat above that line, so a failed copy would have continued into the build and surfaced as the macro error again. With -e, a missing macros.json stops the hook on the cp.

The destination is the security directory, not a renamed file. cp macros.json ~/Library/org.swift.swiftpm/security/ leaves the filename intact, which is the name SwiftPM looks up.

The hook can keep the plugin line beside this copy. They answer different prompts. SwiftGen still needs the misspelled plugin default. DependenciesMacrosPlugin needed the file.

When the macro leaves

Months later I removed swift-dependencies. The allowlist became an empty array, and the hook was still copying that array over the cloud user's file on every build. An empty list and a missing file mean the same thing for a user who has never enabled a macro. I deleted macros.json and deleted the cp. The plugin line stayed, because SwiftGen was still there.

Remove the entry in the same pull request that removes the package. A fingerprint left behind is a revision you no longer resolve. It will not make the build fail, and it will not document anything a reviewer can check. When the last entry is gone, delete the copy as well.

The next macro

Enable it in Xcode on a machine you trust. Open ~/Library/org.swift.swiftpm/security/macros.json and copy the new object into the macros.json you commit. Match targetName to the target in the error, the one declared as a .macro target. Commit that change with the Package.resolved update that brought the package in.

The next time you bump that package, Xcode will ask again, because the commit changed. Copy the new fingerprint into the same pull request. Cloud will keep failing the old fingerprint until you do, which is the outcome you want from an allowlist.

The plugin default remains the right scope for the plugins already covered by that other post. It skips a check. The macro file records a revision. I want the revision in git.


Stay updated by subscribing to my blog's RSS feed.
RSS feed icon