Skip to content

Use -print-target-info instead of a hardcoded triple #2883

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
Aug 25, 2020
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
1 change: 1 addition & 0 deletions Sources/Build/XCFrameworkInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ See http://swift.org/CONTRIBUTORS.txt for Swift project authors
*/

import TSCBasic
import TSCUtility
import PackageModel
import SPMBuildCore
import Foundation
Expand Down
7 changes: 6 additions & 1 deletion Sources/PackageLoading/ManifestLoader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,7 @@ public final class ManifestLoader: ManifestLoaderProtocol {
}
}

private static var _hostTriple: Triple?
private static var _packageDescriptionMinimumDeploymentTarget: String?

/// Parse the manifest at the given path to JSON.
Expand Down Expand Up @@ -660,11 +661,15 @@ public final class ManifestLoader: ManifestLoaderProtocol {

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

cmd += compilerFlags
Expand Down
3 changes: 1 addition & 2 deletions Sources/SPMBuildCore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ add_library(SPMBuildCore
BuildSystem.swift
BuiltTestProduct.swift
Sanitizers.swift
Toolchain.swift
Triple.swift)
Toolchain.swift)
# NOTE(compnerd) workaround for CMake not setting up include flags yet
set_target_properties(SPMBuildCore PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})
Expand Down
14 changes: 7 additions & 7 deletions Tests/BuildTests/BuildPlanTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ final class BuildPlanTests: XCTestCase {
toolchain: SPMBuildCore.Toolchain = MockToolchain(),
flags: BuildFlags = BuildFlags(),
shouldLinkStaticSwiftStdlib: Bool = false,
destinationTriple: SPMBuildCore.Triple = hostTriple,
destinationTriple: TSCUtility.Triple = hostTriple,
indexStoreMode: BuildParameters.IndexStoreMode = .off,
useExplicitModuleBuild: Bool = false
) -> BuildParameters {
Expand All @@ -81,7 +81,7 @@ final class BuildPlanTests: XCTestCase {
}

func mockBuildParameters(environment: BuildEnvironment) -> BuildParameters {
let triple: SPMBuildCore.Triple
let triple: TSCUtility.Triple
switch environment.platform {
case .macOS:
triple = Triple.macOS
Expand Down Expand Up @@ -1869,7 +1869,7 @@ final class BuildPlanTests: XCTestCase {
)
XCTAssertNoDiagnostics(diagnostics)

func createResult(for dest: SPMBuildCore.Triple) throws -> BuildPlanResult {
func createResult(for dest: TSCUtility.Triple) throws -> BuildPlanResult {
return BuildPlanResult(plan: try BuildPlan(
buildParameters: mockBuildParameters(destinationTriple: dest),
graph: graph, diagnostics: diagnostics,
Expand Down Expand Up @@ -2313,7 +2313,7 @@ final class BuildPlanTests: XCTestCase {
])
}

func testBinaryTargets(platform: String, arch: String, destinationTriple: SPMBuildCore.Triple)
func testBinaryTargets(platform: String, arch: String, destinationTriple: TSCUtility.Triple)
throws {
let fs = InMemoryFileSystem(emptyFiles:
"/Pkg/Sources/exe/main.swift",
Expand Down Expand Up @@ -2458,9 +2458,9 @@ final class BuildPlanTests: XCTestCase {

func testBinaryTargets() throws {
try testBinaryTargets(platform: "macos", arch: "x86_64", destinationTriple: .macOS)
let arm64Triple = try SPMBuildCore.Triple("arm64-apple-macosx")
let arm64Triple = try TSCUtility.Triple("arm64-apple-macosx")
try testBinaryTargets(platform: "macos", arch: "arm64", destinationTriple: arm64Triple)
let arm64eTriple = try SPMBuildCore.Triple("arm64e-apple-macosx")
let arm64eTriple = try TSCUtility.Triple("arm64e-apple-macosx")
try testBinaryTargets(platform: "macos", arch: "arm64e", destinationTriple: arm64eTriple)
}

Expand Down Expand Up @@ -2594,7 +2594,7 @@ fileprivate extension TargetBuildDescription {
}
}

fileprivate extension SPMBuildCore.Triple {
fileprivate extension TSCUtility.Triple {
static let x86_64Linux = try! Triple("x86_64-unknown-linux-gnu")
static let arm64Linux = try! Triple("aarch64-unknown-linux-gnu")
static let arm64Android = try! Triple("aarch64-unknown-linux-android")
Expand Down
1 change: 1 addition & 0 deletions swift-tools-support-core/Sources/TSCUtility/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ add_library(TSCUtility
SimplePersistence.swift
StringExtensions.swift
StringMangling.swift
Triple.swift
URL.swift
Verbosity.swift
Version.swift
Expand Down