|
10 | 10 | // |
11 | 11 | //===----------------------------------------------------------------------===// |
12 | 12 | import TSCBasic |
| 13 | +import SwiftOptions |
13 | 14 |
|
14 | 15 | /// Toolchain for Darwin-based platforms, such as macOS and iOS. |
15 | 16 | /// |
@@ -119,4 +120,62 @@ public final class DarwinToolchain: Toolchain { |
119 | 120 | \(isShared ? "_dynamic.dylib" : ".a") |
120 | 121 | """ |
121 | 122 | } |
| 123 | + |
| 124 | + public enum ToolchainValidationError: Error, DiagnosticData { |
| 125 | + case osVersionBelowMinimumDeploymentTarget(String) |
| 126 | + case iOSVersionAboveMaximumDeploymentTarget(Int) |
| 127 | + case unsupportedTargetVariant(variant: Triple) |
| 128 | + |
| 129 | + public var description: String { |
| 130 | + switch self { |
| 131 | + case .osVersionBelowMinimumDeploymentTarget(let target): |
| 132 | + return "Swift requires a minimum deployment target of \(target)" |
| 133 | + case .iOSVersionAboveMaximumDeploymentTarget(let version): |
| 134 | + return "iOS \(version) does not support 32-bit programs" |
| 135 | + case .unsupportedTargetVariant(variant: let variant): |
| 136 | + return "unsupported '\(variant.isiOS ? "-target" : "-target-variant")' value '\(variant)'; use 'ios-macabi' instead" |
| 137 | + } |
| 138 | + } |
| 139 | + } |
| 140 | + |
| 141 | + public func validateArgs(_ parsedOptions: inout ParsedOptions, |
| 142 | + targetTriple: Triple, |
| 143 | + targetVariantTriple: Triple?) throws { |
| 144 | + // TODO: Validating arclite library path when link-objc-runtime. |
| 145 | + |
| 146 | + // Validating apple platforms deployment targets. |
| 147 | + try validateDeploymentTarget(&parsedOptions, targetTriple: targetTriple) |
| 148 | + if let targetVariantTriple = targetVariantTriple, |
| 149 | + !targetTriple.isValidForZipperingWithTriple(targetVariantTriple) { |
| 150 | + throw ToolchainValidationError.unsupportedTargetVariant(variant: targetVariantTriple) |
| 151 | + } |
| 152 | + |
| 153 | + // TODO: Validating darwin unsupported -static-stdlib argument. |
| 154 | + // TODO: If a C++ standard library is specified, it has to be libc++. |
| 155 | + } |
| 156 | + |
| 157 | + func validateDeploymentTarget(_ parsedOptions: inout ParsedOptions, |
| 158 | + targetTriple: Triple) throws { |
| 159 | + // Check minimum supported OS versions. |
| 160 | + if targetTriple.isMacOSX, |
| 161 | + targetTriple.version(for: .macOS) < Triple.Version(10, 9, 0) { |
| 162 | + throw ToolchainValidationError.osVersionBelowMinimumDeploymentTarget("OS X 10.9") |
| 163 | + } |
| 164 | + // tvOS triples are also iOS, so check it first. |
| 165 | + else if targetTriple.isTvOS, |
| 166 | + targetTriple.version(for: .tvOS(.device)) < Triple.Version(9, 0, 0) { |
| 167 | + throw ToolchainValidationError.osVersionBelowMinimumDeploymentTarget("tvOS 9.0") |
| 168 | + } else if targetTriple.isiOS { |
| 169 | + if targetTriple.version(for: .iOS(.device)) < Triple.Version(7, 0, 0) { |
| 170 | + throw ToolchainValidationError.osVersionBelowMinimumDeploymentTarget("iOS 7") |
| 171 | + } |
| 172 | + if targetTriple.arch?.is32Bit == true, |
| 173 | + targetTriple.version(for: .iOS(.device)) >= Triple.Version(11, 0, 0) { |
| 174 | + throw ToolchainValidationError.iOSVersionAboveMaximumDeploymentTarget(targetTriple.version(for: .iOS(.device)).major) |
| 175 | + } |
| 176 | + } else if targetTriple.isWatchOS, |
| 177 | + targetTriple.version(for: .watchOS(.device)) < Triple.Version(2, 0, 0) { |
| 178 | + throw ToolchainValidationError.osVersionBelowMinimumDeploymentTarget("watchOS 2.0") |
| 179 | + } |
| 180 | + } |
122 | 181 | } |
0 commit comments