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

Error when trying to use: https://github.com/serialport/serialport-rs #1905

Closed
mpep2 opened this issue Apr 29, 2024 · 11 comments
Closed

Error when trying to use: https://github.com/serialport/serialport-rs #1905

mpep2 opened this issue Apr 29, 2024 · 11 comments
Labels
bug Something isn't working

Comments

@mpep2
Copy link

mpep2 commented Apr 29, 2024

Describe the bug

I got the following error when trying to generate for the above mentioned package:

Error: function=Ident { sym: new, span: bytes(48557..48560) }

Caused by:
    0: when trying to parse DartFn
    1: Unknown ident: Into

Steps to reproduce

  1. Download the mentioned repository code into rust/src/api
  2. rename lib.rs to serialport.rs and add it to mod.rs file
  3. run flutter_rust_bridge_codegen generate

Logs

$ flutter_rust_bridge_codegen generate
[7.3s] Parse  
  └── [7.1s] Run cargo expand  
  └── [0.2s] Parse source graph                                                                                                                                                                            Error: function=Ident { sym: new, span: bytes(48557..48560) }

Caused by:
    0: when trying to parse DartFn
    1: Unknown ident: Into

Expected behavior

No response

Generated binding code

No response

OS

No response

Version of flutter_rust_bridge_codegen

2.0.0-dev.32

Flutter info

[✓] Flutter (Channel beta, 3.22.0-0.1.pre, on macOS 14.4.1 23E224 darwin-arm64, locale en-US)

Version of clang++

No response

Additional context

No response

@mpep2 mpep2 added the bug Something isn't working label Apr 29, 2024
Copy link

welcome bot commented Apr 29, 2024

Hi! Thanks for opening your first issue here! 😄

@fzyzcjy
Copy link
Owner

fzyzcjy commented Apr 29, 2024

Hi, IMHO generate directly on the whole serialport codebase without modification may not work. This is because, though flutter_rust_bridge understands a lot of Rust syntax, Rust is so flexible that there are still scenarios that is not supported. As for your specific case, I guess it may be something like Into<Sth> together with some fn that makes flutter_rust_bridge confused.

To debug this, one way is to add --verbose and see which one gives error. Another way is to bisect the code (comment out some of them and see results). In addition, you can also keep the original crate untouched, and create a thin wrapper in your crate to call the original crate.

@fzyzcjy fzyzcjy added the awaiting Waiting for responses, PR, further discussions, upstream release, etc label Apr 29, 2024
@mpep2
Copy link
Author

mpep2 commented Apr 29, 2024

I remove Into from the code and now I get this error:

[2024-04-29T12:56:06.215Z ERROR flutter_rust_bridge_codegen-2.0.0-dev.32/src/library/utils/logs.rs:52] panicked at .cargo/registry/src/index.crates.io-6f17d22bba15001f/flutter_rust_bridge_codegen-2.0.0-dev.32/src/library/codegen/polisher/auto_upgrade.rs:58:41:
no entry found for key
thread 'main' panicked at .cargo/registry/src/index.crates.io-6f17d22bba15001f/flutter_rust_bridge_codegen-2.0.0-dev.32/src/library/codegen/polisher/auto_upgrade.rs:58:41:
no entry found for key
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

@mpep2
Copy link
Author

mpep2 commented Apr 29, 2024

I succeeded in generating the code but now the problem is that the types are no translated e.g. u8 is translated as:

class U8 extends RustOpaque {
  U8.dcoDecode(List<dynamic> wire) : super.dcoDecode(wire, _kStaticData);

  U8.sseDecode(int ptr, int externalSizeOnNative)
      : super.sseDecode(ptr, externalSizeOnNative, _kStaticData);

  static final _kStaticData = RustArcStaticData(
    rustArcIncrementStrongCount:
        RustLib.instance.api.rust_arc_increment_strong_count_U8,
    rustArcDecrementStrongCount:
        RustLib.instance.api.rust_arc_decrement_strong_count_U8,
    rustArcDecrementStrongCountPtr:
        RustLib.instance.api.rust_arc_decrement_strong_count_U8Ptr,
  );
}

@fzyzcjy
Copy link
Owner

fzyzcjy commented Apr 30, 2024

Hi, it would be great to provide a minimal reproducible sample to see what is going on.

@mpep2
Copy link
Author

mpep2 commented Apr 30, 2024

I am using simple template with 2 files (https://github.com/berkowski/tokio-serial/tree/master/src). with lib.rs renamed to serialport.rs
Cargo file:

[lib]
crate-type = ["cdylib", "staticlib"]

[dependencies]
flutter_rust_bridge = "=2.0.0-dev.32"

[features]
default = []
libudev = ["mio-serial/libudev"]
rt = ["tokio/rt-multi-thread"]
codec = ["tokio-util/codec", "bytes"]

[dependencies.futures]
version = "^0.3"

[dependencies.tokio]
version = "^1.8"
default-features = false
features = ["net"]

[dependencies.tokio-util]
version = "^0.7"
default-features = false
optional = true

[dependencies.mio-serial]
version = "^5.0.3"
default-features = false

[dependencies.bytes]
version = "^1"
default-features = false
optional = true

[dependencies.log]
version = "^0.4"

[dependencies.cfg-if]
version = "^1"

[dev-dependencies.tokio]
version = "^1.8"
features = ["macros", "rt", "process", "time", "fs", "io-util"]
default-features = false

[dev-dependencies.env_logger]
version = "^0.10.0"

mod.rs:

pub mod serialport;
pub mod frame;

@fzyzcjy
Copy link
Owner

fzyzcjy commented Apr 30, 2024

Briefly checked it, and I suspect it is &[u8] that confuses flutter_rust_bridge. Maybe we can mimic how to deal with &str (by treating it as a String) to work on &[u8] (by treating it as Vec<u8>).

As a workaround, you can try to modify it manually to Vec<u8> (and change a few lines of code to adapt to it) before this feature is implemented

@patmuk
Copy link
Contributor

patmuk commented May 15, 2024

@mpep2 how did you solve this error?

[2024-04-29T12:56:06.215Z ERROR flutter_rust_bridge_codegen-2.0.0-dev.32/src/library/utils/logs.rs:52] panicked at .cargo/registry/src/index.crates.io-6f17d22bba15001f/flutter_rust_bridge_codegen-2.0.0-dev.32/src/library/codegen/polisher/auto_upgrade.rs:58:41:
no entry found for key
thread 'main' panicked at .cargo/registry/src/index.crates.io-6f17d22bba15001f/flutter_rust_bridge_codegen-2.0.0-dev.32/src/library/codegen/polisher/auto_upgrade.rs:58:41:
no entry found for key
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

I get this as well, having changed from v2.0.0-dev.32 to v2.0.0-dev.33.

@patmuk
Copy link
Contributor

patmuk commented May 15, 2024

Solved it.
I accidentally removed

[dependencies]
flutter_rust_bridge = "=2.0.0-dev.33"

from my cargo.toml

@fzyzcjy
Copy link
Owner

fzyzcjy commented May 19, 2024

Close since the question seems to be answered. Feel free to reopen if needed!

@fzyzcjy fzyzcjy closed this as completed May 19, 2024
@fzyzcjy fzyzcjy removed the awaiting Waiting for responses, PR, further discussions, upstream release, etc label May 19, 2024
Copy link
Contributor

github-actions bot commented Jun 2, 2024

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants