Commit 698fe6f
committed
Address C12+C14: MetalRT stub pattern for public-repo compile
The MetalRT engine (libmetalrt_engine.a + .metallib shaders) is a
closed-source private dependency. Public repo users could not compile
with RAC_BACKEND_METALRT=ON without access to the private engine.
This change introduces a stub pattern that lets the public repo compile
cleanly, and fails with a clear runtime error when MetalRT inference
is requested without the engine binary installed.
Pattern (extensible to future private backends, e.g. Qualcomm NPU):
1. Compile-time (CMake):
New RAC_METALRT_ENGINE_AVAILABLE option. OFF by default (public):
the stub header + stub .c file under src/backends/metalrt/stubs/
are compiled in, every metalrt_* symbol resolves to a no-op.
ON (internal): the real private metalrt_c_api.h from METALRT_ROOT
is used and libmetalrt_engine.a is linked with find_library REQUIRED
(configure fails hard if engine claimed-available but missing,
matching llamacpp/onnx behavior).
2. Fixes the C12 orphan-target concern: rac_backend_metalrt is now an
OBJECT library folded into rac_commons via
target_sources(rac_commons PRIVATE $<TARGET_OBJECTS:rac_backend_metalrt>)
mirroring the RAG pattern. No separate librac_backend_metalrt.a to
distribute — wrappers ride in librac_commons.a (and RACommons
xcframework on iOS); engine + tokenizers ship separately in
RABackendMetalRT.xcframework when the authorized developer enables
it.
3. Runtime: rac_backend_metalrt_register() on a stub build logs a
clear warning and skips provider registration entirely. The service
registry then returns BACKEND_NOT_FOUND at loadModel call sites,
which Swift maps to SDKError.componentNotAvailable. No crashes, no
silent no-ops. metalrt_can_handle also short-circuits to RAC_FALSE
as belt-and-suspenders.
4. New error code RAC_ERROR_BACKEND_UNAVAILABLE = -604 in the backend
range (-600..-699) for callers that need to distinguish "backend
not found" from "backend compiled as stub". Error message added.
5. build-ios.sh: passes -DRAC_METALRT_ENGINE_AVAILABLE=ON whenever
--backend metalrt is selected, so the internal MetalRT iOS build
continues to work end-to-end (RACommons xcframework with real
wrappers + RABackendMetalRT xcframework with engine + tokenizers).
Files:
- src/backends/metalrt/stubs/metalrt_c_api.h (new, public stub)
- src/backends/metalrt/stubs/metalrt_c_api_stub.c (new, no-op)
- src/backends/metalrt/CMakeLists.txt (two-branch + OBJECT)
- CMakeLists.txt (fold rac_backend_metalrt into rac_commons)
- src/backends/metalrt/rac_backend_metalrt_register.cpp
(short-circuit can_handle + register on stub builds)
- include/rac/core/rac_error.h + src/core/rac_error.cpp
(RAC_ERROR_BACKEND_UNAVAILABLE)
- scripts/build-ios.sh (pass RAC_METALRT_ENGINE_AVAILABLE=ON)
Verified: all 5 MetalRT wrapper .cpp files compile cleanly against the
stub header with clang -std=c++20 -DRAC_METALRT_ENGINE_AVAILABLE=0.
Default build (RAC_BUILD_BACKENDS=OFF) still configures cleanly.
When the MetalRT project is open-sourced or moved into a private SPM
binary pipeline, the only change needed is flipping
RAC_METALRT_ENGINE_AVAILABLE=ON plus wiring the binary fetch — the
stub and wrappers stay untouched.1 parent 5ff6e30 commit 698fe6f
9 files changed
Lines changed: 445 additions & 60 deletions
File tree
- examples/ios/RunAnywhereAI
- sdk/runanywhere-commons
- include/rac/core
- scripts
- src
- backends/metalrt
- stubs
- core
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
507 | 507 | | |
508 | 508 | | |
509 | 509 | | |
510 | | - | |
| 510 | + | |
511 | 511 | | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
512 | 536 | | |
513 | 537 | | |
514 | 538 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
365 | 365 | | |
366 | 366 | | |
367 | 367 | | |
| 368 | + | |
| 369 | + | |
368 | 370 | | |
369 | 371 | | |
370 | 372 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
204 | 204 | | |
205 | 205 | | |
206 | 206 | | |
| 207 | + | |
207 | 208 | | |
208 | 209 | | |
209 | 210 | | |
| |||
311 | 312 | | |
312 | 313 | | |
313 | 314 | | |
| 315 | + | |
314 | 316 | | |
315 | 317 | | |
316 | 318 | | |
| |||
Lines changed: 70 additions & 32 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
3 | 22 | | |
4 | | - | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
5 | 28 | | |
6 | 29 | | |
7 | 30 | | |
8 | 31 | | |
9 | 32 | | |
10 | 33 | | |
11 | 34 | | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
| 35 | + | |
| 36 | + | |
28 | 37 | | |
29 | 38 | | |
30 | 39 | | |
31 | 40 | | |
32 | | - | |
33 | 41 | | |
34 | 42 | | |
35 | 43 | | |
36 | 44 | | |
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 | + | |
45 | 74 | | |
46 | | - | |
47 | | - | |
48 | | - | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
49 | 79 | | |
50 | | - | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
51 | 88 | | |
52 | 89 | | |
53 | | - | |
| 90 | + | |
| 91 | + | |
54 | 92 | | |
55 | 93 | | |
56 | 94 | | |
| |||
Lines changed: 22 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
337 | 337 | | |
338 | 338 | | |
339 | 339 | | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
340 | 349 | | |
341 | 350 | | |
342 | 351 | | |
| |||
345 | 354 | | |
346 | 355 | | |
347 | 356 | | |
| 357 | + | |
348 | 358 | | |
349 | 359 | | |
350 | 360 | | |
| |||
488 | 498 | | |
489 | 499 | | |
490 | 500 | | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
491 | 513 | | |
492 | 514 | | |
493 | 515 | | |
| |||
0 commit comments