8000 feat: [wip] add support for uniffi-rs foreign bindings by paolodamico · Pull Request #482 · recmo/uint · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: [wip] add support for uniffi-rs foreign bindings #482

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

paolodamico
Copy link
@paolodamico paolodamico commented Jun 4, 2025

Motivation

Motivation for this PR is allowing UInts to be lowered & lifted to foreign bindings (e.g. Swift & Kotlin) through Mozilla's https://github.com/mozilla/uniffi-rs. Rust libraries relying on uniffi, would be able to work with UInts in foreign code. For us, we would rely on this for https://github.com/worldcoin/walletkit & https://github.com/worldcoin/bedrock

Solution

There are two conceptual solutions.

  1. (Current). Introducing a new type to lower/lift UInts to foreign code. A U256 for example would be lowered as a struct with 4xu64, not to dissimilar to the main UInt type. This is the most Rust-compatible, no changes are needed on the Rust side for downstream crates. The trade-off is that on the foreign side, no methods can be exposed for the type. Everything would have to be exposed as first-level functions (and potentially patched on the foreign side with extensions).
  2. Introduce a wrapper around UInt which can be extended to expose additional functionality to foreign code (see 4ee8e1c#diff-335af168ef5906f688caca114e10649fb5ccb74611bce562a82533c4324cb043). Trade-off is it'll require conversions in the Rust side.

In any case, uniffi does not support exposing generics (the BITS/LIMBS), so explicit declarations for aliases will have to be used. An alternative approach would be introducing a new type, but I don't think that's the best approach.

PR Checklist

  • Added Tests Manual tests for now. Adding tests once we discuss the solution
  • Added Documentation Still needs to be updated once we discuss the solution
  • Updated the changelog

@paolodamico
Copy link
Author

curious to hear high level thoughts around potential approaches for this

@prestwich
Copy link
Collaborator
prestwich commented Jun 9, 2025

Can you provide quick swift code snippets showing what developer experience would be like with each approach?

I'm concerned about the inability to push generics through the interface requiring declaring a separate type for each variant. if we home those types here, users are limited in what types they can use, and if homed elsewhere, there may be multiple incompatible U256 variants defined in different crates. Is there a way to lower these as something like a slice of limbs?

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
0