Skip to content

Commit a938092

Browse files
authored
Use -print-target-info instead of a hardcoded triple (swiftlang#2932)
(cherry picked from commit 9c8b37c) rdar://problem/67948987
1 parent 91bdc78 commit a938092

File tree

6 files changed

+17
-10
lines changed

6 files changed

+17
-10
lines changed

Sources/Build/XCFrameworkInfo.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ See http://swift.org/CONTRIBUTORS.txt for Swift project authors
99
*/
1010

1111
import TSCBasic
12+
import TSCUtility
1213
import PackageModel
1314
import SPMBuildCore
1415
import Foundation

Sources/PackageLoading/ManifestLoader.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,7 @@ public final class ManifestLoader: ManifestLoaderProtocol {
494494
}
495495
}
496496

497+
private static var _hostTriple: Triple?
497498
private static var _packageDescriptionMinimumDeploymentTarget: String?
498499

499500
/// Parse the manifest at the given path to JSON.
@@ -558,11 +559,15 @@ public final class ManifestLoader: ManifestLoaderProtocol {
558559

559560
// Use the same minimum deployment target as the PackageDescription library (with a fallback of 10.15).
560561
#if os(macOS)
562+
if Self._hostTriple == nil {
563+
Self._hostTriple = Triple.getHostTriple(usingSwiftCompiler: resources.swiftCompiler)
564+
}
565+
let triple = Self._hostTriple!
561566
if Self._packageDescriptionMinimumDeploymentTarget == nil {
562567
Self._packageDescriptionMinimumDeploymentTarget = (try MinimumDeploymentTarget.computeMinimumDeploymentTarget(of: macOSPackageDescriptionPath))?.versionString ?? "10.15"
563568
}
564569
let version = Self._packageDescriptionMinimumDeploymentTarget!
565-
cmd += ["-target", "x86_64-apple-macosx\(version)"]
570+
cmd += ["-target", "\(triple.tripleString(forPlatformVersion: version))"]
566571
#endif
567572

568573
cmd += compilerFlags

Sources/SPMBuildCore/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ add_library(SPMBuildCore
1111
BuildSystem.swift
1212
BuiltTestProduct.swift
1313
Sanitizers.swift
14-
Toolchain.swift
15-
Triple.swift)
14+
Toolchain.swift)
1615
# NOTE(compnerd) workaround for CMake not setting up include flags yet
1716
set_target_properties(SPMBuildCore PROPERTIES
1817
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})

Tests/BuildTests/BuildPlanTests.swift

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ final class BuildPlanTests: XCTestCase {
5959
config: BuildConfiguration = .debug,
6060
flags: BuildFlags = BuildFlags(),
6161
shouldLinkStaticSwiftStdlib: Bool = false,
62-
destinationTriple: Triple = hostTriple,
62+
destinationTriple: TSCUtility.Triple = hostTriple,
6363
indexStoreMode: BuildParameters.IndexStoreMode = .off
6464
) -> BuildParameters {
6565
return BuildParameters(
@@ -75,7 +75,7 @@ final class BuildPlanTests: XCTestCase {
7575
}
7676

7777
func mockBuildParameters(environment: BuildEnvironment) -> BuildParameters {
78-
let triple: Triple
78+
let triple: TSCUtility.Triple
7979
switch environment.platform {
8080
case .macOS:
8181
triple = Triple.macOS
@@ -1765,7 +1765,7 @@ final class BuildPlanTests: XCTestCase {
17651765
)
17661766
XCTAssertNoDiagnostics(diagnostics)
17671767

1768-
func createResult(for dest: Triple) throws -> BuildPlanResult {
1768+
func createResult(for dest: TSCUtility.Triple) throws -> BuildPlanResult {
17691769
return BuildPlanResult(plan: try BuildPlan(
17701770
buildParameters: mockBuildParameters(destinationTriple: dest),
17711771
graph: graph, diagnostics: diagnostics,
@@ -2207,7 +2207,8 @@ final class BuildPlanTests: XCTestCase {
22072207
])
22082208
}
22092209

2210-
func testBinaryTargets(platform: String, arch: String, destinationTriple: Triple) throws {
2210+
func testBinaryTargets(platform: String, arch: String, destinationTriple: TSCUtility.Triple)
2211+
throws {
22112212
let fs = InMemoryFileSystem(emptyFiles:
22122213
"/Pkg/Sources/exe/main.swift",
22132214
"/Pkg/Sources/Library/Library.swift",
@@ -2345,9 +2346,9 @@ final class BuildPlanTests: XCTestCase {
23452346

23462347
func testBinaryTargets() throws {
23472348
try testBinaryTargets(platform: "macos", arch: "x86_64", destinationTriple: .macOS)
2348-
let arm64Triple = try Triple("arm64-apple-macosx")
2349+
let arm64Triple = try TSCUtility.Triple("arm64-apple-macosx")
23492350
try testBinaryTargets(platform: "macos", arch: "arm64", destinationTriple: arm64Triple)
2350-
let arm64eTriple = try Triple("arm64e-apple-macosx")
2351+
let arm64eTriple = try TSCUtility.Triple("arm64e-apple-macosx")
23512352
try testBinaryTargets(platform: "macos", arch: "arm64e", destinationTriple: arm64eTriple)
23522353
}
23532354

@@ -2481,7 +2482,7 @@ fileprivate extension TargetBuildDescription {
24812482
}
24822483
}
24832484

2484-
fileprivate extension Triple {
2485+
fileprivate extension TSCUtility.Triple {
24852486
static let x86_64Linux = try! Triple("x86_64-unknown-linux-gnu")
24862487
static let arm64Linux = try! Triple("aarch64-unknown-linux-gnu")
24872488
static let arm64Android = try! Triple("aarch64-unknown-linux-android")

swift-tools-support-core/Sources/TSCUtility/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ add_library(TSCUtility
2929
SimplePersistence.swift
3030
StringExtensions.swift
3131
StringMangling.swift
32+
Triple.swift
3233
URL.swift
3334
Verbosity.swift
3435
Version.swift

0 commit comments

Comments
 (0)