Repository navigation
Expand file tree
/
Copy pathPackage.swift
More file actions
360 lines (356 loc) · 13.5 KB
/
Copy pathPackage.swift
File metadata and controls
360 lines (356 loc) · 13.5 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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
// swift-tools-version:5.10
// SPDX-License-Identifier: Apache-2.0
import PackageDescription
// The FB* XCFrameworks built by `scripts/build.sh` are STATIC archives
// (upstream idb switched its frameworks to MACH_O_TYPE staticlib), so the
// FB* code links into the consuming binary and nothing is loaded at
// runtime. Two consequences wired up below:
//
// 1. The FB* Swift modules import the reverse-engineered private-framework
// Clang modules bundled with idb (CoreSimulator, SimulatorKit, ...).
// Every target that compiles `import FBControlCore` /
// `import FBSimulatorControl` — directly or through iOSSimBackend's
// swiftmodule — needs those module maps on the compiler search path.
// `scripts/build.sh` stages them under build_products/PrivateHeaders/.
// 2. The static archives defer their CoreSimulator /
// AccessibilityPlatformTranslation class references to the final link,
// which must weak-link the .tbd stubs (the real frameworks are loaded
// at runtime by FBSimulatorControlFrameworkLoader).
//
// The ObjC-heavy archives are `-force_load`ed (per archive, NOT a blanket
// `-ObjC`): their category-only members (e.g. FBControlCoreLogger+OSLog)
// export no referenced symbol, so a normal archive link drops them and
// the first runtime use dies with "unrecognized selector"
// (+[FBControlCoreLoggerFactory osLoggerWithLevel:], reproduced).
// CompanionUtilities is deliberately NOT force-loaded: it is pure Swift
// (everything it provides is pulled in by ordinary symbol references),
// and force-loading it makes Xcode 26.5-built binaries abort with
// "freed pointer was not the last allocation" — a Swift task-allocator
// trap in unrelated async code (bisected per-archive; Xcode 27 B4 builds
// don't trip it).
//
// Both flag sets use `Context.packageDirectory` because SwiftPM resolves
// relative compiler/linker arguments against an unspecified working
// directory that differs between the classic and SwiftBuild backends.
// unsafeFlags make this package unusable as a SwiftPM dependency of
// another package; sim-use is a root package (CLI tool), so that is fine.
let privateHeadersDir = "\(Context.packageDirectory)/build_products/PrivateHeaders"
// The bare -I is needed too: the private headers include their siblings
// framework-style (e.g. <CoreSimulator/NSObject-Protocol.h>), which
// resolves as a subdirectory of the PrivateHeaders root.
let privateModuleMapFlags: [String] = ["-Xcc", "-I\(privateHeadersDir)"] + [
"CoreSimulator", "SimulatorApp", "SimulatorKit", "AXRuntime",
"AccessibilityPlatformTranslation",
].flatMap {
["-Xcc", "-fmodule-map-file=\(privateHeadersDir)/\($0)/module.modulemap"]
}
let fbLinkerFlags: [String] = [
"FBControlCore", "FBSimulatorControl", "XCTestBootstrap", "FBDeviceControl",
].flatMap {
[
"-Xlinker", "-force_load",
"-Xlinker",
"\(Context.packageDirectory)/build_products/XCFrameworks/\($0).xcframework/macos-arm64_x86_64/\($0).framework/Versions/A/\($0)",
]
} + [
"CoreSimulator", "AccessibilityPlatformTranslation",
].flatMap {
["-Xlinker", "-weak_library", "-Xlinker", "\(privateHeadersDir)/\($0)/\($0).tbd"]
}
#if os(Linux)
// Linux builds the Android half only. The Android backend drives the
// device through `adb` plus the bridge APK's HTTP server and needs none
// of the Apple frameworks below: no iOS backends, no FB* XCFrameworks,
// and no SimUseVideo (AVFoundation), so `record-video` / `stream-video`
// are left out. `sim-use` is built from `SimUseLinux`, which exposes the
// Android verbs at the top level plus the `android` namespace.
let package = Package(
name: "SimUse",
products: [
.executable(
name: "sim-use",
targets: ["SimUseLinux"]
),
.library(
name: "SimUseCore",
targets: ["SimUseCore"]
),
.library(
name: "AndroidBackend",
targets: ["AndroidBackend"]
),
],
dependencies: [
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.5.0"),
],
targets: [
.target(
name: "SimUseCore",
dependencies: [
.product(name: "ArgumentParser", package: "swift-argument-parser"),
],
path: "Sources/SimUseCore",
plugins: ["VersionPlugin"]
),
.target(
name: "AndroidBackend",
dependencies: [
"SimUseCore",
.product(name: "ArgumentParser", package: "swift-argument-parser"),
],
path: "Sources/AndroidBackend",
// Host-side video capture: the two verbs and the streaming
// process only they use.
exclude: [
"Adb/AdbStreamingProcess.swift",
"Verbs/AndroidRecordVideoCommand.swift",
"Verbs/AndroidStreamVideoCommand.swift",
],
resources: [
.copy("Resources"),
]
),
.executableTarget(
name: "SimUseLinux",
dependencies: [
"SimUseCore",
"AndroidBackend",
.product(name: "ArgumentParser", package: "swift-argument-parser"),
],
path: "Sources/SimUseLinux",
plugins: ["VersionPlugin"]
),
.testTarget(
name: "SimUseCoreTests",
dependencies: ["SimUseCore"],
path: "Tests/SimUseCoreTests"
),
.testTarget(
name: "AndroidBackendTests",
dependencies: ["AndroidBackend", "SimUseCore"],
path: "Tests/AndroidBackendTests",
exclude: [
"AndroidRecordVideoArgumentTests.swift",
]
),
.plugin(
name: "VersionPlugin",
capability: .buildTool(),
path: "Plugins/VersionPlugin"
),
]
)
#else
let package = Package(
name: "SimUse",
platforms: [
.macOS(.v14)
],
products: [
.executable(
name: "sim-use",
targets: ["SimUse"]
),
.library(
name: "SimUseCore",
targets: ["SimUseCore"]
),
.library(
name: "SimUseVideo",
targets: ["SimUseVideo"]
),
.library(
name: "AndroidBackend",
targets: ["AndroidBackend"]
),
.library(
name: "iOSSimBackend",
targets: ["iOSSimBackend"]
),
.library(
name: "iOSDeviceBackend",
targets: ["iOSDeviceBackend"]
),
],
dependencies: [
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.5.0"),
],
targets: [
.target(
name: "SimUseCore",
dependencies: [
.product(name: "ArgumentParser", package: "swift-argument-parser"),
],
path: "Sources/SimUseCore",
// VERSION is consumed by the daemon (DaemonClient version-
// check gate, DaemonServer ping response). Generating it
// per-target is cheap and keeps the daemon dependency-free
// of higher targets.
plugins: ["VersionPlugin"]
),
// Platform-neutral host-side video plumbing (H.264 parsing/muxing/
// encoding, frame utilities) shared by both backends. Must stay
// FB*-free: anything that needs FBSimulatorControl belongs in
// iOSSimBackend, anything adb-shaped in AndroidBackend.
.target(
name: "SimUseVideo",
dependencies: [
"SimUseCore",
.product(name: "ArgumentParser", package: "swift-argument-parser"),
],
path: "Sources/SimUseVideo"
),
.target(
name: "iOSSimBackend",
dependencies: [
"SimUseCore",
"SimUseVideo",
"FBSimulatorControl",
"FBControlCore",
"XCTestBootstrap",
"CompanionUtilities",
.product(name: "ArgumentParser", package: "swift-argument-parser"),
],
path: "Sources/iOSSimBackend",
swiftSettings: [
.unsafeFlags(privateModuleMapFlags)
],
plugins: ["VersionPlugin"]
),
// Physical iOS devices, driven over the accessibility audit daemon
// (usbmux lockdown -> DTX). sim-use installs no XCUITest runner and
// needs no Developer Disk Image; the target app must already be
// development-signed. With no element geometry, this target cannot
// share iOSSimBackend's frame-based machinery.
.target(
name: "iOSDeviceBackend",
dependencies: [
"SimUseCore",
"FBDeviceControl",
"FBControlCore",
.product(name: "ArgumentParser", package: "swift-argument-parser"),
],
path: "Sources/iOSDeviceBackend"
),
.target(
name: "AndroidBackend",
dependencies: [
"SimUseCore",
"SimUseVideo",
.product(name: "ArgumentParser", package: "swift-argument-parser"),
],
path: "Sources/AndroidBackend",
// Resources/ holds `sim-use-device-bridge.apk` at runtime
// (built by `scripts/build-bridge.sh`). Copy the whole
// directory so the SPM build doesn't require the APK to
// exist at build time — `AndroidDeviceController` surfaces
// a clear "Bridge APK not found" error when the resource
// is missing.
resources: [
.copy("Resources"),
]
),
.executableTarget(
name: "SimUse",
dependencies: [
.product(name: "ArgumentParser", package: "swift-argument-parser"),
"SimUseCore",
"SimUseVideo",
"AndroidBackend",
"iOSSimBackend",
"iOSDeviceBackend",
"FBSimulatorControl",
"FBControlCore",
"XCTestBootstrap",
"FBDeviceControl",
"CompanionUtilities"
],
path: "Sources/SimUse",
resources: [
.copy("Resources/skills"),
// Built Viewer SPA assets (Vite output). Re-generated by
// `scripts/build-viewer.sh`; committed so `swift build`
// works without Node on contributor machines that don't
// touch the Viewer. The `viewer` subcommand reads this
// tree via `Bundle.module.resourceURL` and serves it
// out of a local HTTP listener.
.copy("Resources/viewer"),
],
swiftSettings: [
.unsafeFlags(["-parse-as-library"] + privateModuleMapFlags)
],
linkerSettings: [
.unsafeFlags([
"-Xlinker", "-dead_strip",
"-Xlinker", "-headerpad_max_install_names",
] + fbLinkerFlags)
],
plugins: ["VersionPlugin"]
),
.testTarget(
name: "SimUseTests",
dependencies: ["SimUse", "iOSSimBackend", "iOSDeviceBackend", "SimUseCore", "SimUseVideo"],
path: "Tests",
// `Tests/` is the umbrella path; the sub-target test
// directories below sit under it as separate testTargets.
// List them by name in `exclude` so SwiftPM doesn't double-
// claim their sources. Add new test sub-directories here
// when adding new testTargets, or move them out from under
// `Tests/` to drop this maintenance burden.
exclude: [
"SimUseCoreTests",
"AndroidBackendTests",
],
resources: [
.copy("README.md"),
.copy("Fixtures")
],
swiftSettings: [
.unsafeFlags(privateModuleMapFlags)
],
linkerSettings: [
.unsafeFlags(fbLinkerFlags)
]
),
.testTarget(
name: "SimUseCoreTests",
dependencies: ["SimUseCore"],
path: "Tests/SimUseCoreTests"
),
.testTarget(
name: "AndroidBackendTests",
dependencies: ["AndroidBackend", "SimUseCore"],
path: "Tests/AndroidBackendTests"
// `Fixtures/` here is empty (`.gitkeep` only) — listing
// it as a resource would emit a SwiftPM warning. Add a
// `.copy("Fixtures")` entry when real fixture files
// land.
),
.plugin(
name: "VersionPlugin",
capability: .buildTool(),
path: "Plugins/VersionPlugin"
),
.binaryTarget(
name: "FBControlCore",
path: "build_products/XCFrameworks/FBControlCore.xcframework"
),
.binaryTarget(
name: "FBSimulatorControl",
path: "build_products/XCFrameworks/FBSimulatorControl.xcframework"
),
.binaryTarget(
name: "XCTestBootstrap",
path: "build_products/XCFrameworks/XCTestBootstrap.xcframework"
),
.binaryTarget(
name: "CompanionUtilities",
path: "build_products/XCFrameworks/CompanionUtilities.xcframework"
),
.binaryTarget(
name: "FBDeviceControl",
path: "build_products/XCFrameworks/FBDeviceControl.xcframework"
),
]
)
#endif