Skip to content

Revert "Use platform_version to pass deployment target information to the linker" #218

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 21, 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
69 changes: 40 additions & 29 deletions Sources/SwiftDriver/Jobs/DarwinToolchain+LinkerSupport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
//
//===----------------------------------------------------------------------===//
import TSCBasic
import TSCUtility
import SwiftOptions

extension DarwinToolchain {
Expand Down Expand Up @@ -113,36 +112,49 @@ extension DarwinToolchain {
commandLine.appendPath(clangRTPath)
}

private func addPlatformVersionArg(to commandLine: inout [Job.ArgTemplate],
for triple: Triple, sdkPath: VirtualPath?) {
assert(triple.isDarwin)
let platformName = triple.darwinPlatform!.linkerPlatformName
let platformVersion = triple.darwinLinkerPlatformVersion
let sdkVersion: Version
if let sdkPath = sdkPath,
let sdkInfo = getTargetSDKInfo(sdkPath: sdkPath) {
sdkVersion = sdkInfo.sdkVersion(for: triple)
} else {
sdkVersion = Version(0, 0, 0)
}

commandLine.append(.flag("-platform_version"))
commandLine.append(.flag(platformName))
commandLine.append(.flag(platformVersion.description))
commandLine.append(.flag(sdkVersion.description))
}

private func addDeploymentTargetArgs(
to commandLine: inout [Job.ArgTemplate],
targetTriple: Triple,
targetVariantTriple: Triple?,
sdkPath: VirtualPath?
targetVariantTriple: Triple?
) {
addPlatformVersionArg(to: &commandLine, for: targetTriple, sdkPath: sdkPath)
if let variantTriple = targetVariantTriple {
assert(targetTriple.isValidForZipperingWithTriple(variantTriple))
addPlatformVersionArg(to: &commandLine, for: variantTriple,
sdkPath: sdkPath)
// FIXME: Properly handle deployment targets.

let flag: String

switch targetTriple.darwinPlatform! {
case .iOS(.device):
flag = "-iphoneos_version_min"
case .iOS(.simulator):
flag = "-ios_simulator_version_min"
case .iOS(.catalyst):
flag = "-maccatalyst_version_min"
case .macOS:
flag = "-macosx_version_min"
case .tvOS(.device):
flag = "-tvos_version_min"
case .tvOS(.simulator):
flag = "-tvos_simulator_version_min"
case .watchOS(.device):
flag = "-watchos_version_min"
case .watchOS(.simulator):
flag = "-watchos_simulator_version_min"
}

commandLine.appendFlag(flag)
commandLine.appendFlag(targetTriple.version().description)

if let variant = targetVariantTriple {
if targetTriple.isiOS {
assert(targetTriple.isValidForZipperingWithTriple(variant))
assert(variant.isMacOSX)
commandLine.appendFlag("-macosx_version_min")
commandLine.appendFlag(variant.version().description)
} else {
assert(targetTriple.isValidForZipperingWithTriple(variant))
assert(variant.isMacCatalyst)
commandLine.appendFlag("-maccatalyst_version_min")
commandLine.appendFlag(variant.version().description)
}
}
}

Expand Down Expand Up @@ -272,8 +284,7 @@ extension DarwinToolchain {
addDeploymentTargetArgs(
to: &commandLine,
targetTriple: targetTriple,
targetVariantTriple: targetVariantTriple,
sdkPath: try sdkPath.map(VirtualPath.init(path:))
targetVariantTriple: targetVariantTriple
)
try addProfileGenerationArgs(
to: &commandLine,
Expand Down
14 changes: 7 additions & 7 deletions Sources/SwiftDriver/Toolchains/DarwinToolchain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public final class DarwinToolchain: Toolchain {
case .iOSVersionAboveMaximumDeploymentTarget(let version):
return "iOS \(version) does not support 32-bit programs"
case .unsupportedTargetVariant(variant: let variant):
return "unsupported '\(variant.isiOS ? "-target-variant" : "-target")' value '\(variant.triple)'; use 'ios-macabi' instead"
return "unsupported '\(variant.isiOS ? "-target" : "-target-variant")' value '\(variant)'; use 'ios-macabi' instead"
case .argumentNotSupported(let argument):
return "\(argument) is no longer supported for Apple platforms"
case .darwinOnlySupportsLibCxx:
Expand Down Expand Up @@ -208,14 +208,14 @@ public final class DarwinToolchain: Toolchain {
}
}

struct DarwinSDKInfo: Decodable {
private enum CodingKeys: String, CodingKey {
private struct DarwinSDKInfo: Decodable {
enum CodingKeys: String, CodingKey {
case version = "Version"
case versionMap = "VersionMap"
}

struct VersionMap: Decodable {
private enum CodingKeys: String, CodingKey {
enum CodingKeys: String, CodingKey {
case macOSToCatalystMapping = "macOS_iOSMac"
}

Expand All @@ -242,8 +242,8 @@ public final class DarwinToolchain: Toolchain {
}
}

private var version: Version
private var versionMap: VersionMap
var version: Version
var versionMap: VersionMap

init(from decoder: Decoder) throws {
let keyedContainer = try decoder.container(keyedBy: CodingKeys.self)
Expand Down Expand Up @@ -272,7 +272,7 @@ public final class DarwinToolchain: Toolchain {
// SDK info is computed lazily. This should not generally be accessed directly.
private var _sdkInfo: DarwinSDKInfo? = nil

func getTargetSDKInfo(sdkPath: VirtualPath) -> DarwinSDKInfo? {
private func getTargetSDKInfo(sdkPath: VirtualPath) -> DarwinSDKInfo? {
if let info = _sdkInfo {
return info
} else {
Expand Down
70 changes: 0 additions & 70 deletions Sources/SwiftDriver/Utilities/Triple+Platforms.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,29 +102,6 @@ public enum DarwinPlatform: Hashable {
}
}

/// The name the linker uses to identify this platform.
public var linkerPlatformName: String {
switch self {
case .macOS:
return "macos"
case .iOS(.device):
return "ios"
case .iOS(.simulator):
return "ios-simulator"
case .iOS(.catalyst):
return "mac-catalyst"
case .tvOS(.device):
return "tvos"
case .tvOS(.simulator):
return "tvos-simulator"
case .watchOS(.device):
return "watchos"
case .watchOS(.simulator):
return "watchos-simulator"
}
}


/// The name used to identify this platform in compiler_rt file names.
public var libraryNameSuffix: String {
switch self {
Expand Down Expand Up @@ -207,53 +184,6 @@ extension Triple {
}
}

// The Darwin platform version used for linking.
public var darwinLinkerPlatformVersion: Version {
precondition(self.isDarwin)
switch darwinPlatform! {
case .macOS:
// The integrated driver falls back to `osVersion` for ivalid macOS
// versions, this decision might be worth revisiting.
let macVersion = _macOSVersion ?? osVersion
// The first deployment of arm64 for macOS is version 11
if macVersion.major < 11 && arch == .aarch64 {
return Version(11, 0, 0)
}

return macVersion
case .iOS(.catalyst):
// Mac Catalyst on arm was introduced with an iOS deployment target of
// 14.0; the linker doesn't want to see a deployment target before that.
if _iOSVersion.major < 14 && arch == .aarch64 {
return Version(14, 0, 0)
}

// Mac Catalyst was introduced with an iOS deployment target of 13.0;
// the linker doesn't want to see a deployment target before that.
if _iOSVersion.major < 13 {
return Version(13, 0, 0)
}

return _iOSVersion
case .iOS(.device), .iOS(.simulator), .tvOS(_):
// The first deployment of arm64 simulators is iOS/tvOS 14.0;
// the linker doesn't want to see a deployment target before that.
if _isSimulatorEnvironment && _iOSVersion.major < 14 && arch == .aarch64 {
return Version(14, 0, 0)
}

return _iOSVersion
case .watchOS(_):
// The first deployment of arm64 simulators is watchOS 7;
// the linker doesn't want to see a deployment target before that.
if _isSimulatorEnvironment && osVersion.major < 7 && arch == .aarch64 {
return Version(7, 0, 0)
}

return osVersion
}
}

/// The platform name, i.e. the name clang uses to identify this target in its
/// resource directory.
///
Expand Down
Loading