uniffi-rs icon indicating copy to clipboard operation
uniffi-rs copied to clipboard

[discuss] Make UniFFI operate as a cargo subcommand

Open rfk opened this issue 4 years ago • 1 comments

Currently, users of UniFFI need to have the uniffi-bindgen tool installed separately on their system in order to generate foreign-language bindings. Experience has shown us that this causes a number of annoyances for development in practice:

  • The version of the uniffi-bindgen command needs to match the version of the uniffi runtime dependency configured in your project's Cargo.toml. You'll get a not-as-helpful-as-it-should-be error message if they don't match.
  • When doing local development on UniFFI itself, you need to remember to cargo run -p uniffi_bindgen or similar to get the local version rather than the installed version.

This was so annoying for application-services that we actually implemented our own wrapper crate around uniffi_bindgen in order to ensure that a consistent version was always used, and we not generate the foreign-language bindings by calling cargo uniffi-bindgen ... rather than uniffi-bindgen ....

I think that's a strong signal that we should lean in to UniFFI operating as a cargo subcommand, simplifying the mental model of how the tool works. Some strawman examples:

  • cargo uniffi scaffolding [...]: generate Rust scaffolding for the current crate
  • cargo uniffi bindgen [...]: generate foreign-language bindings for the current crate

By default, users would still need to have a cargo-uniffi executable installed on their system in order for this to work. But they would also have the option of using a cargo alias to customize how the cargo uniffi command works, e.g. by calling out to a version built locally as part of the crate in a similar way to what we do in applicaton-services.

The important part would be that the interface to UniFFI is always through cargo uniffi [...] rather than "run uniffi-bindgen, but for appservices run cargo uniffi-bindgen, and for local development run cargo run -p uniffi_bindgen, and...".

┆Issue is synchronized with this Jira Task ┆Issue Number: UNIFFI-63

rfk avatar Jun 02 '21 23:06 rfk

Looking at this and maybe thinking about it in a different way -- does it potentially make sense to have an interactive UniFFI CLI? Thinking of something like create-react-app that gives us potential flexibility in terms of other commands we might want to add later (scaffolding, bindgen, etc) and abstracts away having to worry about which uniffi-bindgen we'd be using.

Edit: Making this a little clearer of the differentiation of uniffi-bindgen, and kinda running wild with the idea:

  1. Being able to run the CLI and taking some of the manual parts out of using UniFFi
  • Automatically generates a base-level build.rs file
  • Choosing which languages you're currently targeting and (1) checks dependencies? (2) adds a basic build file e.g gradle?
  1. Install/use the appropriate uniffi-bindgen

skhamis avatar Aug 03 '21 18:08 skhamis