Skip to content

swift-precompiled/swift-syntax

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 

Repository files navigation

Precompiled Swift Syntax

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.

Getting Started

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.

(back to top)

Why is this needed?

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.

(back to top)

Troubleshooting

General Xcode troubleshooting

If Xcode throws build or symbol errors, run this clean-slate sequence:

  1. Product ▸ Clean Build Folder (⇧⌘K)
  2. File ▸ Packages ▸ Reset Package Caches (ignore any errors)
  3. Quit and relaunch Xcode
  4. File ▸ Packages ▸ Update to Latest Package Versions

Warnings about swift-syntax dependencies

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).

CI/CD impact

In headless pipelines you cannot patch transitive Package.swift files or use Xcode workspace overrides, so the build fails with no immediate workaround.

References

We are developing an automated workaround for CI environments, but the underlying issue must be fixed in SwiftPM by Apple.

(back to top)

Further Reading

(back to top)

Acknowledgements

Special thanks to

Led by @vatsal_manot as a part of @PreternaturalAI’s ongoing work.

(back to top)

About

@PreternaturalAI's attempt at precompiling swift-syntax.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •