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(WIP): adding uniffi bindings to support android and ios #473

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

Conversation

sebasti810
Copy link

@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
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
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
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
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