Skip to content

Commit c1a5aad

Browse files
committed
[Documentation] Tidy up reference section.
1 parent 580d2d7 commit c1a5aad

File tree

1 file changed

+78
-65
lines changed

1 file changed

+78
-65
lines changed

Documentation/Reference.md

Lines changed: 78 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* [Source Layouts](#source-layouts)
1010
* [Other Rules](#other-rules)
1111
* [Package Manifest File Format Reference](#package-manifest-file-format-reference)
12+
* [Package Declaration](#package-declaration)
1213
* [Package](#package)
1314
* [Package Dependency](#package-dependency)
1415
* [Version](#version)
@@ -24,35 +25,31 @@
2425

2526
The modules that `swift build` creates are determined from the filesystem layout of your source files.
2627

27-
For example, if you created a directory with the following layout:
28+
For example, if you create a directory with the following layout:
2829

2930
example/
3031
example/Sources/bar.swift
3132
example/Sources/baz.swift
3233

33-
Running `swift build` within directory `example` would produce a single library target: `example/.build/debug/example.a`
34+
this defines a single module (named after the package name from `Package.swift).
3435

35-
To create multiple modules create multiple subdirectories:
36+
To create multiple modules, you can create multiple subdirectories:
3637

3738
example/Sources/foo/foo.swift
3839
example/Sources/bar/bar.swift
3940

40-
Running `swift build` would produce two library targets:
41-
42-
* `example/.build/debug/foo.a`
43-
* `example/.build/debug/bar.a`
41+
which would define two modules, `foo` and `bar`.
4442

4543
To generate an executable module (instead of a library module) add a `main.swift` file to that module’s subdirectory:
4644

4745
example/Sources/foo/main.swift
4846
example/Sources/bar/bar.swift
4947

50-
Running `swift build` would now produce:
48+
and `swift build` will now produce the:
5149

5250
* `example/.build/debug/foo`
53-
* `example/.build/debug/bar.a`
5451

55-
Where `foo` is an executable and `bar.a` a static library.
52+
executable output file.
5653

5754
### Other Rules
5855

@@ -64,17 +61,33 @@ Where `foo` is an executable and `bar.a` a static library.
6461

6562
## Package Manifest File Format Reference
6663

67-
Instructions for how to build a package are provided by the `Package.swift` manifest file. `Package.swift` is a Swift file defining a single `Package` object. The Package is configured via the APIs used to form that object.
64+
Instructions for how to build a package are provided by the `Package.swift` manifest file. `Package.swift` is a Swift file defining a single `Package` object. This object is configured via the APIs defined in the `PackageDescription` Swift module supplied with the Swift Package Manager.
65+
66+
### Package Declaration
67+
68+
Every `Package.swift` file should follow the following format:
69+
70+
```swift
71+
import PackageDescription
72+
73+
/// The package description.
74+
let package = Package(/* ... */)
75+
76+
// ... subsequent package configuration APIs can be used here to further
77+
// configure the package ...
78+
```
79+
80+
Conceptually, the description defined by the `Package.swift` file is _combined_ with the information on the package derived from the filesystem conventions described previously.
6881

6982
### Package
7083

7184
```swift
7285
Package(
73-
name: String,
74-
pkgConfig: String? = nil,
75-
providers: [SystemPackageProvider]? = nil,
76-
targets: [Target] = [],
77-
dependencies: [Dependency] = [],
86+
name: String,
87+
pkgConfig: String? = nil,
88+
providers: [SystemPackageProvider]? = nil,
89+
targets: [Target] = [],
90+
dependencies: [Package.Dependency] = [],
7891
exclude: [String] = []
7992
)
8093
```
@@ -86,7 +99,9 @@ Package(
8699
\- [dependencies](#dependencies): Declare dependencies on external packages.
87100
\- [exclude](#exclude): Exclude files and directories from package sources.
88101

89-
### name
102+
Creates a new package instance. There should only be one package declared per manifest. The parameters here supply the package description and are documented in further detail below.
103+
104+
#### name
90105

91106
```swift
92107
import PackageDescription
@@ -96,31 +111,30 @@ let package = Package(
96111
)
97112
```
98113

99-
It is the minimal requirement for a manifest to be valid. When the sources are located directly under `Sources/` directory, there is only one module and the module name is same as the package name.
114+
This is the minimal requirement for a manifest to be valid. When the sources are located directly under `Sources/` directory, there is only one module and the module name will be the same as the package name.
100115

101-
### targets
116+
#### targets
102117

103-
Targets property is used when you have more than one module in your package and want to declare a dependency between them.
118+
The targets property is required when you have more than one module in your package and need to declare a dependency between them.
104119

105120
```swift
106121
import PackageDescription
107122

108123
let package = Package(
109124
name: "Hello",
110125
targets: [
111-
Target(name: "TestSupport"),
112126
Target(name: "Bar", dependencies: ["Foo"]),
113127
]
114128
)
115129
```
116130

117-
Here `Foo` and `Bar` are modules present under `Sources/` directory. `Foo` module will be built before `Bar` module and `Bar` can import `Foo` if `Foo` is a library.
131+
The name identifies which target (or module) the information is being associated with, and the list of dependencies specifies the names of other targets in the same package which must be built before that target. In the example here, `Foo` and `Bar` are modules present under `Sources/` directory, and a dependency is being establish on `Foo` from `Bar`. This will cause the `Foo` module to be built before `Bar` module so that it can be imported:
118132

119-
Note: It is also possible to declare target dependencies between a test and regular module.
133+
_NOTE: It is also possible to declare target dependencies between a test and regular module._
120134

121-
### dependencies
135+
#### dependencies
122136

123-
This is the list of packages that the current package depends on. You can specify a URL (or local path) to any valid Swift package.
137+
This is the list of packages that the current package depends on and information about the required versions. You can specify a URL (or local path) to any valid Swift package.
124138

125139
```swift
126140
import PackageDescription
@@ -135,9 +149,9 @@ let package = Package(
135149
)
136150
```
137151

138-
See [Package Dependency](#package-dependency).
152+
This is a list of `Package.Dependency` instances, see [Package Dependency](#package-dependency) for available options.
139153

140-
### exclude
154+
#### exclude
141155

142156
Use this property to exclude files and directories from the package sources.
143157

@@ -153,7 +167,7 @@ let package = Package(
153167
This is helpful when you want to place files like resources or fixtures that should not be considered by the convention system
154168
as possible sources.
155169

156-
### pkgConfig
170+
#### pkgConfig
157171

158172
This property should only be used for System Module Packages. It defines the name of the pkg-config (.pc) file
159173
that should be searched and read to get the additional flags like include search path, linker search path, system libraries
@@ -171,15 +185,14 @@ let package = Package(
171185
Here `gtk+-3.0.pc` will be searched in standard locations for the current system. Users can provide their own paths for location of pc files
172186
using the environment variable, `PKG_CONFIG_PATH`, which will be searched before the standard locations.
173187

174-
Note: This feature does not require pkg-config to be installed. However, if installed it will used to find additional platform specific pc file
175-
locations which might be unknown to SwiftPM.
188+
_NOTE: This feature does not require pkg-config to be installed. However, if installed it will used to find additional platform specific pc filelocations which might be unknown to SwiftPM._
176189

177-
### providers
190+
#### providers
178191

179192
This property should only be used for system module packages. It can be used to provide _hints_ for other users to install a System Module using
180193
a system package manager like homebrew, apt-get etc.
181194

182-
Note: SwiftPM will *never* execute the command and only suggest the users to run it.
195+
_NOTE: SwiftPM will *never* execute the command and only suggest the users to run it._
183196

184197
```swift
185198
import PackageDescription
@@ -199,70 +212,72 @@ the user is on i.e. macOS, Ubuntu, etc.
199212

200213
### Package Dependency
201214

202-
Package Dependency represents location and Version range of an external dependency.
215+
A `Package.Dependency` represents the location and and required version information of an external dependency. The version range controls what versions of a package dependency are expected to work with the current package. When the package manager is fetching the complete set of packages required to build a package, it considers all of the version range specifications from all of the packages in order to select appropriate versions.
203216

204217
```swift
205-
Dependency.Package(url: String, versions: Range<Version>)
218+
.Package(url: String, versions: Range<Version>)
206219
```
207-
\- url: URL or local path to a Package.
208-
\- versions: A range of [Version](#version).
220+
\- *url*: URL or local path to a Package.
221+
\- *versions*: The range of [versions](#version) which are required.
209222

210223
```swift
211-
Dependency.Package(url: String, versions: ClosedRange<Version>)
224+
.Package(url: String, versions: ClosedRange<Version>)
212225
```
213-
\- url: URL or local path to a Package.
214-
\- versions: A closed range of [Version](#version).
226+
\- *url*: URL or local path to a Package.
227+
\- *versions*: The closed range of [versions](#version) which are required.
215228

216229
```swift
217-
Dependency.Package(url: String, majorVersion: Int)
230+
.Package(url: String, majorVersion: Int)
218231
```
219-
\- url: URL or local path to a Package.
220-
\- majorVersion: Major version to consider. Latest available minor Version will be considered.
232+
\- *url*: URL or local path to a Package.
233+
\- *majorVersion*: The major version which is required.
221234

235+
This is a short-hand form for specifying a range including all versions of a major version, and is the recommended way for specifying a dependency following the [semantic versioning](http://semver.org) standard.
222236

223237
```swift
224-
Dependency.Package(url: String, majorVersion: Int, minor: Int)
238+
.Package(url: String, majorVersion: Int, minor: Int)
225239
```
226-
\- url: URL or local path to a Package.
227-
\- majorVersion: Major version to consider.
228-
\- minor: Minor version to consider.
240+
\- *url*: URL or local path to a Package.
241+
\- *majorVersion*: Major version to consider.
242+
\- *minor*: Minor version to consider.
243+
244+
As for the prior API, this is a short-hand form for specifying a range that inclues all versions of a major and minor version.
229245

230246
```swift
231-
Dependency.Package(url: String, _ version: Version)
247+
.Package(url: String, _ version: Version)
232248
```
233-
\- url: URL or local path to a Package.
234-
\- version: The specific [Version](#version) to consider.
235-
249+
\- *url*: URL or local path to a Package.
250+
\- *version*: The exact [Version](#version) which is required.
251+
236252
### Version
237253

238-
A struct representing [Semantic Versioning](http://semver.org).
254+
A struct representing a [semantic version](http://semver.org).
239255

240256
```swift
241257
Version(
242-
_ major: Int,
243-
_ minor: Int,
258+
_ major: Int,
259+
_ minor: Int,
244260
_ patch: Int,
245-
prereleaseIdentifiers: [String] = [],
261+
prereleaseIdentifiers: [String] = [],
246262
buildMetadataIdentifier: String? = nil
247263
)
248264
```
249265

250-
\- major: The major version, incremented when you make incompatible API changes.
251-
\- minor: The minor version, incremented when you add functionality in a backwards-compatible manner.
252-
\- patch: The patch version, incremented when you make backwards-compatible bug fixes.
253-
\- prereleaseIdentifiers: Used to denote a pre-released version for eg: alpha, beta, etc.
254-
\- buildMetadataIdentifier: Optional build meta data for eg: timestamp, hash, etc.
266+
\- *major*: The major version, incremented when you make incompatible API changes.
267+
\- *minor*: The minor version, incremented when you add functionality in a backwards-compatible manner.
268+
\- *patch*: The patch version, incremented when you make backwards-compatible bug fixes.
269+
\- *prereleaseIdentifiers*: Used to denote a pre-released version for eg: alpha, beta, etc.
270+
\- *buildMetadataIdentifier*: Optional build meta data for eg: timestamp, hash, etc.
255271

256-
Version can be initialized using a string literal in following format:
272+
A `Version` struct can be initialized using a string literal in following format:
257273

258274
``` "major.minor.patch[-prereleaseIdentifiers][+buildMetadata]" ```
259275

260-
prereleaseIdentifiers and buildMetadata are optional.
261-
Note: prereleaseIdentifiers are separated by dot (.)
276+
where `prereleaseIdentifiers` and `buildMetadata` are optional. _NOTE: prereleaseIdentifiers are separated by dot (.)._
262277

263278
### Customizing Builds
264279

265-
That the manifest is Swift allows for powerful customization, for example:
280+
Using Swift as the format for the manifest allows for powerful customization, for example:
266281

267282
```swift
268283
import PackageDescription
@@ -280,5 +295,3 @@ With a standard configuration file format like JSON such a feature would result
280295
### Depending on Apple Modules
281296

282297
At this time there is no explicit support for depending on Foundation, AppKit, etc, though importing these modules should work if they are present in the proper system location. We will add explicit support for system dependencies in the future. Note that at this time the Package Manager has no support for iOS, watchOS, or tvOS platforms.
283-
284-

0 commit comments

Comments
 (0)