TL;DR: The power of Swift Macros relies heavily on the massive SwiftSyntax library, which often drags down project compilation speeds during cold builds. Starting with Swift 6.1.1, you can enable the “Prebuilts” feature to skip compiling this library from source, significantly reducing build times.
Since the introduction of Macros in Swift 5.9, developers have embraced them to boost productivity. However, the underlying dependency, SwiftSyntax, has a large codebase. Recompiling it from source every time you clean the build folder consumes a considerable amount of time.
Starting with Swift 6.1.1 (Xcode 16.4), Apple introduced support for prebuilt versions of Swift-Syntax. With a simple configuration change, developers can use binary artifacts directly, eliminating the need to compile the library from source.
How to Enable
1. For Xcode Development
Run the following command in your terminal to modify Xcode’s hidden preferences and enable prebuilt support:
# Enable prebuilt support
defaults write com.apple.dt.Xcode IDEPackageEnablePrebuilts YES
# To disable it, run:
defaults delete com.apple.dt.Xcode IDEPackageEnablePrebuilts
2. For Command Line (SPM / CI Environments)
If you use Swift Package Manager in a CI/CD pipeline or directly in the terminal, add the following flag to your commands:
swift build --enable-experimental-prebuilts
swift test --enable-experimental-prebuilts
Important Considerations
- Version Requirements: You must use Swift 6.1.1 (Xcode 16.4) or later.
- Clear Cache: Before enabling this feature for the first time, it is recommended to thoroughly clean your old build cache. Otherwise, the changes might not take effect immediately:
- Xcode: Go to
Product->Clean Build Folder. Manually deleting theDerivedDatafolder is also recommended. - CLI: Delete the
.builddirectory in your project root.
- Xcode: Go to
- Network Access: The prebuilt binaries are downloaded during package resolution. Ensure your network environment can access Apple’s CDNs or relevant mirrors.
Results
Enabling prebuilts can reduce the compilation time for projects using custom macros from tens of seconds down to just a few seconds, vastly improving the build experience.