Skip to content

About

Rust to Kotlin KMP template

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

rust-to-kotlin

A template for integrating Rust with Kotlin Multiplatform (KMP) using UniFFI and gobley.

The template provides a complete build pipeline for exposing a Rust crate to Kotlin Multiplatform targets, including JVM, Android, and iOS. The entire workflow is managed through a single justfile.

Supported Platforms

  • JVM
  • Android
  • iOS
  • Linux
  • macOS
  • Windows

Prerequisites

Install the following tools before getting started.

Rust

Rust is pinned to version 1.89.0 using rust-toolchain.toml.

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

Then install the required cross-compilation targets:

just setup

just

# Fedora / RHEL
sudo dnf install just

# Debian / Ubuntu
sudo apt install just

# macOS
brew install just

JDK 21

# Fedora / RHEL
sudo dnf install java-21-openjdk-devel

# Debian / Ubuntu
sudo apt install openjdk-21-jdk

# macOS
brew install openjdk@21

Android SDK and NDK

Install the required Android SDK platform and NDK:

sdkmanager "platform-tools" \
           "platforms;android-36" \
           "ndk;30.0.14904198"

Set the Android SDK and NDK environment variables:

export ANDROID_SDK_ROOT="$HOME/Android/Sdk"
export ANDROID_NDK_HOME="$ANDROID_SDK_ROOT/ndk/30.0.14904198"

Install cargo-ndk:

cargo install cargo-ndk

Zig and cargo-zigbuild

These tools are required for Linux and macOS builds.

# Fedora / RHEL
sudo dnf install zig

# Debian / Ubuntu
snap install zig --classic

# macOS
brew install zig

Then install cargo-zigbuild:

cargo install cargo-zigbuild

clang, lld, and cargo-xwin

These tools are required for Windows builds.

# Fedora / RHEL
sudo dnf install clang lld cmake llvm

Install cargo-xwin:

cargo install cargo-xwin

gobley-uniffi-bindgen

Install the Gobley UniFFI binding generator:

cargo install gobley-uniffi-bindgen

Xcode

Xcode is required for iOS and macOS builds.

This step is only required on macOS:

xcode-select --install

Getting Started

At minimum, you need:

  • Rust
  • just
  • JDK 21
  • gobley-uniffi-bindgen

Once the required tools are installed, run:

just setup

Then build the complete project:

just

Common Commands

Build Everything

Build all supported targets, generate Kotlin bindings, and assemble the KMP library.

just

Build for the Host

Build the Rust library for the host Linux x86_64 target.

just build-host

Generate Kotlin Bindings

Regenerate the Kotlin bindings based on the current Rust API.

just generate-bindings

Build the KMP Library

Assemble the Kotlin Multiplatform library using Gradle.

just build-kmp

Run KMP Tests

Run JVM and Android host tests.

just test-kmp

Run JVM tests only:

just test-kmp-jvm

Publish to Local Maven Repository

Publish the KMP library to the local Maven repository.

just publish-local

The library will be available under:

~/.m2

Clean Build Outputs

Remove generated build artifacts and outputs.

just clean

Available Recipes

To view all available just recipes:

just --list

The justfile is the central entry point for the build, binding generation, testing, packaging, and publishing workflow.

About

Rust to Kotlin KMP template

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages