Skip to content

Conversation

@joe-p
Copy link
Collaborator

@joe-p joe-p commented Sep 21, 2025

Add a ffi_uniffi feature to the generated API clients and makes the necessary changes to the templates

@joe-p joe-p requested a review from a team as a code owner September 21, 2025 11:40
@joe-p joe-p requested review from Copilot and lempira and removed request for a team September 21, 2025 11:40
Copy link
Contributor

Copilot AI left a 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 UnknownJsonValue that switches between String for FFI and serde_json::Value for 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.

@joe-p joe-p marked this pull request as draft September 21, 2025 12:12
@joe-p joe-p force-pushed the feat/algod_client_ffi branch 2 times, most recently from 8b3267f to 31d4a85 Compare September 21, 2025 15:41
@joe-p joe-p force-pushed the feat/algod_client_ffi branch from 31d4a85 to e6188c9 Compare September 21, 2025 15:47
@joe-p joe-p marked this pull request as ready for review September 21, 2025 15:58
http_client: Arc<dyn HttpClient>,
}

{% for impl_block in ["common", "rust", "ffi"] %}
Copy link
Collaborator Author

@joe-p joe-p Sep 21, 2025

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

  1. A common impl that includes ctors and methods that don't have an optional string
  2. A Rust impl that uses Option<&str> for optional strings
  3. An FFI impl that uses Option<String> for optional strings

Comment on lines +154 to +162
{% 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(),
})
})?
}
Copy link
Collaborator Author

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?

Copy link
Collaborator

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.

@joe-p joe-p merged commit e4f2bf3 into main Sep 22, 2025
17 checks passed
@joe-p joe-p deleted the feat/algod_client_ffi branch September 22, 2025 13:49
@engineering-ci
Copy link
Contributor

🎉 This PR is included in version 1.0.0-alpha.66 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants