uniffi_bindgen_kotlin_multiplatform

Crates.iouniffi_bindgen_kotlin_multiplatform
lib.rsuniffi_bindgen_kotlin_multiplatform
version0.1.0
sourcesrc
created_at2023-11-25 21:45:52.13841
updated_at2023-11-25 21:45:52.13841
descriptiona Kotlin Multiplatform bindings generator for rust (codegen and cli tooling)
homepagehttps://trixnity.gitlab.io/uniffi-kotlin-multiplatform-bindings
repositoryhttps://gitlab.com/trixnity/uniffi-kotlin-multiplatform-bindings
max_upload_size
id1048593
size161,925
Didier Villevalois (ptitjes)

documentation

https://trixnity.gitlab.io/uniffi-kotlin-multiplatform-bindings

README

UniFFI Kotlin Multiplatform bindings

This project contains Kotlin Multiplatform bindings generation for UniFFI.

Currently only the Kotlin targets JVM and Native are supported. JS support would be awesome, but needs WASM support within uniffi.

You can find examples on how to use the bindings in the tests directory.

How to use

As neither the bindgen crate nor the Gradle plugin are published yet, you have to do some additional Gradle configuration. (See below Use locally)

Using the Gradle plugin

plugins {
    kotlin("multiplatform")
    id("io.gitlab.trixnity.uniffi.kotlin.multiplatform") version "0.1.0"
}

uniffi {
    // The directory containing the Rust crate.
    crateDirectory = layout.projectDirectory.dir("rust")
    
    // The name of the crate as in Cargo.toml's package.name.
    crateName = "my_crate"
    
    // The name of the library as in Cargo.toml's library.name. Defaults to "${crateName}".
    libraryName = "my_crate"
    
    // The UDL file. Defaults to "${crateDirectory}/src/${crateName}.udl".
    udlFile = layout.projectDirectory.file("rust/src/my_crate.udl")
    
    // The UDL namespace as in the UDL file. Defaults to "${crateName}".
    namespace = "my_crate"
    
    // The profile to build the crate. Defaults to "debug".
    profile = "debug"
}

kotlin {
    // The plugin will react to the targets definition
    jvm()
    linuxX64()
}

Directly using the bindgen CLI

TODO

Use locally

As neither the bindgen crate nor the Gradle plugin are published yet, you have to do some additional Gradle configuration.

Publish Gradle plugin in a local repository

Clone the repository and build it. Add a publishing repository definition at the end of build-logic/gradle-plugin/build.gradle.kts:

publishing {
    repositories {
        maven {
            name = "local"
            url = uri("<path-to-local-plugin-repository>")
        }
    }
}

Then invoke ./gradlew :build-logic:gradle-plugin:publishAllPublicationsToLocalRepository.

Specify the local repository

Add the local repository in you settings.gradle.kts:

pluginManagement {
    repositories {
        maven {
            name = "local"
            url = uri("<path-to-local-plugin-repository>")
        }
        // ...
    }
}

Finally, configure the uniffi extension with the exact path to the bindgen of this repository.

uniffi {
    // ...
    bindgenCratePath = "<path-to-our-bindgen>"
}
Commit count: 64

cargo fmt