Swift 5.7 "JIT session error: Symbols not found" when using Foundation - swift

I use some swift scripts as Build Phases during the build process of an Xcode project.
Everything is fine on Xcode 13. But when I try to build the project with the Xcode 14 Beta, I get "JIT session error: Symbols not found" errors.
It seems to be a problem with swift 5.7 which is bundled with Xcode 14.
To reproduce, create a file Test.swift with the following content:
import Foundation
print(ProcessInfo.processInfo.globallyUniqueString)
With swift 5.6 this works fine:
% swift --version
swift-driver version: 1.45.2 Apple Swift version 5.6.1 (swiftlang-5.6.0.323.66 clang-1316.0.20.12)
Target: arm64-apple-macosx12.0
% swift Test.swift
594EC474-26AB-4B1B-97AA-56BCC09BE202-29864-00000021D05F7451
But as soon as I switch to swift 5.7 the script breaks:
% swift --version
swift-driver version: 1.55.1 Apple Swift version 5.7 (swiftlang-5.7.0.113.202 clang-1400.0.16.2)
Target: arm64-apple-macosx12.0
% swift Test.swift
JIT session error: Symbols not found: [ _$sSS10FoundationE36_unconditionallyBridgeFromObjectiveCySSSo8NSStringCSgFZ ]
Failed to materialize symbols: { (main, { _main, __swift_FORCE_LOAD_$_swiftXPC_$_Test, _$ss27_finalizeUninitializedArrayySayxGABnlF, __swift_FORCE_LOAD_$_swiftDispatch_$_Test, _$ss5print_9separator10terminatoryypd_S2StFfA1_, _$ss5print_9separator10terminatoryypd_S2StFfA0_, __swift_FORCE_LOAD_$_swiftIOKit_$_Test, __swift_FORCE_LOAD_$_swiftCoreFoundation_$_Test, __swift_FORCE_LOAD_$_swiftDarwin_$_Test, $.Test.__inits.0, _$sSa12_endMutationyyF, __swift_FORCE_LOAD_$_swiftObjectiveC_$_Test }) }
I didn't find anything on this issue during my internet search. But I cannot believe, I'm the only one, running into this issue.
Is this "just" an issue with the swift 5.7/Xcode14 beta or did something change with swift 5.7's handling JIT scripting?

Related

Swift Version Conflict: this SDK is not supported by the compiler - using BUILD_LIBRARY_FOR_DISTRIBUTION setting. What could be the issue?

I'm building a Swift static library with:
Xcode 13.2 (Swift compiler 5.5.2)
iOS Deployment target 12.0
Build library for distribution YES
Skip install NO
Swift language version 5 and tried with 4.2
Dependency managed with CocoaPods:
Japx 3.0.0
Alamofire 5.2.2
RxSwift
When I try to add it to an iOS project with this setup:
Xcode 13.3 (Swift compiler 5.6)
iOS Deployment target 12.0
Swift language version 5 and tried with 4.2
and build I get this error:
Failed to build module 'LibraryX'; this SDK is not supported by the compiler (the SDK is built with 'Apple Swift version 5.5.2 effective-4.2 (swiftlang-1300.0.47.5 clang-1300.0.29.30)', while this compiler is 'Apple Swift version 5.6 effective-4.2 (swiftlang-5.6.0.323.62 clang-1316.0.20.8)'). Please select a toolchain which matches the SDK.
These are the headers in the .swiftinterface
// swift-interface-format-version: 1.0
// swift-compiler-version: Apple Swift version 5.5.2 effective-4.2 (swiftlang-1300.0.47.5 clang-1300.0.29.30)
// swift-module-flags: -target arm64-apple-ios12.0 -enable-objc-interop -enable-library-evolution -swift-version 4.2 -enforce-exclusivity=checked -Onone -module-name LibraryX
Obviously if I build the project with the same compiler version or building the library with the iOS project everything works fine. But the purpose here is to release a precompiled library and not its source code.
Every time that I lookup this error online I've found "You have to set Build library for distribution to Yes"
I tried to add the source code of the static library to a new Framework project, but I get the same result.
I also had this error, in my case it was unable to import a sub-dependency of my XCFramework during reading .swiftinterface file, however was showing this absolutely misleading error.
After repeatedly cleaning up DerivedData and trying different Xcode versions (13.0, 13.4.1) I've seen 2 errors: "this SDK is not supported by the compiler", and "No module named 'AnotherLib'" which was an incorrectly specified dependency inside of my Swift Package.
So, maybe only first part of the message is correct "Failed to build module 'LibraryX'", but the reason is something else, NOT the difference in compiler versions.

