Skip to content

ZettaScaleLabs/zenoh-kotlin

 
 

Repository files navigation

CI Release status Discussion Discord License License

Eclipse Zenoh

The Eclipse Zenoh: Zero Overhead Pub/sub, Store/Query and Compute.

Zenoh (pronounce /zeno/) unifies data in motion, data at rest and computations. It carefully blends traditional pub/sub with geo-distributed storages, queries and computations, while retaining a level of time and space efficiency that is well beyond any of the mainstream stacks.

Check the website zenoh.io and the roadmap for more detailed information.


Kotlin Kotlin API

This repository provides a Kotlin binding based on the main Zenoh implementation written in Rust.

The code relies on the Zenoh JNI native library, which written in Rust and communicates with the Kotlin layer via the Java Native Interface (JNI).

Documentation

The documentation of the API is published here.

Alternatively, you can build it locally as explained below.


How to import

⚠️ Note nº1: About the released packages

The released packages can be found in the "packages" section of this repository, or in the links below:

These are 'nightly' packages that need to be imported as explained in the following sections of this README. We plan to publish our packages into Maven central in the very short term.

Android Android

For this first version we have published a Github package with the library which can be imported on your projects.

Checkout the Zenoh demo app for an example on how to use the library.

First add the Github packages repository to your settings.gradle.kts:

dependencyResolutionManagement {
    // ...
    repositories {
        google()
        mavenCentral()
        maven {
            name = "GitHubPackages"
            url = uri("https://maven.pkg.github.com/eclipse-zenoh/zenoh-kotlin")
            credentials {
                username = providers.gradleProperty("user").get()
                password = providers.gradleProperty("token").get()
            }
        }
    }
}

where the username and token are your github username and a personal access token you need to generate on github with package read permissions (see the Github documentation). This is required by Github in order to import the package, even if it's from a public repository.

After that add to the dependencies in the app's build.gradle.kts:

implementation("org.eclipse.zenoh:zenoh-kotlin-android:1.0.0")

Platforms

The library targets the following platforms:

  • x86
  • x86_64
  • arm
  • arm64

SDK

The minimum SDK is 30.

Permissions

Zenoh is a communications protocol, therefore the permissions required are:

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

Java JVM

Similar to Android, we have published a Github package to import on your projects.

First add the Github packages repository to your settings.gradle.kts:

dependencyResolutionManagement {
    // ...
    repositories {
        google()
        mavenCentral()
        maven {
            name = "GitHubPackages"
            url = uri("https://maven.pkg.github.com/eclipse-zenoh/zenoh-kotlin")
            credentials {
                username = providers.gradleProperty("user").get()
                password = providers.gradleProperty("token").get()
            }
        }
    }
}

where the username and token are your github username and a personal access token you need to generate on github with package read permissions (see the Github documentation). This is required by Github in order to import the package, even if it's from a public repository.

After that add to the dependencies in the app's build.gradle.kts:

implementation("io.zenoh:zenoh-kotlin-jvm:1.0.0")

Platforms

For the moment, the library targets the following platforms:

  • x86_64-unknown-linux-gnu
  • aarch64-unknown-linux-gnu
  • x86_64-apple-darwin
  • aarch64-apple-darwin
  • x86_64-pc-windows-msvc

How to build it

What you need

Basically:

and in case of targetting Android you'll also need:

JVM JVM

To publish a library for a JVM project into Maven local, run

gradle -Prelease=true publishJvmPublicationToMavenLocal

This will first, trigger the compilation of Zenoh-JNI in release (if you want debug, specify -Prelease=false), and second publish the library into maven local, containing the native library as a resource that will be loaded during runtime.

⚠️ The native library will be compiled against the default rustup target on your machine, so although it may work fine for you on your desktop, the generated publication may not be working on another computer with a different operating system and/or a different cpu architecture.

Once we have published the package, we should be able to find it under ~/.m2/repository/io/zenoh/zenoh-kotlin-jvm/1.0.0.

Finally, in the build.gradle.kts file of the project where you intend to use this library, add mavenLocal to the list of repositories and add zenoh-kotlin as a dependency:

repositories {
    mavenCentral()
    mavenLocal()
}

dependencies {
    testImplementation(kotlin("test"))
    implementation("io.zenoh:zenoh-kotlin-jvm:1.0.0")
}

Android Android

In order to use these bindings in a native Android project, what we will do is to build them as an Android NDK Library, publishing it into Maven local for us to be able to easily import it in our project.

It is required to have the NDK (native development kit) installed, since we are going to compile Zenoh JNI for multiple android native targets. The currently used NDK version is 26.0.10792818. It can be set up by using Android Studio (go to Preferences > Languages & Frameworks > Android SDK > SDK Tools, tick Show Package Details and pick the right NDK version), or alternatively it can be found here.

The native platforms we are going to target are the following ones:

  • x86
  • x86_64
  • arm
  • arm64

Therefore, if they are not yet already added to the Rust toolchain, run:

rustup target add armv7-linux-androideabi; \
rustup target add i686-linux-android; \
rustup target add aarch64-linux-android; \
rustup target add x86_64-linux-android

to install them.

So, in order to publish the library onto Maven Local, run:

gradle -Pandroid=true publishAndroidReleasePublicationToMavenLocal

This will first trigger the compilation of the Zenoh-JNI for the previously mentioned targets, and secondly will publish the library, containing the native binaries.

You should now be able to see the package under ~/.m2/repository/io/zenoh/zenoh-kotlin-android/1.0.0 with the following files:

zenoh-kotlin-android-1.0.0-sources.jar
zenoh-kotlin-android-1.0.0.aar
zenoh-kotlin-android-1.0.0.module
zenoh-kotlin-android-1.0.0.pom

Now the library is published on maven local, let's now see how to import it into an Android project.

First, we need to indicate we want to look into mavenLocal for our library, so in your top level build.gradle.kts you need to specify the mavenLocal repository:

repositories {
    mavenCentral()
    ...
    mavenLocal() // We add this line
}

Then in your app's build.gradle.kts file add the dependency:

implementation("io.zenoh:zenoh-kotlin-android:1.0.0")

And finally, do not forget to add the required internet permissions on your manifest!

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

And that was it! You can now import the code from the io.zenoh package and use it at your will.

Building the documentation

Because it's a Kotlin project, we use Dokka to generate the documentation.

In order to build it, run:

gradle zenoh-kotlin:dokkaHtml

Running the tests

To run the tests, run:

gradle jvmTest

This will compile the native library on debug mode (if not already available) and run the tests afterward against the JVM target. Running the tests against the Android target (by using gradle testDebugUnitTest) is equivalent to running them against the JVM one, since they are common tests executed locally as Unit tests.

Logging

Rust logs are propagated when setting the RUST_LOG environment variable.

For instance running the ZPub test as follows:

RUST_LOG=debug gradle ZPub

causes the logs to appear in standard output.

The log levels are the ones from Rust: trace, info, debug, error and warn.


Examples

You can find some examples located under the /examples folder. Once we've built the project, to run them, simply run ./gradlew <EXAMPLE_NAME>.

For instance in order to run the ZPub example, type:

./gradlew ZPub

You can find more info about these examples on the examples README file.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Kotlin 66.1%
  • Rust 33.3%
  • Shell 0.6%