# \[Preview\] Swift-Syntax Prebuilts for Macros

**URL:** <https://forums.swift.org/t/preview-swift-syntax-prebuilts-for-macros/80202>\
**Category:** Package Manager\
**Tags:** packagemanager, macros, announcement\
**Created:** [May 29, 2025, 3:21pm UTC](https://forums.swift.org/t/preview-swift-syntax-prebuilts-for-macros/80202 "2025-05-29T15:21:35Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![dschaefer2](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/dschaefer2/32/46516_2.png) [@dschaefer2](https://forums.swift.org/u/dschaefer2)\
**Post date:** [May 29, 2025, 3:21pm UTC](https://forums.swift.org/t/preview-swift-syntax-prebuilts-for-macros/80202/1 "2025-05-29T15:21:35Z")

</div>

The introduction of macros to Swift has given developers the ability to create more expressive libraries that can be distributed as a Swift package. Macros can greatly improve the developer ergonomics making Swift packages an even more appealing environment in which to work.

One issue developers run into when adding dependencies on these packages is that build times all of a sudden get significantly longer. This is especially true when building in release mode and on CI machines with limited CPU and memory. There has been much discussion here: [Compilation extremely slow since macros adoption](https://forums.swift.org/t/compilation-extremely-slow-since-macros-adoption/67921), where people have reported extended build times of 5 minutes or more.

The key contributing factor to this build performance is the need to build the swift-syntax library that is the foundation of macro implementations. It’s a fairly large amount of Swift code required to create and present the Swift syntax tree to the macro.

As discussed at length here [Distribute a prebuilt swift-syntax binary · Issue #2421 · swiftlang/swift-syntax · GitHub](https://github.com/swiftlang/swift-syntax/issues/2421), one possible solution would be to provide a prebuilt library for swift-syntax that could be downloaded by Swift Package Manager and integrated into the build for macros. The good news, if you follow along with the SwiftPM PRs, is that’s what I’ve been working on for the last few months. With one final fix in Swift 6.1.1, it’s now ready for the community to try out.

Supporting prebuilt binaries for Swift can be challenging but SwiftPM takes care of that for you. It will download the prebuilt binary for the resolved version of swift-syntax, for the current running host platform and for the current version of the compiler and integrate them into the build. If prebuilts aren’t available for that combination, SwiftPM will build from source as it does today. Note that currently we have prebuilts for swift-syntax versions 600.0.1 and 601.0.1.

I encourage you to give it a try. I have added a flag to `swift build` and `swift test` to enable the feature:

```swift
swift build --enable-experimental-prebuilts

```

You should see an extra message when SwiftPM is downloading the zip file containing the prebuilts, and of course, your build should be faster, especially if you use `-c release` . You may also see your macros run faster since the swift-syntax prebuilts are built in release mode to help improve performance.

It is also available in Xcode 16.4 by enabling a user default.

```swift
defaults write com.apple.dt.Xcode IDEPackageEnablePrebuilts YES

```

Set it to `NO` to disable it or delete that key.

```swift
defaults delete com.apple.dt.Xcode IDEPackageEnablePrebuilts

```

Please report any problems you have to the SwiftPM Github Issues, [GitHub · Where software is built](https://github.com/swiftlang/swift-package-manager/issues). And, of course, I'd also love to hear if this is helping you. It has been fun to test it and I hope you find the same.

---

<div class="post-metadata">

**Author:** ![pelekon](https://avatars.discourse-cdn.com/v4/letter/p/db5fbb/32.png) [@pelekon](https://forums.swift.org/u/pelekon)\
**Post date:** [May 29, 2025, 3:28pm UTC](https://forums.swift.org/t/preview-swift-syntax-prebuilts-for-macros/80202/2 "2025-05-29T15:28:53Z")

</div>

I'm glad to finally see this, thank you for the work you put into this feature!

---

<div class="post-metadata">

**Author:** ![Jon\_Shier](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jon_shier/32/921_2.png) [@Jon\_Shier](https://forums.swift.org/u/Jon_Shier)\
**Post date:** [May 29, 2025, 3:40pm UTC](https://forums.swift.org/t/preview-swift-syntax-prebuilts-for-macros/80202/3 "2025-05-29T15:40:26Z")

</div>

Looks great! Nice to get that time back, and it'll be interesting to see if it helps with overall macro performance. Is there a message we should see in Xcode's log when it's downloaded or used? And in the future, is there a release cadence for prebuilts of new swift-syntax versions? Where should we report the need?

---

<div class="post-metadata">

**Author:** ![dschaefer2](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/dschaefer2/32/46516_2.png) [@dschaefer2](https://forums.swift.org/u/dschaefer2)\
**Post date:** [May 29, 2025, 3:44pm UTC](https://forums.swift.org/t/preview-swift-syntax-prebuilts-for-macros/80202/4 "2025-05-29T15:44:38Z")

</div>

> [@Jon\_Shier](#):
>
> Is there a message we should see in Xcode's log when it's downloaded or used?

There isn't one right now. You just don't see Swift Syntax things getting built. Definitely something I want added in.

---

<div class="post-metadata">

**Author:** ![Jon\_Shier](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jon_shier/32/921_2.png) [@Jon\_Shier](https://forums.swift.org/u/Jon_Shier)\
**Post date:** [May 29, 2025, 3:46pm UTC](https://forums.swift.org/t/preview-swift-syntax-prebuilts-for-macros/80202/5 "2025-05-29T15:46:46Z")

</div>

It is very nice not to see swift-syntax built, especially the x86 version!

---

<div class="post-metadata">

**Author:** ![dschaefer2](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/dschaefer2/32/46516_2.png) [@dschaefer2](https://forums.swift.org/u/dschaefer2)\
**Post date:** [May 29, 2025, 3:47pm UTC](https://forums.swift.org/t/preview-swift-syntax-prebuilts-for-macros/80202/6 "2025-05-29T15:47:49Z")

</div>

> [@Jon\_Shier](#):
>
> And in the future, is there a release cadence for prebuilts of new swift-syntax versions?

I'm hoping the prebuilts get done for every swift-syntax release. I've made it fairly easy to add new ones to the generator script (which is actually in SwiftPM).

---

<div class="post-metadata">

**Author:** ![dfed](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/dfed/32/20056_2.png) [@dfed](https://forums.swift.org/u/dfed)\
**Post date:** [May 29, 2025, 4:33pm UTC](https://forums.swift.org/t/preview-swift-syntax-prebuilts-for-macros/80202/7 "2025-05-29T16:33:14Z")

</div>

Is this experimental feature supposed to work when a target has both macros and a plugin? Seeing the following error in [an open source project that has both](https://github.com/dfed/SafeDI/tree/main/Examples/ExampleMultiProjectIntegration):

```swift
/Users/dfed/Library/Developer/Xcode/DerivedData/ExampleMultiProjectIntegration-ezjrqaajoaqjyhgouvuvughguadc/SourcePackages/prebuilts/swift-syntax/600.0.1/6.1-MacroSupport-macos_aarch64/include/_SwiftSyntaxCShims/module.modulemap:1:8: error: redefinition of module '_SwiftSyntaxCShims'
module _SwiftSyntaxCShims {
       ^
/Users/dfed/Library/Developer/Xcode/DerivedData/ExampleMultiProjectIntegration-ezjrqaajoaqjyhgouvuvughguadc/SourcePackages/checkouts/swift-syntax/Sources/_SwiftSyntaxCShims/include/module.modulemap:1:8: note: previously defined here
module _SwiftSyntaxCShims {
       ^

```

Edit: [This similar Package](https://github.com/dfed/SafeDI/tree/main/Examples/ExamplePackageIntegration) seems to compile on command line using `swift build --enable-experimental-prebuilts`, but there's no compile-time performance gain from using prebuilt binaries.

I think there are two issues here:

1. The performance speedup seems to **only** be for macros, not plugins or other utilizations of SwiftSyntax
2. In Xcode, utilizing both macros and plugins (or other utilizations of SwiftSyntax) can lead to compilation failure with the `IDEPackageEnablePrebuilts` user default enabled

---

<div class="post-metadata">

**Author:** ![gsabran](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/gsabran/32/11927_2.png) [@gsabran](https://forums.swift.org/u/gsabran)\
**Post date:** [May 29, 2025, 5:24pm UTC](https://forums.swift.org/t/preview-swift-syntax-prebuilts-for-macros/80202/8 "2025-05-29T17:24:29Z")

</div>

This is great! Thanks a lot for doing this.

Are prebuilts only available for Swift syntax, or can any Package create prebuilts for its consumers? I could not spot where in [swift-syntax/Package.swift at main · swiftlang/swift-syntax · GitHub](https://github.com/swiftlang/swift-syntax/blob/main/Package.swift) the pre-built was described.

---

<div class="post-metadata">

**Author:** ![Jon\_Shier](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jon_shier/32/921_2.png) [@Jon\_Shier](https://forums.swift.org/u/Jon_Shier)\
**Post date:** [May 29, 2025, 5:40pm UTC](https://forums.swift.org/t/preview-swift-syntax-prebuilts-for-macros/80202/9 "2025-05-29T17:40:03Z")

</div>

Packages can already do binary dependencies by publishing such.

---

<div class="post-metadata">

**Author:** ![Jon\_Shier](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jon_shier/32/921_2.png) [@Jon\_Shier](https://forums.swift.org/u/Jon_Shier)\
**Post date:** [May 29, 2025, 5:51pm UTC](https://forums.swift.org/t/preview-swift-syntax-prebuilts-for-macros/80202/10 "2025-05-29T17:51:32Z")

</div>

Looks like this knocks our incremental build penalty from 40s to 16s in the Emit Swift Module phase, so the release build certainly helps with the overhead. On to the next bottleneck I guess.

---

<div class="post-metadata">

**Author:** ![dschaefer2](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/dschaefer2/32/46516_2.png) [@dschaefer2](https://forums.swift.org/u/dschaefer2)\
**Post date:** [May 29, 2025, 6:12pm UTC](https://forums.swift.org/t/preview-swift-syntax-prebuilts-for-macros/80202/11 "2025-05-29T18:12:57Z")

</div>

> [@dfed](#):
>
> I think there are two issues here:
> 
> 1. The performance speedup seems to **only** be for macros, not plugins or other utilizations of SwiftSyntax
> 2. In Xcode, utilizing both macros and plugins (or other utilizations of SwiftSyntax) can lead to compilation failure with the `IDEPackageEnablePrebuilts` user default enabled

#1. Yes, this is only for macros right now. That was done because we calculate where to use the prebuilts at package load time where we don't know what the target platform is. Macros are guaranteed to be host only where plug-in tools it is not.

I'll take a look at #2. So this is a plugin that depends on an executable (called a plugin tool) that also uses swift-syntax. Thanks for all your help finding that.

---

<div class="post-metadata">

**Author:** ![vanvoorden](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/vanvoorden/32/33619_2.png) [@vanvoorden](https://forums.swift.org/u/vanvoorden)\
**Post date:** [May 29, 2025, 6:31pm UTC](https://forums.swift.org/t/preview-swift-syntax-prebuilts-for-macros/80202/12 "2025-05-29T18:31:50Z")

</div>

> [@dschaefer2](#):
>
> Supporting prebuilt binaries for Swift can be challenging but SwiftPM takes care of that for you. It will download the prebuilt binary for the resolved version of swift-syntax, for the current running host platform and for the current version of the compiler and integrate them into the build. If prebuilts aren’t available for that combination, SwiftPM will build from source as it does today.

Ahh… interesting!

From the perspective of what happens _after_ the build… do there exist any public artifacts in or adjacent to the compiled products that would indicate this product was or was not built with a `swift-syntax` prebuild dependency? Or is the intention for the prebuild and postbuild dependencies to produce the same identical outputs?

If there was no public artifact indicating this was from prebuild… are there going to be any kind of safety valves at all if the security of these binary prebuild artifacts are ever compromised?

Would we know if Apple would have any announcement to make as far as whether App Store submissions might have any restrictions on prebuild dependencies?

---

<div class="post-metadata">

**Author:** ![dschaefer2](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/dschaefer2/32/46516_2.png) [@dschaefer2](https://forums.swift.org/u/dschaefer2)\
**Post date:** [May 29, 2025, 6:51pm UTC](https://forums.swift.org/t/preview-swift-syntax-prebuilts-for-macros/80202/13 "2025-05-29T18:51:09Z")

</div>

> [@vanvoorden](#):
>
> From the perspective of what happens _after_ the build… do there exist any public artifacts in or adjacent to the compiled products that would indicate this product was or was not built with a `swift-syntax` prebuild dependency? Or is the intention for the prebuild and postbuild dependencies to produce the same identical outputs?

This is only used for macro targets. The prebuilt library itself is not used in the product code.

And artifacts are signed to allow SwiftPM to ensure they are what was published.

---

<div class="post-metadata">

**Author:** ![vanvoorden](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/vanvoorden/32/33619_2.png) [@vanvoorden](https://forums.swift.org/u/vanvoorden)\
**Post date:** [May 29, 2025, 7:03pm UTC](https://forums.swift.org/t/preview-swift-syntax-prebuilts-for-macros/80202/14 "2025-05-29T19:03:25Z")

</div>

> [@dschaefer2](#):
>
> This is only used for macro targets.

Ahh… makes sense. Is the plan then for supporting "transitive" macro dependencies? Where `MyLibraryPackage` depends on `YourMacroPackage` that depends on `swift-syntax`? If I build `MyLibraryPackage` with `enable-experimental-prebuilts` do we plan to respect the prebuild option down through the dependency graph of `MyLibraryPackage`?

---

<div class="post-metadata">

**Author:** ![Jon\_Shier](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jon_shier/32/921_2.png) [@Jon\_Shier](https://forums.swift.org/u/Jon_Shier)\
**Post date:** [May 29, 2025, 7:47pm UTC](https://forums.swift.org/t/preview-swift-syntax-prebuilts-for-macros/80202/15 "2025-05-29T19:47:32Z")

</div>

It already works like that. The prebuilt replaces the source build of swift-syntax if the resolved version has a prebuilt.

---

<div class="post-metadata">

**Author:** ![dschaefer2](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/dschaefer2/32/46516_2.png) [@dschaefer2](https://forums.swift.org/u/dschaefer2)\
**Post date:** [May 29, 2025, 10:28pm UTC](https://forums.swift.org/t/preview-swift-syntax-prebuilts-for-macros/80202/16 "2025-05-29T22:28:47Z")

</div>

> [@dschaefer2](#):
>
> I'll take a look at #2. So this is a plugin that depends on an executable (called a plugin tool) that also uses swift-syntax. Thanks for all your help finding that.

Ah, I see @dfed. You have a library of extensions to swift-syntax that's used both in the macros and build plugin tool. That's causing the two environments to mix. Sorry about that. Thanks again for finding this. I'll work on a solution.

---

<div class="post-metadata">

**Author:** ![compnerd](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/compnerd/32/2165_2.png) [@compnerd](https://forums.swift.org/u/compnerd)\
**Post date:** [May 29, 2025, 11:03pm UTC](https://forums.swift.org/t/preview-swift-syntax-prebuilts-for-macros/80202/17 "2025-05-29T23:03:20Z")

</div>

Is this limited to macOS or is there a solution for other platforms as well?

---

<div class="post-metadata">

**Author:** ![dfed](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/dfed/32/20056_2.png) [@dfed](https://forums.swift.org/u/dfed)\
**Post date:** [May 29, 2025, 11:36pm UTC](https://forums.swift.org/t/preview-swift-syntax-prebuilts-for-macros/80202/18 "2025-05-29T23:36:38Z")

</div>

Aha! That is indeed what I'm doing. Is the issue @dschaefer2 that I have an intermediary module with a dependency on SwiftSyntax, or is it that the intermediary module is shared with another executable that is not a macro? (The more I know, the more I can be clever and work around the problem in the interim)

Edit: looks like it was the intermediary module being shared that was the issue! [Managed to work around it](https://github.com/dfed/SafeDI/pull/161) using symlinks rather than dependencies. My build times just improved a ton – thank you!

---

<div class="post-metadata">

**Author:** ![Jon\_Shier](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jon_shier/32/921_2.png) [@Jon\_Shier](https://forums.swift.org/u/Jon_Shier)\
**Post date:** [May 30, 2025, 3:11am UTC](https://forums.swift.org/t/preview-swift-syntax-prebuilts-for-macros/80202/19 "2025-05-30T03:11:35Z")

</div>

This whole feature seemed to be delayed due to building cross platform support, so yes, it supports many other platforms. You can see the full list of supported platforms in the manifest at [https://download.swift.org/prebuilts/swift-syntax/601.0.1/6.1-manifest.json](https://download.swift.org/prebuilts/swift-syntax/601.0.1/6.1-manifest.json)

---

<div class="post-metadata">

**Author:** ![Sarunas](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/sarunas/32/37050_2.png) [@Sarunas](https://forums.swift.org/u/Sarunas)\
**Post date:** [May 30, 2025, 9:04am UTC](https://forums.swift.org/t/preview-swift-syntax-prebuilts-for-macros/80202/20 "2025-05-30T09:04:21Z")

</div>

Great! Saves nearly 3 minutes for a simple build on Linux!

Please note that it only works if using "swiftlang/swift-syntax", but does not if the older repo name "apple/swift-syntax" is still present in Package.swift.

Is there any way to pass `--enable-experimental-prebuilts` via environmental variable ? `OTHER_SWIFT_FLAGS` does not seem to be used.

Is there any plans to add iOS builds? For the use case when Xcode is used to build an XCFramework starting with:

```swift
xcodebuild archive -scheme SpmPackage -quiet -configuration Release -skipPackagePluginValidation -skipMacroValidation -destination 'generic/platform=iOS Simulator'

```

[Next page](https://forums.swift.org/t/preview-swift-syntax-prebuilts-for-macros/80202.md?page=2)