Swift Package Manager - How to `Always Embed Swift Standard Libraries`?

We have CLI tool written in Swift for common usage (Android and iOS developers) on macOS.
Android developers without Xcode installation get the following error:
dyld: Library not loaded: #rpath/libswiftCore.dylib
Referenced from: ~/git/myClITool/macosBin Reason: image not found
Abort trap: 6
We found that enabling Always Embed Swift Standard Libraries in Xcode would most likely help, but this CLI tool is exported with SPM, ignoring all Xcode settings.
How can I achieve this build behaviour using SPM only?
Found the following commandline argument: --static-swift-stdlib
Example usage:
swift build --static-swift-stdlib -c release
This would have produced the output we were looking for. Unfortunately since Swift 5, this argument no longer works for any platforms.
When used, SPM throws the following warning:
warning: Swift compiler no longer supports statically linking the
Swift libraries. They're included in the OS by default starting with
macOS Mojave 10.14.4 beta 3. For macOS Mojave 10.14.3 and earlier,
there's an optional Swift library package that can be downloaded from
"More Downloads" for Apple Developers at
https://developer.apple.com/download/more/
Related Swift bugticket: https://bugs.swift.org/browse/SR-648

Swift/Carthage - Can I get it to compile to different version?

I have both Xcode 7.3.1 and Xcode 8.2.1 installed, as I'm taking over a project that was compiled with Xcode 7.3. Carthage is being used to pull in RealmSwift, but it's compiling it to Swift 3 and I'm getting the error:
"Module file was created by a newer version of the compiler"
I tried using the following command, but I believe it's still compiling (locally) to Swift 3.
carthage update --platform iOS --no-use-binaries
Is it possible to pull in 3rd party frameworks and compile them to Swift 2?

Trouble getting Vapor to work with Xcode 8 beta 3

