Skip to content

Commit b2ff126

Browse files
authored
[SourceKitLSP] Start using SwiftPM independent BuildDestination typ… (#7884)
…e in `BuildTarget` API ### Motivation: `BuildTriple` is going away to it's as good time as any to introduce a new type to be used by SourceKit-LSP. ### Modifications: - Adds a new `BuildDestination` API to be used by SourceKit-LSP instead of `BuildTriple` - Removes `BuildTriple` use from `BuildTarget` ### Result: `BuildTriple` is no longer used by SourceKit-LSP.
1 parent 8975fb5 commit b2ff126

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

Sources/SourceKitLSPAPI/BuildDescription.swift

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@ import class Build.ClangModuleBuildDescription
2323
import class Build.SwiftModuleBuildDescription
2424
import struct PackageGraph.ResolvedModule
2525
import struct PackageGraph.ModulesGraph
26-
import enum PackageGraph.BuildTriple
2726
internal import class PackageModel.UserToolchain
2827

29-
public typealias BuildTriple = PackageGraph.BuildTriple
28+
public enum BuildDestination {
29+
case host
30+
case target
31+
}
3032

3133
public protocol BuildTarget {
3234
/// Source files in the target
@@ -38,7 +40,7 @@ public protocol BuildTarget {
3840
/// The name of the target. It should be possible to build a target by passing this name to `swift build --target`
3941
var name: String { get }
4042

41-
var buildTriple: BuildTriple { get }
43+
var destination: BuildDestination { get }
4244

4345
/// Whether the target is part of the root package that the user opened or if it's part of a package dependency.
4446
var isPartOfRootPackage: Bool { get }
@@ -70,8 +72,8 @@ private struct WrappedClangTargetBuildDescription: BuildTarget {
7072
return description.clangTarget.name
7173
}
7274

73-
public var buildTriple: BuildTriple {
74-
return description.target.buildTriple
75+
public var destination: BuildDestination {
76+
return description.destination == .host ? .host : .target
7577
}
7678

7779
public func compileArguments(for fileURL: URL) throws -> [String] {
@@ -95,8 +97,8 @@ private struct WrappedSwiftTargetBuildDescription: BuildTarget {
9597
return description.target.name
9698
}
9799

98-
public var buildTriple: BuildTriple {
99-
return description.target.buildTriple
100+
public var destination: BuildDestination {
101+
return description.destination == .host ? .host : .target
100102
}
101103

102104
var sources: [URL] {

Sources/SourceKitLSPAPI/PluginTargetBuildDescription.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import struct PackageGraph.ResolvedModule
1919
private import class PackageLoading.ManifestLoader
2020
internal import struct PackageModel.ToolsVersion
2121
internal import protocol PackageModel.Toolchain
22-
import enum PackageGraph.BuildTriple
2322

2423
struct PluginTargetBuildDescription: BuildTarget {
2524
private let target: ResolvedModule
@@ -45,8 +44,9 @@ struct PluginTargetBuildDescription: BuildTarget {
4544
return target.name
4645
}
4746

48-
var buildTriple: BuildTriple {
49-
return target.buildTriple
47+
var destination: BuildDestination {
48+
// Plugins are always built for the host.
49+
.host
5050
}
5151

5252
func compileArguments(for fileURL: URL) throws -> [String] {

0 commit comments

Comments
 (0)