Skip to content

Use Triple equality for finding matching binaries #4270

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
Apr 1, 2022
Merged
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
20 changes: 14 additions & 6 deletions Sources/SPMBuildCore/BinaryTarget+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ extension BinaryTarget {
}

public func parseArtifactArchives(for triple: Triple, fileSystem: FileSystem) throws -> [ExecutableInfo] {
// The host triple might contain a version which we don't want to take into account here.
let versionLessTriple = try triple.withoutVersion()
// We return at most a single variant of each artifact.
let metadata = try ArtifactsArchiveMetadata.parse(fileSystem: fileSystem, rootPath: self.artifactPath)
// Currently we filter out everything except executables.
Expand All @@ -68,19 +70,25 @@ extension BinaryTarget {
return executables.flatMap { entry in
// FIXME: this filter needs to become more sophisticated
entry.value.variants.filter {
let tripleStrings = $0.supportedTriples.map { $0.tripleString }
if triple.isDarwin() {
return tripleStrings.contains(triple.tripleString(forPlatformVersion: ""))
} else {
return tripleStrings.contains(triple.tripleString)
}
return $0.supportedTriples.contains(versionLessTriple)
}.map{
ExecutableInfo(name: entry.key, executablePath: AbsolutePath($0.path, relativeTo: self.artifactPath))
}
}
}
}

fileprivate extension Triple {
func withoutVersion() throws -> Triple {
if isDarwin() {
let stringWithoutVersion = tripleString(forPlatformVersion: "")
return try Triple(stringWithoutVersion)
} else {
return self
}
}
}

fileprivate extension Triple.OS {
/// Returns a representation of the receiver that can be compared with platform strings declared in an XCFramework.
var asXCFrameworkPlatformString: String? {
Expand Down