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

feat: adding uniffi bindings to support android and ios #473

Merged
merged 16 commits into from
Jan 10, 2025

Conversation

sebasti810
Copy link
Contributor

@sebasti810 sebasti810 commented Dec 10, 2024

Mobile bindings for Lumina node via UniFFI

This PR adds iOS and Android bindings for the node using Mozilla's UniFFI.
I followed the approach from wasm and tested it successfully in the iOS and Android simulator.

Current State

  • Basic node operations (start, stop, querying, etc.)
  • Platform-specific storage paths
  • Event handling
  • Example projects for iOS and Android

TODOs

  • Improve runtime (using #[uniffi::export(async_runtime = "tokio")])
  • Improve error handling
  • Improve types
  • Add docs
  • Finish and test example projects

@zvolin zvolin requested review from oblique, zvolin and fl0rek December 10, 2024 11:53
@oblique
Copy link
Member

oblique commented Dec 12, 2024

We refactored how we construct a Node. We introduced NodeBuilder and made private the NodeConfig. So this PR needs an update.

@sebasti810
Copy link
Contributor Author

sebasti810 commented Dec 12, 2024

@oblique i rebased, now it works again. test-wasm ci will still fail at the moment. Should I make the crate wasm compatible or should we just ignore it and use something like:
cargo clippy --workspace --exclude native --all-targets --target=wasm32-unknown-unknown -- -D warnings
instead of:
cargo clippy --all --all-targets --target=wasm32-unknown-unknown -- -D warnings

Cargo.toml Outdated Show resolved Hide resolved
Copy link
Member

@zvolin zvolin left a comment

Choose a reason for hiding this comment

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

thank you for the contribution, we're supper happy about it and would love to getting it upstream 🙇

node-native/Cargo.toml Outdated Show resolved Hide resolved
node-native/src/lib.rs Outdated Show resolved Hide resolved
node-native/src/types.rs Outdated Show resolved Hide resolved
@zvolin
Copy link
Member

zvolin commented Dec 13, 2024

test-wasm ci will still fail at the moment. Should I make the crate wasm compatible or should we just ignore it and use something like

I think we don't care about wasm in this new crate so you could just put this in top of lib.rs

#![cfg(not(target_arch = "wasm32"))]

@sebasti810
Copy link
Contributor Author

I think we don't care about wasm in this new crate so you could just put this in top of lib.rs

#![cfg(not(target_arch = "wasm32"))]

true, that's enough. I thought we would then have to update the Cargo.toml etc. as well with target-specific dependencies, but that is not the case. Thank you

@sebasti810 sebasti810 force-pushed the main branch 2 times, most recently from 9cf49c0 to 8a858d8 Compare December 17, 2024 09:07
@sebasti810 sebasti810 requested a review from zvolin December 17, 2024 09:07
node-uniffi/src/lib.rs Outdated Show resolved Hide resolved
node-uniffi/src/types.rs Outdated Show resolved Hide resolved
node-uniffi/src/types.rs Outdated Show resolved Hide resolved
node-uniffi/src/types.rs Outdated Show resolved Hide resolved
node-uniffi/src/types.rs Outdated Show resolved Hide resolved
node-uniffi/src/types.rs Outdated Show resolved Hide resolved

/// Events emitted by the node.
#[derive(uniffi::Enum)]
pub enum NodeEvent {
Copy link
Member

Choose a reason for hiding this comment

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

Can we use the one from lumina-node crate?

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 can, but I haven't yet found a solution to make PeerId from libp2p and Vec<u16,u16> compatible with uniffi without the specific wrappers i wrote in types.rs. Afaik, e.g. tuple types are not directly supported because they cannot be cleanly mapped to equivalent types in different target languages. Of course, I could bring the wrappers into the lumina node if that's wanted :)

node-uniffi/Cargo.toml Outdated Show resolved Hide resolved
node-uniffi/src/lib.rs Outdated Show resolved Hide resolved
node-uniffi/src/lib.rs Outdated Show resolved Hide resolved
node-uniffi/src/lib.rs Outdated Show resolved Hide resolved
Copy link
Member

@zvolin zvolin left a comment

Choose a reason for hiding this comment

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

looks very nice already, some nits from me

node-uniffi/src/lib.rs Outdated Show resolved Hide resolved
node-uniffi/src/lib.rs Outdated Show resolved Hide resolved
node-uniffi/src/lib.rs Outdated Show resolved Hide resolved
node-uniffi/src/lib.rs Outdated Show resolved Hide resolved
node-uniffi/src/error.rs Outdated Show resolved Hide resolved
@sebasti810 sebasti810 changed the title feat(WIP): adding uniffi bindings to support android and ios feat: adding uniffi bindings to support android and ios Dec 30, 2024
@sebasti810 sebasti810 marked this pull request as ready for review December 30, 2024 07:56
@zvolin
Copy link
Member

zvolin commented Jan 9, 2025

don't bother with this clippy failure, we have a new toolchain an ci related changes elsewhere and gonna get it in soon. The team is back so we are gonna address this PR soon, thanks for patience 🙏

Signed-off-by: Yiannis Marangos <[email protected]>
@zvolin zvolin merged commit 840014c into eigerco:main Jan 10, 2025
27 checks passed
@zvolin
Copy link
Member

zvolin commented Jan 10, 2025

Ooops, I wanted to add lumina-node-uniffi to the clippy and test jobs on ci and I forgot to write git push sebasti810 main but just typed git push and it merged the PR 🤦‍♂️. The coincidence was that I was granted admin to tweak the CI required checks and admin role has ability to bypass required checks (like approvals). So the lesson is never give admin to anyone :)
Anyway, we have discussed the PR on daily and we agreed that we want to approve and merge it, so it is okay 🙃 I wanted to approve it right after this push anyway.

Thank you for your contribution! It's an amazing feature 🙏

zvolin added a commit that referenced this pull request Jan 10, 2025
@zvolin zvolin mentioned this pull request Jan 28, 2025
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.

3 participants