Skip to content

Commit c85fc1b

Browse files
committed
Update documentation
<rdar://problem/41444374>
1 parent 46318c5 commit c85fc1b

File tree

7 files changed

+148
-44
lines changed

7 files changed

+148
-44
lines changed

Documentation/PackageDescriptionV3.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* [Package Dependency](#package-dependency)
1616
* [Version](#version)
1717
* [PackageDescription API Version 4](PackageDescriptionV4.md)
18+
* [PackageDescription API Version 4.2](PackageDescriptionV4_2.md)
1819
* [Resources](Resources.md)
1920

2021
---

Documentation/PackageDescriptionV4.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* [Target Format Reference](#target-format-reference)
1010
* [Package Manifest File Format Reference](#package-manifest-file-format-reference)
1111
* [Version](#version)
12+
* [PackageDescription API Version 4.2](PackageDescriptionV4_2.md)
1213
* [Resources](Resources.md)
1314

1415
---
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# PackageDescription API Version 4.2
2+
3+
## Table of Contents
4+
5+
* [Overview](README.md)
6+
* [Usage](Usage.md)
7+
* [PackageDescription API Version 3](PackageDescriptionV3.md)
8+
* [PackageDescription API Version 4](PackageDescriptionV4.md)
9+
* [**PackageDescription API Version 4.2**](PackageDescriptionV4_2.md)
10+
* [Swift Language Version](#swift-language-version)
11+
* [Local Dependencies](#local-dependencies)
12+
* [System Library Targets](#system-library-targets)
13+
* [Resources](Resources.md)
14+
15+
---
16+
17+
The PackageDescription 4.2 contains one breaking and two additive changes.
18+
19+
## Swift Language Version
20+
21+
The `swiftLanguageVersions` takes an array of `SwiftVersion` enum:
22+
23+
```swift
24+
public enum SwiftVersion {
25+
case v3
26+
case v4
27+
case v4_2
28+
case version(String)
29+
}
30+
```
31+
32+
Example usage:
33+
34+
```swift
35+
// swift-tools-version:4.2
36+
37+
import PackageDescription
38+
39+
let package = Package(
40+
name: "HTTPClient",
41+
...
42+
swiftLanguageVersions: [.v4, .v4_2]
43+
)
44+
```
45+
46+
## Local Dependencies
47+
48+
Local dependences are packages on disk that can be referred directly using their
49+
paths. Local dependencies are only allowed in the root package and they override
50+
all dependencies with same name in the package graph. Example declaration:
51+
52+
```swift
53+
import PackageDescription
54+
55+
let package = Package(
56+
name: "MyPackage",
57+
dependencies: [
58+
.package(path: "../example-package-playingcard"),
59+
],
60+
targets: [
61+
.target(
62+
name: "MyPackage",
63+
dependencies: ["PlayingCard"]
64+
),
65+
]
66+
)
67+
```
68+
69+
## System Library Targets
70+
71+
System library targets supply the same metadata needed to adapt system libraries
72+
to work with the package manager, but as a target. This allows packages to embed
73+
these targets with the libraries that need them.
74+
75+
```swift
76+
// swift-tools-version:4.2
77+
import PackageDescription
78+
79+
let package = Package(
80+
name: "ZLib",
81+
products: [
82+
.library(name: "ZLib", targets: ["ZLib"]),
83+
],
84+
targets: [
85+
.systemLibrary(
86+
name: "CZLib")
87+
.target(
88+
name: "ZLib",
89+
dependencies: ["CZLib"]),
90+
]
91+
)
92+
```

Documentation/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ We’ve designed the system to make it really easy to share packages on services
1818
* [Usage](Usage.md)
1919
* [PackageDescription API Version 3](PackageDescriptionV3.md)
2020
* [PackageDescription API Version 4](PackageDescriptionV4.md)
21+
* [PackageDescription API Version 4.2](PackageDescriptionV4_2.md)
2122
* [Resources](Resources.md)
2223

2324
---
@@ -84,7 +85,7 @@ Dependencies are specified in your `Package.swift` manifest file.
8485
1. The conflict may be in unfamiliar dependencies (of dependencies) that the user did not explicitly request.
8586
2. Due to the nature of development it would be rare for two dependency graphs to be the same. Thus the amount of help other users (often even the package authors) can offer is limited. Internet searches will likely prove fruitless.
8687

87-
A good package manager should be designed from the start to minimize the risk of dependency hell and where this is not possible, to mitigate it and provide tooling so that the end-user can solve the scenario with a minimum of trouble. The [Package Manager Community Proposal](PackageManagerCommunityProposal.md) contains our thoughts on how we intend to iterate with these hells in mind.
88+
A good package manager should be designed from the start to minimize the risk of dependency hell and where this is not possible, to mitigate it and provide tooling so that the end-user can solve the scenario with a minimum of trouble. The [Package Manager Community Proposal](Internals/PackageManagerCommunityProposal.md) contains our thoughts on how we intend to iterate with these hells in mind.
8889

8990
The following are some of the most common “dependency hell” scenarios:
9091

Documentation/Resources.md

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,25 @@
66
* [Usage](Usage.md)
77
* [PackageDescription API Version 3](PackageDescriptionV3.md)
88
* [PackageDescription API Version 4](PackageDescriptionV4.md)
9+
* [PackageDescription API Version 4.2](PackageDescriptionV4_2.md)
910
* [**Resources**](Resources.md)
1011
* [Support](#support)
1112
* [Reporting a good SwiftPM Bug](#reporting-a-good-swiftpm-bug)
12-
* [Community Proposal](#community-proposal)
1313

1414
---
1515

1616
## Support
1717

18-
User-to-user support for Swift Package Manager is available on [swift-forums](https://forums.swift.org/c/development/SwiftPM).
18+
User-to-user support for Swift Package Manager is available on
19+
[swift-forums](https://forums.swift.org/c/development/SwiftPM).
1920

2021
---
2122

2223
## Reporting a good SwiftPM Bug
2324

24-
Use the [Swift bug tracker](http://bugs.swift.org) to report bugs with Swift Package Manager. Sign up if you haven't already and click the "Create" button to start filing an issue.
25+
Use the [Swift bug tracker](http://bugs.swift.org) to report bugs with Swift
26+
Package Manager. Sign up if you haven't already and click the "Create" button to
27+
start filing an issue.
2528

2629
Fill the following fields:
2730
* `Summary`: One line summary of the problem you're facing
@@ -30,16 +33,14 @@ Fill the following fields:
3033
* `Component/s`: Package Manager
3134
* `Attachment`: Attach relevant files like logs, project
3235

33-
Please include a minimal example package which can reproduce the issue. The sample package can be attached with the report or you can include URL of the package hosted on places like GitHub.
34-
Also, include the verbose logs by adding `--verbose` or `-v` after a subcommand. For e.g.:
36+
Please include a minimal example package which can reproduce the issue. The
37+
sample package can be attached with the report or you can include URL of the
38+
package hosted on places like GitHub.
39+
Also, include the verbose logs by adding `--verbose` or `-v` after a subcommand.
40+
For e.g.:
3541

3642
$ swift build --verbose
3743
$ swift package -v update
3844

39-
If the bug is with a generated Xcode project, include how the project was generated and the Xcode build log.
40-
41-
---
42-
43-
## Project History
44-
45-
To learn the original intentions for Swift Package Manager, read the [Community Proposal](PackageManagerCommunityProposal.md).
45+
If the bug is with a generated Xcode project, include how the project was
46+
generated and the Xcode build log.

Documentation/Usage.md

Lines changed: 39 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
* [Shell completion scripts](#shell-completion-scripts)
2727
* [PackageDescription API Version 3](PackageDescriptionV3.md)
2828
* [PackageDescription API Version 4](PackageDescriptionV4.md)
29+
* [PackageDescription API Version 4.2](PackageDescriptionV4_2.md)
2930
* [Resources](Resources.md)
3031

3132
---
@@ -70,29 +71,37 @@ its sources. Complete reference for layout is
7071

7172
## Define Dependencies
7273

73-
All you need to do to depend on a package is define the dependency and the
74-
version, in manifest of your package. For e.g. if you want to use
75-
https://github.com/apple/example-package-playingcard as a dependency, add the
76-
github URL in dependencies of your `Package.swift`:
74+
To depend on a package, define the dependency and the version in manifest of
75+
your package, and add a product from that package as a dependency. For e.g. if
76+
you want to use https://github.com/apple/example-package-playingcard as
77+
a dependency, add the GitHub URL in dependencies of your `Package.swift`:
7778

7879
```swift
7980
import PackageDescription
8081

8182
let package = Package(
8283
name: "MyPackage",
8384
dependencies: [
84-
.Package(url: "https://github.com/apple/example-package-playingcard.git", majorVersion: 3),
85+
.package(url: "https://github.com/apple/example-package-playingcard.git", from: "3.0.4"),
86+
],
87+
targets: [
88+
.target(
89+
name: "MyPackage",
90+
dependencies: ["PlayingCard"]
91+
),
92+
.testTarget(
93+
name: "MyPackageTests",
94+
dependencies: ["MyPackage"]
95+
),
8596
]
8697
)
8798
```
8899

89-
Now you should be able to `import PlayingCard` anywhere in your package and use
90-
the public APIs.
100+
Now you should be able to `import PlayingCard` in the `MyPackage` target.
91101

92102
## Publish a package
93103

94-
To publish a package, you just have to initialize a git repository and create a
95-
semantic version tag:
104+
To publish a package, create and push a semantic version tag:
96105

97106
$ git init
98107
$ git add .
@@ -108,10 +117,9 @@ https://github.com/apple/example-package-fisheryates
108117

109118
## Require System Libraries
110119

111-
You can link against system libraries using the package manager. To do so,
112-
there needs to be a special package for each system library that contains a
113-
module map for that library. Such a wrapper package does not contain any code
114-
of its own.
120+
You can link against system libraries using the package manager. To do so, there
121+
needs to be a special package for each system library that contains a modulemap
122+
for that library. Such a wrapper package does not contain any code of its own.
115123

116124
Let's see an example of using [libgit2](https://libgit2.github.com) from an
117125
executable.
@@ -204,7 +212,7 @@ import PackageDescription
204212
let package = Package(
205213
name: "example",
206214
dependencies: [
207-
.Package(url: "../Clibgit", majorVersion: 1)
215+
.package(url: "../Clibgit", from: "1.0.0")
208216
]
209217
)
210218
```
@@ -286,7 +294,7 @@ import PackageDescription
286294
let package = Package(
287295
name: "example",
288296
dependencies: [
289-
.Package(url: "../CJPEG", majorVersion: 1)
297+
.package(url: "../CJPEG", from: "1.0.0")
290298
]
291299
)
292300
```
@@ -301,8 +309,8 @@ executable:
301309
example$
302310

303311
We have to specify path where the libjpeg is present using `-Xlinker` because
304-
there is no pkg-config file for it. We plan to provide solution to avoid
305-
passing the flag in commandline.
312+
there is no pkg-config file for it. We plan to provide solution to avoid passing
313+
the flag in commandline.
306314

307315
### Packages That Provide Multiple Libraries
308316

@@ -345,8 +353,8 @@ that system libraries and system packagers will provide module maps and thus
345353
this component of the package manager will become redundant.
346354

347355
*Notably* the above steps will not work if you installed JPEG and JasPer with
348-
[Homebrew](http://brew.sh) since the files will be installed to `/usr/local`
349-
for now adapt the paths, but as said, we plan to support basic relocations like
356+
[Homebrew](http://brew.sh) since the files will be installed to `/usr/local` for
357+
now adapt the paths, but as said, we plan to support basic relocations like
350358
these.
351359

352360

@@ -373,8 +381,8 @@ uses libarchive with xz you must make a `CArchive+CXz` package that depends on
373381

374382
## Packaging legacy code
375383

376-
You may be working with code that builds both as a package and not. For
377-
example, you may be packaging a project that also builds with Xcode.
384+
You may be working with code that builds both as a package and not. For example,
385+
you may be packaging a project that also builds with Xcode.
378386

379387
In these cases, you can use the build configuration `SWIFT_PACKAGE` to
380388
conditionally compile code for Swift packages.
@@ -387,27 +395,27 @@ import Foundation
387395

388396
## Handling version-specific logic
389397

390-
The package manager is designed to support packages which work with a variety
391-
of Swift project versions, including both the language and the package manager
398+
The package manager is designed to support packages which work with a variety of
399+
Swift project versions, including both the language and the package manager
392400
version.
393401

394402
In most cases, if you want to support multiple Swift versions in a package you
395403
should do so by using the language-specific version checks available in the
396-
source code itself. However, in some circumstances this may become
397-
unmanageable; in particular, when the package manifest itself cannot be written
398-
to be Swift version agnostic (for example, because it optionally adopts new
399-
package manager features not present in older versions).
404+
source code itself. However, in some circumstances this may become unmanageable;
405+
in particular, when the package manifest itself cannot be written to be Swift
406+
version agnostic (for example, because it optionally adopts new package manager
407+
features not present in older versions).
400408

401409
The package manager has support for a mechanism to allow Swift version-specific
402-
customizations for the both package manifest and the package versions which
403-
will be considered.
410+
customizations for the both package manifest and the package versions which will
411+
be considered.
404412

405413
### Version-specific tag selection
406414

407415
The tags which define the versions of the package available for clients to use
408416
can _optionally_ be suffixed with a marker in the form of `@swift-3`. When the
409-
package manager is determining the available tags for a repository, _if_ a
410-
version-specific marker is available which matches the current tool version,
417+
package manager is determining the available tags for a repository, _if_
418+
a version-specific marker is available which matches the current tool version,
411419
then it will *only* consider the versions which have the version-specific
412420
marker. Conversely, version-specific tags will be ignored by any non-matching
413421
tool version.

0 commit comments

Comments
 (0)