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

Getting started with third party packages #2352

Open
ethicnology opened this issue Oct 17, 2024 · 4 comments
Open

Getting started with third party packages #2352

ethicnology opened this issue Oct 17, 2024 · 4 comments
Labels
enhancement New feature or request

Comments

@ethicnology
Copy link

Is your feature request related to a problem? Please describe.
Hey there, I love to see it getting more and more mature. I would like to start to use it on some projects but I'm facing "getting started" problem. The one-liner to generate a flutter app with some rust functions is great but when it comes to third parties libraries I feel lost. I've read various sections of the documentation but it miss step by step approach so we can step in without many doubts

Describe the solution you'd like

  • 101 Imports and use a rust third party package into your dart/flutter app
  • 101 Generating a dart/flutter package from a rust third party (may be a good answer to flutter crypto libraries chaos)

Describe what you've tried

  1. flutter_rust_bridge one liner
  2. cd rust
  3. Import a third party library: cargo add nostr
  4. cd ..
  5. flutter_rust_bridge_codegen generate

error:

flutter_rust_bridge_codegen-2.5.0/src/library/codegen/ir/mir/ty/enumeration.rs:51:32:
enum_pool does not contain MirTypeEnumRef { ident: MirEnumIdent(NamespacedName { namespace: Namespace { joined_path: "nostr::nips::nip19" }, name: "Nip19" }), is_exception: false }
thread 'main' panicked at flutter_rust_bridge_codegen-2.5.0/src/library/codegen/ir/mir/ty/enumeration.rs:51:32:
enum_pool does not contain MirTypeEnumRef { ident: MirEnumIdent(NamespacedName { namespace: Namespace { joined_path: "nostr::nips::nip19" }, name: "Nip19" }), is_exception: false }
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Additional context
I give here the example with the nostr third party package but I do not seek a specific answer for this, I'm looking for a more comprehensive way of using your tool his limits and how to work around.

@ethicnology ethicnology added the enhancement New feature or request label Oct 17, 2024
@fzyzcjy
Copy link
Owner

fzyzcjy commented Oct 17, 2024

Hi, automatically scanning a whole third party package is experimental feature and may not support too complex arbitrary packages (since there are so many corner cases for Rust). Looks like nostr may contain some edge cases that does not support yet. But feel free to use the https://cjycode.com/flutter_rust_bridge/guides/third-party/manual manual way or to improve this experimental feature!

@ethicnology
Copy link
Author

Thanks to your last answer I've took the manual way

I've created a simple function that consume the third party crate:

use nostr::key::{Keys, SecretKey};

#[flutter_rust_bridge::frb(init)]
pub fn init_app() {
    flutter_rust_bridge::setup_default_user_utils();
}

#[flutter_rust_bridge::frb(sync)]
pub fn generate_nostr_keys() -> (String, String) {
    let keys = Keys::generate();
    let secret = keys.secret_key().to_secret_hex();
    let public = keys.public_key().to_string();
    return (secret, public);
}

While it's work fine on macos and ios, I'm facing this error targeting chrome with build-web related to secp256k1, probably a dependency of the third-party crate nostr

The following warnings were emitted during compilation:

warning: [email protected]: error: unable to create target: 'No available targets are compatible with triple "wasm32-unknown-unknown"'
warning: [email protected]: 1 error generated.
warning: [email protected]: error: unable to create target: 'No available targets are compatible with triple "wasm32-unknown-unknown"'
warning: [email protected]: 1 error generated.

error: failed to run custom build command for `secp256k1-sys v0.10.1`

…

warning: build failed, waiting for other jobs to finish...
Error: Compiling your crate to WebAssembly failed
Caused by: Compiling your crate to WebAssembly failed
Caused by: failed to execute `cargo build`: exited with exit status: 101
  full command: cd "rust" && "cargo" "build" "--lib" "--target" "wasm32-unknown-unknown" "-Z" "build-std=std,panic_abort"

Is there a work-around ?

@ethicnology
Copy link
Author

I also had trouble building on ios and macos using web_socket_channel but this has nothing to do with rust third-party package, it's a compatibility issue between flutter_rust_bridge and web_socket_channel

@fzyzcjy
Copy link
Owner

fzyzcjy commented Oct 22, 2024

Hi, that looks like a Rust compilation error. Thus maybe google / ask on the spcfici crate secp256k1-sys, since this is not flutter_rust_bridge can control.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants