You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Documentation/Reference.md
+77-65Lines changed: 77 additions & 65 deletions
Original file line number
Diff line number
Diff line change
@@ -24,35 +24,31 @@
24
24
25
25
The modules that `swift build` creates are determined from the filesystem layout of your source files.
26
26
27
-
For example, if you created a directory with the following layout:
27
+
For example, if you create a directory with the following layout:
28
28
29
29
example/
30
30
example/Sources/bar.swift
31
31
example/Sources/baz.swift
32
32
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).
34
34
35
-
To create multiple modules create multiple subdirectories:
35
+
To create multiple modules, you can create multiple subdirectories:
36
36
37
37
example/Sources/foo/foo.swift
38
38
example/Sources/bar/bar.swift
39
39
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`.
44
41
45
42
To generate an executable module (instead of a library module) add a `main.swift` file to that module’s subdirectory:
46
43
47
44
example/Sources/foo/main.swift
48
45
example/Sources/bar/bar.swift
49
46
50
-
Running`swift build`would now produce:
47
+
and`swift build`will now produce the:
51
48
52
49
*`example/.build/debug/foo`
53
-
*`example/.build/debug/bar.a`
54
50
55
-
Where `foo` is an executable and `bar.a` a static library.
51
+
executable output file.
56
52
57
53
### Other Rules
58
54
@@ -64,17 +60,33 @@ Where `foo` is an executable and `bar.a` a static library.
64
60
65
61
## Package Manifest File Format Reference
66
62
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
+
importPackageDescription
71
+
72
+
/// The package description.
73
+
letpackage=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.
68
80
69
81
### Package
70
82
71
83
```swift
72
84
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] = [],
78
90
exclude: [String] = []
79
91
)
80
92
```
@@ -86,7 +98,9 @@ Package(
86
98
\-[dependencies](#dependencies): Declare dependencies on external packages.
87
99
\-[exclude](#exclude): Exclude files and directories from package sources.
88
100
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
90
104
91
105
```swift
92
106
importPackageDescription
@@ -96,31 +110,30 @@ let package = Package(
96
110
)
97
111
```
98
112
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.
100
114
101
-
### targets
115
+
####targets
102
116
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.
104
118
105
119
```swift
106
120
importPackageDescription
107
121
108
122
letpackage=Package(
109
123
name: "Hello",
110
124
targets: [
111
-
Target(name: "TestSupport"),
112
125
Target(name: "Bar", dependencies: ["Foo"]),
113
126
]
114
127
)
115
128
```
116
129
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:
118
131
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._
120
133
121
-
### dependencies
134
+
####dependencies
122
135
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.
124
137
125
138
```swift
126
139
importPackageDescription
@@ -135,9 +148,9 @@ let package = Package(
135
148
)
136
149
```
137
150
138
-
See [Package Dependency](#package-dependency).
151
+
This is a list of `Package.Dependency` instances, see [Package Dependency](#package-dependency) for available options.
139
152
140
-
### exclude
153
+
####exclude
141
154
142
155
Use this property to exclude files and directories from the package sources.
143
156
@@ -153,7 +166,7 @@ let package = Package(
153
166
This is helpful when you want to place files like resources or fixtures that should not be considered by the convention system
154
167
as possible sources.
155
168
156
-
### pkgConfig
169
+
####pkgConfig
157
170
158
171
This property should only be used for System Module Packages. It defines the name of the pkg-config (.pc) file
159
172
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(
171
184
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
172
185
using the environment variable, `PKG_CONFIG_PATH`, which will be searched before the standard locations.
173
186
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._
176
188
177
-
### providers
189
+
####providers
178
190
179
191
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
180
192
a system package manager like homebrew, apt-get etc.
181
193
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._
183
195
184
196
```swift
185
197
importPackageDescription
@@ -199,70 +211,72 @@ the user is on i.e. macOS, Ubuntu, etc.
199
211
200
212
### Package Dependency
201
213
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.
\- 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.
221
233
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.
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 (.)._
262
276
263
277
### Customizing Builds
264
278
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:
266
280
267
281
```swift
268
282
importPackageDescription
@@ -280,5 +294,3 @@ With a standard configuration file format like JSON such a feature would result
280
294
### Depending on Apple Modules
281
295
282
296
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.
0 commit comments