-
Notifications
You must be signed in to change notification settings - Fork 7
feat: ffi_uniffi feature for api clients #261
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
Conversation
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.
Pull Request Overview
This PR adds a ffi_uniffi feature flag to the generated API clients to enable Foreign Function Interface (FFI) bindings using the UniFFI framework for Rust-to-other-language interoperability.
- Adds conditional compilation attributes for UniFFI-compatible types across model structs and enums
- Introduces a type alias
UnknownJsonValuethat switches betweenStringfor FFI andserde_json::Valuefor native Rust usage - Updates templates to generate FFI-compatible client APIs with proper error handling and parameter type adjustments
Reviewed Changes
Copilot reviewed 253 out of 254 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| Template files | Updated Jinja2 templates to add conditional UniFFI derive attributes and type aliases |
| Generated client files | Applied template changes to add FFI support across indexer and algod clients |
| FFI transact library | Modified to use From trait instead of TryFrom for cleaner conversions |
| Cargo.toml files | Added ffi_uniffi feature with required dependencies |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
8b3267f to
31d4a85
Compare
31d4a85 to
e6188c9
Compare
| http_client: Arc<dyn HttpClient>, | ||
| } | ||
|
|
||
| {% for impl_block in ["common", "rust", "ffi"] %} |
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.
This is the main change in the PR outside of the uniffi macros. The main problem is that uniffi can't handle Option<&str> so we need to use Option<String> over the FFI. To avoid negatively impacting the rust users by requiring ownership unnecessarily multiple impls are rendered for the client
- A common impl that includes ctors and methods that don't have an optional string
- A Rust impl that uses
Option<&str>for optional strings - An FFI impl that uses
Option<String>for optional strings
| {% if get_success_response_type(operation) == "UnknownJsonValue" %} | ||
| #[cfg(feature = "ffi_uniffi")] | ||
| { | ||
| result.map(|v| { | ||
| serde_json::to_string(&v).map_err(|e| Error::Serde { | ||
| message: e.to_string(), | ||
| }) | ||
| })? | ||
| } |
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.
We can't use serde_json::Value over the FFI, so I think serializing to string for unknown objects is the best option?
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.
I think this is probably the best option. Otherwise we would have to workout the response types ourselves and manually maintain them, which can be a decent amount of work.
|
🎉 This PR is included in version 1.0.0-alpha.66 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
Add a ffi_uniffi feature to the generated API clients and makes the necessary changes to the templates