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
Adds documentation for the Swift 6.1 traits feature
### Motivation:
- Show how to consume packages that provide traits
- Show how to present traits from your package(s)
- Updating PackageDescription API to use slightly more readable content
related to traits.
### Modifications:
- updated PackageDescription API around traits
- added curation (organization) for Traits and Package/Dependency/Traits
- extended `Using Dependencies` article to touch on traits and how to
consume packages that provide them
- added an article to share patterns to use when providing a traits from
your own package
### Result:
Updated content and one additional article in the central documentation
for Swift Package Manager that illustrates how to consume and provide
packages with traits.
---------
Co-authored-by: Franz Busch <[email protected]>
Co-authored-by: Bri Peticca <[email protected]>
@@ -28,25 +67,26 @@ public struct Trait: Hashable, ExpressibleByStringLiteral {
28
67
29
68
/// The trait's canonical name.
30
69
///
31
-
/// This is used when enabling the trait or when referring to it from other modifiers in the manifest.
70
+
/// Use the trait's name to enable the trait or when referring to it from other modifiers in the manifest.
71
+
/// The trait's name also defines the conditional block that the compiler supports when the trait is active.
32
72
///
33
73
/// The following rules are enforced on trait names:
34
74
/// - The first character must be a [Unicode XID start character](https://unicode.org/reports/tr31/#Figure_Code_Point_Categories_for_Identifier_Parsing)
35
75
/// (most letters), a digit, or `_`.
36
76
/// - Subsequent characters must be a [Unicode XID continue character](https://unicode.org/reports/tr31/#Figure_Code_Point_Categories_for_Identifier_Parsing)
37
77
/// (a digit, `_`, or most letters), `-`, or `+`.
38
-
/// - `default` and `defaults` (in any letter casing combination) are not allowed as trait names to avoid confusion with default traits.
78
+
/// - The names `default` and `defaults` (in any letter casing combination) aren't allowed as trait names to avoid confusion with default traits.
39
79
publicvarname:String
40
80
41
81
/// The trait's description.
42
82
///
43
-
/// Use this to explain what functionality this trait enables.
83
+
/// Use the description to explain the additional functionality that the trait enables.
44
84
publicvardescription:String?
45
85
46
86
/// A set of other traits of this package that this trait enables.
47
87
publicvarenabledTraits:Set<String>
48
88
49
-
/// Initializes a new trait.
89
+
/// Creates a trait with a name, a description, and set of additional traits it enables.
50
90
///
51
91
/// - Parameters:
52
92
/// - name: The trait's canonical name.
@@ -62,11 +102,13 @@ public struct Trait: Hashable, ExpressibleByStringLiteral {
62
102
self.enabledTraits = enabledTraits
63
103
}
64
104
105
+
/// Creates a trait with the name you provide.
106
+
/// - Parameter value: The trait's canonical name.
Copy file name to clipboardExpand all lines: Sources/PackageManagerDocs/Documentation.docc/AddingDependencies.md
+45-7Lines changed: 45 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,14 +1,14 @@
1
1
# Adding dependencies to a Swift package
2
2
3
-
Use other swift packages, system libraries, or binary dependencies in your package.
3
+
Use other Swift packages, system libraries, or binary dependencies in your package.
4
4
5
5
## Overview
6
6
7
7
To depend on another Swift package, define a dependency and the requirements for its version if it's remote, then add a product of that dependency to one or more of your targets.
8
8
9
9
A remote dependency requires a location, represented by a URL, and a requirement on the versions the package manager may use.
10
10
11
-
The following example illustrates a package that depends on [PlayingCard](https://github.com/apple/example-package-playingcard), using `from` to require at least version `3.0.4`, and allow any other version up to the next major version that is available at the time of dependency resolution.
11
+
The following example illustrates a package that depends on [PlayingCard](https://github.com/apple/example-package-playingcard), using `from` to require at least version `4.0.0`, and allow any other version up to the next major version that is available at the time of dependency resolution.
12
12
It then uses the product `PlayingCard` as a dependency for the target `MyPackage`:
@@ -43,15 +43,52 @@ For more information on resolving package versions, see <doc:ResolvingPackageVer
43
43
44
44
### Constraining dependency versions
45
45
46
-
Constrain the version of a remote dependency when you when you declare the dependency.
47
-
The package manager uses git tags interpretted as semantic versions to identify eligible versions of packages.
46
+
Constrain the version of a remote dependency when you declare the dependency.
47
+
The package manager uses git tags, interpreted as a semantic version, to identify eligible versions of packages.
48
48
49
-
> Note: tags for package versions should include all three components of a semantic version: major, minor, and patch.
49
+
> Note: tags for package versions should include all three components of a semantic version: major, minor, and patch.
50
50
> Tags that only include one or two of those components are not interpreted as semantic versions.
51
51
52
52
Use the version requirement when you declare the dependency to limit what the package manager can choose.
53
53
The version requirement can be a range of possible semantic versions, a specific semantic version, a branch name, or a commit hash.
54
-
The API reference documentation for [Package.Dependency](https://developer.apple.com/documentation/packagedescription/package/dependency) defines the methods to use.
54
+
The API reference documentation for [Package.Dependency](https://docs.swift.org/swiftpm/documentation/packagedescription/package/dependency) defines the methods to use.
55
+
56
+
### Packages with Traits
57
+
58
+
Traits, introduced with Swift 6.1, allow packages to offer additional API that may include optional dependencies.
59
+
Packages should offer traits to provide API beyond the core of a package.
60
+
For example, a package may provide an experimental API, an optional API that requires additional dependencies, or functionality that isn't critical that a developer may want to enable only in specific circumstances.
61
+
62
+
If a package offers traits and you depend on it without defining the traits to use, the package uses its default set of traits.
63
+
In the following example, the dependency `example-package-playingcard` uses its default traits, if it offers any:
To determine what traits a package offers, including its defaults, either inspect its `Package.swift` manifest or use <doc:PackageShowDependencies> to print out the resolved dependencies and their traits.
72
+
73
+
Enabling a trait should only expand the API offered by a package.
74
+
If a package offers default traits, you can choose to not use those traits by declaring an empty set of traits when you declare the dependency.
75
+
The following example dependency declaration uses the dependency with no traits, even if the package normally provides a set of default traits to enable:
Swift package manager determines the traits to enable using the entire graph of dependencies in a project.
86
+
The traits enabled for a dependency is the union of all of the traits that for packages that depend upon it.
87
+
For example, if you opt out of all traits, but a dependency you use uses the same package with some trait enabled, the package will use the depdendency with the requested traits enabled.
88
+
89
+
> Note: By disabling any default traits, you may be removing available APIs from the dependency you use.
90
+
91
+
To learn how to provide packages with traits, see <doc:PackageTraits>.
55
92
56
93
### Local Dependencies
57
94
@@ -77,6 +114,7 @@ For more information on creating a binary target, see [Creating a multiplatform
0 commit comments