-
Notifications
You must be signed in to change notification settings - Fork 58
Expand file tree
/
Copy pathPackage.swift
More file actions
210 lines (188 loc) · 7.63 KB
/
Copy pathPackage.swift
File metadata and controls
210 lines (188 loc) · 7.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
// swift-tools-version: 6.2
import PackageDescription
#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif
let defaultTraits: Set<String> = [
"JSON"
]
var traits: Set<Trait> = [
.trait(
name: "Logging",
description: "Adds support for swift-log integration."
),
.trait(
name: "JSON",
description: "Adds support for parsing JSON configuration files."
),
.trait(
name: "Reloading",
description:
"Adds support for reloading built-in provider variants, such as ReloadingFileProvider.",
enabledTraits: [
"Logging"
]
),
.trait(
name: "CommandLineArguments",
description: "Adds support for parsing command line arguments."
),
.trait(
name: "YAML",
description: "Adds support for parsing YAML configuration files."
),
.trait(
name: "PropertyList",
description: "Adds support for parsing property list configuration files."
),
]
// Workaround to ensure that all traits are included in documentation. Swift Package Index adds
// SPI_GENERATE_DOCS (https://github.com/SwiftPackageIndex/SwiftPackageIndex-Server/issues/2336)
// when building documentation, so only tweak the default traits in this condition.
let spiGenerateDocs = ProcessInfo.processInfo.environment["SPI_GENERATE_DOCS"] != nil
// Conditionally add the swift-docc plugin only when previewing docs locally.
// Preview with:
// ```
// SWIFT_PREVIEW_DOCS=1 swift package --disable-sandbox preview-documentation --target Configuration
// ```
let previewDocs = ProcessInfo.processInfo.environment["SWIFT_PREVIEW_DOCS"] != nil
// Enable all traits for other CI actions.
let enableAllTraitsExplicit = ProcessInfo.processInfo.environment["ENABLE_ALL_TRAITS"] != nil
let enableAllTraits = spiGenerateDocs || previewDocs || enableAllTraitsExplicit
let addDoccPlugin = previewDocs || spiGenerateDocs
let enableAllCIFlags = enableAllTraitsExplicit
traits.insert(
.default(
enabledTraits: enableAllTraits ? Set(traits.map(\.name)) : defaultTraits
),
)
let package = Package(
name: "swift-configuration",
products: [
.library(name: "Configuration", targets: ["Configuration"]),
.library(name: "ConfigurationTesting", targets: ["ConfigurationTesting"]),
],
traits: traits,
dependencies: [
.package(url: "https://github.com/apple/swift-system", from: "1.5.0"),
.package(url: "https://github.com/apple/swift-collections", from: "1.3.0"),
.package(url: "https://github.com/swift-server/swift-service-lifecycle", from: "2.8.0"),
.package(url: "https://github.com/apple/swift-log", from: "1.6.3"),
.package(url: "https://github.com/apple/swift-metrics", from: "2.7.0"),
.package(url: "https://github.com/jpsim/Yams", "5.4.0"..<"7.0.0"),
],
targets: [
// Configuration library
.target(
name: "Configuration",
dependencies: [
.product(
name: "SystemPackage",
package: "swift-system"
),
.product(
name: "DequeModule",
package: "swift-collections"
),
.product(
name: "Logging",
package: "swift-log",
condition: .when(traits: ["Logging"])
),
.product(
name: "Metrics",
package: "swift-metrics",
condition: .when(traits: ["Reloading"])
),
.product(
name: "ServiceLifecycle",
package: "swift-service-lifecycle",
condition: .when(traits: ["Reloading"])
),
.product(
name: "Yams",
package: "Yams",
condition: .when(traits: ["YAML"])
),
],
exclude: [
"ConfigReader+methods.swift.gyb",
"ConfigSnapshotReader+methods.swift.gyb",
]
),
// Unit tests
.testTarget(
name: "ConfigurationTests",
dependencies: [
"Configuration",
"ConfigurationTestingInternal",
"ConfigurationTesting",
],
exclude: [
"ConfigReaderTests/ConfigReaderMethodTestsGet1.swift.gyb",
"ConfigReaderTests/ConfigReaderMethodTestsGet2.swift.gyb",
"ConfigReaderTests/ConfigReaderMethodTestsGet3.swift.gyb",
"ConfigReaderTests/ConfigReaderMethodTestsGet4.swift.gyb",
"ConfigReaderTests/ConfigReaderMethodTestsGet5.swift.gyb",
"ConfigReaderTests/ConfigReaderMethodTestsFetch1.swift.gyb",
"ConfigReaderTests/ConfigReaderMethodTestsFetch2.swift.gyb",
"ConfigReaderTests/ConfigReaderMethodTestsFetch3.swift.gyb",
"ConfigReaderTests/ConfigReaderMethodTestsFetch4.swift.gyb",
"ConfigReaderTests/ConfigReaderMethodTestsFetch5.swift.gyb",
"ConfigReaderTests/ConfigReaderMethodTestsWatch1.swift.gyb",
"ConfigReaderTests/ConfigReaderMethodTestsWatch2.swift.gyb",
"ConfigReaderTests/ConfigReaderMethodTestsWatch3.swift.gyb",
"ConfigReaderTests/ConfigReaderMethodTestsWatch4.swift.gyb",
"ConfigReaderTests/ConfigReaderMethodTestsWatch5.swift.gyb",
"ConfigReaderTests/ConfigSnapshotReaderMethodTestsGet1.swift.gyb",
"ConfigReaderTests/ConfigSnapshotReaderMethodTestsGet2.swift.gyb",
"ConfigReaderTests/ConfigSnapshotReaderMethodTestsGet3.swift.gyb",
]
),
// Testing (a public library)
.target(
name: "ConfigurationTesting",
dependencies: [
"Configuration",
"ConfigurationTestingInternal",
]
),
// Internals
.target(
name: "ConfigurationTestingInternal",
dependencies: [
"Configuration",
.product(name: "ServiceLifecycle", package: "swift-service-lifecycle"),
]
),
]
)
for target in package.targets {
var settings = target.swiftSettings ?? []
// https://github.com/apple/swift-evolution/blob/main/proposals/0335-existential-any.md
// Require `any` for existential types.
settings.append(.enableUpcomingFeature("ExistentialAny"))
// https://github.com/swiftlang/swift-evolution/blob/main/proposals/0444-member-import-visibility.md
settings.append(.enableUpcomingFeature("MemberImportVisibility"))
// https://github.com/swiftlang/swift-evolution/blob/main/proposals/0409-access-level-on-imports.md
settings.append(.enableUpcomingFeature("InternalImportsByDefault"))
// https://docs.swift.org/compiler/documentation/diagnostics/nonisolated-nonsending-by-default/
settings.append(.enableUpcomingFeature("NonisolatedNonsendingByDefault"))
settings.append(
.enableExperimentalFeature(
"AvailabilityMacro=Configuration 1.0:macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0"
)
)
if enableAllCIFlags {
// Ensure all public types are explicitly annotated as Sendable or not Sendable.
settings.append(.unsafeFlags(["-Xfrontend", "-require-explicit-sendable"]))
}
target.swiftSettings = settings
}
if addDoccPlugin {
package.dependencies.append(
.package(url: "https://github.com/swiftlang/swift-docc-plugin", from: "1.0.0")
)
}