cunarist / rinf

Rust for native business logic, Flutter for flexible and beautiful GUI
MIT License
1.88k stars 65 forks source link

Location of libhub.so with flutter-pi #338

Closed hilpara closed 3 months ago

hilpara commented 3 months ago

I try to get the rinf run on armv7-board with flutter-pi. I just don't know where the libhub.so should be located on a target device. flutter-pi wants assets to be ./data/flutter_assets and the app.so in ./lib/libapp.so. Where should I copy the libhub.so? With every combination with ./native/hub/libhub.so or only libhub.so I will get

Failed to load dynamic library 'libhub.so': libhub.so: cannot open shared object file: No such file or directory

temeddix commented 3 months ago

Hi @hilpara , would you try placing your libhub.so near the app executable file? I'm not very familiar with using flutter-pi, so we would need to find out together.

hilpara commented 3 months ago

Well I already tried to put it next to app.so (under ./lib) and also to flutter_assets (./data/flutter_asssets). The worst thing is, that it doesn't say where it tries to find the file. I was also wondering if I need to do something with Cargokit? I just compiled the rust part with cargo. This worked with flutter_rust_bridge, but I'm not really familiar what Cargokit does.

temeddix commented 3 months ago

You might not need Cargokit here(Maybe), since what it's doing is compiling the Rust crate for you automatically(At least on Linux).

Are you using flutter build linux for this? How is the process of building on flutter-pi?

hilpara commented 3 months ago

There is a tool to build for flutter-pi Flutterpi_tool So no, Iā€˜m not directly using flutter to build. As I wrote, this all works for flutter_rust_bridge, but I wanted to test rinf and make compare which would work better for me.

temeddix commented 3 months ago

I'm not aware of how exactly flutter_rust_bridge gets things done, but I do know that it also adopted Cargokit. Therefore I think that we share the similar build process, but I'm not really sure why loading dynamic library works with flutter_rust_bridge and not with Rinf(When built with pure cargo build).

However, thank you for your attention on Rinf. I hope you could choose the right tool for you in the end.

hilpara commented 3 months ago

With flutter_rust_bridge I also have to compile the rust program separately, because flutter do not have target for armv7. They have defined explicitly a path to rust library so I did find where to place that (it was also first trial and error for me). So all I have to do is, is to copy the .so file to ./rust/target/release/. I could not find such a thing from rinf files.

temeddix commented 3 months ago

Thanks for the details :)

Now I think we should provide ways to manually specify library paths, instead of hardcoding in the codebase. Do you think this would help?

hilpara commented 3 months ago

I think so. It would also help to get some kind of error message where the app tries to load the libraries. There will always be at least libhub, so maybe you could first check if it is found or not and print the search path. I have just started to learn flutter/dart so I do not know if you can do that at all.

temeddix commented 3 months ago

In the context of Flutter-pi, would using environment variables for setting library file path be better, or would calling a function (such as setHubLibPath) be better?

hilpara commented 3 months ago