I was following the instructions here, but was not able to get vapor working on my mac. Here're my xcode and swift versions
Xcode 8.0
Build version 8S174q
Apple Swift version 3.0-dev (LLVM 8fcf602916, Clang cf0a734990, Swift 000d413a62)
Target: x86_64-apple-macosx10.9
When I try to install the toolbox using this command
curl -sL toolbox.qutheory.io | bash
The installation is unsuccessful and yields this message
⚠️ It looks like your Command Line Tools version is incorrect.
Make sure Xcode > Preferences > Locations > Command Line Tools is set correctly.
Correct: Xcode 8.0 (8S162m)
Current: Xcode 8.0
Build version 8S174q
⚠️ It looks like your Swift install location has been modified.
Correct: /usr/bin/swift
Current: /Users/<name>/.swiftenv/shims/swift
❌ Incompatible
Reason: Invalid Swift version
Output must contain 'swiftlang-800.0.33.1'
Current 'swift -version' output:
Apple Swift version 3.0-dev (LLVM 8fcf602916, Clang cf0a734990, Swift 000d413a62) Target: x86_64-apple-macosx10.9
📖 Visit our docs for step-by-step instructions on installing Swift correctly.
http://docs.qutheory.io
👋 or Join our Slack and we'll help you get setup.
http://slack.qutheory.io
From this, I can gather that my swift location is wrong (I don't remember changing it) and that my xcode build number is wrong (because xcode beta 2 is no longer available for download, so I got xcode beta 3.)
Can anybody help me to get this working without changing too much, or is this framework still too finicky to work with a slightly different setup?
Unfortunately it's impossible to create packages that work between different Swift 3 development previews because of how much changes in each preview. Things that compiled today might not compile tomorrow and there is no way to selectively target a given preview in code.
Because of this, the Swift version declared in https://github.com/qutheory/vapor#-current-environment for a given Vapor version must be the one used.
Vapor 0.14 relied on the Swift 3.0 preview 2 version that comes with Xcode 8 beta 2. There is currently no way to download Xcode 8 beta 2 now that Apple has stopped hosting it upon the release of Xcode 8 beta 3. That was an oversight.
Vapor 0.15 will not rely on Xcode 8 beta previews and should be released in a few days.
Open Xcode and make sure the correct SDK is selected:
👀 Xcode > Preferences > Locations > Command Line Tools
Select XCode 8
Then continue with the tutorial you are following.

How do I see which version of Swift I'm using?

I just created a new Swift project within Xcode. I am wondering which version of Swift it's using.
How can I see, in Xcode or the terminal, what version of Swift I am using inside my project?
What I do is say in the Terminal:
$ xcrun swift -version
Output for Xcode 6.3.2 is:
Apple Swift version 1.2 (swiftlang-602.0.53.1 clang-602.0.53)
Of course that assumes that your xcrun is pointing at your copy of Xcode correctly. If, like me, you're juggling several versions of Xcode, that can be a worry! To make sure that it is, say
$ xcrun --find swift
and look at the path to Xcode that it shows you. For example:
/Applications/Xcode.app/...
If that's your Xcode, then the output from -version is accurate. If you need to repoint xcrun, use the Command Line Tools pop-up menu in Xcode's Locations preference pane.
Project build settings have a block 'Swift Compiler - Languages', which stores information about Swift Language Version in key-value format. It will show you all available (supported) Swift Language Version for your Xcode and active version also by a tick mark.
Project ► (Select Your Project Target) ► Build Settings ► (Type
'swift_version' in the Search bar) Swift Compiler Language ► Swift Language
Version ► Click on Language list to open it (and there will be a tick mark on any one of list-item, that will be current swift version).
Look at this snapshot, for easy understanding:
With help of following code, programmatically you can find Swift version supported by your project.
#if swift(>=5.7)
print("Hello, Swift 5.7")
#elseif swift(>=5.6)
print("Hello, Swift 5.6")
#elseif swift(>=5.5)
print("Hello, Swift 5.5")
#elseif swift(>=5.4)
print("Hello, Swift 5.4")
#elseif swift(>=5.3)
print("Hello, Swift 5.3")
#elseif swift(>=5.2)
print("Hello, Swift 5.2")
#elseif swift(>=5.1)
print("Hello, Swift 5.1")
#elseif swift(>=5.0)
print("Hello, Swift 5.0")
#elseif swift(>=4.2)
print("Hello, Swift 4.2")
#elseif swift(>=4.1)
print("Hello, Swift 4.1")
#elseif swift(>=4.0)
print("Hello, Swift 4.0")
#elseif swift(>=3.2)
print("Hello, Swift 3.2")
#elseif swift(>=3.0)
print("Hello, Swift 3.0")
#elseif swift(>=2.2)
print("Hello, Swift 2.2")
#elseif swift(>=2.1)
print("Hello, Swift 2.1")
#elseif swift(>=2.0)
print("Hello, Swift 2.0")
#elseif swift(>=1.2)
print("Hello, Swift 1.2")
#elseif swift(>=1.1)
print("Hello, Swift 1.1")
#elseif swift(>=1.0)
print("Hello, Swift 1.0")
#endif
Here is result using Playground (with Xcode 11.x)
Open the Terminal and write:
swift -version
From Xcode 8.3 onward Build Settings has key Swift Language Version with a value of swift version your target is using.
For older Xcodes use this solution,
open terminal and type following command(s)
Case 1: You have installed only one Xcode App
swift -version
Case 2: You have installed multiple Xcode Apps
Switch active developer directory (Replace Xcode_7.3.app from
following command with your Xcode app file name from Application directory for which you want
to check swift version)
sudo xcode-select --switch /Applications/Xcode_7.3.app/Contents/Developer
Then
swift -version
NOTE: From Xcode 8 to Xcode 8.2.x you can use swift 2.3 even though Xcode 8 uses swift 3.x as default swift version. To use swift 2.3, just turn on flag Use Legacy Swift Language Version to YES from Build Setting and XCode will use Swift 2.3 for that project target.
You can see and select which Swift version Xcode is using in:
Target -> Build Settings -> Swift Language Version:
This is available in Xcode 8.3 and Xcode 9 (haven't checked older versions)
To see the default version of swift installed on your machine then from the command line, type the following :
swift --version
Apple Swift version 4.1.2 (swiftlang-902.0.54 clang-902.0.39.2)
Target: x86_64-apple-darwin17.6.0
This is most likely the version that is included in the app store version of Xcode that you have installed (unless you have changed it).
If you want to determine the actual version of Swift being used by a particular version of Xcode (a beta, for instance) then from the command line, invoke the swift binary within the Xcode bundle and pass it the parameter --version
/Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift --version
Apple Swift version 4.2 (swiftlang-1000.0.16.7 clang-1000.10.25.3)
Target: x86_64-apple-darwin17.6.0
This reddit post helped me:
https://www.reddit.com/r/swift/comments/4o8atc/xcode_8_which_swift/d4anpet
Xcode 8 uses Swift 3.0 as default. But you can turn on Swift 2.3. Go to project's Build Settings and set 'Use Legacy Swift Language Version' to YES.
Good old reddit :)
In case anyone is looking for quick one-to-one mapping of Swift version based on Xcode Version:
Xcode 13.4.1 : Swift version 5.6.1
Xcode 13.2 : Swift version 5.5.2
Xcode 12.5 : Swift version 5.4.2
Xcode 12.3 : Swift version 5.3.2
Xcode 12.2 : Swift version 5.3.1
Xcode 11.6 : Swift version 5.2.4
Xcode 11.5 : Swift version 5.2.4
Xcode 11.4 : Swift version 5.2
Xcode 11.3 : Swift version 5.1.3
Xcode 11.2.1 : Swift version 5.1.2
Xcode 11.1 : Swift version 5.1
Obtained with running following command as mentioned on different Xcode versions:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift --version
/usr/bin/swiftc --version
and swift version <--> Xcode version
Either you can run a command on terminal
xcrun swift -version
or
You can refer below table to check which Xcode is using which version of swift language.
Xcode 13.4.1 : Swift version 5.6.1
Xcode 13.3 : Swift version 5.6
Xcode 13.2 : Swift version 5.5.2
Xcode 12.5 : Swift version 5.4.2
Xcode 12.3 : Swift version 5.3.2
Xcode 12.2 : Swift version 5.3.1
Xcode 11.6 : Swift version 5.2.4
Xcode 11.5 : Swift version 5.2.4
Xcode 11.4 : Swift version 5.2
Xcode 11.3 : Swift version 5.1.3
Xcode 11.2.1 : Swift version 5.1.2
Xcode 11.1 : Swift version 5.1
I am using Swift from Google Colab. Here's how to check it in Colab.
!/swift/toolchain/usr/bin/swift --version
The result is 5.0-dev
hi frind code type in terminal
swift -v
print teminal Welcome to Apple Swift version 5.2.4 (swiftlang-1103.0.32.9 clang-1103.0.32.53).
if you want to check the run code for a particular version of swift you can use
#if compiler(>=5.1) //4.2, 3.0, 2.0 replace whatever swft version you wants to check
#endif
Updated answer for how to find which version of Swift your project is using in a few click in Xcode 12 to help out rookies like me.
Click on your Project (top level Blue Icon in the left hand pane)
Click on Build Settings (5th item in the Project > Header)
Scroll down to Swift Compiler - Language, and look at the dropdown.
By just entering swift command in the terminal, it will show the version, while logging to Swift console.(something like below)
System-IOSs-MacBook-Air swift
Welcome to Apple Swift version 5.1 (swiftlang-1100.0.270.13 clang-1100.0.33.7).
Type :help for assistance.
Bonus contribution:
I'm using a custom node.js script to extract a clean string for use with Jazzy documentation. You might get some use of this if you can find a place to work it into your dev process:
Invoked from a Bash script:
#!/bin/bash
swiftversion=$(node SwiftVerSlicer.js "${xcrun swift -version}");
echo $swiftversion
SwiftVerSlicer.js:
// begin script
const inputString = `${process.argv[2]}`
let searchTerm = (inputString.indexOf('(') - 1)//-1 cause whitespace
let version = inputString.slice(0,searchTerm)
console.log(version)
// end script
You can also use regex of course, but do whatever you like :]
Select your project
Build Setting
search for "swift language"
now you can see which swift version you are using in your project
https://i.stack.imgur.com/Ojn3m.png
You will get this under the project setting