-
Notifications
You must be signed in to change notification settings - Fork 240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow external crates to write their own binding generators #1201
Conversation
Use &Path rather than AsRef<Path>. We can call `as_ref()` before calling into `BindingGenerator` and keep the implementation code simple. Added code to extract the binding-specific config from the `uniffi.toml` config that contains it. Instead of leveraging `From<&ComponentInterface>` and `MergeWith`, have some `BindingGeneratorConfig` methods that explicitly do what we need them to do: update the values read from TOML with defaults from `ComponentInterface`. When implementing custom types, I wasn't sure how to properly implement the `MergeWith` trait. For example, what if we have 2 configs, each with a custom type map should we try to take entries from both? Having methods specific to the actual process can avoid issues like that. In the custom types case, we never get custom types from the component interface, so we don't need to worry about merging them.
- Updated `BindingsGeneratorConfig` and added an empty implementation for bindings that don't have config values. - Instead of having `generate_external_bindings` construct the `BindingsGenerator` it now inputs one instead. The advantage here is that bindings generators can have whatever fields they want. For the desktop JS project I want to make a generator store an enum that controls if it's generating the .webidl, .cpp, .h, or .jsm file. - Have `write_bindings()` input the config since we're no longer passing that to the `BindingsGenerator` constructor. - Removed the `compile_bindings()` and `run_script()` methods. These are going to be replaced with some other system to run tests. - Separated the trait bounds for the `AsRef<Path>` arguments to `write_bindings()`. I think the previous code required all of them to be the same type. Now one can be a `PathBuf` and another can be a `Path`. - Made ComponentInterface public, since it's used in `BindingsGenerator` - Added `ComponentInterface` method to get all FFI functions, except the `RustBuffer` ones - Pass in an owned ComponentInterface rather than a reference - Don't return an error when `uniffi.toml` is missing - Added some anyhow context calls for better error tracking
Seperate bindings mvp
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lovely, thanks Tarik!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me and it's been used for our desktop JS code for a while so I think we can have decent confidence in the code.
The one issue is the export hack should be removed since it's been implemented in a better way.
These are the first bits needed to implement an external binding generator that lives in an outside crate.
Most of the changes are in the
uniffi_bindgen/src/lib.rs
to define a traitBindingGenerator
that an external crate can use to take advantage of the logic inuniffi
to parse theudl
into aComponentInterface
.This is not a breaking change, and only exposes the functionality (it doesn't change the existing crates)
cc @bendk @mhammond