forked from realm/realm-swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Package.swift
342 lines (330 loc) · 12.2 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
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
// swift-tools-version:5.3
import PackageDescription
import Foundation
let coreVersionStr = "11.13.0"
let cocoaVersionStr = "10.25.0"
let coreVersionPieces = coreVersionStr.split(separator: ".")
let coreVersionExtra = coreVersionPieces[2].split(separator: "-")
let cxxSettings: [CXXSetting] = [
.headerSearchPath("."),
.headerSearchPath("include"),
.define("REALM_SPM", to: "1"),
.define("REALM_ENABLE_SYNC", to: "1"),
.define("REALM_COCOA_VERSION", to: "@\"\(cocoaVersionStr)\""),
.define("REALM_VERSION", to: "\"\(coreVersionStr)\""),
.define("REALM_DEBUG", .when(configuration: .debug)),
.define("REALM_NO_CONFIG"),
.define("REALM_INSTALL_LIBEXECDIR", to: ""),
.define("REALM_ENABLE_ASSERTIONS", to: "1"),
.define("REALM_ENABLE_ENCRYPTION", to: "1"),
.define("REALM_VERSION_MAJOR", to: String(coreVersionPieces[0])),
.define("REALM_VERSION_MINOR", to: String(coreVersionPieces[1])),
.define("REALM_VERSION_PATCH", to: String(coreVersionExtra[0])),
.define("REALM_VERSION_EXTRA", to: "\"\(coreVersionExtra.count > 1 ? String(coreVersionExtra[1]) : "")\""),
.define("REALM_VERSION_STRING", to: "\"\(coreVersionStr)\""),
.define("REALM_ASYNC_WRITES", .when(configuration: .debug)),
]
let testCxxSettings: [CXXSetting] = cxxSettings + [
// Command-line `swift build` resolves header search paths
// relative to the package root, while Xcode resolves them
// relative to the target root, so we need both.
.headerSearchPath("Realm"),
.headerSearchPath(".."),
]
// Xcode 12.5's xctest crashes when reading obj-c metadata if the Swift tests
// aren't built targeting macOS 11. We still want all of the non-test code to
// target the normal lower version, though.
func hostMachineArch() -> String {
var systemInfo = utsname()
uname(&systemInfo)
let machineBytes = Mirror(reflecting: systemInfo.machine).children.map { UInt8($0.value as! Int8) }.prefix { $0 != 0 }
return String(bytes: machineBytes, encoding: .utf8)!
}
let testSwiftSettings: [SwiftSetting]?
#if swift(>=5.4) && !swift(>=5.5)
testSwiftSettings = [.unsafeFlags(["-target", "\(hostMachineArch())-apple-macosx11.0"]),
.define("REALM_ASYNC_WRITES", .when(configuration: .debug)),
]
#else
testSwiftSettings = [.define("REALM_ASYNC_WRITES", .when(configuration: .debug))]
#endif
// SPM requires all targets to explicitly include or exclude every file, which
// gets very awkward when we have four targets building from a single directory
let objectServerTestSources = [
"Object-Server-Tests-Bridging-Header.h",
"ObjectServerTests-Info.plist",
"RLMBSONTests.mm",
"RLMCollectionSyncTests.mm",
"RLMFlexibleSyncServerTests.mm",
"RLMObjectServerPartitionTests.mm",
"RLMObjectServerTests.mm",
"RLMServerTestObjects.m",
"RLMSyncTestCase.h",
"RLMSyncTestCase.mm",
"RLMTestUtils.h",
"RLMTestUtils.m",
"RLMUser+ObjectServerTests.h",
"RLMUser+ObjectServerTests.mm",
"RLMWatchTestUtility.h",
"RLMWatchTestUtility.m",
"RealmServer.swift",
"SwiftCollectionSyncTests.swift",
"SwiftFlexibleSyncServerTests.swift",
"SwiftMongoClientTests.swift",
"SwiftObjectServerPartitionTests.swift",
"SwiftObjectServerTests.swift",
"SwiftServerObjects.swift",
"SwiftSyncTestCase.swift",
"SwiftUIServerTests.swift",
"TimeoutProxyServer.swift",
"WatchTestUtility.swift",
"certificates",
"include",
"setup_baas.rb",
]
func objectServerTestSupportTarget(name: String, dependencies: [Target.Dependency], sources: [String]) -> Target {
.target(
name: name,
dependencies: dependencies,
path: "Realm/ObjectServerTests",
exclude: objectServerTestSources.filter { !sources.contains($0) },
sources: sources,
cxxSettings: testCxxSettings,
swiftSettings: testSwiftSettings
)
}
func objectServerTestTarget(name: String, sources: [String]) -> Target {
.testTarget(
name: name,
dependencies: ["RealmSwift", "RealmTestSupport", "RealmSyncTestSupport", "RealmSwiftSyncTestSupport"],
path: "Realm/ObjectServerTests",
exclude: objectServerTestSources.filter { !sources.contains($0) },
sources: sources,
cxxSettings: testCxxSettings,
swiftSettings: testSwiftSettings
)
}
let package = Package(
name: "Realm",
platforms: [
.macOS(.v10_10),
.iOS(.v11),
.tvOS(.v9),
.watchOS(.v2)
],
products: [
.library(
name: "Realm",
targets: ["Realm"]),
.library(
name: "RealmSwift",
targets: ["Realm", "RealmSwift"]),
],
dependencies: [
.package(name: "RealmDatabase", url: "https://github.com/realm/realm-core", .exact(Version(coreVersionStr)!))
],
targets: [
.target(
name: "Realm",
dependencies: [.product(name: "RealmCore", package: "RealmDatabase")],
path: ".",
exclude: [
"CHANGELOG.md",
"CONTRIBUTING.md",
"Carthage",
"Configuration",
"Jenkinsfile.releasability",
"LICENSE",
"Package.swift",
"README.md",
"Realm.podspec",
"Realm.xcodeproj",
"Realm/ObjectServerTests",
"Realm/RLMPlatform.h.in",
"Realm/Realm-Info.plist",
"Realm/Swift/RLMSupport.swift",
"Realm/TestUtils",
"Realm/Tests",
"RealmSwift",
"RealmSwift.podspec",
"SUPPORT.md",
"build.sh",
"ci_scripts/ci_post_clone.sh",
"contrib",
"dependencies.list",
"docs",
"examples",
"include",
"logo.png",
"plugin",
"scripts",
],
sources: [
"Realm/RLMAccessor.mm",
"Realm/RLMAnalytics.mm",
"Realm/RLMArray.mm",
"Realm/RLMClassInfo.mm",
"Realm/RLMCollection.mm",
"Realm/RLMConstants.m",
"Realm/RLMDecimal128.mm",
"Realm/RLMDictionary.mm",
"Realm/RLMEmbeddedObject.mm",
"Realm/RLMManagedArray.mm",
"Realm/RLMManagedDictionary.mm",
"Realm/RLMManagedSet.mm",
"Realm/RLMMigration.mm",
"Realm/RLMObject.mm",
"Realm/RLMObjectBase.mm",
"Realm/RLMObjectId.mm",
"Realm/RLMObjectSchema.mm",
"Realm/RLMObjectStore.mm",
"Realm/RLMObservation.mm",
"Realm/RLMPredicateUtil.mm",
"Realm/RLMProperty.mm",
"Realm/RLMQueryUtil.mm",
"Realm/RLMRealm.mm",
"Realm/RLMRealmConfiguration.mm",
"Realm/RLMRealmUtil.mm",
"Realm/RLMResults.mm",
"Realm/RLMSchema.mm",
"Realm/RLMSet.mm",
"Realm/RLMSwiftCollectionBase.mm",
"Realm/RLMSwiftSupport.m",
"Realm/RLMSwiftValueStorage.mm",
"Realm/RLMThreadSafeReference.mm",
"Realm/RLMUpdateChecker.mm",
"Realm/RLMUtil.mm",
"Realm/RLMUUID.mm",
"Realm/RLMValue.mm",
// Sync source files
"Realm/NSError+RLMSync.m",
"Realm/RLMApp.mm",
"Realm/RLMAPIKeyAuth.mm",
"Realm/RLMBSON.mm",
"Realm/RLMCredentials.mm",
"Realm/RLMEmailPasswordAuth.mm",
"Realm/RLMFindOneAndModifyOptions.mm",
"Realm/RLMFindOptions.mm",
"Realm/RLMMongoClient.mm",
"Realm/RLMMongoCollection.mm",
"Realm/RLMNetworkTransport.mm",
"Realm/RLMProviderClient.mm",
"Realm/RLMPushClient.mm",
"Realm/RLMRealm+Sync.mm",
"Realm/RLMRealmConfiguration+Sync.mm",
"Realm/RLMSyncConfiguration.mm",
"Realm/RLMSyncManager.mm",
"Realm/RLMSyncSession.mm",
"Realm/RLMSyncSubscription.mm",
"Realm/RLMSyncUtil.mm",
"Realm/RLMUpdateResult.mm",
"Realm/RLMUser.mm",
"Realm/RLMUserAPIKey.mm"
],
publicHeadersPath: "include",
cxxSettings: cxxSettings
),
.target(
name: "RealmSwift",
dependencies: ["Realm"],
path: "RealmSwift",
exclude: [
"Nonsync.swift",
"RealmSwift-Info.plist",
"Tests",
]
),
.target(
name: "RealmTestSupport",
dependencies: ["Realm"],
path: "Realm/TestUtils",
cxxSettings: testCxxSettings
),
.testTarget(
name: "RealmTests",
dependencies: ["Realm", "RealmTestSupport"],
path: "Realm/Tests",
exclude: [
"PrimitiveArrayPropertyTests.tpl.m",
"PrimitiveDictionaryPropertyTests.tpl.m",
"PrimitiveRLMValuePropertyTests.tpl.m",
"PrimitiveSetPropertyTests.tpl.m",
"RealmTests-Info.plist",
"Swift",
"SwiftUITestHost",
"SwiftUITestHostUITests",
"TestHost",
"array_tests.py",
"dictionary_tests.py",
"fileformat-pre-null.realm",
"mixed_tests.py",
"set_tests.py",
"SwiftUISyncTestHost",
"SwiftUISyncTestHostUITests"
],
cxxSettings: testCxxSettings
),
.testTarget(
name: "RealmObjcSwiftTests",
dependencies: ["Realm", "RealmTestSupport"],
path: "Realm/Tests/Swift",
exclude: ["RealmObjcSwiftTests-Info.plist"],
swiftSettings: testSwiftSettings
),
.testTarget(
name: "RealmSwiftTests",
dependencies: ["RealmSwift", "RealmTestSupport"],
path: "RealmSwift/Tests",
exclude: [
"RealmSwiftTests-Info.plist",
"QueryTests.swift.gyb"
],
swiftSettings: testSwiftSettings
),
// Object server tests have support code written in both obj-c and
// Swift which is used by both the obj-c and swift test code. SPM
// doesn't support mixed targets, so this ends up requiring four
// different targest.
objectServerTestSupportTarget(
name: "RealmSyncTestSupport",
dependencies: ["Realm", "RealmSwift", "RealmTestSupport"],
sources: ["RLMSyncTestCase.mm",
"RLMUser+ObjectServerTests.mm",
"RLMServerTestObjects.m"]
),
objectServerTestSupportTarget(
name: "RealmSwiftSyncTestSupport",
dependencies: ["RealmSwift", "RealmTestSupport", "RealmSyncTestSupport"],
sources: [
"SwiftSyncTestCase.swift",
"TimeoutProxyServer.swift",
"WatchTestUtility.swift",
"RealmServer.swift",
"SwiftServerObjects.swift"
]
),
objectServerTestTarget(
name: "SwiftObjectServerTests",
sources: [
"SwiftObjectServerTests.swift",
"SwiftCollectionSyncTests.swift",
"SwiftObjectServerPartitionTests.swift",
"SwiftUIServerTests.swift",
"SwiftMongoClientTests.swift",
"SwiftFlexibleSyncServerTests.swift"
]
),
objectServerTestTarget(
name: "ObjcObjectServerTests",
sources: [
"RLMBSONTests.mm",
"RLMCollectionSyncTests.mm",
"RLMObjectServerPartitionTests.mm",
"RLMObjectServerTests.mm",
"RLMWatchTestUtility.m",
"RLMFlexibleSyncServerTests.mm"
]
)
],
cxxLanguageStandard: .cxx1z
)