-
Notifications
You must be signed in to change notification settings - Fork 353
Expand file tree
/
Copy pathPackage.swift
More file actions
367 lines (343 loc) · 15.4 KB
/
Package.swift
File metadata and controls
367 lines (343 loc) · 15.4 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
361
362
363
364
365
366
367
// swift-tools-version: 5.9
import PackageDescription
import Foundation
// =============================================================================
// RunAnywhere SDK - Swift Package Manager Distribution
// =============================================================================
//
// This is the SINGLE Package.swift for both local development and SPM consumption.
//
// FOR EXTERNAL USERS (consuming via GitHub):
// .package(url: "https://github.com/RunanywhereAI/runanywhere-sdks", from: "0.17.0")
//
// FOR LOCAL DEVELOPMENT:
// 1. Run: cd sdk/runanywhere-swift && ./scripts/build-swift.sh --setup
// 2. Open the example app in Xcode
// 3. The app references this package via relative path
//
// =============================================================================
// Combined ONNX Runtime xcframework (local dev) is created by:
// cd sdk/runanywhere-swift && ./scripts/create-onnxruntime-xcframework.sh
// =============================================================================
// BINARY TARGET CONFIGURATION
// =============================================================================
//
// useLocalNatives = true → Use local XCFrameworks from sdk/runanywhere-swift/Binaries/
// For local development. Run first-time setup:
// cd sdk/runanywhere-swift && ./scripts/build-swift.sh --setup
//
// useLocalNatives = false → Download XCFrameworks from GitHub releases (PRODUCTION)
// For external users via SPM. No setup needed.
//
// To toggle this value, use:
// ./scripts/build-swift.sh --set-local (sets useLocalNatives = true)
// ./scripts/build-swift.sh --set-remote (sets useLocalNatives = false)
//
// Historical name: this used to be called `useLocalBinaries`. The concept is
// the same — it's been renamed to `useLocalNatives` for consistency with the
// equivalent toggle in the other client SDKs (Kotlin, Flutter, React Native).
// =============================================================================
let useLocalNatives = false // Toggle: true for local dev, false for release
// Version for remote XCFrameworks (used when useLocalNatives = false)
// Updated automatically by CI/CD during releases
let sdkVersion = "0.19.13"
// MetalRT remote binary availability flag.
// Set to `false` until a real checksum for RABackendMetalRT-v<sdkVersion>.zip
// has been published. When `false`, the MetalRT product/targets are only
// exposed under `useLocalNatives = true`, so SPM resolution will not fail
// for external consumers due to a placeholder checksum.
let metalrtRemoteBinaryAvailable = false
let includeMetalRT = useLocalNatives || metalrtRemoteBinaryAvailable
let package = Package(
name: "runanywhere-sdks",
platforms: [
.iOS(.v17),
.macOS(.v14),
],
products: [
// =================================================================
// Core SDK - always needed
// =================================================================
.library(
name: "RunAnywhere",
targets: ["RunAnywhere"]
),
// =================================================================
// ONNX Runtime Backend - adds STT/TTS/VAD capabilities
// =================================================================
.library(
name: "RunAnywhereONNX",
targets: ["ONNXRuntime"]
),
// =================================================================
// LlamaCPP Backend - adds LLM text generation
// =================================================================
.library(
name: "RunAnywhereLlamaCPP",
targets: ["LlamaCPPRuntime"]
),
// =================================================================
// WhisperKit Backend - adds STT via Apple Neural Engine
// =================================================================
.library(
name: "RunAnywhereWhisperKit",
targets: ["WhisperKitRuntime"]
),
] + metalRTProducts(),
dependencies: [
.package(url: "https://github.com/apple/swift-crypto.git", from: "3.0.0"),
.package(url: "https://github.com/Alamofire/Alamofire.git", from: "5.9.0"),
.package(url: "https://github.com/JohnSundell/Files.git", from: "4.3.0"),
.package(url: "https://github.com/devicekit/DeviceKit.git", from: "5.6.0"),
.package(url: "https://github.com/getsentry/sentry-cocoa", from: "8.40.0"),
// ml-stable-diffusion for CoreML-based image generation
.package(url: "https://github.com/apple/ml-stable-diffusion.git", from: "1.1.0"),
// WhisperKit for Neural Engine STT
.package(url: "https://github.com/argmaxinc/WhisperKit.git", from: "0.9.0"),
],
targets: [
// =================================================================
// C Bridge Module - Core Commons
// =================================================================
.target(
name: "CRACommons",
dependencies: ["RACommonsBinary"],
path: "sdk/runanywhere-swift/Sources/RunAnywhere/CRACommons",
publicHeadersPath: "include"
),
// =================================================================
// C Bridge Module - LlamaCPP Backend Headers
// =================================================================
.target(
name: "LlamaCPPBackend",
dependencies: ["RABackendLlamaCPPBinary"],
path: "sdk/runanywhere-swift/Sources/LlamaCPPRuntime/include",
publicHeadersPath: "."
),
// =================================================================
// C Bridge Module - ONNX Backend Headers
//
// ONNX Runtime is now statically linked into RABackendONNX.a — no
// separate ONNXRuntime{iOS,macOS}Binary targets needed. They were
// previously distributed as separate xcframeworks but are bundled
// since v0.19.0.
// =================================================================
.target(
name: "ONNXBackend",
dependencies: [
"RABackendONNXBinary",
],
path: "sdk/runanywhere-swift/Sources/ONNXRuntime/include",
publicHeadersPath: "."
),
// =================================================================
// Core SDK
// =================================================================
.target(
name: "RunAnywhere",
dependencies: [
.product(name: "Crypto", package: "swift-crypto"),
.product(name: "Alamofire", package: "Alamofire"),
.product(name: "Files", package: "Files"),
.product(name: "DeviceKit", package: "DeviceKit"),
.product(name: "Sentry", package: "sentry-cocoa"),
.product(name: "StableDiffusion", package: "ml-stable-diffusion"),
"CRACommons",
"RACommonsBinary",
],
path: "sdk/runanywhere-swift/Sources/RunAnywhere",
exclude: ["CRACommons"],
swiftSettings: [
.define("SWIFT_PACKAGE")
],
linkerSettings: [
.linkedLibrary("c++"),
]
),
// =================================================================
// ONNX Runtime Backend
// =================================================================
.target(
name: "ONNXRuntime",
dependencies: [
"RunAnywhere",
"ONNXBackend",
"RABackendONNXBinary",
],
path: "sdk/runanywhere-swift/Sources/ONNXRuntime",
exclude: ["include"],
linkerSettings: [
.linkedLibrary("c++"),
.linkedFramework("Accelerate"),
.linkedFramework("CoreML"),
.linkedLibrary("archive"),
.linkedLibrary("bz2"),
]
),
// =================================================================
// LlamaCPP Runtime Backend
// =================================================================
.target(
name: "LlamaCPPRuntime",
dependencies: [
"RunAnywhere",
"LlamaCPPBackend",
"RABackendLlamaCPPBinary",
],
path: "sdk/runanywhere-swift/Sources/LlamaCPPRuntime",
exclude: ["include"],
linkerSettings: [
.linkedLibrary("c++"),
.linkedFramework("Accelerate"),
.linkedFramework("Metal"),
.linkedFramework("MetalKit"),
]
),
// =================================================================
// WhisperKit Runtime Backend (Apple Neural Engine STT)
// =================================================================
.target(
name: "WhisperKitRuntime",
dependencies: [
"RunAnywhere",
.product(name: "WhisperKit", package: "whisperkit"),
],
path: "sdk/runanywhere-swift/Sources/WhisperKitRuntime",
linkerSettings: [
.linkedFramework("CoreML"),
.linkedFramework("Accelerate"),
]
),
// =================================================================
// RunAnywhere unit tests (e.g. AudioCaptureManager – Issue #198)
// =================================================================
.testTarget(
name: "RunAnywhereTests",
dependencies: ["RunAnywhere"],
path: "sdk/runanywhere-swift/Tests/RunAnywhereTests"
),
] + metalRTTargets() + binaryTargets()
)
// =============================================================================
// METALRT PRODUCT / TARGET GATING
// =============================================================================
// The RABackendMetalRT.xcframework is not yet published to GitHub releases
// with a real checksum. To avoid SPM resolution failures for external
// consumers due to a placeholder zero-checksum binary target, the MetalRT
// product and its dependent targets are only included when:
// - `useLocalNatives == true` (local dev with a checked-out xcframework), or
// - `metalrtRemoteBinaryAvailable == true` (once a real checksum is wired in).
func metalRTProducts() -> [Product] {
guard includeMetalRT else { return [] }
return [
.library(
name: "RunAnywhereMetalRT",
targets: ["MetalRTRuntime"]
),
]
}
func metalRTTargets() -> [Target] {
guard includeMetalRT else { return [] }
return [
// MetalRT C Bridge Module - exposes rac_backend_metalrt_register()
.target(
name: "MetalRTBackend",
dependencies: ["RABackendMetalRTBinary"],
path: "sdk/runanywhere-swift/Sources/MetalRTRuntime/include",
publicHeadersPath: "."
),
// MetalRT Runtime Backend (custom Metal GPU kernels)
.target(
name: "MetalRTRuntime",
dependencies: [
"RunAnywhere",
"MetalRTBackend",
"RABackendMetalRTBinary",
],
path: "sdk/runanywhere-swift/Sources/MetalRTRuntime",
exclude: ["include"],
resources: [
.copy("Resources/default.metallib"),
],
linkerSettings: [
.linkedLibrary("c++"),
.linkedFramework("Accelerate"),
.linkedFramework("Metal"),
.linkedFramework("CoreGraphics"),
.linkedFramework("ImageIO"),
]
),
]
}
// =============================================================================
// BINARY TARGET SELECTION
// =============================================================================
// Returns local or remote binary targets based on useLocalNatives setting
func binaryTargets() -> [Target] {
if useLocalNatives {
// =====================================================================
// LOCAL DEVELOPMENT MODE
// Use XCFrameworks from sdk/runanywhere-swift/Binaries/
// Run: cd sdk/runanywhere-swift && ./scripts/build-swift.sh --setup
//
// For macOS support, build with --include-macos:
// ./scripts/build-swift.sh --setup --include-macos
// =====================================================================
// ONNX Runtime is statically linked into RABackendONNX — no separate
// local xcframework targets needed (v0.19.0+).
return [
.binaryTarget(
name: "RACommonsBinary",
path: "sdk/runanywhere-swift/Binaries/RACommons.xcframework"
),
.binaryTarget(
name: "RABackendLlamaCPPBinary",
path: "sdk/runanywhere-swift/Binaries/RABackendLLAMACPP.xcframework"
),
.binaryTarget(
name: "RABackendONNXBinary",
path: "sdk/runanywhere-swift/Binaries/RABackendONNX.xcframework"
),
.binaryTarget(
name: "RABackendMetalRTBinary",
path: "sdk/runanywhere-swift/Binaries/RABackendMetalRT.xcframework"
),
]
} else {
// =====================================================================
// PRODUCTION MODE (for external SPM consumers)
// Download XCFrameworks from GitHub releases
// All xcframeworks include iOS + macOS slices (v0.19.0+)
// =====================================================================
var targets: [Target] = [
.binaryTarget(
name: "RACommonsBinary",
url: "https://github.com/RunanywhereAI/runanywhere-sdks/releases/download/v\(sdkVersion)/RACommons-ios-v\(sdkVersion).zip",
checksum: "a1caaf12186c896b49bfccc7348a71c3b3428b282e5ac3f5a3181a022b5401da"
),
.binaryTarget(
name: "RABackendLlamaCPPBinary",
url: "https://github.com/RunanywhereAI/runanywhere-sdks/releases/download/v\(sdkVersion)/RABackendLLAMACPP-ios-v\(sdkVersion).zip",
checksum: "7ff978fbc87726423c682298f04354c7c11dfbfe9403b51f63d49df9c92e097a"
),
.binaryTarget(
name: "RABackendONNXBinary",
url: "https://github.com/RunanywhereAI/runanywhere-sdks/releases/download/v\(sdkVersion)/RABackendONNX-ios-v\(sdkVersion).zip",
checksum: "0f8575559ac96a9a7b872bb3adca3608acef38fdec1ab8ccf9b0716a8d627c6c"
),
]
// MetalRT remote binary is only appended once a real checksum has been
// published. Until then the MetalRT product/targets are omitted from
// the package graph entirely (see metalRTProducts/metalRTTargets).
if metalrtRemoteBinaryAvailable {
targets.append(
.binaryTarget(
name: "RABackendMetalRTBinary",
url: "https://github.com/RunanywhereAI/runanywhere-sdks/releases/download/v\(sdkVersion)/RABackendMetalRT-ios-v\(sdkVersion).zip",
checksum: "0000000000000000000000000000000000000000000000000000000000000000" // TODO: replace with real checksum
)
)
}
return targets
}
}