Skip to content

Commit 61087c7

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

File tree

1 file changed

+77
-65
lines changed

1 file changed

+77
-65
lines changed

Documentation/Reference.md

Lines changed: 77 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -24,35 +24,31 @@
2424

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

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

2929
example/
3030
example/Sources/bar.swift
3131
example/Sources/baz.swift
3232

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

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

3737
example/Sources/foo/foo.swift
3838
example/Sources/bar/bar.swift
3939

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

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

4744
example/Sources/foo/main.swift
4845
example/Sources/bar/bar.swift
4946

50-
Running `swift build` would now produce:
47+
and `swift build` will now produce the:
5148

5249
* `example/.build/debug/foo`
53-
* `example/.build/debug/bar.a`
5450

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

5753
### Other Rules
5854

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

6561
## Package Manifest File Format Reference
6662

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.
63+
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.
64+
65+
### Package Declaration
66+
67+
Every `Package.swift` file should follow the following format:
68+
69+
```swift
70+
import PackageDescription
71+
72+
/// The package description.
73+
let package = Package(/* ... */)
74+
75+
// ... subsequent package configuration APIs can be used here to further
76+
// configure the package ...
77+
```
78+
79+
Conceptually, the description defined by the `Package.swift` file is _combined_ with the information on the package derived from the filesystem conventions described previously.
6880

6981
### Package
7082

7183
```swift
7284
Package(
73-
name: String,
74-
pkgConfig: String? = nil,
75-
providers: [SystemPackageProvider]? = nil,
76-
targets: [Target] = [],
77-
dependencies: [Dependency] = [],
85+
name: String,
86+
pkgConfig: String? = nil,
87+
providers: [SystemPackageProvider]? = nil,
88+
targets: [Target] = [],
89+
dependencies: [Package.Dependency] = [],
7890
exclude: [String] = []
7991
)
8092
```
@@ -86,7 +98,9 @@ Package(
8698
\- [dependencies](#dependencies): Declare dependencies on external packages.
8799
\- [exclude](#exclude): Exclude files and directories from package sources.
88100

89-
### name
101+
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.
102+
103+
#### name
90104

91105
```swift
92106
import PackageDescription
@@ -96,31 +110,30 @@ let package = Package(
96110
)
97111
```
98112

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.
113+
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.
100114

101-
### targets
115+
#### targets
102116

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

105119
```swift
106120
import PackageDescription
107121

108122
let package = Package(
109123
name: "Hello",
110124
targets: [
111-
Target(name: "TestSupport"),
112125
Target(name: "Bar", dependencies: ["Foo"]),
113126
]
114127
)
115128
```
116129

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.
130+
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:
118131

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

121-
### dependencies
134+
#### dependencies
122135

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.
136+
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.
124137

125138
```swift
126139
import PackageDescription
@@ -135,9 +148,9 @@ let package = Package(
135148
)
136149
```
137150

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

140-
### exclude
153+
#### exclude
141154

142155
Use this property to exclude files and directories from the package sources.
143156

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

156-
### pkgConfig
169+
#### pkgConfig
157170

158171
This property should only be used for System Module Packages. It defines the name of the pkg-config (.pc) file
159172
that should be searched and read to get the additional flags like include search path, linker search path, system libraries
@@ -171,15 +184,14 @@ let package = Package(
171184
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
172185
using the environment variable, `PKG_CONFIG_PATH`, which will be searched before the standard locations.
173186

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.
187+
_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._
176188

177-
### providers
189+
#### providers
178190

179191
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
180192
a system package manager like homebrew, apt-get etc.
181193

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

184196
```swift
185197
import PackageDescription
@@ -199,70 +211,72 @@ the user is on i.e. macOS, Ubuntu, etc.
199211

200212
### Package Dependency
201213

202-
Package Dependency represents location and Version range of an external dependency.
214+
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.
203215

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

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

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

234+
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.
222235

223236
```swift
224-
Dependency.Package(url: String, majorVersion: Int, minor: Int)
237+
.Package(url: String, majorVersion: Int, minor: Int)
225238
```
226-
\- url: URL or local path to a Package.
227-
\- majorVersion: Major version to consider.
228-
\- minor: Minor version to consider.
239+
\- *url*: URL or local path to a Package.
240+
\- *majorVersion*: Major version to consider.
241+
\- *minor*: Minor version to consider.
242+
243+
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.
229244

230245
```swift
231-
Dependency.Package(url: String, _ version: Version)
246+
.Package(url: String, _ version: Version)
232247
```
233-
\- url: URL or local path to a Package.
234-
\- version: The specific [Version](#version) to consider.
235-
248+
\- *url*: URL or local path to a Package.
249+
\- *version*: The exact [Version](#version) which is required.
250+
236251
### Version
237252

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

240255
```swift
241256
Version(
242-
_ major: Int,
243-
_ minor: Int,
257+
_ major: Int,
258+
_ minor: Int,
244259
_ patch: Int,
245-
prereleaseIdentifiers: [String] = [],
260+
prereleaseIdentifiers: [String] = [],
246261
buildMetadataIdentifier: String? = nil
247262
)
248263
```
249264

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.
265+
\- *major*: The major version, incremented when you make incompatible API changes.
266+
\- *minor*: The minor version, incremented when you add functionality in a backwards-compatible manner.
267+
\- *patch*: The patch version, incremented when you make backwards-compatible bug fixes.
268+
\- *prereleaseIdentifiers*: Used to denote a pre-released version for eg: alpha, beta, etc.
269+
\- *buildMetadataIdentifier*: Optional build meta data for eg: timestamp, hash, etc.
255270

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

258273
``` "major.minor.patch[-prereleaseIdentifiers][+buildMetadata]" ```
259274

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

263277
### Customizing Builds
264278

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

267281
```swift
268282
import PackageDescription
@@ -280,5 +294,3 @@ With a standard configuration file format like JSON such a feature would result
280294
### Depending on Apple Modules
281295

282296
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)