Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift build settings in Xcode to use lower 4.0.3 version instead of 5.0.1 are not enforced

I'm creating a simple Swift framework in Xcode 10.3 and trying to use a lower Swift 4.0.3 version. I went to the Xcode build settings and switch from 5.0.1 to 4.0.3 and then build the project.

enter image description here

I ran otool against resulted framework to make sure it's built using correct Swift version but the libraries included are still from Swift 5.0.1 (corresponds to 1001.0.82 from the output below):

otool -l SwiftyHello.framework/SwiftyHello

cmd LC_LOAD_DYLIB
cmdsize 56
name @rpath/libswiftCore.dylib (offset 24)
time stamp 2 Wed Dec 31 16:00:02 1969
current version **1001.0.82**
compatibility version 1.0.0

My toolchain is running Swift 5.0.1:

swift -version

Apple Swift version 5.0.1 (swiftlang-1001.0.82.4 clang-1001.0.46.5)
Target: x86_64-apple-darwin18.7.0

How can I make sure that the Swift framework is built using Swift 4.0.3?

like image 812
Alexey Strakh Avatar asked Sep 12 '19 21:09

Alexey Strakh


1 Answers

SWIFT_VERSION (Swift Language Version) key does nothing with an actual Swift version of the resulting binary. From $ swift --help:

-swift-version Interpret input according to a specific Swift language version number

So, basically, Xcode executes Swift compiler with -swift-version 4 argument. It changes how Swift compiler parses the source files, but do not affect the binary in any way.

To build the actual Swift 4 binary, you have to install the Swift 4 toolchain. Then you would be able to pick the correct toolchain from the menu Xcode -> Toolchains. But, honestly, I wouldn't recommend doing this way, because Apple does not care about older versions of toolchains, and Xcode usually behaves unstable with them.

Instead, I'd recommend you install older Xcode (in your case 9.3) from the Apple Downloads website and build the project from there.

Alternatively, you can set up relatively simple CI/CD inside Github Actions, CircleCI or TravisCI and build in multiple Xcode versions at the same time there. And use the latest Xcode locally. Because they these CIs provide you multiple virtual environments with different Xcode and macOS versions.

like image 105
dosi Avatar answered Nov 09 '22 03:11

dosi