@temeddix thanks for the quick help. The app works now (rinf 6.11.1), but it shows a panic message (it doesn't affect to test app):

thread 'tokio-runtime-worker' panicked at native/hub/src/messages/basic.rs:65:16: A receiver can be taken only once stack backtrace: 0: 0xb03ca4a8 - std::backtrace_rs::backtrace::libunwind::trace::h7f9db2c337de4d40 at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/std/src/../../backtrace/src/backtrace/libunwind.rs:105:5 1: 0xb03ca4a8 - std::backtrace_rs::backtrace::trace_unsynchronized::he2df5c6895be172a at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5 2: 0xb03ca4a8 - std::sys_common::backtrace::_print_fmt::hc2ed2b4d69e09848 at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/std/src/sys_common/backtrace.rs:68:5 3: 0xb03ca4a8 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h31de16d00753bdd4 at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/std/src/sys_common/backtrace.rs:44:22 4: 0xb03e9750 - core::fmt::rt::Argument::fmt::h95dbd5d7ff5d78ca at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/fmt/rt.rs:142:9 5: 0xb03e9750 - core::fmt::write::h41c10105e2751a4f at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/fmt/mod.rs:1153:17 6: 0xb03c8140 - std::io::Write::write_fmt::heb000277ba252e11 at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/std/src/io/mod.rs:1843:15 7: 0xb03ca28c - std::sys_common::backtrace::_print::h0a9835424281b81c at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/std/src/sys_common/backtrace.rs:47:5 8: 0xb03ca28c - std::sys_common::backtrace::print::hc3a7a9c6d9c59981 at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/std/src/sys_common/backtrace.rs:34:9 9: 0xb03cbbd4 - std::panicking::default_hook::{{closure}}::he6537d82807cf32d at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/std/src/panicking.rs:272:22 10: 0xb03cb7d0 - std::panicking::default_hook::hec5660c82d3802bc at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/std/src/panicking.rs:292:9 11: 0xb03cc27c - std::panicking::rust_panic_with_hook::h680fd20125a3f542 at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/std/src/panicking.rs:779:13 12: 0xb03cbf90 - std::panicking::begin_panic_handler::{{closure}}::hf800f7b24575a34a at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/std/src/panicking.rs:657:13 13: 0xb03ca9e4 - std::sys_common::backtrace::__rust_end_short_backtrace::h95f2f55ae6ffb9d0 at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/std/src/sys_common/backtrace.rs:171:18 14: 0xb03cbd58 - rust_begin_unwind at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/std/src/panicking.rs:645:5 15: 0xb0388dd4 - core::panicking::panic_fmt::h6f9dd8056ab12d5f at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/panicking.rs:72:14 16: 0xb03e89f4 - core::panicking::panic_display::h286195a1ab7c9c87 at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/panicking.rs:197:5 17: 0xb0388d9c - core::panicking::panic_str::h1c237a5f2e65be48 at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/panicking.rs:172:5 18: 0xb0388d9c - core::option::expect_failed::h9e6f8523e73adf2d at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/option.rs:1995:5 19: 0xb038a004 - hub::messages::basic::SmallText::get_dart_signal_receiver::h397f2b8653f9dd9b 20: 0xb038ed98 - hub::main::{{closure}}::h86ccb1bc0a901c6c 21: 0xb038ead8 - tokio::runtime::task::core::Core<T,S>::poll::hb52131cb77782b52 22: 0xb039008c - tokio::runtime::task::harness::Harness<T,S>::poll::h58c65eb570f7c19e 23: 0xb03a9738 - tokio::runtime::scheduler::multi_thread::worker::Context::run_task::h6a62537a5d2c3afa 24: 0xb03a8c08 - tokio::runtime::scheduler::multi_thread::worker::Context::run::h8b5d1e63c1ac12c2 25: 0xb03942fc - tokio::runtime::context::runtime::enter_runtime::h5194b70bc5d02054 26: 0xb03a851c - tokio::runtime::scheduler::multi_thread::worker::run::h9e407890b028a25d 27: 0xb03972d8 - <tokio::runtime::blocking::task::BlockingTask<T> as core::future::future::Future>::poll::hc9d3a3a5728ffd77 28: 0xb039d754 - tokio::runtime::task::core::Core<T,S>::poll::ha110363545c1cb05 29: 0xb039dd94 - tokio::runtime::task::harness::Harness<T,S>::poll::hbd1305ddb84ec64a 30: 0xb03975d4 - std::sys_common::backtrace::__rust_begin_short_backtrace::h910bcddc60aa38b0 31: 0xb039fbe8 - core::ops::function::FnOnce::call_once{{vtable.shim}}::h3eb75a45daa7ef2e 32: 0xb03ce008 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h63816478f43a3fff at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/alloc/src/boxed.rs:2020:9 33: 0xb03ce008 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hc69bfbfe7e1987ed at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/alloc/src/boxed.rs:2020:9 34: 0xb03ce008 - std::sys::pal::unix::thread::Thread::new::thread_start::h1258e9bb2da77b73 at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/std/src/sys/pal/unix/thread.rs:108:17

temeddix commented 3 months ago

This error message is not something related to loading native libraries. Do you mind checking if you've called get_dart_signal_receiver twice for the same message struct in Rust?

hilpara commented 3 months ago

All I did was to follow the guide, so I didn't do anything my self. flutter create my_app flutter pub add rinf rinf template

Then added path to libhub.so and compiled all. I was just wandering if there is a 'bug' in template generation. But it doesn't matter at the moment, I will have to dive deeper to rinf, rust and flutter.

dhiyaaulauliyaa commented 3 months ago

hi @hilpara, where did you store the libhub.so file on your raspi?

hilpara commented 3 months ago

@dhiyaaulauliyaa, I do not have raspi, but it doesn't matter. I copied it to flutter_assets folder and added await initializeRust(compiledLibPath: "/root/myapp/data/flutter_assets/libhub.so"); to lib/main.dart.

I did bump to next problem and maybe I should make a new issue: I followed the Basic Tutorial and after clicking the button, the app crashes

thread caused non-unwinding panic. aborting. Aborted (core dumped)

I hope you have better results.

dhiyaaulauliyaa commented 3 months ago

@dhiyaaulauliyaa, I do not have raspi, but it doesn't matter. I copied it to flutter_assets folder and added await initializeRust(compiledLibPath: "/root/myapp/data/flutter_assets/libhub.so"); to lib/main.dart.

I did bump to next problem and maybe I should make a new issue: I followed the Basic Tutorial and after clicking the button, the app crashes

thread caused non-unwinding panic. aborting. Aborted (core dumped)

I hope you have better results.

thanks for the answer. i did found out that we can customize the path in initializeRust function. šŸ˜…

actually i didn't build using flutter-pi, instead i built using flutter-elinux. still got the problem though:

Unhandled Exception: Invalid argument(s): Failed to load dynamic library '/usr/share/hmi-assets/libhub.so': /lib/libc.so.6: versionGLIBC_2.33' not found (required by /usr/share/hmi-assets/libhub.so)`

i guess this because the so file generated in my machine doesn't suit the environtment in my target board. in process to troubleshoot this. however, the location of libhub.so doesn't an issue anymore šŸ˜€

temeddix commented 3 months ago

Right now Rinf doesn't have support for flutter-pi, but I will be happy to participate in this project if somebody provides a PR or fixes related to this :)

dhiyaaulauliyaa commented 3 months ago

update: i successfully build and run flutter+rinf on embedded board using flutter-elinux. thanks for the amazing package šŸ‘šŸ»