forked from cx-org/CombineX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPackage.swift
137 lines (111 loc) · 4.11 KB
/
Package.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
// swift-tools-version:5.0
import PackageDescription
// MARK: - Package
let package = Package(
name: "CombineX",
platforms: [
.macOS(.v10_10), .iOS(.v8), .tvOS(.v9), .watchOS(.v2),
],
products: [
// Open source implementation of Combine.
.library(name: "CombineX", targets: ["CombineX", "CXFoundation"]),
// Virtual Combine interface.
.library(name: "CXShim", targets: ["CXShim"]),
// Test infrastructure for Combine, built on CXShim.
.library(name: "CXTest", targets: ["CXTest"])
],
dependencies: [
.package(url: "https://github.com/ddddxxx/Semver.git", .upToNextMinor(from: "0.2.1")),
],
targets: [
.target(name: "CXLibc"),
.target(name: "CXUtility", dependencies: ["CXLibc"]),
.target(name: "CXNamespace"),
.target(name: "CombineX", dependencies: ["CXLibc", "CXUtility", "CXNamespace"]),
.target(name: "CXFoundation", dependencies: ["CXUtility", "CXNamespace", "CombineX"]),
.target(name: "CXCompatible", dependencies: ["CXNamespace"]),
.target(name: "CXShim", dependencies: [/* depends on concrete combine implementation */]),
.target(name: "CXTest", dependencies: ["CXUtility", "CXShim"]),
],
swiftLanguageVersions: [
.v5,
]
)
// MARK: - Combine Implementations
enum CombineImplementation {
case combine
case combineX
case openCombine
static var `default`: CombineImplementation {
#if canImport(Combine)
return .combine
#else
return .combineX
#endif
}
init?(_ description: String) {
let desc = description.lowercased().filter { $0.isLetter }
switch desc {
case "combine": self = .combine
case "combinex": self = .combineX
case "opencombine": self = .openCombine
default: return nil
}
}
var swiftSettings: [SwiftSetting] {
switch self {
case .combine: return [.define("USE_COMBINE")]
case .combineX: return [.define("USE_COMBINEX")]
case .openCombine: return [.define("USE_OPEN_COMBINE")]
}
}
var extraPackageDependencies: [Package.Dependency] {
switch self {
case .openCombine: return [.package(url: "https://github.com/broadwaylamb/OpenCombine", .upToNextMinor(from: "0.11.0"))]
default: return []
}
}
var shimTargetDependencies: [Target.Dependency] {
switch self {
case .combine: return ["CXCompatible"]
case .combineX: return ["CombineX", "CXFoundation"]
case .openCombine: return ["OpenCombine", "OpenCombineDispatch"]
}
}
}
// MARK: - Helpers
extension ProcessInfo {
var combineImplementation: CombineImplementation {
return environment["CX_COMBINE_IMPLEMENTATION"].flatMap(CombineImplementation.init) ?? .default
}
var isCI: Bool {
return (environment["CX_CONTINUOUS_INTEGRATION"] as NSString?)?.boolValue ?? false
}
}
extension Optional where Wrapped: RangeReplaceableCollection {
mutating func append(contentsOf newElements: [Wrapped.Element]) {
if newElements.isEmpty { return }
if let wrapped = self {
self = wrapped + newElements
} else {
self = .init(newElements)
}
}
}
// MARK: - Config Package
import Foundation
var combineImp = ProcessInfo.processInfo.combineImplementation
var isCI = ProcessInfo.processInfo.isCI
// uncommenet the following line to test against combine
//combineImp = .combine; isCI = true
package.dependencies.append(contentsOf: combineImp.extraPackageDependencies)
let shimTarget = package.targets.first(where: { $0.name == "CXShim" })!
shimTarget.dependencies = combineImp.shimTargetDependencies
shimTarget.swiftSettings.append(contentsOf: combineImp.swiftSettings)
if combineImp == .combine && isCI {
package.platforms = [.macOS("10.15"), .iOS("13.0"), .tvOS("13.0"), .watchOS("6.0")]
} else {
#if compiler(>=5.3)
package.platforms = [.macOS(.v10_10), .iOS(.v9), .tvOS(.v9), .watchOS(.v2)]
#endif
}