[Preview] Swift-Syntax Prebuilts for Macros

I was excited to give this a try but unfortunately, we have to depend on SwiftPM's release/6.1 branch, which in turn pins us on SwiftSyntax's release/6.1. I believe that's the reason I'm not seeing a build time difference - that branch doesn't have any pre-built libraries.

Is that perhaps something that's going to be available at some point or is this only ever to cover SwiftSyntax releases? (I wish we didn't have to depend on SwiftPM but we have to at the moment.)

This is awesome to see :slight_smile:

Filed this to track adding this swift.org API to the OpenAPI doc: Prebuilts API is missing from the OpenAPI doc · Issue #1009 · swiftlang/swift-org-website · GitHub

1 Like

Of course. Swift Everywhere :). It's essentially every platform we have a toolchain for. The full list is here for 6.1:

5 Likes

Awesome! Yeah I've seen symlinks used a few times to get around hurdles. We still need to address those things to improve the ergonomics.

1 Like

Not at the moment. We have it turned on by default in the 6.2 branch so this should only be temporary. It is still experimental in 6.1.

5 Likes

It's really only for releases at the moment. On the 6.2 branch, I've tightened up the compiler dependency checking so that opens the door to support snapshot builds. Lots more to figure out there first though.

3 Likes

Uh oh. After a promising start:

Downloading package prebuilt https://download.swift.org/prebuilts/swift-syntax/601.0.1/6.1-MacroSupport-macos_aarch64.zip
Downloaded https://download.swift.org/prebuilts/swift-syntax/601.0.1/6.1-MacroSupport-macos_aarch64.zip (0.56s)

I get:

error: cannot load module 'SwiftSyntax' built with SDK 'macosx15.4' when using SDK 'macosx15.5'
1 Like

Hi all,

Very excited to try this out on CI today. In my first run I am getting some download errors from swift-collections. It seems to just download the source and build as a backup, but I figured I would bring it up and file a bug if needed.

This is building with Xcode 16.4.

INFO [2025-05-30 08:50:08.11]: ▸ skipping cache due to an error: Couldn’t fetch updates from remote repositories:
INFO [2025-05-30 08:50:08.11]: ▸     POST git-upload-pack (165 bytes)
INFO [2025-05-30 08:50:08.11]: ▸     error: non-monotonic index ./objects/pack/pack-d8d5209b3c67c0fcb18c9f531b10a98e6bf1c35d.idx
INFO [2025-05-30 08:50:08.11]: ▸     error: non-monotonic index ./objects/pack/pack-d8d5209b3c67c0fcb18c9f531b10a98e6bf1c35d.idx

truncated...

INFO [2025-05-30 08:50:08.11]: ▸     error: non-monotonic index ./objects/pack/pack-d8d5209b3c67c0fcb18c9f531b10a98e6bf1c35d.idx
INFO [2025-05-30 08:50:08.11]: ▸     From https://github.com/apple/swift-collections
INFO [2025-05-30 08:50:08.11]: ▸      - [deleted]         (none)     -> lorentey-patch-2
INFO [2025-05-30 08:50:08.11]: ▸      - [deleted]         (none)     -> silence-32bit-warning
INFO [2025-05-30 08:50:08.11]: ▸      - [deleted]         (none)     -> wip-filter-set
INFO [2025-05-30 08:50:08.11]: ▸      - [deleted]         (none)     -> refs/pull/371/merge
INFO [2025-05-30 08:50:08.11]: ▸      - [deleted]         (none)     -> refs/pull/390/merge
INFO [2025-05-30 08:50:08.11]: ▸      - [deleted]         (none)     -> refs/pull/411/merge

and truncated again...

INFO [2025-05-30 10:13:08.88]: ▸     fatal: bad object 762bc5757de4bcf86cc3b3266e3df93f76469089
INFO [2025-05-30 10:13:08.98]: ▸     error: https://github.com/apple/swift-collections.git did not send all necessary objects

I believe I'm seeing this same issue and have made a demo repo. This repo is the result of creating a new macro template in Xcode, but then rewriting the unit test target to use the open source swift-macro-testing library.

The tests run successfully on macOS when not using prebuilts, and start failing with import MyMacroMacros <-- Missing required module 'SwiftCompilerPlugin' when prebuilts are on.

Thanks for doing this and I hope this repo helps!

1 Like

@gregcotten Are you on Xcode or Command Line Tools 16.4?

Definitely. Thanks! It's the same issue. The failure happens in Xcode if you have a macro or a macro test that depends on a library that depends on swift-syntax.

2 Likes

Packages can already do binary dependencies by publishing such.

This is only true for Apple platforms. Please, for all that is holy, include that stipulation rather than making grandiose, unqualified, universal statements. I have gone down so many rabbit holes looking for ways to do this on Linux because of the many, many posts on this forum that make similar blanket statements without acknowledging the existence of other platforms.

That binary dependencies still cannot be specified in Package.swift on non-Apple platforms continues to hamper Swift's adoption on those platforms.

The fact that this Swift-Syntax-specific feature supports non-Apple platforms may, some day, lead to fully generalized prebuilt binary dependency support for non-Apple platforms in SwiftPM. Maybe. Until then, those of us hoping to broaden Swift's appeal on those other platforms are being left out in the cold.

7 Likes

@Josh_Wisenbaker That's not related to this feature. Please report that to the Apple Feedback system. Thanks!

I don't think Apple Feedback is necessarily the right place for that either. It looks like a git issue, and therefore the best place to start would be somewhere like Stack Overflow or the git mailing lists on kernel.org.

Is there any possibility this git clone is corrupted with any experimental or development branches that might have been force pushed to new commit hashes?

Is your repo open source?

There were no changes to the git clone process. It happens as normal. The prebuilts are calculated at package manifest load time.

1 Like

It's not open source, but I can try to reproduce it with one that is.

This is happening when running on Jenkins, I will try locally as well.

1 Like

My thinking was it was something in the git clone checkout at the beginning of this CI job… not necessarily something funny inside SPM directly.

Xcode 16.4

> xcode-select -p
/Applications/Xcode.app/Contents/Developer
> swift --version
swift-driver version: 1.120.5 Apple Swift version 6.1.2 (swiftlang-6.1.2.1.2 clang-1700.0.13.5)
Target: arm64-apple-macosx15.0

This is something I've been waiting for for a long time and it has made a huge difference in our project. On an M4 Pro MBP a clean build has gone down from around 180s to 120s, a 33% improvement!

However, we have run into one issue: when building for Swift UI Previews we get the following build errors:

cannot load module 'SwiftDiagnostics' built with SDK 'macosx15.5' 
when using SDK 'iphonesimulator18.5': 
/Users/michael/Library/Developer/Xcode/DerivedData/Argent-abjsbansejjcbwcjgelbjpjlnxuc/SourcePackages/prebuilts/swift-syntax/600.0.1/6.1-MacroSupport-macos_aarch64/Modules/SwiftDiagnostics.swiftmodule

We are using the "Legacy Previews Execution" option, if that makes any difference (we never been able to run our previews without this option for reasons which are not clear to us).

Which means we are left between choosing between the productivity benefits of faster builds or the productivity benefits of using SwiftUI Previews :neutral_face:

2 Likes