Skip to content

Expose the build triple of a BuildTarget in SourceKitLSPAPI #7555

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Sources/SourceKitLSPAPI/BuildDescription.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,18 @@ import class Build.ClangTargetBuildDescription
import class Build.SwiftTargetBuildDescription
import struct PackageGraph.ResolvedModule
import struct PackageGraph.ModulesGraph
import enum PackageGraph.BuildTriple
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MaxDesiatov Do you prefer to expose the BuildTriple type or would you prefer to define an equivalent BuildTriple type in SourceKitLSPAPI and then map between the two?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now IMO it's best to create public typealias BuildTriple = PackageGraph.BuildTriple in SourceKitLSPAPI, which can be replaced with something more advanced later.


public typealias BuildTriple = PackageGraph.BuildTriple

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

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

var buildTriple: BuildTriple { get }

/// Whether the target is part of the root package that the user opened or if it's part of a package dependency.
var isPartOfRootPackage: Bool { get }

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

public var buildTriple: BuildTriple {
return description.target.buildTriple
}

public func compileArguments(for fileURL: URL) throws -> [String] {
let filePath = try resolveSymlinks(try AbsolutePath(validating: fileURL.path))
let commandLine = try description.emitCommandLine(for: filePath)
Expand All @@ -74,6 +83,10 @@ private struct WrappedSwiftTargetBuildDescription: BuildTarget {
return description.target.name
}

public var buildTriple: BuildTriple {
return description.target.buildTriple
}

var sources: [URL] {
return description.sources.map { URL(fileURLWithPath: $0.pathString) }
}
Expand Down
5 changes: 5 additions & 0 deletions Sources/SourceKitLSPAPI/PluginTargetBuildDescription.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import struct PackageGraph.ResolvedModule
private import class PackageLoading.ManifestLoader
internal import struct PackageModel.ToolsVersion
private import class PackageModel.UserToolchain
import enum PackageGraph.BuildTriple

struct PluginTargetBuildDescription: BuildTarget {
private let target: ResolvedModule
Expand All @@ -38,6 +39,10 @@ struct PluginTargetBuildDescription: BuildTarget {
return target.name
}

var buildTriple: BuildTriple {
return target.buildTriple
}

func compileArguments(for fileURL: URL) throws -> [String] {
// FIXME: This is very odd and we should clean this up by merging `ManifestLoader` and `DefaultPluginScriptRunner` again.
let loader = ManifestLoader(toolchain: try UserToolchain(swiftSDK: .hostSwiftSDK()))
Expand Down