Skip to content

Commit 6fc7651

Browse files
authored
Merge pull request swiftlang#29 from benlangmuir/update-recommended-toolchain
Update recommended toolchain to 2018-12-02-a
2 parents 5d4dfcb + 5181e28 commit 6fc7651

File tree

5 files changed

+63
-9
lines changed

5 files changed

+63
-9
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ SourceKit-LSP is an implementation of the [Language Server Protocol](https://mic
77

88
SourceKit-LSP is under heavy development! The best way to try it out is to build it from source. You will also need a Swift development toolchain and an editor that supports LSP.
99

10-
1. Install the `swift-DEVELOPMENT-SNAPSHOT-2018-11-25-a` toolchain snapshot from https://swift.org/download/#snapshots. Set the environment variable `SOURCEKIT_TOOLCHAIN_PATH` to the absolute path to the toolchain or otherwise configure your editor to use this toolchain. See [Toolchains](#toolchains) for more information.
10+
1. Install the `swift-DEVELOPMENT-SNAPSHOT-2018-12-02-a` toolchain snapshot from https://swift.org/download/#snapshots. Set the environment variable `SOURCEKIT_TOOLCHAIN_PATH` to the absolute path to the toolchain or otherwise configure your editor to use this toolchain. See [Toolchains](#toolchains) for more information.
1111

1212
2. Build the language server executable `sourcekit-lsp` using `swift build`. See [Building](#building-sourcekit-lsp) for more information.
1313

@@ -73,7 +73,7 @@ SourceKit-LSP depends on tools such as `sourcekitd` and `clangd`, which it loads
7373

7474
### Recommended Toolchain
7575

76-
Use the `swift-DEVELOPMENT-SNAPSHOT-2018-11-25-a` toolchain snapshot from https://swift.org/download/#snapshots. SourceKit-LSP is still early in its development and we are actively adding functionality to the toolchain to support it.
76+
Use the `swift-DEVELOPMENT-SNAPSHOT-2018-12-02-a` toolchain snapshot from https://swift.org/download/#snapshots. SourceKit-LSP is still early in its development and we are actively adding functionality to the toolchain to support it.
7777

7878
### Selecting the Toolchain
7979

Sources/SKCore/ToolchainRegistry.swift

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ public final class ToolchainRegistry {
3636
/// Mutex for registering and accessing toolchains.
3737
var queue: DispatchQueue = DispatchQueue(label: "toolchain-registry-queue")
3838

39+
/// The currently selected toolchain identifier on Darwin.
40+
public internal(set) lazy var darwinToolchainOverride: String? = {
41+
if let id = getenv("TOOLCHAINS"), !id.isEmpty, id != "default" {
42+
return id
43+
}
44+
return nil
45+
}()
46+
3947
/// Creates an empty toolchain registry.
4048
public init() {}
4149
}
@@ -75,16 +83,16 @@ extension ToolchainRegistry {
7583

7684
/// The default toolchain.
7785
///
78-
/// On Darwin, this is typically the toolchain with the identifier
79-
/// `darwinDefaultToolchainIdentifier`, i.e. the default toolchain of the active Xcode. Otherwise
80-
/// it is the first toolchain that was registered, if any.
86+
/// On Darwin, this is typically the toolchain with the identifier `darwinToolchainIdentifier`,
87+
/// i.e. the default toolchain of the active Xcode. Otherwise it is the first toolchain that was
88+
/// registered, if any.
8189
///
8290
/// The default toolchain must be only of the registered toolchains.
8391
public var `default`: Toolchain? {
8492
get {
8593
return queue.sync {
8694
if _default == nil {
87-
if let tc = toolchainIdentifiers[ToolchainRegistry.darwinDefaultToolchainIdentifier] {
95+
if let tc = toolchainIdentifiers[darwinToolchainIdentifier] {
8896
_default = tc
8997
} else {
9098
_default = _toolchains.first
@@ -108,10 +116,16 @@ extension ToolchainRegistry {
108116
}
109117

110118
/// The standard default toolchain identifier on Darwin.
119+
public static let darwinDefaultToolchainIdentifier: String = "com.apple.dt.toolchain.XcodeDefault"
120+
121+
/// The current toolchain identifier on Darwin, which is either specified byt the `TOOLCHAINS`
122+
/// environment variable, or defaults to `darwinDefaultToolchainIdentifier`.
111123
///
112124
/// The value of `default.identifier` may be different if the default toolchain has been
113-
/// explicitly overridden, or if there is no toolchain with this identifier.
114-
public static let darwinDefaultToolchainIdentifier: String = "com.apple.dt.toolchain.XcodeDefault"
125+
/// explicitly overridden in code, or if there is no toolchain with this identifier.
126+
public var darwinToolchainIdentifier: String {
127+
return darwinToolchainOverride ?? ToolchainRegistry.darwinDefaultToolchainIdentifier
128+
}
115129

116130
/// All toolchains, in the order they were added.
117131
public var toolchains: [Toolchain] {

Tests/SKCoreTests/ToolchainRegistryTests.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ final class ToolchainRegistryTests: XCTestCase {
3737
Platform.currentPlatform = .darwin
3838

3939
let tr = ToolchainRegistry()
40+
tr.darwinToolchainOverride = nil
4041
XCTAssertNil(tr.default)
4142
let a = Toolchain(identifier: "a", displayName: "a", path: nil)
4243
try! tr.registerToolchain(a)
@@ -69,6 +70,7 @@ final class ToolchainRegistryTests: XCTestCase {
6970
#if os(macOS)
7071
let fs = InMemoryFileSystem()
7172
let tr1 = ToolchainRegistry(fs)
73+
tr1.darwinToolchainOverride = nil
7274

7375
let xcodeDeveloper = ToolchainRegistry.currentXcodeDeveloperPath!
7476
let toolchains = xcodeDeveloper.appending(components: "Toolchains")
@@ -90,6 +92,7 @@ final class ToolchainRegistryTests: XCTestCase {
9092
XCTAssertEqual(tr1.toolchains.count, 1)
9193

9294
let tr = ToolchainRegistry(fs)
95+
tr.darwinToolchainOverride = nil
9396

9497
XCTAssertEqual(tr.default?.identifier, ToolchainRegistry.darwinDefaultToolchainIdentifier)
9598
XCTAssertEqual(tr.default?.path, toolchains.appending(component: "XcodeDefault.xctoolchain"))
@@ -161,6 +164,11 @@ final class ToolchainRegistryTests: XCTestCase {
161164
let tc = Toolchain(path, fs)
162165
XCTAssertNotNil(tc)
163166
XCTAssertEqual(tc?.identifier, "org.fake.explicit")
167+
168+
let overrideReg = ToolchainRegistry(fs)
169+
overrideReg.darwinToolchainOverride = "org.fake.global.B"
170+
XCTAssertEqual(overrideReg.darwinToolchainIdentifier, "org.fake.global.B")
171+
XCTAssertEqual(overrideReg.default?.identifier, "org.fake.global.B")
164172
#endif
165173
}
166174

Tests/SKSwiftPMWorkspaceTests/SwiftPMWorkspaceTests.swift

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,37 @@ final class SwiftPMWorkspaceTests: XCTestCase {
187187
checkNot(bcxx.asString, arguments: arguments)
188188
check("-o", build.appending(components: "lib.build", "a.cpp.o").asString, arguments: arguments)
189189
}
190+
191+
func testDeploymentTargetSwift() {
192+
// FIXME: should be possible to use InMemoryFileSystem.
193+
let fs = localFileSystem
194+
let tempDir = try! TemporaryDirectory(removeTreeOnDeinit: true)
195+
try! fs.createFiles(root: tempDir.path, files: [
196+
"pkg/Sources/lib/a.swift": "",
197+
"pkg/Package.swift": """
198+
// swift-tools-version:5.0
199+
import PackageDescription
200+
let package = Package(name: "a",
201+
platforms: [.macOS(.v10_13)],
202+
products: [], dependencies: [],
203+
targets: [.target(name: "lib", dependencies: [])])
204+
"""
205+
])
206+
let packageRoot = tempDir.path.appending(component: "pkg")
207+
let ws = try! SwiftPMWorkspace(
208+
workspacePath: packageRoot,
209+
toolchainRegistry: ToolchainRegistry.shared,
210+
fileSystem: fs)!
211+
212+
let aswift = packageRoot.appending(components: "Sources", "lib", "a.swift")
213+
let arguments = ws.settings(for: aswift.asURL, language: .swift)!.compilerArguments
214+
check("-target", arguments: arguments) // Only one!
215+
#if os(macOS)
216+
check("-target", "x86_64-apple-macosx10.13", arguments: arguments)
217+
#else
218+
check("-target", "x86_64-unknown-linux", arguments: arguments)
219+
#endif
220+
}
190221
}
191222

192223
private func checkNot(

Tests/SKSwiftPMWorkspaceTests/XCTestManifests.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
import XCTest
33

44
extension SwiftPMWorkspaceTests {
5-
// DO NOT MODIFY: This is autogenerated, use:
5+
// DO NOT MODIFY: This is autogenerated, use:
66
// `swift test --generate-linuxmain`
77
// to regenerate.
88
static let __allTests__SwiftPMWorkspaceTests = [
99
("testBasicCXXArgs", testBasicCXXArgs),
1010
("testBasicSwiftArgs", testBasicSwiftArgs),
11+
("testDeploymentTargetSwift", testDeploymentTargetSwift),
1112
("testMultiFileSwift", testMultiFileSwift),
1213
("testMultiTargetSwift", testMultiTargetSwift),
1314
]

0 commit comments

Comments
 (0)