Skip to content

About

Zenoh JNI bindings and Kotlin wrappers - generated from zenoh-flat via prebindgen

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

 
 

Repository files navigation

Zenoh Flat JNI

CI Maven Central License

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.

Overview

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 from prebindgen

Features

  • 🦀 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

Installation

Maven Central

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>

Usage

Kotlin Example

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()
}

Development

Prerequisites

  • Rust 1.70+ with JNI support
  • Gradle 7.0+
  • JDK 11+
  • Android SDK (for Android builds)

Build from Source

# 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 build

Local Development with Workspace

To 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

Testing

# Run Rust tests
cargo test --all

# Run Kotlin tests
./gradlew jvmTest

# Lint
cargo clippy --all-targets --all-features -- -D warnings
cargo fmt --check

Building for Android

./gradlew -Pandroid=true build

Architecture

The generated bindings are created via prebindgen in the build process:

  1. Rust source (zenoh-flat) marked with #[prebindgen] annotations
  2. Proc-macro captures annotated items to JSONL format
  3. prebindgen::lang::JniGen reads JSONL and generates:
    • Rust JNI wrapper functions
    • Kotlin data classes and enums
  4. Gradle packages Rust dylib + Kotlin sources into a JAR
  5. Maven Central publishes the multi-platform JAR

Integration with zenoh-java

zenoh-flat-jni is a standalone library that can be consumed by:

Both projects depend on zenoh-flat-jni as a Maven artifact, enabling independent versioning and release cycles.

Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines.

License

This project is licensed under either of

at your option.

Acknowledgments

This project is part of the Eclipse Zenoh ecosystem and is maintained by the ZettaScale team.

About

Zenoh JNI bindings and Kotlin wrappers - generated from zenoh-flat via prebindgen

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages