Hi, I use a MBP running macos 14.2. I installed Command Line Tools package on it a while back, which provided swift 5.10.
$ /Library/Developer/CommandLineTools/usr/bin/swift --version
Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4)
Target: arm64-apple-darwin23.2.0
I downloaded and installed swift 6.0.1 toolchain from swift.org website today. As there is no Xcode but VS Code installed on the MBP, I also decide to give vscode swift extension a try.
$ /Library/Developer/Toolchains/swift-6.0.1-RELEASE.xctoolchain/usr/bin/swift --version
Apple Swift version 6.0.1 (swift-6.0.1-RELEASE)
Target: arm64-apple-macosx14.0
Issue 1) xcrun failed to use the version in toolchain
I followed the insturctions on swift.org website and ran these commands, but xcrun
failed to use the version in toolchain. The log showed that xcrun
did get TOOLCHAINS
value correctly, but for unclear reason it still chose the version under /Library/Developer/CommandLineTools
.
% export TOOLCHAINS=$(plutil -extract CFBundleIdentifier raw /Library/Developer/Toolchains/swift-latest.xctoolchain/Info.plist)
% echo $TOOLCHAINS
org.swift.6010202409231a
% xcrun -v swift --version
xcrun: note: database key is: /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk|/Library/Developer/CommandLineTools|<manpath>
xcrun: note: lookup resolved in '/var/folders/gr/3jgnlnxn5nv6h47k5rdq1l2m0000gp/T/xcrun_db' : '/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/share/man:/Library/Developer/CommandLineTools/usr/share/man:/Library/Developer/CommandLineTools/Toolchains/XcodeDefault.xctoolchain/usr/share/man:'
xcrun: note: PATH = '/Library/Developer/Toolchains/swift-6.0.1-RELEASE.xctoolchain/usr/bin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/opt/X11/bin:/Users/xh01983184/Library/Python/3.9/bin'
xcrun: note: SDKROOT = '/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk'
xcrun: note: TOOLCHAINS = 'org.swift.6010202409231a'
xcrun: note: DEVELOPER_DIR = '/Library/Developer/CommandLineTools'
xcrun: note: XCODE_DEVELOPER_USR_PATH = ''
xcrun: note: xcrun_db = '/var/folders/gr/3jgnlnxn5nv6h47k5rdq1l2m0000gp/T/xcrun_db'
xcrun: note: xcrun via swift (xcrun)
xcrun: note: database key is: swift|/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk|org.swift.6010202409231a|/Library/Developer/CommandLineTools|
xcrun: note: lookup resolved in '/var/folders/gr/3jgnlnxn5nv6h47k5rdq1l2m0000gp/T/xcrun_db' : '/Library/Developer/CommandLineTools/usr/bin/swift'
Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4)
Target: arm64-apple-darwin23.2.0
Unsetting TOOLCHAINS
environment variable and passing --toolchain org.swift.6010202409231a
explicitly has the same result.
As I wasn't sure if this related to the fact that there was no Xcode installed, I skipped the issue and continued to try VS Code. My assumption was that VS Code wouldn't depend on xcrun
, but it turned out it had similar issue too.
Issue 2) VS Code failed too
I checked Swift extension settings and noticed it used PATH
environment variable:
Swift: Path
Override the default path of the folder containing the Swift executables. The default is to look in the PATH environment variable. This path is also used to search for other executables used by the extension like sourcekit-lsp and lldb.
So I made sure /Library/Developer/Toolchains/swift-6.0.1-RELEASE.xctoolchain/usr/bin
was at the beginning of PATH
and restated VS code. However, VS Code also failed to use the toolchain. Below are a few weird behaviors I observed:
A) When I selected Swift: Select Toolchain
command in command palette, a pop-up menu list toolchains in use and available. Below was the text for the toolchain in use:
Swift 6.0.1 // the version is correct
/Library/Developer/CommandLineTools/usr // the location is incorrect!
B) To make sure which version was used by VS Code, I created a excutable package with the following code. Its output indicated it failed to use the version in toolchain too.
#if swift(>=6.0)
print("version: (6.0...)")
#elseif swift(>=5.10)
print("version: (5.10..<6.0)")
#else
print("unexpected version!")
#endif
// output:
// version: (5.10..<6.0)
C) While investigating it, I checked the package build log and found VS Code also used xcrun
. Below is a complete build log. It showed that a) VS Code used xcrun
, and b) VS Code used the swift version in /Library/Developer/CommandLineTools
, instead of toolchain.
* Executing task: swift: Resolve Package Dependencies
> /Library/Developer/CommandLineTools/usr/bin/swift package resolve
warning: could not determine XCTest paths: terminated(1): /usr/bin/xcrun --sdk macosx --show-sdk-platform-path output:
xcrun: error: unable to lookup item 'PlatformPath' from command line tools installation
xcrun: error: unable to lookup item 'PlatformPath' in SDK '/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk'
* Terminal will be reused by tasks, press any key to close it.
* Executing task: swift: Build Debug test1
> /Library/Developer/CommandLineTools/usr/bin/swift build --product test1 -Xswiftc -diagnostic-style=llvm
warning: could not determine XCTest paths: terminated(1): /usr/bin/xcrun --sdk macosx --show-sdk-platform-path output:
xcrun: error: unable to lookup item 'PlatformPath' from command line tools installation
xcrun: error: unable to lookup item 'PlatformPath' in SDK '/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk'
Building for debugging...
[1/1] Write swift-version--1AB21518FC5DEDBE.txt
Build complete! (0.14s)
* Terminal will be reused by tasks, press any key to close it.
* Executing task: swift: Build Debug test1
> /Library/Developer/CommandLineTools/usr/bin/swift build --product test1 -Xswiftc -diagnostic-style=llvm
warning: could not determine XCTest paths: terminated(1): /usr/bin/xcrun --sdk macosx --show-sdk-platform-path output:
xcrun: error: unable to lookup item 'PlatformPath' from command line tools installation
xcrun: error: unable to lookup item 'PlatformPath' in SDK '/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk'
Building for debugging...
[1/1] Write swift-version--1AB21518FC5DEDBE.txt
Build complete! (0.04s)
* Terminal will be reused by tasks, press any key to close it.
* Executing task: swift: Build Debug test1
> /Library/Developer/CommandLineTools/usr/bin/swift build --product test1 -Xswiftc -diagnostic-style=llvm
warning: could not determine XCTest paths: terminated(1): /usr/bin/xcrun --sdk macosx --show-sdk-platform-path output:
xcrun: error: unable to lookup item 'PlatformPath' from command line tools installation
xcrun: error: unable to lookup item 'PlatformPath' in SDK '/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk'
Building for debugging...
[1/1] Write swift-version--1AB21518FC5DEDBE.txt
Build complete! (1.47s)
* Terminal will be reused by tasks, press any key to close it.
What am I missing? Thanks for any help.