Running a specific Swift toolchain on Big Sur

So, I just installed Big Sur (and Xcode 12 with Swift 5.3) and I'm trying to run a project that doesn't yet support Swift 5.3. I downloaded the Swift 5.2 toolchain, which I normally invoke with

$ xcrun -toolchain "swift 5.2" swiftc test.swift

Which goes fine when test.swift is an empty file, but it fails when I add import Foundation:

$ xcrun -toolchain "swift 5.2" swiftc test.swift
/Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.16.sdk/System/Library/Frameworks/Combine.framework/Modules/Combine.swiftmodule/x86_64-apple-macos.swiftinterface:817:78: error: 'where' clause cannot be attached to a non-generic declaration
  public func assign(to published: Combine.Published<Self.Output>.Publisher) where Self.Failure == Swift.Never
                                                                             ^
<unknown>:0: error: failed to load module 'Combine'
/Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.16.sdk/System/Library/Frameworks/Combine.framework/Modules/Combine.swiftmodule/x86_64-apple-macos.swiftinterface:817:78: error: 'where' clause cannot be attached to a non-generic declaration
  public func assign(to published: Combine.Published<Self.Output>.Publisher) where Self.Failure == Swift.Never

Is Swift 5.2 not compatible with the 10.16 SDK? Do I need to download the 10.15 SDK in some way? Or maybe Xcode 11.5? I really have no idea.

Old versions of Xcode are probably your solution here.

What happens if you change swift version in Xcode 12 to 5.2 instead? If that works, try to specify Swift version in CLI.

How would that change my command, you think? Using something like xcode-select, or maybe passing the SDK into xcrun manually with a flag?

In this case I'm only using the CLI, so there's no Xcode project in which to change the Swift version. The -toolchain flag on xcrun is my way of specifying the Swift version in the CLI.

Using xcode-select with Xcode 11 worked, thanks a lot :slight_smile:

So in order to resolve the issue you one have to point the toolchain to the right collection swiftinterface? That's confusing given that you were not looking for backward compatibility, just wanted to use older version of Swift.

You’re right, it is weird. Does this mean it’s impossible to compile Swift 5.2 apps with the Big Sur SDK? If so, is this a bug or is it intentional? I really have no idea.

The Big Sur SDK (evidently) uses features from Swift 5.3. Since Swift 5.2 is forward-compatible with Swift 5.3, any existing apps will should work when compiled as Swift 5.3. However, a Swift 5.2 compiler won't be able to use the Big Sur SDK; thus far, Apple hasn't put effort into making sure a new SDK compiles with an older version of the Swift compiler.* The compiler doesn't (yet?) have features for that either, though it gets discussed every now and then.

* Historically, Apple has put a little more effort into making sure their Objective-C code compiles with older versions of Clang…but only while it's not an undue burden. That is something that's easier with a preprocessor, though.

Thanks, that actually helps a lot :thinking:

Guess I’ll have to keep Swift 5.2 and the Catalina SDK for a while longer then.