Skip to content

Commit 02123f4

Browse files
Merge PR #476: MetalRT backend + iOS demo polish (rebased on main)
Introduces a new MetalRT GPU-accelerated inference backend (LLM/STT/TTS/VLM) for Apple Silicon on iOS + substantial iOS example-app polish (thinking mode, benchmark metrics, tool-calling fixes, voice-session error gating). Note: RAC_FRAMEWORK_METALRT = 10. Genie (which claimed slot 10 on the reverted smonga/genie_support merge) is not currently on main. If #462 re-adds Genie, we will renumber Genie to slot 11 in that merge. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2 parents 6f3bce8 + ef75217 commit 02123f4

82 files changed

Lines changed: 4825 additions & 372 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Package.swift

Lines changed: 82 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,15 @@ let useLocalBinaries = false // Toggle: true for local dev, false for release
4343
// Updated automatically by CI/CD during releases
4444
let sdkVersion = "0.19.7"
4545

46+
// MetalRT remote binary availability flag.
47+
// Set to `false` until a real checksum for RABackendMetalRT-v<sdkVersion>.zip
48+
// has been published. When `false`, the MetalRT product/targets are only
49+
// exposed under `useLocalBinaries = true`, so SPM resolution will not fail
50+
// for external consumers due to a placeholder checksum.
51+
let metalrtRemoteBinaryAvailable = false
52+
53+
let includeMetalRT = useLocalBinaries || metalrtRemoteBinaryAvailable
54+
4655
let package = Package(
4756
name: "runanywhere-sdks",
4857
platforms: [
@@ -81,7 +90,8 @@ let package = Package(
8190
name: "RunAnywhereWhisperKit",
8291
targets: ["WhisperKitRuntime"]
8392
),
84-
],
93+
94+
] + metalRTProducts(),
8595
dependencies: [
8696
.package(url: "https://github.com/apple/swift-crypto.git", from: "3.0.0"),
8797
.package(url: "https://github.com/Alamofire/Alamofire.git", from: "5.9.0"),
@@ -221,9 +231,62 @@ let package = Package(
221231
path: "sdk/runanywhere-swift/Tests/RunAnywhereTests"
222232
),
223233

224-
] + binaryTargets()
234+
] + metalRTTargets() + binaryTargets()
225235
)
226236

237+
// =============================================================================
238+
// METALRT PRODUCT / TARGET GATING
239+
// =============================================================================
240+
// The RABackendMetalRT.xcframework is not yet published to GitHub releases
241+
// with a real checksum. To avoid SPM resolution failures for external
242+
// consumers due to a placeholder zero-checksum binary target, the MetalRT
243+
// product and its dependent targets are only included when:
244+
// - `useLocalBinaries == true` (local dev with a checked-out xcframework), or
245+
// - `metalrtRemoteBinaryAvailable == true` (once a real checksum is wired in).
246+
func metalRTProducts() -> [Product] {
247+
guard includeMetalRT else { return [] }
248+
return [
249+
.library(
250+
name: "RunAnywhereMetalRT",
251+
targets: ["MetalRTRuntime"]
252+
),
253+
]
254+
}
255+
256+
func metalRTTargets() -> [Target] {
257+
guard includeMetalRT else { return [] }
258+
return [
259+
// MetalRT C Bridge Module - exposes rac_backend_metalrt_register()
260+
.target(
261+
name: "MetalRTBackend",
262+
dependencies: ["RABackendMetalRTBinary"],
263+
path: "sdk/runanywhere-swift/Sources/MetalRTRuntime/include",
264+
publicHeadersPath: "."
265+
),
266+
// MetalRT Runtime Backend (custom Metal GPU kernels)
267+
.target(
268+
name: "MetalRTRuntime",
269+
dependencies: [
270+
"RunAnywhere",
271+
"MetalRTBackend",
272+
"RABackendMetalRTBinary",
273+
],
274+
path: "sdk/runanywhere-swift/Sources/MetalRTRuntime",
275+
exclude: ["include"],
276+
resources: [
277+
.copy("Resources/default.metallib"),
278+
],
279+
linkerSettings: [
280+
.linkedLibrary("c++"),
281+
.linkedFramework("Accelerate"),
282+
.linkedFramework("Metal"),
283+
.linkedFramework("CoreGraphics"),
284+
.linkedFramework("ImageIO"),
285+
]
286+
),
287+
]
288+
}
289+
227290
// =============================================================================
228291
// BINARY TARGET SELECTION
229292
// =============================================================================
@@ -251,6 +314,10 @@ func binaryTargets() -> [Target] {
251314
name: "RABackendONNXBinary",
252315
path: "sdk/runanywhere-swift/Binaries/RABackendONNX.xcframework"
253316
),
317+
.binaryTarget(
318+
name: "RABackendMetalRTBinary",
319+
path: "sdk/runanywhere-swift/Binaries/RABackendMetalRT.xcframework"
320+
),
254321
]
255322

