[Preview] Swift-Syntax Prebuilts for Macros

Ah, I got it backwards. Looks like you have an older version of the prebuilts cached. We had to republish the macOS prebuilts for the new Xcode version.

The prebuilts are cached in your ~/.swiftpm/cache/prebuilts. To get a clean start, remove that directory as well as the SwiftPM scratch directory (.build) or the DerivedData directory for your project if you're using Xcode.

1 Like

That did it! Is this something we will need to do whenever we upgrade Xcode, or is that now sorted out?

Excellent. Should be sorted out. I have submitted a change to SwiftPM 6.2 to be more specific what compiler version generated the prebuilts so we can make sure it matches.

1 Like

Is there a way you could make a sample project exhibiting this and raise an issue in the bug reporter? @dschaefer2 is this something you have seen internally?

Same here: When using "legacy previews execution" (which I need due to this issue - FB16398108), the build fails with swift-syntax prebuilts:

[...]/SourcePackages/checkouts/MyMacro/Sources/MyMacrosPlugin/MyMacro.swift:9:8: Cannot load module 'SwiftSyntax' built with SDK 'macosx15.5' when using SDK 'iphonesimulator18.5': [...]/SourcePackages/prebuilts/swift-syntax/601.0.1/6.1-MacroSupport-macos_aarch64/Modules/SwiftSyntax.swiftmodule

Is there a way you could make a sample project exhibiting this and raise an issue in the bug reporter?

Unfortunately no. It's not even clear to us why we need to use "Legacy Previews Execution" in our project. We have our previews conditionally compiled with #if DEBUG but we are not doing conditional compilation specific to running previews, it's the same build.

Our project is huge, so it would be very difficult to create a sample project that exhibited this behaviour, since we don't know why we need to use "Legacy Previews Execution", which seems to be the cause of this issue, see: [Preview] Swift-Syntax Prebuilts for Macros - #45 by ChristophK above.

1 Like

BTW, I can reproduce this. (proper reply below)

1 Like

BTW, I can reproduce this. But, yes, this is crossing into Xcode. Could you raise a bug in the Feedback system (it'll come to me). Bug Reporting - Apple Developer

3 Likes

BTW, I can reproduce this. But, yes, this is crossing into Xcode. Could you raise a bug in the Feedback system (it'll come to me).

Thanks! I just created FB17778220.

3 Likes

Just filed this issue about prebuilts not working in Penny.

:tada: This works like a charm for our iOS app builds!

We're using Xcode 16.4 and swift-syntax 601.0.1. We added a script that sets defaults write com.apple.dt.Xcode IDEPackageEnablePrebuilts YES on local machines and in CI, and see great performance wins across the board, and as expected, especially in release builds.

Thank you for making this available in a very simple and largely transparent way :folded_hands:

4 Likes

This is an amazing improvement, and was much awaited!

I think I found another problem in the interaction of macros, the less known but very useful swift build --explicit-target-dependency-import-check=error option[1], and the new --enable-experimental-prebuilts flag. Here's a very simple reproducer:

  1. Clone https://github.com/swiftlang/swift-testing.
  2. Check out tag 6.1.1 (because main uses a version of Swift Syntax which isn't prebuilt yet!)
  3. swift build --explicit-target-dependency-import-check=error --enable-experimental-prebuilts

This attempts to build the library with its macros but produces errors due to the dependency check:

error: Target TestingMacros imports another target (SwiftDiagnostics) in the package without declaring it a dependency.
error: Target TestingMacrosTests imports another target (SwiftSyntaxMacros) in the package without declaring it a dependency.

(In fact, it randomly varies by build which missing dependency it lists above.)

In contrast, if I rm -rf ~/.swiftpm/cache/prebuilts and retry the above without --enable-experimental-prebuilts, then no such errors appear.

(Edit: Removed mention about --build-tests failing. I guess the tests only failed to build because the regular target itself didn't build successfully.)


  1. I keep wondering why it's not on by default, at least warn by default! â†Šī¸Ž

Ah, thanks! Could you raise a GitHub issue over at GitHub - swiftlang/swift-package-manager: The Package Manager for the Swift Programming Language for that? The prebuilts come down as a single static library so there will be modules in there that you don't use. We'll have to figure out what to do there.

Although mentioned in the Xcode 26b1 release notes, there don't appear to be any prebuilt available for that version yet, even with the default enabled. What sort of latency should be expect between beta release and prebuilts going forward?

They are there as of 90 minutes ago. However if you've been playing with the beta before that it's caching that you tried and it wasn't there. It's a bit awkward to clean up but I'm working on a fix for that. For now you need to do the following:

  • remove the following directory ~/Library/Developer/Xcode/DerivedData/<project name>/SourcePackages/prebuilts. That's the cache for that project.
  • In Xcode File menu select Packages -> Reset Package Caches, to force reloading of the package and setting up the prebuilts.
  • Clean Build Folder and Build again

I'll add the clean up of the prebuilts to the reset function in SwiftPM and Xcode.

2 Likes

Interesting. Can projects easily switch between Xcode 16.4 and the 26 beta series while keeping prebuilts working for both?

That should work. The prebuilts are tagged with the compiler version so you should see both in that directory.

I'm not yet seeing anything for https://download.swift.org/prebuilts/swift-syntax/601.0.1/6.2-manifest.json, did that URL change?

BTW, this all applies to SwiftPM as well. The prebuilts cache is in the scratch path (i.e. .build directory).

Yes, we're now more fine grained with the compiler version so we can get betas and Swift toolchain snapshot builds working along the way.