vknabel / vscode-swift-development-environment

New home of Swift Development Environment for VS Code
https://marketplace.visualstudio.com/items?itemName=vknabel.vscode-swift-development-environment
Apache License 2.0
175 stars 14 forks source link

Possible to use on macOS without XCode? (trying CommandLineTools / swift.org toolchain) #79

Closed nrser closed 3 years ago

nrser commented 4 years ago

Does it / should it work without XCode installed -- just CommandLineTools and/or the swift.org "Toolchain" download?

I just have some small executables that compile file with a Makefile (via xcrun --sdk macosx swiftc ...), but would really help to have types and hints and all that. Seems like almost everyone on Mac installs XCode, but I'm stuck with a low bandwidth, unstable connection, and it's not making much progress on that 8G download.

An outline of what I've tried follows, feel free to ask for any clarification or further information...

I'm on Mojave 10.14.6, fully up-to-date. xcode-select is aimed at the command line tools:

$ xcode-select -p
/Library/Developer/CommandLineTools

This seems to give me Swift 5.0.1:

$ which swift
/usr/bin/swift
$ 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

Didn't find any sourcekit-lsp under /Library/Developer/CommandLineTools, so I downloaded the swift-5.2.5-RELEASE.xctoolchain from swift.org, which includes sourcekit-lsp at

/Library/Developer/Toolchains/swift-5.2.5-RELEASE.xctoolchain/usr/bin/sourcekit-lsp

I toyed around with SDE's settings, current have:

{
    "sde.languageServerMode": "sourcekit-lsp",
    "sourcekit-lsp.serverPath": "/Library/Developer/Toolchains/Swift-5.2.5-RELEASE.xctoolchain/usr/bin/sourcekit-lsp",
    "sourcekit-lsp.toolchainPath": "/Library/Developer/Toolchains/Swift-5.2.5-RELEASE.xctoolchain",
    "swift.path.swift_driver_bin": "/Library/Developer/Toolchains/Swift-5.2.5-RELEASE.xctoolchain/usr/bin/swift"
}

When I click in a .swift file, in VCode's output for swift I see:

error response (Request Failed): error: Swift does not support the SDK 'MacOSX10.14.sdk'

I see a MacOSX10.14.sdk in the command line tools at:

/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk

(actually, a symlink to a MacOSX.sdk file in that same directory), but I don't know how to get sourcekit-lsp to use it (or if it's usable with the swift-5.2.5-RELEASE.xctoolchain).

I also tried swift-5.1.3-RELEASE.xctoolchain, thinking maybe Swift 5.2 wasn't compatible with macOS 10.14 or something. Didn't seem to really make a difference.

I've seen this error in the output as well:

failed to create SwiftPMWorkspace: terminated(72): xcrun --sdk macosx --find xctest output:
    xcrun: error: unable to find utility "xctest", not a developer tool or in PATH

Thanks in advance for any help or insight.

vknabel commented 4 years ago

Hi @nrser! Sorry for the late response. I had quite a lot to do recently.

As of now I have never tested sourckit-lsp without Xcode installed. Does the alternative sourcekite driver work on your machine without Xcode? Might be worth a try.

To be honest testing compatibility has a relatively low priority as it takes me hours to setup and get back to daily work (uninstalling Xcode release and beta, after debugging, downloading both and reinstalling again).

Though there is a workaround. You can try developing inside a container. There is also a dev container for Swift. In those cases the extension and Swift would run on a lightweight Linux. I haven't tried those yet, but heard relatively often, that they do work very well.