Open mpep2 opened 2 weeks ago
Hi! Thanks for opening your first issue here! :smile:
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.
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
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,
);
}
Hi, it would be great to provide a minimal reproducible sample to see what is going on.
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;
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
@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.
Solved it. I accidentally removed
[dependencies]
flutter_rust_bridge = "=2.0.0-dev.33"
from my cargo.toml
Describe the bug
I got the following error when trying to generate for the above mentioned package:
Steps to reproduce
rust/src/api
Logs
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
Version of
clang++
No response
Additional context
No response