Closed Phill030 closed 3 days ago
Hi! Thanks for opening your first issue here! :smile:
Hi,
SEVERE: error[E0277]:
std::sync::mpsc::Receiver<ClientPackets>
cannot be shared between threads safely
e.g. https://users.rust-lang.org/t/cannot-be-shared-between-threads-safely/49146
What about putting it in a Mutex
What about putting it in a Mutex
I thought it is not recommended to edit an autogenerated file?
Trying to fix it though results in this error in frb_generated.rs
error[E0277]: the trait bound `std::io::Error: SseEncode` is not satisfied
--> flutter_bridge\src\frb_generated.rs:68:21
|
67 | transform_result_sse(
| -------------------- required by a bound introduced by this call
68 | (move || async move { crate::api::main::init_app().await })().await,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `SseEncode` is not implemented for `std::io::Error`
|
= help: the following other types implement trait `SseEncode`:
bool
i32
usize
u8
anyhow::Error
RustOpaqueBase<tokio::sync::RwLock<OwnedReadHalf>, frb_generated::MoiArc<tokio::sync::RwLock<OwnedReadHalf>>>
RustOpaqueBase<tokio::sync::RwLock<OwnedWriteHalf>, frb_generated::MoiArc<tokio::sync::RwLock<OwnedWriteHalf>>>
RustOpaqueBase<tokio::sync::RwLock<tokio::sync::mpsc::Sender<ClientPackets>>, frb_generated::MoiArc<tokio::sync::RwLock<tokio::sync::mpsc::Sender<ClientPackets>>>>
and 8 others
note: required by a bound in `transform_result_sse`
--> flutter_bridge\src\frb_generated.rs:29:1
|
29 | / flutter_rust_bridge::frb_generated_boilerplate!(
30 | | default_stream_sink_codec = SseCodec,
31 | | default_rust_opaque = RustOpaqueMoi,
32 | | default_rust_auto_opaque = RustAutoOpaqueMoi,
33 | | );
| | ^
| | |
| |_required by a bound in this function
| required by this bound in `transform_result_sse`
= note: this error originates in the macro `$crate::frb_generated_sse_codec` which comes from the expansion of the macro `flutter_rust_bridge::frb_generated_boilerplate` (in Nightly builds, run with -Z macro-backtrace for more info)
I thought it is not recommended to edit an autogenerated file?
Well, I mean editing your code and change the type a little bit.
It's kinda complicated to import all the types after every code generation and wrapping it in a Mutex doesn't really satisfy my usecase.
Not very sure whether the message is conveyed clearly. So I meant that, maybe change
to
pub async fn read_messages(mut reader: OwnedReadHalf, sender: Mutex<Sender<ClientPackets>>) {
which will not need to be done after every code generation. Indeed this just changes the source code.
That would be a unnecessary workaround. My code works fine without the bridge and every time I generate the files, all my types are missing. OwnedReadHalf
, OwnedWriteHalf
, ClientPackets
, ServerPackets
, etc. are all not used in the generated files no matter if I change it to a Mutex in my Sourcecode. There must be something wrong with the Generator since the initial error is
error[E0277]: the trait bound `std::io::Error: SseEncode` is not satisfied
--> flutter_bridge\src\frb_generated.rs:68:21
|
67 | transform_result_sse(
| -------------------- required by a bound introduced by this call
68 | (move || async move { crate::api::main::init_app().await })().await,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `SseEncode` is not implemented for `std::io::Error`
|
= help: the following other types implement trait `SseEncode`:
bool
i32
usize
u8
anyhow::Error
RustOpaqueBase<tokio::sync::RwLock<OwnedReadHalf>, frb_generated::MoiArc<tokio::sync::RwLock<OwnedReadHalf>>>
RustOpaqueBase<tokio::sync::RwLock<OwnedWriteHalf>, frb_generated::MoiArc<tokio::sync::RwLock<OwnedWriteHalf>>>
RustOpaqueBase<tokio::sync::RwLock<tokio::sync::mpsc::Sender<ClientPackets>>, frb_generated::MoiArc<tokio::sync::RwLock<tokio::sync::mpsc::Sender<ClientPackets>>>>
and 8 others
note: required by a bound in `transform_result_sse`
--> flutter_bridge\src\frb_generated.rs:29:1
|
29 | / flutter_rust_bridge::frb_generated_boilerplate!(
30 | | default_stream_sink_codec = SseCodec,
31 | | default_rust_opaque = RustOpaqueMoi,
32 | | default_rust_auto_opaque = RustAutoOpaqueMoi,
33 | | );
| | ^
| | |
| |_required by a bound in this function
| required by this bound in `transform_result_sse`
= note: this error originates in the macro `$crate::frb_generated_sse_codec` which comes from the expansion of the macro `flutter_rust_bridge::frb_generated_boilerplate` (in Nightly builds, run with -Z macro-backtrace for more info)
which has nothing to do with a Mutex
Oh I see, I originally thought you meant a "cannot be shared between threads safely" errror. In that case, could you please provide a minimal reproducible sample (e.g. create a brand new project, modify as few lines as possible in it, and run it, and see the error)?
I think I may have found one possible cause. switching the init_app()
function in Rust for example to async
, breaks the generated code by throwing this error:
error[E0277]: the trait bound `impl std::future::Future<Output = ()>: SseEncode` is not satisfied
--> src\frb_generated.rs:66:38
|
66 | transform_result_sse((move || Result::<_, ()>::Ok(crate::api::main::init_app()))())
| -------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `SseEncode` is not implemented for `impl std::future::Future<Output = ()>`
| |
| required by a bound introduced by this call
|
= help: the following other types implement trait `SseEncode`:
bool
i32
()
note: required by a bound in `transform_result_sse`
--> src\frb_generated.rs:28:1
|
28 | / flutter_rust_bridge::frb_generated_boilerplate!(
29 | | default_stream_sink_codec = SseCodec,
30 | | default_rust_opaque = RustOpaqueMoi,
31 | | default_rust_auto_opaque = RustAutoOpaqueMoi,
32 | | );
| | ^
| | |
| |_required by a bound in this function
| required by this bound in `transform_result_sse`
= note: this error originates in the macro `$crate::frb_generated_sse_codec` which comes from the expansion of the macro `flutter_rust_bridge::frb_generated_boilerplate` (in Nightly builds, run with -Z macro-backtrace for more info)
#[flutter_rust_bridge::frb(init)]
pub async fn init_app() {
[...]
}
is there any alternative?
Nice observation - that looks like a bug, async fn
is supported by frb. Feel free to PR, alternatively I will work on it in the next batch (hopefully within several days together with other things)
Btw, what if you remove the #[frb(init)]
- does it still error?
P.S. after modification, flutter_rust_bridge_codgen generate
needs to be re-run
It's a weird behavior, I created a new project with FRB and I got no errors when using async in the init function. In my old script I commented all my Rust code (only in the Bridge folder) and got following error AFTER trying to launcher Flutter with no Rust errors visible:
SEVERE : error : failed to run custom build command for `dart-sys-fork v4.1.1` [C:\Users\Philipp\Downloads\flutter_rust_bridge_bug-master\flutter_rust_bridge_bug-master\family_app\build\windows\x64\plugins\rust_lib_family_app\rust_lib_family_app_cargokit.vcxproj]
SEVERE: C:\Users\Philipp\.cargo\registry\src\index.crates.io-6f17d22bba15001f\dart-sys-fork-4.1.1\dart-sdk\include\dart_api_dl.c(26): warning C4152: nonstandard extension, function/data pointer conversion in expression
SEVERE: C:\Users\Philipp\.cargo\registry\src\index.crates.io-6f17d22bba15001f\dart-sys-fork-4.1.1\dart-sdk\include\dart_api_dl.c(33): warning C4100: 'external_size': unreferenced formal parameter
SEVERE: C:\Users\Philipp\.cargo\registry\src\index.crates.io-6f17d22bba15001f\dart-sys-fork-4.1.1\dart-sdk\include\dart_api_dl.c(33): warning C4100: 'object': unreferenced formal parameter
SEVERE: C:\Users\Philipp\.cargo\registry\src\index.crates.io-6f17d22bba15001f\dart-sys-fork-4.1.1\dart-sdk\include\dart_api_dl.c(40): warning C4100: 'external_allocation_size': unreferenced formal parameter
SEVERE: C:\Users\Philipp\.cargo\registry\src\index.crates.io-6f17d22bba15001f\dart-sys-fork-4.1.1\dart-sdk\include\dart_api_dl.c(39): warning C4100: 'strong_ref_to_object': unreferenced formal parameter
SEVERE: C:\Users\Philipp\.cargo\registry\src\index.crates.io-6f17d22bba15001f\dart-sys-fork-4.1.1\dart-sdk\include\dart_api_dl.c(38): warning C4100: 'object': unreferenced formal parameter
SEVERE: C:\Users\Philipp\.cargo\registry\src\index.crates.io-6f17d22bba15001f\dart-sys-fork-4.1.1\dart-sdk\include\dart_api_dl.c : fatal error C1083: Cannot open compiler generated file: '': Invalid argument
SEVERE : error occurred: Command "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.39.33519\\bin\\HostX64\\x64\\cl.exe" "-nologo" "-MD" "-Z7" "-Brepro" "-I" "C:\\Users\\Philipp\\.cargo\\registry\\src\\index.crates.io-6f17d22bba15001f\\dart-sys-fork-4.1.1\\dart-sdk\\include" "-W4" "-FoC:/Users/Philipp/Downloads/flutter_rust_bridge_bug-master/flutter_rust_bridge_bug-master/family_app/build/windows/x64/plugins/rust_lib_family_app/cargokit_build\\x86_64-pc-windows-msvc\\debug\\build\\dart-sys-fork-5065ce4c84b1ffbf\\out\\d1c77295b97ecd40-dart_api_dl.o" "-c" "C:\\Users\\Philipp\\.cargo\\registry\\src\\index.crates.io-6f17d22bba15001f\\dart-sys-fork-4.1.1\\dart-sdk\\include\\dart_api_dl.c" with args cl.exe did not execute successfully (status code exit code: 1). [C:\Users\Philipp\Downloads\flutter_rust_bridge_bug-master\flutter_rust_bridge_bug-master\family_app\build\windows\x64\plugins\rust_lib_family_app\rust_lib_family_app_cargokit.vcxproj]
SEVERE : warning : build failed, waiting for other jobs to finish... [C:\Users\Philipp\Downloads\flutter_rust_bridge_bug-master\flutter_rust_bridge_bug-master\family_app\build\windows\x64\plugins\rust_lib_family_app\rust_lib_family_app_cargokit.vcxproj]
C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(254,5): error MSB8066: Custom build for 'C:\Users\Philipp\Downloads\flutter_rust_bridge_bug-master\flutter_rust_bridge_bug-master\family_app\build\windows\x64\CMakeFiles\a02731e01f04b1b06338480881f96f2c\rust_lib_family_app.dll.rule;C:\Users\Philipp\Downloads\flutter_rust_bridge_bug-master\flutter_rust_bridge_bug-master\family_app\build\windows\x64\CMakeFiles\b2a1a40e75578b69304d3a8b851273ea\rust_lib_family_app_cargokit.rule' exited with code -1. [C:\Users\Philipp\Downloads\flutter_rust_bridge_bug-master\flutter_rust_bridge_bug-master\family_app\build\windows\x64\plugins\rust_lib_family_app\rust_lib_family_app_cargokit.vcxproj]
Error: Build process failed.
Hmm, maybe the old one has some wrong configurations? One way without debugging is to just create a brand new project, and copy-paste original code to it.
I've created a new project, which only imports the dependencies from a workspace. The code itself works after manually importing the types inside the generated file but it seems like the Thread is blocking the Window from showing up.
Update: I don't know how but it finally works
Only issue right now is manually importing all my types. Interesting thing, that as soon as I import them in frb_generated.rs
, it appears, that they don't need to be imported in frb_generated.io.rs
that as soon as I import them in frb_generated.rs, it appears, that they don't need to be imported in frb_generated.io.rs
Btw, just to be sure: the generated files should not be modified by hand.
As for imports, just pub use YourType
in your files, and it should be automatically useable.
Close since this seems to work. Feel free to reopen if having any issues!
Describe the bug
I'm trying to implement my Rust code into Flutter but as soon as I start the debugger, the compilation stops logging only the error, provided in
Logs
. After runningflutter_rust_bridge_codegen generate
, the generated Rust files contain many missing Types, from different workspace folders: & the error:Steps to reproduce
flutter_rust_bridge_codegen generate
Logs
Expected behavior
The App should open and there shouldn't be a compilation error.
Generated binding code
No response
OS
Windows 10
Version of
flutter_rust_bridge_codegen
2.0.0-dev.32
Flutter info
Version of
clang++
No response
Additional context
The Rust code itself works without using Flutter.