|
11 | 11 | * [Build an Executable](#build-an-executable)
|
12 | 12 | * [Create a Package](#create-a-package)
|
13 | 13 | * [Distribute a Package](#distribute-a-package)
|
| 14 | + * [Handling version-specific logic](#version-specific-logic) |
14 | 15 | * [Reference](Reference.md)
|
15 | 16 | * [Resources](Resources.md)
|
16 | 17 |
|
@@ -323,3 +324,76 @@ import Foundation
|
323 | 324 | ## Distribute a Package
|
324 | 325 |
|
325 | 326 | *Content to come.*
|
| 327 | + |
| 328 | +## Handling version-specific logic |
| 329 | + |
| 330 | +The package manager is designed to support packages which work with a variety of |
| 331 | +Swift project versions, including both the language and the package manager version. |
| 332 | + |
| 333 | +In most cases, if you want to support multiple Swift versions in a package you |
| 334 | +should do so by using the language-specific version checks available in the |
| 335 | +source code itself. However, in some circumstances this may become |
| 336 | +unmanageable; in particular, when the package manifest itself cannot be written |
| 337 | +to be Swift version agnostic (for example, because it optionally adopts new |
| 338 | +package manager features not present in older versions). |
| 339 | + |
| 340 | +The package manager has support for a mechanism to allow Swift version-specific |
| 341 | +customizations for the both package manifest and the package versions which will |
| 342 | +be considered. |
| 343 | + |
| 344 | +### Version-specific tag selection |
| 345 | + |
| 346 | +The tags which define the versions of the package available for clients to use |
| 347 | +can _optionally_ be suffixed with a marker in the form of `@swift-3`. When the |
| 348 | +package manager is determining the available tags for a repository, _if_ a |
| 349 | +version-specific marker is available which matches the current tool version, |
| 350 | +then it will *only* consider the versions which have the version-specific |
| 351 | +marker. Conversely, version-specific tags will be ignored by any non-matching |
| 352 | +tool version. |
| 353 | + |
| 354 | +For example, suppose the package `Foo` has the tags |
| 355 | +`[1.0.0, 1.2.0@swift-3, 1.3.0]`. If version 3.0 of the package manager is |
| 356 | +evaluating the available versions for this repository, it will only ever |
| 357 | +consider version `1.2.0`. However, version 4.0 would consider only `1.0.0` and |
| 358 | +`1.3.0`. |
| 359 | + |
| 360 | +This feature is intended for use in the following scenarios: |
| 361 | + |
| 362 | +1. A package wishes to maintain support for Swift 3.0 in older versions, but |
| 363 | + newer versions of the package require Swift 4.0 for the manifest to be |
| 364 | + readable. Since Swift 3.0 will not know to ignore those versions, it would |
| 365 | + fail when performing dependency resolution on the package if no action is |
| 366 | + taken. In this case, the author can re-tag the last versions which supported |
| 367 | + Swift 3.0 appropriately. |
| 368 | + |
| 369 | +2. A package wishes to maintain dual support for Swift 3.0 and Swift 4.0 at the |
| 370 | + same version numbers, but this requires substantial differences in the |
| 371 | + code. In this case, the author can maintain parallel tag sets for both |
| 372 | + versions. |
| 373 | + |
| 374 | +It is *not* expected the packages would ever use this feature unless absolutely |
| 375 | +necessary to support existing clients. In particular, packages *should not* |
| 376 | +adopt this syntax for tagging versions supporting the _latest GM_ Swift version. |
| 377 | + |
| 378 | +The package manager supports looking for any of the following marked tags, in |
| 379 | +order of preference: |
| 380 | + |
| 381 | +1. `MAJOR.MINOR.PATCH` (e.g., `[email protected]`) |
| 382 | +2. `MAJOR.MINOR` (e.g., `[email protected]`) |
| 383 | +3. `MAJOR` (e.g., `1.2.0@swift-3`) |
| 384 | + |
| 385 | +### Version-specific manifest selection |
| 386 | + |
| 387 | +The package manager will additionally look for a version-specific marked |
| 388 | +manifest version when loading the particular version of a package, by searching |
| 389 | +for a manifest in the form of `[email protected]`. The set of markers looked |
| 390 | +for is the same as for version-specific tag selection. |
| 391 | + |
| 392 | +This feature is intended for use in cases where a package wishes to maintain |
| 393 | +compatibility with multiple Swift project versions, but requires a substantively |
| 394 | +different manifest file for this to be viable (e.g., due to changes in the |
| 395 | +manifest API). |
| 396 | + |
| 397 | +It is *not* expected the packages would ever use this feature unless absolutely |
| 398 | +necessary to support existing clients. In particular, packages *should not* |
| 399 | +adopt this syntax for tagging versions supporting the _latest GM_ Swift version. |
0 commit comments