Skip to content

Commit da5df4c

Browse files
committed
Use versioned host triples for non-Darwin platforms
Only Darwin platforms have the property of defaulting to the manifest-specified version in the target triple. For other platforms, revert to the previous behavior of including the version.
1 parent ce5fdf1 commit da5df4c

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

Sources/Basics/Triple+Basics.swift

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,15 @@ extension Triple {
8686

8787
/// Determine the versioned host triple using the Swift compiler.
8888
public static func getVersionedHostTriple(usingSwiftCompiler swiftCompiler: AbsolutePath) throws -> Triple {
89-
try Self.getHostTriple(usingSwiftCompiler: swiftCompiler, versioned: true)
89+
try Self.getHostTriple(usingSwiftCompiler: swiftCompiler).versionedTriple
9090
}
9191

9292
/// Determine the unversioned host triple using the Swift compiler.
9393
public static func getUnversionedHostTriple(usingSwiftCompiler swiftCompiler: AbsolutePath) throws -> Triple {
94-
try Self.getHostTriple(usingSwiftCompiler: swiftCompiler, versioned: false)
94+
try Self.getHostTriple(usingSwiftCompiler: swiftCompiler).unversionedTriple
9595
}
9696

97-
private static func getHostTriple(usingSwiftCompiler swiftCompiler: AbsolutePath, versioned: Bool) throws -> Triple {
97+
public static func getHostTriple(usingSwiftCompiler swiftCompiler: AbsolutePath) throws -> (versionedTriple: Triple, unversionedTriple: Triple) {
9898
// Call the compiler to get the target info JSON.
9999
let compilerOutput: String
100100
do {
@@ -113,9 +113,11 @@ extension Triple {
113113
)
114114
}
115115
// Get the triple string from the parsed JSON.
116-
let tripleString: String
116+
let versionedTripleString: String
117+
let unversionedTripleString: String
117118
do {
118-
tripleString = try parsedTargetInfo.get("target").get(versioned ? "triple" : "unversionedTriple")
119+
versionedTripleString = try parsedTargetInfo.get("target").get("triple")
120+
unversionedTripleString = try parsedTargetInfo.get("target").get("unversionedTriple")
119121
} catch {
120122
throw InternalError(
121123
"Target info does not contain a triple string (\(error.interpolationDescription)).\nTarget info: \(parsedTargetInfo)"
@@ -124,10 +126,10 @@ extension Triple {
124126

125127
// Parse the triple string.
126128
do {
127-
return try Triple(tripleString)
129+
return try (Triple(versionedTripleString), Triple(unversionedTripleString))
128130
} catch {
129131
throw InternalError(
130-
"Failed to parse triple string (\(error.interpolationDescription)).\nTriple string: \(tripleString)"
132+
"Failed to parse triple string (\(error.interpolationDescription)).\nVersioned triple string: \(versionedTripleString), unversioned triple string \(unversionedTripleString)"
131133
)
132134
}
133135
}

Sources/SPMBuildCore/BuildParameters/BuildParameters.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,13 @@ public struct BuildParameters: Encodable {
173173
testingParameters: Testing = .init(),
174174
apiDigesterMode: APIDigesterMode? = nil
175175
) throws {
176-
// Default to the unversioned triple if none is provided so that we defer to the package's requested deployment target.
177-
let triple = try triple ?? .getUnversionedHostTriple(usingSwiftCompiler: toolchain.swiftCompilerPath)
176+
// Default to the unversioned triple if none is provided so that we defer to the package's requested deployment target, for Darwin platforms. For other platforms, continue to include the version since those don't have the concept of a package-specified version, and the version is meaningful for some platforms including Android and FreeBSD.
177+
let triple = try triple ?? {
178+
let hostTriple = try Triple.getHostTriple(
179+
usingSwiftCompiler: toolchain.swiftCompilerPath)
180+
return hostTriple.versionedTriple.isDarwin() ? hostTriple.unversionedTriple : hostTriple.versionedTriple
181+
}()
182+
178183
self.debuggingParameters = debuggingParameters ?? .init(
179184
triple: triple,
180185
shouldEnableDebuggingEntitlement: configuration == .debug,

0 commit comments

Comments
 (0)