Zenoh JNI bindings and Kotlin wrappers for the Zenoh pub/sub, store/query and compute framework.
This project provides low-level JNI bindings (Rust) and high-level Kotlin wrappers generated from the zenoh-flat Rust crate using prebindgen.
The Zenoh Flat JNI library generates multi-language FFI bindings from a single annotated Rust source (zenoh-flat). It consists of:
- Rust JNI layer (
src/) - Native bindings to Zenoh APIs - Kotlin wrappers (
kotlin/) - Type-safe Kotlin classes for JVM and Android - Generated Kotlin (
generated-kotlin/) - Auto-generated Kotlin sources fromprebindgen
- 🦀 Native Rust performance - Direct JNI binding to Zenoh
- 🎯 Type-safe API - Kotlin data classes and enums for type safety
- 📱 Multi-platform - Support for JVM (Linux, macOS, Windows) and Android
- 🔒 Memory-safe - Automatic resource management via Kotlin classes
- 🚀 Zero-copy - Efficient data transfer between Rust and JVM
Add the dependency to your build.gradle.kts:
dependencies {
implementation("org.eclipse.zenoh:zenoh-flat-jni:1.9.0")
}Or in pom.xml:
<dependency>
<groupId>org.eclipse.zenoh</groupId>
<artifactId>zenoh-flat-jni</artifactId>
<version>1.9.0</version>
</dependency>import io.zenoh.jni.*
fun main() {
// Initialize Zenoh
val config = ZConfig()
val session = config.openSession()
// Put a key-value pair
val keyExpr = ZKeyExpr.from("demo/example")
session.put(keyExpr, "Hello, Zenoh!")
// Close resources
keyExpr.drop()
session.drop()
}- Rust 1.70+ with JNI support
- Gradle 7.0+
- JDK 11+
- Android SDK (for Android builds)
# Clone the repository with dependencies
git clone https://github.com/ZettaScaleLabs/zenoh-flat-jni.git
cd zenoh-flat-jni
# Build Rust library
cargo build --release
# Build Kotlin (optional, for local development)
./gradlew buildTo use local versions of zenoh-flat and prebindgen:
# Ensure you have the PREBINDGEN workspace checked out locally
mkdir -p ~/zenoh-workspace
cd ~/zenoh-workspace
git clone https://github.com/ZettaScaleLabs/prebindgen.git
git clone https://github.com/ZettaScaleLabs/zenoh-flat-jni.git
cd zenoh-flat-jni
# Adjust paths in Cargo.toml (temporarily):
# zenoh-flat = { version = "1.9.0", path = "../../PREBINDGEN/zenoh-flat", ... }
# prebindgen = { path = "../../PREBINDGEN/prebindgen/prebindgen" }
cargo build --release# Run Rust tests
cargo test --all
# Run Kotlin tests
./gradlew jvmTest
# Lint
cargo clippy --all-targets --all-features -- -D warnings
cargo fmt --check./gradlew -Pandroid=true buildThe generated bindings are created via prebindgen in the build process:
- Rust source (
zenoh-flat) marked with#[prebindgen]annotations - Proc-macro captures annotated items to JSONL format
prebindgen::lang::JniGenreads JSONL and generates:- Rust JNI wrapper functions
- Kotlin data classes and enums
- Gradle packages Rust dylib + Kotlin sources into a JAR
- Maven Central publishes the multi-platform JAR
zenoh-flat-jni is a standalone library that can be consumed by:
- zenoh-java - Higher-level Zenoh API for JVM/Android
- zenoh-kotlin - Kotlin-first Zenoh API
Both projects depend on zenoh-flat-jni as a Maven artifact, enabling independent versioning and release cycles.
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
This project is licensed under either of
- Eclipse Public License 2.0 (LICENSE or http://www.eclipse.org/legal/epl-2.0)
- Apache License, Version 2.0 (LICENSE or https://www.apache.org/licenses/LICENSE-2.0)
at your option.
This project is part of the Eclipse Zenoh ecosystem and is maintained by the ZettaScale team.