forked from ordo-one/package-benchmark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Package.swift
205 lines (183 loc) · 7.18 KB
/
Package.swift
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
// swift-tools-version: 5.7
import class Foundation.ProcessInfo
import PackageDescription
// If the environment variable BENCHMARK_DISABLE_JEMALLOC is set, we'll build the package without Jemalloc support
let disableJemalloc = ProcessInfo.processInfo.environment["BENCHMARK_DISABLE_JEMALLOC"]
let package = Package(
name: "Benchmark",
platforms: [
.macOS(.v13),
.iOS(.v16)
],
products: [
.plugin(name: "BenchmarkCommandPlugin", targets: ["BenchmarkCommandPlugin"]),
.plugin(name: "BenchmarkPlugin", targets: ["BenchmarkPlugin"]),
.library(
name: "Benchmark",
targets: ["Benchmark"]
),
],
dependencies: [
.package(url: "https://github.com/apple/swift-system", .upToNextMajor(from: "1.2.0")),
.package(url: "https://github.com/apple/swift-argument-parser", .upToNextMajor(from: "1.1.0")),
.package(url: "https://github.com/swift-extras/swift-extras-json", .upToNextMajor(from: "0.6.0")),
// .package(url: "https://github.com/SwiftPackageIndex/SPIManifest", from: "0.12.0"),
.package(url: "https://github.com/ordo-one/TextTable", .upToNextMajor(from: "0.0.1")),
.package(url: "https://github.com/ordo-one/package-datetime", .upToNextMajor(from: "1.0.1")),
.package(url: "https://github.com/ordo-one/package-histogram", .upToNextMajor(from: "0.0.1")),
.package(url: "https://github.com/ordo-one/Progress.swift", .upToNextMajor(from: "1.0.0")),
.package(url: "https://github.com/apple/swift-docc-plugin", .upToNextMajor(from: "1.1.0")),
.package(url: "https://github.com/apple/swift-atomics", .upToNextMajor(from: "1.0.0")),
],
targets: [
// Plugins used by users of the package
// The actual 'benchmark' command plugin
.plugin(
name: "BenchmarkCommandPlugin",
capability: .command(
intent: .custom(
verb: "benchmark",
description: "Run the Benchmark performance test suite."
)
),
dependencies: [
"BenchmarkTool",
],
path: "Plugins/BenchmarkCommandPlugin"
),
// Plugin that generates the boilerplate needed to interface with the Benchmark infrastructure
.plugin(
name: "BenchmarkPlugin",
capability: .buildTool(),
dependencies: [
"BenchmarkBoilerplateGenerator",
],
path: "Plugins/BenchmarkPlugin"
),
// Tool that the plugin executes to perform the actual work, the real benchmark driver
.executableTarget(
name: "BenchmarkTool",
dependencies: [
.product(name: "ArgumentParser", package: "swift-argument-parser"),
.product(name: "SystemPackage", package: "swift-system"),
.product(name: "ExtrasJSON", package: "swift-extras-json"),
.product(name: "TextTable", package: "TextTable"),
"Benchmark",
],
path: "Plugins/BenchmarkTool"
),
// Tool that generates the boilerplate
.executableTarget(
name: "BenchmarkBoilerplateGenerator",
dependencies: [
.product(name: "ArgumentParser", package: "swift-argument-parser"),
.product(name: "SystemPackage", package: "swift-system"),
],
path: "Plugins/BenchmarkBoilerplateGenerator"
),
// Tool that simply generates the man page for the BenchmarkPlugin as we can't use SAP in it... :-/
.executableTarget(
name: "BenchmarkHelpGenerator",
dependencies: [
.product(name: "ArgumentParser", package: "swift-argument-parser"),
],
path: "Plugins/BenchmarkHelpGenerator"
),
// Getting OS specific information
.target(
name: "CDarwinOperatingSystemStats",
dependencies: [
],
path: "Platform/CDarwinOperatingSystemStats"
),
// Getting OS specific information
.target(
name: "CLinuxOperatingSystemStats",
dependencies: [
],
path: "Platform/CLinuxOperatingSystemStats"
),
// Hooks for ARC
.target(name: "SwiftRuntimeHooks"),
.testTarget(
name: "BenchmarkTests",
dependencies: ["Benchmark"]
),
]
)
// Check if this is a SPI build, then we need to disable jemalloc for macOS
let macOSSPIBuild: Bool // Disables jemalloc for macOS SPI builds as the infrastructure doesn't have jemalloc there
#if os(macOS) || os(iOS)
if let spiBuildEnvironment = ProcessInfo.processInfo.environment["SPI_BUILD"], spiBuildEnvironment == "1" {
macOSSPIBuild = true
print("Building for SPI@macOS, disabling Jemalloc")
} else {
macOSSPIBuild = false
}
#else
macOSSPIBuild = false
#endif
// Add Benchmark target dynamically
// Shared dependencies
var dependencies: [PackageDescription.Target.Dependency] = [
.product(name: "Histogram", package: "package-histogram"),
.product(name: "ArgumentParser", package: "swift-argument-parser"),
.product(name: "ExtrasJSON", package: "swift-extras-json"),
.product(name: "SystemPackage", package: "swift-system"),
.product(name: "DateTime", package: "package-datetime"),
.product(name: "Progress", package: "Progress.swift"),
.byNameItem(name: "CDarwinOperatingSystemStats", condition: .when(platforms: [.macOS, .iOS])),
.byNameItem(name: "CLinuxOperatingSystemStats", condition: .when(platforms: [.linux])),
.product(name: "Atomics", package: "swift-atomics"),
"SwiftRuntimeHooks",
]
if macOSSPIBuild == false { // jemalloc always disable for macOSSPIBuild
if let disableJemalloc, disableJemalloc != "false", disableJemalloc != "0" {
print("Jemalloc disabled through environment variable.")
} else {
package.dependencies += [.package(url: "https://github.com/ordo-one/package-jemalloc", .upToNextMajor(from: "1.0.0"))]
dependencies += [.product(name: "jemalloc", package: "package-jemalloc")]
}
}
package.targets += [.target(name: "Benchmark", dependencies: dependencies)]
// Add benchmark targets separately
// Benchmark of the DateTime package (which can't depend on Benchmark as we'll get a circular dependency)
package.targets += [
.executableTarget(
name: "BenchmarkDateTime",
dependencies: [
"Benchmark",
],
path: "Benchmarks/DateTime",
plugins: [
"BenchmarkPlugin"
]
)
]
// Benchmark of the benchmark package
package.targets += [
.executableTarget(
name: "Basic",
dependencies: [
"Benchmark",
],
path: "Benchmarks/Basic",
plugins: [
"BenchmarkPlugin"
]
),
]
// Benchmark of the Histogram package
package.targets += [
.executableTarget(
name: "HistogramBenchmark",
dependencies: [
"Benchmark",
.product(name: "Histogram", package: "package-histogram"),
],
path: "Benchmarks/Histogram",
plugins: [
"BenchmarkPlugin"
]
),
]