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

Support when library name is different from crate name #2173

Open
blopker opened this issue Jul 1, 2024 · 5 comments
Open

Support when library name is different from crate name #2173

blopker opened this issue Jul 1, 2024 · 5 comments
Labels
awaiting Waiting for responses, PR, further discussions, upstream release, etc experimental feature Issues related to experimental instead of stable features

Comments

@blopker
Copy link

blopker commented Jul 1, 2024

Describe the bug

I'm not sure if this is a bug or feature request. I'm trying to auto generate bindings for the crate here: https://github.com/Lymphatus/libcaesium. It has a [lib] section in the Cargo file that has a name declared, caesium, which seems to cause issues.

My flutter_rust_bridge.yaml:

rust_input: crate::api,libcaesium
dart_output: lib/src/rust
rust_root: rust/

This is able to generate the bindings, but they won't compile because the bindings try to import with libcaesium, when it needs to use caesium.

I get a lot of errors similar to:

SEVERE:     --> src/frb_generated.rs:2296:20
SEVERE:      |
SEVERE: 2296 |     for FrbWrapper<libcaesium::ChromaSubsampling>
SEVERE:      |                    ^^^^^^^^^^ use of undeclared crate or module `libcaesium`

Thank you!

Steps to reproduce

  1. Add libcaesium to a Flutter project by including libcaesium = { git = "https://github.com/Lymphatus/libcaesium.git", tag = "0.15.5" } in Cargo.toml
  2. Add libcaesium to flutter_rust_bridge.yaml rust_input
  3. Run flutter_rust_bridge_codegen generate
  4. Try to compile the generated code

Logs

SEVERE: error[E0433]: failed to resolve: use of undeclared crate or module `libcaesium`
SEVERE:     --> src/frb_generated.rs:1963:16
SEVERE:      |
SEVERE: 1963 |         return libcaesium::GifParameters {
SEVERE:      |                ^^^^^^^^^^ use of undeclared crate or module `libcaesium`
SEVERE:      |
SEVERE: help: there is a crate or module with a similar name
SEVERE:      |
SEVERE: 1963 |         return caesium::GifParameters {
SEVERE:      |                ~~~~~~~
SEVERE: 
SEVERE: error[E0433]: failed to resolve: use of undeclared crate or module `libcaesium`
SEVERE:     --> src/frb_generated.rs:1976:20
SEVERE:      |
SEVERE: 1976 | impl SseDecode for libcaesium::JpegParameters {
SEVERE:      |                    ^^^^^^^^^^ use of undeclared crate or module `libcaesium`
SEVERE:      |
SEVERE: help: there is a crate or module with a similar name
SEVERE:      |
SEVERE: 1976 | impl SseDecode for caesium::JpegParameters {
SEVERE:      |                    ~~~~~~~

Expected behavior

No response

Generated binding code

No response

OS

MacOS

Version of flutter_rust_bridge_codegen

2.0.0

Flutter info

[✓] Flutter (Channel stable, 3.22.2, on macOS 14.5 23F79 darwin-arm64, locale en-US)
    • Flutter version 3.22.2 on channel stable at /Users/blopker/development/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 761747bfc5 (4 weeks ago), 2024-06-05 22:15:13 +0200
    • Engine revision edd8546116
    • Dart version 3.4.3
    • DevTools version 2.34.3

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
    • Android SDK at /Users/blopker/Library/Android/sdk
    • Platform android-34, build-tools 33.0.1
    • ANDROID_HOME = /Users/blopker/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.7-11185874)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.4)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15F31d
    • CocoaPods version 1.15.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2023.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.7-11185874)

[✓] VS Code (version 1.90.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.90.0

[✓] Connected device (3 available)
    • macOS (desktop)                 • macos                 • darwin-arm64   • macOS 14.5 23F79 darwin-arm64
    • Mac Designed for iPad (desktop) • mac-designed-for-ipad • darwin         • macOS 14.5 23F79 darwin-arm64
    • Chrome (web)                    • chrome                • web-javascript • Google Chrome 126.0.6478.127
    ! Error: Browsing on the local area network for iPhone (2). Ensure the device is unlocked and attached with
      a cable or associated with the same local area network as this Mac.
      The device must be opted into Developer Mode to connect wirelessly. (code -27)

[✓] Network resources
    • All expected network resources are available.

• No issues found!

Version of clang++

No response

Additional context

No response

@blopker blopker added the bug Something isn't working label Jul 1, 2024
Copy link

welcome bot commented Jul 1, 2024

Hi! Thanks for opening your first issue here! 😄

@blopker
Copy link
Author

blopker commented Jul 1, 2024

I should add that making rust_input: crate::api,caesium errors with:

ror: package ID specification `caesium` did not match any packages
	Did you mean `libcaesium`?

When trying to generate the bindings.

@fzyzcjy fzyzcjy added enhancement New feature or request and removed bug Something isn't working labels Jul 1, 2024
@fzyzcjy
Copy link
Owner

fzyzcjy commented Jul 1, 2024

It has a [lib] section in the Cargo file that has a name declared, caesium, which seems to cause issues.

I think so, frb does not yet understand this field.

I'm not sure if this is a bug or feature request.

So yes it looks like a feature request

I guess it is not hard to fix it. Rough idea:

  • we already use cargo_metadata to get various info. then we can read that "name" field and know that rename thing.
  • then, just change the code that originally uses "crate name" into two halves, some use the classical name, some use that new name.

Feel free to PR for this! Alternatively, I may work on it in the next batch.

@blopker
Copy link
Author

blopker commented Jul 1, 2024

Great! I thought I might just be holding it wrong, but good to know it's unimplemented. My workaround is just to make a small Rust wrapper, which was easy enough.

I'm new to Rust, but I may end up trying to do it.

Anyway, thanks for this amazing project! It's been wonderful to work with.

@fzyzcjy
Copy link
Owner

fzyzcjy commented Jul 1, 2024

You are welcome and looking forward to the PR! The wrapper looks reasonable since the API looks small.

@fzyzcjy fzyzcjy added the awaiting Waiting for responses, PR, further discussions, upstream release, etc label Jul 1, 2024
@fzyzcjy fzyzcjy changed the title Can't auto generate third party crate containing named library Support when using the experimental scan full third party crate feature, and when library name is different from crate name Aug 6, 2024
@fzyzcjy fzyzcjy changed the title Support when using the experimental scan full third party crate feature, and when library name is different from crate name Support when library name is different from crate name when using the experimental scan full third party crate feature Aug 6, 2024
@fzyzcjy fzyzcjy changed the title Support when library name is different from crate name when using the experimental scan full third party crate feature [experimental-feature] Support when library name is different from crate name Sep 12, 2024
@fzyzcjy fzyzcjy added experimental feature Issues related to experimental instead of stable features and removed enhancement New feature or request labels Nov 5, 2024
@fzyzcjy fzyzcjy changed the title [experimental-feature] Support when library name is different from crate name Support when library name is different from crate name Nov 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting Waiting for responses, PR, further discussions, upstream release, etc experimental feature Issues related to experimental instead of stable features
Projects
None yet
Development

No branches or pull requests

2 participants