8
8
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
9
9
*/
10
10
11
+ import Foundation
12
+
11
13
/// A target, the basic building block of a Swift package.
12
14
///
13
15
/// Each target contains a set of source files that are compiled into a module or test suite.
@@ -24,6 +26,8 @@ public final class Target {
24
26
case test
25
27
/// A target that adapts a library on the system to work with Swift packages.
26
28
case system
29
+ /// A target that references a binary artifact.
30
+ case _binary = " binary "
27
31
}
28
32
29
33
/// The different types of a target's dependency on another entity.
@@ -56,6 +60,13 @@ public final class Target {
56
60
/// Do not escape the package root; that is, values like `../Foo` or `/Foo` are invalid.
57
61
public var path : String ?
58
62
63
+ /// The url of the binary target.
64
+ public var _url : String ? {
65
+ get { __url }
66
+ set { __url = newValue }
67
+ }
68
+ public var __url : String ?
69
+
59
70
/// The source files in this target.
60
71
///
61
72
/// If this property is `nil`, all valid source files in the target's path will be included and specified paths are relative to the target path.
@@ -136,11 +147,19 @@ public final class Target {
136
147
}
137
148
private var _linkerSettings : [ LinkerSetting ] ?
138
149
150
+ /// The binary target's checksum.
151
+ public var _checksum : String ? {
152
+ get { __checksum }
153
+ set { __checksum = newValue }
154
+ }
155
+ public var __checksum : String ?
156
+
139
157
/// Construct a target.
140
158
private init (
141
159
name: String ,
142
160
dependencies: [ Dependency ] ,
143
161
path: String ? ,
162
+ _url: String ? = nil ,
144
163
exclude: [ String ] ,
145
164
sources: [ String ] ? ,
146
165
resources: [ Resource ] ? = nil ,
@@ -151,11 +170,13 @@ public final class Target {
151
170
cSettings: [ CSetting ] ? = nil ,
152
171
cxxSettings: [ CXXSetting ] ? = nil ,
153
172
swiftSettings: [ SwiftSetting ] ? = nil ,
154
- linkerSettings: [ LinkerSetting ] ? = nil
173
+ linkerSettings: [ LinkerSetting ] ? = nil ,
174
+ _checksum: String ? = nil
155
175
) {
156
176
self . name = name
157
177
self . dependencies = dependencies
158
178
self . path = path
179
+ self . __url = _url
159
180
self . publicHeadersPath = publicHeadersPath
160
181
self . sources = sources
161
182
self . _resources = resources
@@ -167,11 +188,44 @@ public final class Target {
167
188
self . _cxxSettings = cxxSettings
168
189
self . _swiftSettings = swiftSettings
169
190
self . _linkerSettings = linkerSettings
191
+ self . __checksum = _checksum
170
192
171
193
switch type {
172
194
case . regular, . test:
173
- precondition ( pkgConfig == nil && providers == nil )
174
- case . system: break
195
+ precondition (
196
+ _url == nil &&
197
+ pkgConfig == nil &&
198
+ providers == nil &&
199
+ _checksum == nil
200
+ )
201
+ case . system:
202
+ precondition (
203
+ _url == nil &&
204
+ dependencies. isEmpty &&
205
+ exclude. isEmpty &&
206
+ sources == nil &&
207
+ resources == nil &&
208
+ publicHeadersPath == nil &&
209
+ cSettings == nil &&
210
+ cxxSettings == nil &&
211
+ swiftSettings == nil &&
212
+ linkerSettings == nil &&
213
+ _checksum == nil
214
+ )
215
+ case . _binary:
216
+ precondition (
217
+ dependencies. isEmpty &&
218
+ exclude. isEmpty &&
219
+ sources == nil &&
220
+ resources == nil &&
221
+ publicHeadersPath == nil &&
222
+ pkgConfig == nil &&
223
+ providers == nil &&
224
+ cSettings == nil &&
225
+ cxxSettings == nil &&
226
+ swiftSettings == nil &&
227
+ linkerSettings == nil
228
+ )
175
229
}
176
230
}
177
231
@@ -432,13 +486,65 @@ public final class Target {
432
486
pkgConfig: pkgConfig,
433
487
providers: providers)
434
488
}
489
+
490
+ /// Create a binary target referencing a remote artifact.
491
+ ///
492
+ /// A binary target provides the url to a pre-built binary artifact for the target. Currently only supports
493
+ /// artifacts for Apple platforms.
494
+ ///
495
+ /// - Parameters:
496
+ /// - name: The name of the target.
497
+ /// - url: The URL to the binary artifact. Should point to a `zip` archive containing a `XCFramework`.
498
+ /// - checksum: The checksum of the artifact archive for validation.
499
+ @available ( _PackageDescription, introduced: 5.2 )
500
+ public static func _binaryTarget(
501
+ name: String ,
502
+ url: String ,
503
+ checksum: String
504
+ ) -> Target {
505
+ return Target (
506
+ name: name,
507
+ dependencies: [ ] ,
508
+ path: nil ,
509
+ _url: url,
510
+ exclude: [ ] ,
511
+ sources: nil ,
512
+ publicHeadersPath: nil ,
513
+ type: . _binary,
514
+ _checksum: checksum)
515
+ }
516
+
517
+ /// Create a binary target referencing an artifact on disk.
518
+ ///
519
+ /// A binary target provides the path to a pre-built binary artifact for the target. Currently only supports
520
+ /// artifacts for Apple platforms.
521
+ ///
522
+ /// - Parameters:
523
+ /// - name: The name of the target.
524
+ /// - path: The path to the binary artifact. Can point directly to a `XCFramework` or a zip containing the
525
+ /// `XCFramework`.
526
+ @available ( _PackageDescription, introduced: 5.2 )
527
+ public static func _binaryTarget(
528
+ name: String ,
529
+ path: String
530
+ ) -> Target {
531
+ return Target (
532
+ name: name,
533
+ dependencies: [ ] ,
534
+ path: path,
535
+ exclude: [ ] ,
536
+ sources: nil ,
537
+ publicHeadersPath: nil ,
538
+ type: . _binary)
539
+ }
435
540
#endif
436
541
}
437
542
438
543
extension Target : Encodable {
439
544
private enum CodingKeys : CodingKey {
440
545
case name
441
546
case path
547
+ case url
442
548
case sources
443
549
case resources
444
550
case exclude
@@ -451,13 +557,15 @@ extension Target: Encodable {
451
557
case cxxSettings
452
558
case swiftSettings
453
559
case linkerSettings
560
+ case checksum
454
561
}
455
562
456
563
public func encode( to encoder: Encoder ) throws {
457
564
var container = encoder. container ( keyedBy: CodingKeys . self)
458
565
459
566
try container. encode ( name, forKey: . name)
460
567
try container. encode ( path, forKey: . path)
568
+ try container. encode ( _url, forKey: . url)
461
569
try container. encode ( sources, forKey: . sources)
462
570
try container. encode ( _resources, forKey: . resources)
463
571
try container. encode ( exclude, forKey: . exclude)
@@ -466,6 +574,7 @@ extension Target: Encodable {
466
574
try container. encode ( type, forKey: . type)
467
575
try container. encode ( pkgConfig, forKey: . pkgConfig)
468
576
try container. encode ( providers, forKey: . providers)
577
+ try container. encode ( _checksum, forKey: . checksum)
469
578
470
579
if let cSettings = self . _cSettings {
471
580
try container. encode ( cSettings, forKey: . cSettings)
0 commit comments