Skip to content

Commit b048a7e

Browse files
committed
Expose the build triple of a BuildTarget in SourceKitLSPAPI
1 parent 51e7155 commit b048a7e

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

Sources/SourceKitLSPAPI/BuildDescription.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,18 @@ import class Build.ClangTargetBuildDescription
2323
import class Build.SwiftTargetBuildDescription
2424
import struct PackageGraph.ResolvedTarget
2525
import struct PackageGraph.ModulesGraph
26+
import enum PackageGraph.BuildTriple
27+
28+
public typealias BuildTriple = PackageGraph.BuildTriple
2629

2730
public protocol BuildTarget {
2831
var sources: [URL] { get }
2932

3033
/// The name of the target. It should be possible to build a target by passing this name to `swift build --target`
3134
var name: String { get }
3235

36+
var buildTriple: BuildTriple { get }
37+
3338
/// Whether the target is part of the root package that the user opened or if it's part of a package dependency.
3439
var isPartOfRootPackage: Bool { get }
3540

@@ -53,6 +58,10 @@ private struct WrappedClangTargetBuildDescription: BuildTarget {
5358
return description.clangTarget.name
5459
}
5560

61+
public var buildTriple: BuildTriple {
62+
return description.target.buildTriple
63+
}
64+
5665
public func compileArguments(for fileURL: URL) throws -> [String] {
5766
let filePath = try resolveSymlinks(try AbsolutePath(validating: fileURL.path))
5867
let commandLine = try description.emitCommandLine(for: filePath)
@@ -74,6 +83,10 @@ private struct WrappedSwiftTargetBuildDescription: BuildTarget {
7483
return description.target.name
7584
}
7685

86+
public var buildTriple: BuildTriple {
87+
return description.target.buildTriple
88+
}
89+
7790
var sources: [URL] {
7891
return description.sources.map { URL(fileURLWithPath: $0.pathString) }
7992
}

Sources/SourceKitLSPAPI/PluginTargetBuildDescription.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import struct PackageGraph.ResolvedTarget
1717
private import class PackageLoading.ManifestLoader
1818
internal import struct PackageModel.ToolsVersion
1919
private import class PackageModel.UserToolchain
20+
import enum PackageGraph.BuildTriple
2021

2122
struct PluginTargetBuildDescription: BuildTarget {
2223
private let target: ResolvedTarget
@@ -38,6 +39,10 @@ struct PluginTargetBuildDescription: BuildTarget {
3839
return target.name
3940
}
4041

42+
var buildTriple: BuildTriple {
43+
return target.buildTriple
44+
}
45+
4146
func compileArguments(for fileURL: URL) throws -> [String] {
4247
// FIXME: This is very odd and we should clean this up by merging `ManifestLoader` and `DefaultPluginScriptRunner` again.
4348
let loader = ManifestLoader(toolchain: try UserToolchain(swiftSDK: .hostSwiftSDK()))

0 commit comments

Comments
 (0)