256323
// ONNX Runtime xcframeworks - split by platform
@@ -302,6 +369,19 @@ func binaryTargets() -> [Target] {
302369
),
303370
]
304371

372+
// MetalRT remote binary is only appended once a real checksum has been
373+
// published. Until then the MetalRT product/targets are omitted from
374+
// the package graph entirely (see metalRTProducts/metalRTTargets).
375+
if metalrtRemoteBinaryAvailable {
376+
targets.append(
377+
.binaryTarget(
378+
name: "RABackendMetalRTBinary",
379+
url: "https://github.com/RunanywhereAI/runanywhere-sdks/releases/download/v\(sdkVersion)/RABackendMetalRT-v\(sdkVersion).zip",
380+
checksum: "0000000000000000000000000000000000000000000000000000000000000000" // TODO: replace with real checksum
381+
)
382+
)
383+
}
384+
305385
return targets
306386
}
307387
}

examples/ios/RunAnywhereAI/RunAnywhereAI.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
58ABEDD22ED16DA40058D033 /* RunAnywhereONNX in Frameworks */ = {isa = PBXBuildFile; productRef = 58ABEDD12ED16DA40058D033 /* RunAnywhereONNX */; };
1616
58LLAMACPP12ED16DA40058D0 /* RunAnywhereLlamaCPP in Frameworks */ = {isa = PBXBuildFile; productRef = 58LLAMACPP02ED16DA40058D0 /* RunAnywhereLlamaCPP */; };
1717
58WHISPERKIT1ED16DA40058D0 /* RunAnywhereWhisperKit in Frameworks */ = {isa = PBXBuildFile; productRef = 58WHISPERKIT0ED16DA40058D0 /* RunAnywhereWhisperKit */; };
18+
58METALRT12ED16DA40058D0 /* RunAnywhereMetalRT in Frameworks */ = {isa = PBXBuildFile; productRef = 58METALRT02ED16DA40058D0 /* RunAnywhereMetalRT */; };
1819
RACACTIVITY01ACTIVITY01RAC /* DictationActivityAttributes.swift in Sources */ = {isa = PBXBuildFile; fileRef = RACACTIVITY02ACTIVITY02RAC /* DictationActivityAttributes.swift */; };
1920
RACSHARED01RACSHARED01RACS /* SharedConstants.swift in Sources */ = {isa = PBXBuildFile; fileRef = RACSHARED02RACSHARED02RACS /* SharedConstants.swift */; };
2021
RACSHARED03RACSHARED03RACS /* SharedDataBridge.swift in Sources */ = {isa = PBXBuildFile; fileRef = RACSHARED04RACSHARED04RACS /* SharedDataBridge.swift */; };
@@ -169,6 +170,7 @@
169170
541C59DA2E63772A00DD7839 /* RunAnywhere in Frameworks */,
170171
58LLAMACPP12ED16DA40058D0 /* RunAnywhereLlamaCPP in Frameworks */,
171172
58WHISPERKIT1ED16DA40058D0 /* RunAnywhereWhisperKit in Frameworks */,
173+
58METALRT12ED16DA40058D0 /* RunAnywhereMetalRT in Frameworks */,
172174
);
173175
runOnlyForDeploymentPostprocessing = 0;
174176
};
@@ -309,6 +311,7 @@
309311
58ABEDD12ED16DA40058D033 /* RunAnywhereONNX */,
310312
58LLAMACPP02ED16DA40058D0 /* RunAnywhereLlamaCPP */,
311313
58WHISPERKIT0ED16DA40058D0 /* RunAnywhereWhisperKit */,
314+
58METALRT02ED16DA40058D0 /* RunAnywhereMetalRT */,
312315
);
313316
productName = RunAnywhereAI;
314317
productReference = 5480A1F02E2F250200337F2F /* RunAnywhereAI.app */;
@@ -1080,6 +1083,11 @@
10801083
package = 58E021172E52A86000B722EF /* XCLocalSwiftPackageReference "../../.." */;
10811084
productName = RunAnywhereWhisperKit;
10821085
};
1086+
58METALRT02ED16DA40058D0 /* RunAnywhereMetalRT */ = {
1087+
isa = XCSwiftPackageProductDependency;
1088+
package = 58E021172E52A86000B722EF /* XCLocalSwiftPackageReference "../../.." */;
1089+
productName = RunAnywhereMetalRT;
1090+
};
10831091
/* End XCSwiftPackageProductDependency section */
10841092
};
10851093
rootObject = 5480A1E82E2F250200337F2F /* Project object */;

0 commit comments

Comments
 (0)