Member-only story
Solving Swift Macro Trust Issues in Xcode Cloud Builds
Swift macros are powerful but can break your CI pipeline with trust errors. Learn how to implement a simple post-clone script that solves the “Target must be enabled” error in Xcode Cloud once and for all.
The Problem with Swift Macros in CI Environments
Swift macros, introduced in Xcode 15 with Swift 5.9, are a powerful feature that enables code generation and compile-time metaprogramming. While they offer excellent developer productivity benefits, they’ve introduced a new challenge for CI/CD pipelines, particularly in Xcode Cloud.
When you first use a macro locally, Xcode displays a dialog asking you to trust the macro’s package before it can be executed. This works fine on your development machine, but becomes problematic in automated environments like Xcode Cloud where there’s no way to click “OK” on a dialog box.
If you’ve tried to build a project using Swift macros in Xcode Cloud, you’ve likely encountered this frustrating error:
Target must be enabled before it can be used.
A Complete Solution
After some research, I’ve found a reliable solution that works consistently for Xcode Cloud builds using Swift macros. Here’s how to implement it:
Step 1: Create a CI Scripts Folder
First, let’s create a dedicated folder for our CI scripts:
- Right-click your project in Xcode
- Select “New Group”
- Name it
ci_scripts
Step 2: Create the Post-Clone Script
Next, we’ll create a post-clone script that Xcode Cloud will automatically execute after cloning your repository:
- Right-click the
ci_scripts
folder - Select “New File” → “Empty File”
- Name it
ci_post_clone.sh