Skip to content

Commit 5ebf984

Browse files
committed
Merge commit '3392287aace6beccd205a021c677abf7596526e6' into swift-3.0-branch
* commit '3392287aace6beccd205a021c677abf7596526e6': (83 commits) Add a performance fixme to OutputByteStream [Xcodeproj] conditionally add default linker path Minor fixes (#644) [Documenation] Document build configurations [ModuleMapGenerator] Remove framework modulemap support [Xcodeproj] Create symlink'ed dylibs for C frameworks [Basic] Move Dictionary tuple initializer to Basic [Workspace] Use filesystem API for reading file Remove uses of private API (String._contiguousUTF8) Eliminate arithmetic overflows in Version.hashValue [DependencyResolver] Use `merging` for constraint container update. [Xcodeproj] Fix Plist to write in deterministic order. [DependencyResolver] Clean up constraint set subscripting of unassigned identifiers. [Xcodeproj] Add a Plist enum [PackageBuilder] Error on invalid manifest config [Documentation] Document the manifest file [Utility] Priortize pkgconfig env variable [Utility] Use FileSystem APIs to in PkgConfig Improve the error message that's shown when trying to access a package by a local path URL that doesn't refer to a repository. [PackageBuilder] Fix test target ref in manifest for external packages ... # Conflicts: # Sources/Commands/SwiftTestTool.swift
2 parents 4aeab3d + 3392287 commit 5ebf984

File tree

122 files changed

+4060
-2116
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

122 files changed

+4060
-2116
lines changed

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,19 @@ Note: This is in reverse chronological order, so newer entries are added to the
33
Swift 3.0
44
---------
55

6+
* [SE-0135](https://github.com/apple/swift-evolution/blob/master/proposals/0135-package-manager-support-for-differentiating-packages-by-swift-version.md)
7+
8+
The package manager now supports writing Swift 3.0 specific tags and
9+
manifests, in order to support future evolution of the formats used in both
10+
cases while still allowing the Swift 3.0 package manager to continue to
11+
function.
12+
13+
* [SE-0129](https://github.com/apple/swift-evolution/blob/master/proposals/0129-package-manager-test-naming-conventions.md)
14+
15+
Test modules now *must* be named with a `Tests` suffix (e.g.,
16+
`Foo/Tests/BarTests/BarTests.swift`). This name also defines the name of the
17+
Swift module, replacing the old `BarTestSuite` module name.
18+
619
* It is no longer necessary to run `swift build` before running `swift test` (it
720
will always regenerates the build manifest when necessary). In addition, it
821
now accepts (and requires) the same `-Xcc`, etc. options as are used with

Documentation/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ We’ve designed the system to make it really easy to share packages on services
1313
* [About Modules](#about-modules)
1414
* [Building Swift Modules](#building-swift-modules)
1515
* [About Products](#about-products)
16-
* [About Dependencies](#about#dependencies)
16+
* [About Dependencies](#about-dependencies)
1717
* [Dependency Hell](#dependency-hell)
1818
* [Usage](Usage.md)
1919
* [Reference](Reference.md)

Documentation/Reference.md

Lines changed: 195 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,13 @@
99
* [Source Layouts](#source-layouts)
1010
* [Other Rules](#other-rules)
1111
* [Package Manifest File Format Reference](#package-manifest-file-format-reference)
12+
* [Package](#package)
13+
* [Package Dependency](#package-dependency)
14+
* [Version](#version)
1215
* [Customizing Builds](#customizing-builds)
16+
* [Build Configurations](#build-configurations)
17+
* [Debug](#debug)
18+
* [Release](#release)
1319
* [Depending on Apple Modules](#depending-on-apple-modules)
1420
* [Resources](Resources.md)
1521

@@ -61,72 +67,210 @@ Where `foo` is an executable and `bar.a` a static library.
6167

6268
## Package Manifest File Format Reference
6369

64-
Instructions for how to build a package are provided by a manifest file, called `Package.swift`. You can customize this file to declare build targets or dependencies, include or exclude source files, and specify build configurations for the module or individual files.
70+
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.
6571

66-
Here's an example of a `Package.swift` file:
72+
### Package
73+
74+
```swift
75+
Package(
76+
name: String,
77+
pkgConfig: String? = nil,
78+
providers: [SystemPackageProvider]? = nil,
79+
targets: [Target] = [],
80+
dependencies: [Dependency] = [],
81+
exclude: [String] = []
82+
)
83+
```
84+
85+
\- [name](#name): The name of the package.
86+
\- [pkgConfig](#pkgconfig): Name of the pkg-config (.pc) file to get the additional flags for system modules.
87+
\- [providers](#providers): Defines hints to display for installing system modules.
88+
\- [targets](#targets): Additional information on each target.
89+
\- [dependencies](#dependencies): Declare dependencies on external packages.
90+
\- [exclude](#exclude): Exclude files and directories from package sources.
91+
92+
### name
93+
94+
```swift
95+
import PackageDescription
96+
97+
let package = Package(
98+
name: "FooBar"
99+
)
100+
```
101+
102+
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.
103+
104+
### targets
105+
106+
Targets property is used when you have more than one module in your package and want to declare a dependency between them.
67107

68108
```swift
69109
import PackageDescription
70110

71111
let package = Package(
72112
name: "Hello",
73-
dependencies: [
74-
.Package(url: "ssh://[email protected]/Greeter.git", versions: Version(1,0,0)..<Version(2,0,0)),
113+
targets: [
114+
Target(name: "TestSupport"),
115+
Target(name: "Bar", dependencies: ["Foo"]),
75116
]
76117
)
77118
```
78119

79-
A `Package.swift` file is a Swift file that declaratively configures a Package using types defined in the `PackageDescription` module. This manifest declares a dependency on an external package: `Greeter`.
120+
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.
121+
122+
Note: It is also possible to declare target dependencies between a test and regular module.
123+
124+
### dependencies
80125

81-
If your package contains multiple targets that depend on each other you will need to specify their interdependencies. Here is an example:
126+
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.
82127

83128
```swift
84129
import PackageDescription
85130

86131
let package = Package(
87132
name: "Example",
88-
targets: [
89-
Target(
90-
name: "top",
91-
dependencies: [.Target(name: "bottom")]),
92-
Target(
93-
name: "bottom")
133+
dependencies: [
134+
.Package(url: "ssh://[email protected]/Greeter.git", versions: Version(1,0,0)..<Version(2,0,0)),
135+
.Package(url: "../StringExtensions", "1.0.0"),
136+
.Package(url: "https://github.com/MyAwesomePackage", majorVersion: 1, minor: 4),
94137
]
95138
)
96139
```
97140

98-
The targets are named how your subdirectories are named.
141+
See [Package Dependency](#package-dependency).
142+
143+
### exclude
144+
145+
Use this property to exclude files and directories from the package sources.
99146

100-
If you want to exclude some files and folders from Package, you can simple list them in the `exclude`. Every item specifies a relative folder path from the Root folder of the package
147+
Every item specifies a relative path from the root of the package.
101148

102149
```swift
103150
let package = Package(
104-
name: "Example",
105-
exclude: ["tools", "docs", "Sources/libA/images"]
151+
name: "Foo",
152+
exclude: ["Sources/Fixtures", "Sources/readme.md", "Tests/FooTests/images"]
106153
)
107154
```
108155

109-
A package can require dependencies that are only needed during develop, as example for testing purposes. `testDependencies` are only fetched when you build current package. They are not fetched if a package is specified as a dependency in other package.
156+
This is helpful when you want to place files like resources or fixtures that should not be considered by the convention system
157+
as possible sources.
158+
159+
### pkgConfig
160+
161+
This property should only be used for System Module Packages. It defines the name of the pkg-config (.pc) file
162+
that should be searched and read to get the additional flags like include search path, linker search path, system libraries
163+
to link etc.
110164

111165
```swift
112166
import PackageDescription
113167

114168
let package = Package(
115-
name: "Hello",
116-
testDependencies: [
117-
.Package(url: "ssh://[email protected]/Tester.git", versions: Version(1,0,0)..<Version(2,0,0)),
169+
name: "CGtk3",
170+
pkgConfig: "gtk+-3.0"
171+
)
172+
```
173+
174+
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
175+
using the environment variable, `PKG_CONFIG_PATH`, which will be searched before the standard locations.
176+
177+
Note: This feature does not require pkg-config to be installed. However, if installed it will used to find additional platform specific pc file
178+
locations which might be unknown to SwiftPM.
179+
180+
### providers
181+
182+
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
183+
a system package manager like homebrew, apt-get etc.
184+
185+
Note: SwiftPM will *never* execute the command and only suggest the users to run it.
186+
187+
```swift
188+
import PackageDescription
189+
190+
let package = Package(
191+
name: "CGtk3",
192+
pkgConfig: "gtk+-3.0",
193+
providers: [
194+
.Brew("gtk+3"),
195+
.Apt("gtk3")
118196
]
119197
)
120198
```
121199

200+
In this case if SwiftPM determines that GTK 3 package is not installed, it will output an appropriate hint depending on which platform
201+
the user is on i.e. macOS, Ubuntu, etc.
202+
203+
### Package Dependency
204+
205+
Package Dependency represents location and Version range of an external dependency.
206+
207+
```swift
208+
Dependency.Package(url: String, versions: Range<Version>)
209+
```
210+
\- url: URL or local path to a Package.
211+
\- versions: A range of [Version](#version).
212+
213+
```swift
214+
Dependency.Package(url: String, versions: ClosedRange<Version>)
215+
```
216+
\- url: URL or local path to a Package.
217+
\- versions: A closed range of [Version](#version).
218+
219+
```swift
220+
Dependency.Package(url: String, majorVersion: Int)
221+
```
222+
\- url: URL or local path to a Package.
223+
\- majorVersion: Major version to consider. Latest available minor Version will be considered.
224+
225+
226+
```swift
227+
Dependency.Package(url: String, majorVersion: Int, minor: Int)
228+
```
229+
\- url: URL or local path to a Package.
230+
\- majorVersion: Major version to consider.
231+
\- minor: Minor version to consider.
232+
233+
```swift
234+
Dependency.Package(url: String, _ version: Version)
235+
```
236+
\- url: URL or local path to a Package.
237+
\- version: The specific [Version](#version) to consider.
238+
239+
### Version
240+
241+
A struct representing [Semantic Versioning](http://semver.org).
242+
243+
```swift
244+
Version(
245+
_ major: Int,
246+
_ minor: Int,
247+
_ patch: Int,
248+
prereleaseIdentifiers: [String] = [],
249+
buildMetadataIdentifier: String? = nil
250+
)
251+
```
252+
253+
\- major: The major version, incremented when you make incompatible API changes.
254+
\- minor: The minor version, incremented when you add functionality in a backwards-compatible manner.
255+
\- patch: The patch version, incremented when you make backwards-compatible bug fixes.
256+
\- prereleaseIdentifiers: Used to denote a pre-released version for eg: alpha, beta, etc.
257+
\- buildMetadataIdentifier: Optional build meta data for eg: timestamp, hash, etc.
258+
259+
Version can be initialized using a string literal in following format:
260+
261+
``` "major.minor.patch[-prereleaseIdentifiers][+buildMetadata]" ```
262+
263+
prereleaseIdentifiers and buildMetadata are optional.
264+
Note: prereleaseIdentifiers are separated by dot (.)
265+
122266
### Customizing Builds
123267

124268
That the manifest is Swift allows for powerful customization, for example:
125269

126270
```swift
127271
import PackageDescription
128272

129-
var package = Package()
273+
var package = Package(name: "Example")
130274

131275
#if os(Linux)
132276
let target = Target(name: "LinuxSources/foo")
@@ -136,6 +280,36 @@ package.targets.append(target)
136280

137281
With a standard configuration file format like JSON such a feature would result in a dictionary structure with increasing complexity for every such feature.
138282

283+
### Build Configurations
284+
285+
SwiftPM allows two build configurations: Debug (default) and Release.
286+
287+
#### Debug
288+
289+
By default, running `swift build` will build in debug configuration. Alternatively, you can also use `swift build -c debug`. The build artifacts are located in directory called `debug` under build folder.
290+
A Swift target is built with following flags in debug mode:
291+
292+
* `-Onone`: Compile without any optimization.
293+
* `-g`: Generate debug information.
294+
* `-enable-testing`: Enable Swift compiler's testability feature.
295+
296+
A C language target is build with following flags in debug mode:
297+
298+
* `-O0`: Compile without any optimization.
299+
* `-g`: Generate debug information.
300+
301+
#### Release
302+
303+
To build in release mode, type: `swift build -c release`. The build artifacts are located in directory called `release` under build folder.
304+
A Swift target is built with following flags in release mode:
305+
306+
* `-O`: Compile with optimizations.
307+
* `-whole-module-optimization`: Optimize input files (per module) together instead of individually.
308+
309+
A C language target is build with following flags in release mode:
310+
311+
* `-O2`: Compile with optimizations.
312+
139313
### Depending on Apple Modules
140314

141315
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.

Fixtures/TestDependencies/Complex/App/Package.swift

Lines changed: 0 additions & 11 deletions
This file was deleted.

Fixtures/TestDependencies/Complex/App/main.swift

Lines changed: 0 additions & 3 deletions
This file was deleted.

Fixtures/TestDependencies/Complex/Foo/Foo.swift

Lines changed: 0 additions & 4 deletions
This file was deleted.

Fixtures/TestDependencies/Complex/Foo/Package.swift

Lines changed: 0 additions & 8 deletions
This file was deleted.

Fixtures/TestDependencies/Complex/PrivateFooLib/Package.swift

Whitespace-only changes.

Fixtures/TestDependencies/Complex/PrivateFooLib/PrivateFooLib.swift

Lines changed: 0 additions & 3 deletions
This file was deleted.

Fixtures/TestDependencies/Complex/TestingFooLib/Package.swift

Whitespace-only changes.

Fixtures/TestDependencies/Complex/TestingFooLib/TestingFooLib.swift

Lines changed: 0 additions & 3 deletions
This file was deleted.

Fixtures/TestDependencies/Complex/TestingLib/Package.swift

Whitespace-only changes.

Fixtures/TestDependencies/Complex/TestingLib/TestingLib.swift

Lines changed: 0 additions & 3 deletions
This file was deleted.

Fixtures/TestDependencies/Simple/App/Package.swift

Lines changed: 0 additions & 11 deletions
This file was deleted.

Fixtures/TestDependencies/Simple/App/main.swift

Lines changed: 0 additions & 3 deletions
This file was deleted.

Fixtures/TestDependencies/Simple/Foo/Foo.swift

Lines changed: 0 additions & 3 deletions
This file was deleted.

Fixtures/TestDependencies/Simple/Foo/Package.swift

Whitespace-only changes.

Fixtures/TestDependencies/Simple/TestingLib/Package.swift

Whitespace-only changes.

Fixtures/TestDependencies/Simple/TestingLib/TestingLib.swift

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)