Mobile Bindings Overview¶
Status: ready for SDK consumers
Goals¶
- Provide a minimal C ABI that exposes search and grep capabilities without leaking internal C++ types.
- Enable embedders to build thin Swift/Kotlin wrappers on top of a shared library (
libyams_mobile). - Maintain binary compatibility across minor releases via versioned structs and feature flags.
Target Platforms¶
- iOS 15+/macOS 13+ (Swift Package Manager integration)
- Android API 26+ (AAR with JNI bindings)
- Additional consumers via C-compatible dynamic libraries (e.g., React Native, Flutter)
Architectural Shape¶
- Core ABI Layer — versioned header
include/yams/api/mobile_bindings.hcompiled intolibyams_mobile. - Platform Glue — Swift/Kotlin wrappers (future milestone) translate native types and may layer async semantics over the blocking C entrypoints.
- Service Facade — long-lived
yams_mobile_context_tmapping toAppContextwith configurable storage paths, caches, and worker executors. - Lifecycle Hooks — initialization, shutdown, and JSON-based diagnostics helpers.
[Swift/Combine] [Kotlin/Coroutines]
\ /
\ yams_mobile C ABI /
\ /
Core services (grep/search + fixture-driven corpora)
Data Model Principles¶
- All structs are POD with explicit sizes; optional fields are represented via nullable pointers or sentinel flags.
- Strings use UTF-8
char*with caller-managed allocation; response containers return opaque handles with dispose functions. - Errors propagate through
yams_mobile_statusenums plus optional extended payloads.
Threading & Concurrency¶
- Embedders may call APIs from any thread; the library owns a background
boost::asio::thread_poolper context. - The current C ABI exposes synchronous entrypoints only (
yams_mobile_*_execute). Async helpers will ship with platform wrappers. - Swift/Kotlin adapters should wrap the blocking calls using dispatch queues/coroutines to surface async behaviour.
Feature Skeleton¶
| Area | Available entrypoints | Notes |
|---|---|---|
| Context lifecycle | yams_mobile_context_create, yams_mobile_context_destroy |
Config accepts working/cache dirs and a telemetry_sink string (console, stderr, noop, or file:/path). |
| Grep/Search | yams_mobile_grep_execute, yams_mobile_search_execute, destroy helpers, yams_mobile_{grep,search}_result_stats_json |
Blocking calls returning opaque handles plus JSON stats (latency, retry counters). |
| Document ingest | yams_mobile_store_document, yams_mobile_remove_document |
Update/list flows are deferred; wrappers should enforce doc hygiene. |
| Metadata inspection | yams_mobile_get_metadata, yams_mobile_metadata_result_json |
JSON payload mirrors DocumentService metadata map. |
| Vector status | yams_mobile_get_vector_status, yams_mobile_vector_status_result_json |
Returns document counts/storage stats; warmup/model control APIs remain TODO. |
Compatibility Strategy¶
- ABI version encoded in
yams_mobile_version_info(major/minor/patch) and mirrored in the header macrosYAMS_MOBILE_API_VERSION_{MAJOR,MINOR,PATCH}. - Every request struct now embeds a
struct_size/versionheader so older clients continue to function when fields are appended. Callers should initialize structs via theyams_mobile_context_config_default()/yams_mobile_request_header_default()helpers before setting additional fields. - Breaking changes must bump
YAMS_MOBILE_API_VERSION_MAJORand ship a parallel symbol surface (yams_mobile_v2_*) while preserving the previous version for at least one minor release. - CI enforces symbol compatibility with
scripts/ci/check_mobile_abi.sh, comparing the exported surface againstpublic/mobile/abi/yams_mobile_v1.symbolson every PR.
Fixtures & Test Corpora¶
tests/common/search_corpus_presets.hexposesmobileSearchCorpusSpec()which captures the curated mobile dataset (sync deltas, path sensitivity, semantic warm-up, case toggles). Use this in unit/integration tests to align with the demo apps and smoke suites.tests/mobile/mobile_abi_smoke_test.cppvalidates the round-trip ingest/list/search flow against the new corpus and guards the struct header defaults.
Swift Package Demo¶
- The Swift reference package lives under
examples/mobile/swift/YamsMobileDemo. - It provides a
CYamsMobilesystem library target (via the generatedyams_mobile.pc) and a minimal executable harness that callsyams_mobile_get_version()and dispatches grep/search flows. - To build locally:
1. Install YAMS (or build
libyams_mobile) and expose it viaPKG_CONFIG_PATH. 2. Runswift buildinside the package; the manifest referencesCYamsMobilethrough pkg-config. 3. Runswift testto execute the smoke test that mirrors the C++ round-trip harness.
Android Demo¶
- The Android reference lives under
examples/mobile/android/YamsMobileDemowith a Gradle library module that wrapslibyams_mobilevia JNI. src/main/cpp/yams_mobile_jni.cpptranslates Kotlin calls to the C ABI; instrumentation tests insrc/androidTestensureyams_mobile_get_version()and a basic search flow succeed against the mobile corpus fixtures.- Build steps:
1. Place the compiled
libyams_mobile.sofor each ABI underapp/src/main/jniLibs/<abi>/. 2. Run./gradlew connectedAndroidTestto execute the smoke tests on a device/emulator.
Developer Workflow¶
- Initialize the fixtures using
FixtureManager(see smoke test for a template) or reuse the packaged corpora in CI. - Link against
yams_mobileusing pkg-config (Swift) or JNI (Android). - Run the platform demo harnesses to validate bindings before shipping downstream SDK updates.