mozilla / uniffi-rs

a multi-language bindings generator for rust
https://mozilla.github.io/uniffi-rs/
Mozilla Public License 2.0
2.74k stars 226 forks source link

Gradle plugin for generating Kotlin bindings #1303

Open kirillzh opened 2 years ago

kirillzh commented 2 years ago

UniFfi docs mention:

It is possible to generate Kotlin bindings at compile time for Kotlin Android projects. We'd like to make a gradle plugin for that...

Folks at Bitcoin Dev Kit (BDK) team (@thunderbiscuit) implemented a couple of plugin scripts for generating Kotlin JVM and Android bindings, and are open on turning it into a reusable plugin and potentially host it in this repository.

We are thinking of a nice Gradle DSL interface for generating bindings, perhaps:

// jvm or android module
plugins {
  id("org.mozilla.uniffi")
}

uniffi {
  udl = "path/math.udl"
  outputDir = "src/main/kotlin/"
}

We are wondering:

  1. Is there any existing plan of you folks implementing a plugin of your own and open sourcing it?
  2. If not, would you be open to hosting a plugin based on BDK's implementation? What's the process for that?

┆Issue is synchronized with this Jira Task ┆friendlyId: UNIFFI-185

thunderbiscuit commented 1 year ago

Build workflows for production-level libraries tend to be very custom, ours included (at least at this time). A look at some of the Python and Kotlin ones from the Glean and application-services repositories tell the same story (although in even more complex form 🤣). Our plugins have also evolved quite a bit over the past year and I expect will continue to do so as uniffi-rs evolves.

At this point I'm not sure of the exact shape the plugin would need to take to be general enough to work for others, and I'm not sure I have the bandwidth to build a more generic version myself. But I am building general documentation on Rust bindings using uniffi which will tackle some of those build and publish workflows at a high level, as well as outline the particular choices we made between shell scripts, Gradle plugins, and others for our libraries (Kotlin/JVM, Kotlin/Android, Swift, Python).

Feel free to close this issue for now (@kirillzh, @mhammond), but if anyone finds their way here looking for examples of Gradle plugins to help build uniffi libraries, you can find ours here for JVM and here for Android.

Thanks!