-
Notifications
You must be signed in to change notification settings - Fork 318
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
Logging overhaul #2303
Logging overhaul #2303
Conversation
@fzyzcjy I did not know that :) Much better to discuss here as well :) I don't know how to write tests for checking the logging output. Can I provide a |
I guess you can add a callback in dart
Firstly try to put tests in pure_dart (probably add a new file, mimicking https://github.com/fzyzcjy/flutter_rust_bridge/blob/master/frb_example/pure_dart/rust/src/api/misc_no_twin_example_a.rs); if really cannot, feel free to discuss why and maybe create a new package! |
@fzyzcjy I will take care of the testing later ... for now I moved my modifications on However, I need some advice on how to integrate it :)
Then again, the generated files are project independent and will always be the same. So, I could either add my code & the needed parts of the generated code to the runtimes or I could modify the code generation so that my code gets added to the generated files. I think adding it to the runtimes would be conceptually better and easier, as this is nothing the user is supposed to modify. |
Btw you can even just modify dart_minimal temporarily when developing it. I usually do this (modify dart_minimal, do work, after it is done move test to pure_dart) |
That's a good question. Especially the problem is, we need to let frb handle generation of several functions (e.g. the function from rust to dart). Thus one way may be, a macro like
And we may modify the default template to call this |
Thanks, that sounds good! I will first try to implement as much as I can without code generation in the runtimes, so I don't slow down the generation. |
Btw no worries about generation slowdown - such several small function should not take noticable time (o/w frb will be useless for larger projects) |
that is true! Premature optimization ... |
I ran into a problem with the thread handler. I thought we don't need code generation - as everything needed is independent of the user's code. However, When running compile errors``` error[E0433]: failed to resolve: use of undeclared crate or module `flutter_rust_bridge` --> /Users/patmuk/code/own/oss/frb/flutter_rust_bridge_fork_pat/frb_rust/src/for_generated/boilerplate.rs:216:21 | 216 | flutter_rust_bridge::for_generated::FLUTTER_RUST_BRIDGE_RUNTIME_VERSION, | ^^^^^^^^^^^^^^^^^^^ use of undeclared crate or module `flutter_rust_bridge` | ::: /Users/patmuk/code/own/oss/frb/flutter_rust_bridge_fork_pat/frb_rust/src/logging/frb_generated.rs:47:1 | 47 | crate::frb_generated_default_handler!(); | --------------------------------------- in this macro invocation | = note: this error originates in the macro `crate::frb_generated_default_handler` (in Nightly builds, run with -Z macro-backtrace for more info) help: consider importing this module --> /Users/patmuk/code/own/oss/frb/flutter_rust_bridge_fork_pat/frb_rust/src/logging/frb_generated.rs:28:1 | 28 + use crate::for_generated; | error[E0433]: failed to resolve: use of undeclared crate or module `flutter_rust_bridge` --> /Users/patmuk/code/own/oss/frb/flutter_rust_bridge_fork_pat/frb_rust/src/for_generated/boilerplate.rs:219:21 | 219 | flutter_rust_bridge::for_generated::FLUTTER_RUST_BRIDGE_RUNTIME_VERSION, | ^^^^^^^^^^^^^^^^^^^ use of undeclared crate or module `flutter_rust_bridge` | ::: /Users/patmuk/code/own/oss/frb/flutter_rust_bridge_fork_pat/frb_rust/src/logging/frb_generated.rs:47:1 | 47 | crate::frb_generated_default_handler!(); | --------------------------------------- in this macro invocation | = note: this error originates in the macro `crate::frb_generated_default_handler` (in Nightly builds, run with -Z macro-backtrace for more info) help: consider importing this module --> /Users/patmuk/code/own/oss/frb/flutter_rust_bridge_fork_pat/frb_rust/src/logging/frb_generated.rs:28:1 | 28 + use crate::for_generated; | error[E0425]: cannot find function `set_boxed_logger` in crate `log` --> /Users/patmuk/code/own/oss/frb/flutter_rust_bridge_fork_pat/frb_rust/src/logging/log_2_dart.rs:12:10 | 12 | log::set_boxed_logger(Box::new(Log2Dart { | ^^^^^^^^^^^^^^^^ not found in `log` | note: found an item that was configured out --> /Users/patmuk/.cargo/registry/src/index.crates.io-6f17d22bba15001f/log-0.4.22/src/lib.rs:1337:8 | 1337 | pub fn set_boxed_logger(logger: Box) -> Result<(), SetLoggerError> { | ^^^^^^^^^^^^^^^^ note: the item is gated here --> /Users/patmuk/.cargo/registry/src/index.crates.io-6f17d22bba15001f/log-0.4.22/src/lib.rs:1336:1 ```As I understand it, the Macro How to progress here? Should we hardcode the logger to use the default handler? Or is there a way to wire it to wait & use the user instantiated handler? Or - is that best to be code generated, and thus implement the logging code into a macro, as you actually suggested? I will try implementing the macro now. |
Small update: I fixed the error by indeed instantiating the default handler:
Will that be problematic if somebody implements his own thread handler? For now, I am continuing with the "runtime integration" approach. |
Well, I guess it is great to use the HANDLER object that the user chooses. Otherwise it is very confusing or even buggy to have two handlers co-exist. |
Yes, I agree ... but how to solve that? ... by implementing the marco like you suggested? Or is there another way to take the user defined handler? |
Hey @fzyzcjy, I am confused about this:
I implemented the macro definition ( I left the However, it looks like my macro is not called ... how is
in
in Is But But If I set that in Thanks :) |
Good job!
Macro may be the simplest...
macro_rules! hello_logging {
() => {
#[frb(dart_code="put your whole big dart code here")]
#[frb(init)]
pub fn this_function_will_also_be_auto_called_on_init() {
do_whatever_rust_logging_setup_here;
}
}
} and in frb_example // users (or us) just add this line
hello_logging!();
fn other_normal_things(); For flags, iirc the default flags should be working |
Hey @fzyzcjy, As I had a conflict adding the logger ( However, I have the following problems:
I implemented the macro in So, to go step-by-step, I moved the logging code back to Not sure to progress now :( Probably the code-generation in the macro within the |
Oh, I just realized that I made my latest commits branching off that branch ... fixing this now so you can see the code. Looks something else got messed up as well ... as |
try to re-export the log in frb_rust/frb_generated.rs and use |
Looking at https://github.com/fzyzcjy/flutter_rust_bridge/pull/2303/files#diff-ef1c2facb4c5b6480560c71382b03598efa060ea377d481598450f76b342a19e seems you are not doing the macro way. When saying macro way, I mean put everything inside the macro, such that it is exactly as if the user has copy-paste each and every related code to their package. No worries! By implementing that correctly I guess it would be ok |
Yes - I did not want to "throw away" that code, so I checked-out the revision before that changed and committed the new code I am writing based on that ... however, these commits are local only, just realized that now. But as I probably broke something along the way, and I am behind master, I am now re-implementing my changes on the latest master and creat a new branch. Thus it is cleaner - was making too many edits back-and-forth in this branch :( Thanks for the re-export tip! |
Closed as surpassed by the better approach in #2308 |
Changes
Please list issues fixed by this PR here, using format "Fixes #the-issue-number".
Checklist
./frb_internal precommit --mode slow
(orfast
) is run (it internal runs code generator, does auto formatting, etc)../website
folder) are updated.Remark for PR creator
./frb_internal --help
shows utilities for development.