Example demonstrating how to build an iOS & Android app with a common Rust core, with Bazel & UniFFI.
┌─────────────────────────────────────────┐
│ Apps │
├─────────────────┬───────────────────────┤
│ iOS (Swift) │ Android (Kotlin) │
├─────────────────┼───────────────────────┤
│ UniFFI Generated Bindings │
├─────────────────────────────────────────┤
│ Rust Core Library │
└─────────────────────────────────────────┘
├── Sources/
│ ├── core-models/ # Core Rust types and models
│ ├── core-ffi/ # FFI layer with UniFFI bindings
│ ├── features/
│ │ └── feature-a/ # Example feature implementation
│ ├── ios/core/ # iOS Swift wrapper
│ └── android/
│ ├── core/ # Android Kotlin wrapper
│ └── app/ # Android demo app
┌─────────────────────────────────────────────────────────────┐
│ Platform Apps │
├─────────────────────────┬───────────────────────────────────┤
│ iOS Swift App │ Android Kotlin App │
└─────────────────────────┴───────────────────────────────────┘
│ │
▼ ▼
┌─────────────────────────┬───────────────────────────────────┐
│ ios/core │ android/core │
│ (Swift wrapper) │ (Kotlin wrapper) │
└─────────────────────────┴───────────────────────────────────┘
│ │
└─────────────┬─────────────┘
▼
┌─────────────────────┐
│ core-ffi │
│ (UniFFI bindings │
│ main entry point) │
└─────────────────────┘
│ │
│ └─────────────────┐
▼ ▼
┌─────────────────────┐ ┌─────────────────────┐
│ core_models │ │ feature_a_ffi │
│ (base types) │ │ (feature interface) │
└─────────────────────┘ └─────────────────────┘
│
▼
┌─────────────────────────────────┐
│ feature-a-ios. │
| ^── injected via ios/core |
│ feature-a-android │
│ ^── injected via android/core │
└─────────────────────────────────┘
Architecture Notes:
core-ffiis the main UniFFI entry point that exposes the Rust API to Swift/Kotlin- Platform wrappers (
ios/core,android/core) consume the generated UniFFI bindings feature_a_ffidefines interface contracts implemented by platform-specific code through dependency injectioncore_modelsprovides shared types used across all components
# Generate an xcodeproj
make ios-project
# Run all iOS tests
make ios-test# Run all android tests
make android-test
# Build .apk for all architectures
make android-build
# Build & install the app via ADB
make android-install