Skip to content

Antonito/bazel-app-core-native-example

Repository files navigation

Cross-Platform Native Library with Rust, UniFFI, and Bazel

Example demonstrating how to build an iOS & Android app with a common Rust core, with Bazel & UniFFI.

Architecture

┌─────────────────────────────────────────┐
│                 Apps                    │
├─────────────────┬───────────────────────┤
│   iOS (Swift)   │   Android (Kotlin)    │
├─────────────────┼───────────────────────┤
│      UniFFI Generated Bindings          │
├─────────────────────────────────────────┤
│          Rust Core Library              │
└─────────────────────────────────────────┘

Project Structure

├── 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

Dependency Hierarchy

┌─────────────────────────────────────────────────────────────┐
│                     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-ffi is 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_ffi defines interface contracts implemented by platform-specific code through dependency injection
  • core_models provides shared types used across all components

Quick Start

iOS Development

# Generate an xcodeproj
make ios-project

# Run all iOS tests
make ios-test

Android Development

# Run all android tests
make android-test

# Build .apk for all architectures
make android-build

# Build & install the app via ADB
make android-install

About

Demo project of an iOS SwiftUI app and Android Kotlin app using a shared Rust core with Bazel & UniFFI

Resources

License

Stars

1 star

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors