Note
Tested with Xcode 16.3 against the release/6.1
branch.
A precompiled distribution of swiftlang/swift-syntax
that allows you to completely eliminate having to build SwiftSyntax from source.
Add the package dependency to your Package.swift
:
dependencies: [
.package(
url: "https://github.com/swift-precompiled/swift-syntax.git",
branch: "release/6.1"
)
]
That’s it — build & run; SwiftSyntax will not be rebuilt locally.
Swift macros rely on SwiftSyntax to parse and expand your source. Pulling the full package and recompiling it every clean build for every architecture costs a lot of time:
Scenario | Extra build time |
---|---|
Local Debug clean build | ≈ 20 s |
Local Release (WMO) | ≥ 4 min |
Xcode Cloud / CI | Up to 12 min |
Nearly all that time is spent type-checking and compiling SwiftSyntax itself, not running your macros.
If Xcode throws build or symbol errors, run this clean-slate sequence:
- Product ▸ Clean Build Folder (⇧⌘K)
- File ▸ Packages ▸ Reset Package Caches (ignore any errors)
- Quit and relaunch Xcode
- File ▸ Packages ▸ Update to Latest Package Versions
When another package depends on apple/swift-syntax
, SwiftPM will warn:
'foo' dependency on 'https://github.com/apple/swift-syntax.git' conflicts with
dependency on 'https://github.com/swift-precompiled/swift-syntax'
which has the same identity 'swift-syntax'. This will be escalated to an error
in future versions of SwiftPM.
Option | How |
---|---|
Fork & patch | Fork each affected package and change its swiftlang/swift-syntax reference to swift-precompiled/swift-syntax . |
Workspace override | Create an Xcode workspace, clone this repo locally, and add it to the workspace. SwiftPM will prefer the local copy. |
Important
SwiftPM keys packages solely by the identity swift-syntax
.
If swift-precompiled/swift-syntax
and the official swiftlang/swift-syntax
both appear—often via transitive dependencies—SwiftPM throws a “revision conflict.”
The problem affects any fork; even Apple’s own move from apple/swift-syntax.git
to swiftlang/swift-syntax.git
recently impacted thousands of projects across the world (here's an example).
In headless pipelines you cannot patch transitive Package.swift
files or use Xcode workspace overrides, so the build fails with no immediate workaround.
- Point-Free discussion #3262
- Swift Forums: macro-adoption concerns
- Point-Free blog: Being a good citizen in the land of SwiftSyntax
- Swift Forums: override sub-dependency
- Swift Forums: conflict between dependencies that are not sharing a target
- Swift Forums: can't consume two Swift packages with the same name
We are developing an automated workaround for CI environments, but the underlying issue must be fixed in SwiftPM by Apple.
- Swift Forums — Compilation extremely slow since macros adoption
https://forums.swift.org/t/compilation-extremely-slow-since-macros-adoption/67921 - Swift Forums — Macro adoption concerns around SwiftSyntax
https://forums.swift.org/t/macro-adoption-concerns-around-swiftsyntax/66588 - GitHub — Distribute a pre-built SwiftSyntax binary
swiftlang/swift-syntax#2421 - Michael Tsai — Slow Swift Macro Compilation
https://mjtsai.com/blog/2024/02/27/slow-swift-macro-compilation/ - Tuist — Swift Macros at Scale
https://tuist.io/blog/2024/08/26/swift-macros - Medium — Speed Up SwiftSyntaxMacros Package Compilation (Part 1)
https://medium.com/@ruslan_alikhamov/speed-up-swift-swiftsyntaxmacros-package-compilation-part-1-f687ab5607d5 - Medium — Speed Up SwiftSyntaxMacros Package Compilation (Part 2)
https://medium.com/itnext/speed-up-swift-faster-swiftsyntaxmacros-package-compilation-part-2-d5d6bdccfc21 InstantSyntax
swift-syntax-xcframeworks
Special thanks to
Led by @vatsal_manot as a part of @PreternaturalAI’s ongoing work.