Skip to content
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

Seperate bindings mvp #1177

Merged
merged 2 commits into from
Feb 25, 2022
Merged

Conversation

bendk
Copy link
Contributor

@bendk bendk commented Feb 22, 2022

No description provided.

@bendk bendk force-pushed the seperate-bindings-mvp branch 4 times, most recently from 515da92 to db2f6e4 Compare February 23, 2022 15:05
Copy link
Contributor

@tarikeshaq tarikeshaq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few nits and questions, but nothing blocking this 😄 LGTM!

🚢 :shipit:

//
// Basically, if another library adds uniffi as an external crate, then builds into a dylib, that
// library normally won't have the symbols from uniffi. However, if that library calls an extern
// function from function, then it *will* have the symbols. So this is a dummy function that the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: an extern function from function seems off?

@@ -242,18 +246,19 @@ pub trait BindingGenerator: Sized {
/// - `udl_file`: The path to the UDL file
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: we should change the rustdocs to reflect the new arguments

out_dir_override: Option<P>,
pub fn generate_external_bindings(
binding_generator: impl BindingGenerator,
udl_file: impl AsRef<Path>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just out of curiosity, should we change this to be &Path like we did in write_bindings? (I know it was a generic parameter before this change, so no need for any changes here 😄)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could, but to me this feels like the right function to put as_ref() call. I don't really have any strong reason for it though, so I could be easily convinced otherwise.

}
}

impl<'de> Deserialize<'de> for EmptyBindingGeneratorConfig {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we replace this with a derive on the EmptyBindingGeneratorConfig? or does serde complain?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a unit struct, but we want to deserialize from an empty map, so the derive(Deserialize) doesn't work. I'll add a comment about this.

@@ -113,7 +113,7 @@ pub mod interface;
pub mod scaffolding;

use bindings::TargetLanguage;
use interface::ComponentInterface;
pub use interface::ComponentInterface;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this? I have no objections, but it looks like all of interface is pub on line 112 - not that it matters much, there is convenience in getting access to the ComponentInterface with one less module.. maybe interface should be a private module and only expose ComponentInterface 🤷

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm never completely sure how to handle this. In the bindings code we use a several other components from interface. Maybe we could make that module private and add pub use interface::*. Now that these are all separate crates, it seems more natural to import from the uniffi_bindgen rather uniffi_bindgen::interface.

- 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
@bendk bendk force-pushed the seperate-bindings-mvp branch from db2f6e4 to fd0cf3b Compare February 25, 2022 19:50
@bendk bendk merged commit 6f4a033 into mozilla:seperate-bindings-mvp Feb 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants