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

flutter: Make bindings work #668

Closed
wants to merge 8 commits into from

Conversation

ethicnology
Copy link
Contributor

Description

This PR attempt to make the flutter bindings work.

Notes to the reviewers

The commits can be individually reviewed but I will develop a bit more here:

  • 0db0e0f Removes old generated files that are errored because the original binding doesn't exist anymore
  • d1d902d Changes default to new because default is the reserved word in dart which was generating errors.
  • 8457a8a Downgrades flutter_rust_bridge from 2.6.0 to 2.0.0, why ? Because the bindings will be unusable with others frb bindings that don't match the same version. For this reason many frb bindings are staying on 2.0.0 (see bdk-flutter, boltz-flutter, or even my package that I had to change for the same reason bip85
  • 37a59f5 Set an entrypoint classname, if a user want to create an app with multiple flutter_rust_bridge dependencies it will have to initialize using NostrSdk.init() to avoid conflicts with others flutter_rust_bridge dependencies if they still keep RustLib.init()
  • 904797e Regenerates files with previous changes
  • 75e579c Exports the generated bindings so they can be called by the developer
  • 193cee6 Creates a basic example app that we should make work
  • 668551e Comments out some obsolete errored code (facultative)

I'm trying to share my own experience building bip85 bindings using frb.

As I transferred the nostr namespace to you on pub.dev, I also recommend renaming the flutter package nostr instead of nostr_sdk to benefit from visibility.

However the example app doesn't work yet, due to the following error, but it may due to my environement or something I missed in the changes you've implemented in the bindings:

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Invalid argument(s): Failed to load dynamic library 'nostr_sdk_flutter.framework/nostr_sdk_flutter': dlopen(nostr_sdk_flutter.framework/nostr_sdk_flutter, 0x0001): tried: '/Library/Developer/CoreSimulator/Volumes/iOS_22A3351/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 18.0.simruntime/Contents/Resources/RuntimeRootnostr_sdk_flutter.framework/nostr_sdk_flutter' (no such file), '/Users/user/Library/Developer/CoreSimulator/Devices/4662AA9C-CCDA-427E-892A-D3F0F981B7F0/data/Containers/Bundle/Application/3F34743B-2536-4B32-BB63-7A65B4F4F12D/Runner.app/nostr_sdk_flutter.framework/nostr_sdk_flutter' (no such file), '/Library/Developer/CoreSimulator/Volumes/iOS_22A3351/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 18.0.simruntime/Contents/Resources/RuntimeRoot/usr/lib/swift/nostr_sdk_flutter.framework/nostr_sdk_flutter' (no such file), '/usr/lib/swift/nostr_sdk_flutter.framework/nostr_sdk_flutter' (no such file, not in dy<>
Syncing files to device iPhone 16 Plus...

Checklist

  • I followed the contribution guidelines
  • I ran just precommit or just check before committing
    –> My changes apply only to dart bindings
  • I updated the CHANGELOG (if applicable)
    –> still more work need to be done

@ethicnology ethicnology mentioned this pull request Dec 2, 2024
@ethicnology
Copy link
Contributor Author

@yukibtc I would like your opinion on this

@yukibtc
Copy link
Member

yukibtc commented Dec 3, 2024

@yukibtc I would like your opinion on this

Hey, sure. I've to finish a PR and I'll review this

@yukibtc
Copy link
Member

yukibtc commented Dec 3, 2024

Changes looks good.

Regarding the error, I'm unsure about the cause but I was checking if maybe there is some config/dep missing. I noticed that ffigen dependency is not set. I've tried to update (locally) the flutter_rust_bridge.yaml file with this:

rust_input: crate::api
rust_root: rust/
dart_output: lib/src/rust
full_dep: true
c_output: ios/Classes/frb_generated.h 
duplicated_c_output: [macos/Classes/frb_generated.h]

But I receive this error:

--- stderr
  thread 'main' panicked at bindings/nostr-sdk-flutter/rust/build.rs:30:6:
  called `Result::unwrap()` on an `Err` value: ffigen failed. Please refer to https://fzyzcjy.github.io/flutter_rust_bridge/manual/ffigen-troubleshooting for details

I followed the troubleshooting guide but still not works.

@yukibtc
Copy link
Member

yukibtc commented Dec 3, 2024

I see, in general, that the pubspec.yaml have many differences with your or the BDK/Boltz ones. Miss some deps and this section is different:

flutter:
  plugin:
    platforms:
      android:
        package: org.rustnostr.nostr_sdk
        pluginClass: NostrSdkPlugin
      ios:
        pluginClass: NostrSdkPlugin
      linux:
        pluginClass: NostrSdkPlugin
      macos:
        pluginClass: NostrSdkPlugin
      windows:
        pluginClass: NostrSdkPluginCApi

I think it should be replaced with:

flutter:
  plugin:
    platforms:
      android:
        ffiPlugin: true
      ios:
        ffiPlugin: true
      linux:
        ffiPlugin: true
      macos:
        ffiPlugin: true
      windows:
        ffiPlugin: true

I don't remember how I generated the flutter packet. Maybe I generated it incorrectly (not for bindings).

@yukibtc
Copy link
Member

yukibtc commented Dec 5, 2024

I've completely recreated the package and cherry picked your changes. It still return the "Failed to load dynamic library..." error. I think because the rust library name is different from the flutter one: I tried to generate a new package, add the rust code and run the example and works. But when I change the flutter name (or the rust lib name) it no longer works (not find the library, also if I update all the names across the code). I'll try to look for a solution

@yukibtc yukibtc closed this Dec 5, 2024
@yukibtc
Copy link
Member

yukibtc commented Dec 16, 2024

@ethicnology I've moved the bindings to https://github.com/rust-nostr/nostr-sdk-flutter

Now the example works (run with just example).

I tried to rename it to nostr but it create conflicts because there is already a rust crate named nostr in the Cargo.lock. I tried to rename only the flutter package and not the rust one but then it fail to load the library

@ethicnology
Copy link
Contributor Author

@yukibtc

I had the same problem with bip85, I ended up re-creating a project with the proper name (bip85) and rename the rust crates (bip85_extended)

I've also changed the import method in the example using github rather than the relative path

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