From 97ceb388434aaad03bde46e2f5ef9716653dbdae Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Tue, 2 Jan 2024 09:15:24 +0800 Subject: [PATCH 01/20] feat: setup_included_battery --- frb_rust/src/lib.rs | 1 + frb_rust/src/misc/mod.rs | 1 + frb_rust/src/misc/user_utils.rs | 12 ++++++++++++ 3 files changed, 14 insertions(+) create mode 100644 frb_rust/src/misc/user_utils.rs diff --git a/frb_rust/src/lib.rs b/frb_rust/src/lib.rs index 6929d843ba..af86041a2f 100644 --- a/frb_rust/src/lib.rs +++ b/frb_rust/src/lib.rs @@ -26,6 +26,7 @@ pub use crate::handler::handler::Handler; pub use crate::handler::implementation::handler::DefaultHandler; pub use crate::misc::dart_dynamic::DartDynamic; pub use crate::misc::into_into_dart::IntoIntoDart; +pub use crate::misc::user_utils; pub use crate::rust_async::{spawn, spawn_blocking_with, spawn_local, JoinHandle}; pub use crate::rust_opaque::{DartSafe, RustOpaque}; pub use flutter_rust_bridge_macros::frb; diff --git a/frb_rust/src/misc/mod.rs b/frb_rust/src/misc/mod.rs index 318c1489bf..20509951dc 100644 --- a/frb_rust/src/misc/mod.rs +++ b/frb_rust/src/misc/mod.rs @@ -3,5 +3,6 @@ pub(crate) mod into_into_dart; pub(crate) mod manual_impl; pub(crate) mod rust_arc; pub(crate) mod rust_auto_opaque; +pub(crate) mod user_utils; #[cfg(target_family = "wasm")] pub(crate) mod web_utils; diff --git a/frb_rust/src/misc/user_utils.rs b/frb_rust/src/misc/user_utils.rs new file mode 100644 index 0000000000..12b0143ab9 --- /dev/null +++ b/frb_rust/src/misc/user_utils.rs @@ -0,0 +1,12 @@ +pub fn setup_included_battery() { + setup_backtrace(); + setup_log_to_console(); +} + +fn setup_backtrace() { + TODO; +} + +fn setup_log_to_console() { + TODO; +} From ba5b1357bcab926b6800f441180dbbacf3334670 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Tue, 2 Jan 2024 09:18:11 +0800 Subject: [PATCH 02/20] chore: rename --- frb_rust/src/misc/user_utils.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/frb_rust/src/misc/user_utils.rs b/frb_rust/src/misc/user_utils.rs index 12b0143ab9..9100751bae 100644 --- a/frb_rust/src/misc/user_utils.rs +++ b/frb_rust/src/misc/user_utils.rs @@ -1,4 +1,6 @@ -pub fn setup_included_battery() { +/// Setup defaults that is usually useful for a new project. +/// Surely, you are free to customize anything. +pub fn setup_defaults() { setup_backtrace(); setup_log_to_console(); } From 6d700a328bbc82eb396fe60fa341ba8e50f5659b Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Tue, 2 Jan 2024 09:21:03 +0800 Subject: [PATCH 03/20] chore: more name --- frb_rust/src/lib.rs | 2 +- frb_rust/src/misc/user_utils.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/frb_rust/src/lib.rs b/frb_rust/src/lib.rs index af86041a2f..492418a3c8 100644 --- a/frb_rust/src/lib.rs +++ b/frb_rust/src/lib.rs @@ -26,7 +26,7 @@ pub use crate::handler::handler::Handler; pub use crate::handler::implementation::handler::DefaultHandler; pub use crate::misc::dart_dynamic::DartDynamic; pub use crate::misc::into_into_dart::IntoIntoDart; -pub use crate::misc::user_utils; +pub use crate::misc::user_utils::setup_default_utils; pub use crate::rust_async::{spawn, spawn_blocking_with, spawn_local, JoinHandle}; pub use crate::rust_opaque::{DartSafe, RustOpaque}; pub use flutter_rust_bridge_macros::frb; diff --git a/frb_rust/src/misc/user_utils.rs b/frb_rust/src/misc/user_utils.rs index 9100751bae..4f8b289b8f 100644 --- a/frb_rust/src/misc/user_utils.rs +++ b/frb_rust/src/misc/user_utils.rs @@ -1,6 +1,6 @@ /// Setup defaults that is usually useful for a new project. -/// Surely, you are free to customize anything. -pub fn setup_defaults() { +/// Surely, you are free to customize everything. +pub fn setup_default_utils() { setup_backtrace(); setup_log_to_console(); } From 9568e2b45280060e821be28fe8ad41f97867710f Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Tue, 2 Jan 2024 09:29:02 +0800 Subject: [PATCH 04/20] feat: impl --- frb_rust/Cargo.toml | 6 ++++++ frb_rust/src/misc/user_utils.rs | 26 ++++++++++++++++++++++---- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/frb_rust/Cargo.toml b/frb_rust/Cargo.toml index a59066f9de..bdf65455f6 100644 --- a/frb_rust/Cargo.toml +++ b/frb_rust/Cargo.toml @@ -49,6 +49,12 @@ web-sys = { version = "0.3.58", features = [ "BroadcastChannel", ] } +[target.'cfg(target_os = "android")'.dependencies] +android_logger = "0.13" + +[target.'cfg(target_os = "ios")'.dependencies] +oslog = "0.1.0" + [build-dependencies] cc = "1.0" build-target = "0.4.0" diff --git a/frb_rust/src/misc/user_utils.rs b/frb_rust/src/misc/user_utils.rs index 4f8b289b8f..af0e277c2c 100644 --- a/frb_rust/src/misc/user_utils.rs +++ b/frb_rust/src/misc/user_utils.rs @@ -1,14 +1,32 @@ +use std::env; +use std::env::VarError; + /// Setup defaults that is usually useful for a new project. /// Surely, you are free to customize everything. -pub fn setup_default_utils() { - setup_backtrace(); +pub fn setup_default_user_utils() { + // setup log before others, such that we can see logs in other setup functions setup_log_to_console(); + setup_backtrace(); } fn setup_backtrace() { - TODO; + if env::var("RUST_BACKTRACE").err() == Some(VarError::NotPresent) { + env::set_var("RUST_BACKTRACE", "1"); + } else { + debug!("Skip setup RUST_BACKTRACE because there is already environment variable"); + } } fn setup_log_to_console() { - TODO; + #[cfg(target_os = "android")] + let _ = android_logger::init_once( + android_logger::Config::default().with_max_level(LevelFilter::Trace), + ); + + #[cfg(target_os = "ios")] + let _ = oslog::OsLogger::new("frb_user") + .level_filter(LevelFilter::Trace) + .init(); + + // TODO add more platforms, e.g. web, ... } From bb511e6441f62285d4b113b45b25ab7b0a3d5166 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Tue, 2 Jan 2024 09:30:21 +0800 Subject: [PATCH 05/20] feat: call --- frb_example/dart_minimal/rust/src/api/minimal.rs | 6 ++++++ frb_example/pure_dart/rust/src/api/customization.rs | 5 +++++ frb_rust/src/lib.rs | 2 +- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/frb_example/dart_minimal/rust/src/api/minimal.rs b/frb_example/dart_minimal/rust/src/api/minimal.rs index c701fc5479..525e7e0774 100644 --- a/frb_example/dart_minimal/rust/src/api/minimal.rs +++ b/frb_example/dart_minimal/rust/src/api/minimal.rs @@ -1,5 +1,11 @@ +use flutter_rust_bridge::frb; pub use std::panic::{RefUnwindSafe, UnwindSafe}; +#[frb(init)] +pub fn init_app() { + flutter_rust_bridge::setup_default_user_utils(); +} + pub fn minimal_adder(a: i32, b: i32) -> i32 { a + b } diff --git a/frb_example/pure_dart/rust/src/api/customization.rs b/frb_example/pure_dart/rust/src/api/customization.rs index c931d14ff3..a69a5022a5 100644 --- a/frb_example/pure_dart/rust/src/api/customization.rs +++ b/frb_example/pure_dart/rust/src/api/customization.rs @@ -9,6 +9,11 @@ lazy_static! { static ref INIT_TWO_DONE: Mutex = Mutex::new(false); } +#[frb(init)] +pub fn init_app() { + flutter_rust_bridge::setup_default_user_utils(); +} + #[frb(init)] pub fn my_init_one() -> anyhow::Result<()> { *INIT_ONE_DONE.lock().unwrap() = true; diff --git a/frb_rust/src/lib.rs b/frb_rust/src/lib.rs index 492418a3c8..125844dcce 100644 --- a/frb_rust/src/lib.rs +++ b/frb_rust/src/lib.rs @@ -26,7 +26,7 @@ pub use crate::handler::handler::Handler; pub use crate::handler::implementation::handler::DefaultHandler; pub use crate::misc::dart_dynamic::DartDynamic; pub use crate::misc::into_into_dart::IntoIntoDart; -pub use crate::misc::user_utils::setup_default_utils; +pub use crate::misc::user_utils::setup_default_user_utils; pub use crate::rust_async::{spawn, spawn_blocking_with, spawn_local, JoinHandle}; pub use crate::rust_opaque::{DartSafe, RustOpaque}; pub use flutter_rust_bridge_macros::frb; From 581eacecb227e522a26c7cd3c40b93887c017765 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Tue, 2 Jan 2024 09:31:30 +0800 Subject: [PATCH 06/20] feat: template --- .../REPLACE_ME_RUST_CRATE_DIR/src/api/simple.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/frb_codegen/assets/integration_template/REPLACE_ME_RUST_CRATE_DIR/src/api/simple.rs b/frb_codegen/assets/integration_template/REPLACE_ME_RUST_CRATE_DIR/src/api/simple.rs index 83207b7cee..4360c82ae0 100644 --- a/frb_codegen/assets/integration_template/REPLACE_ME_RUST_CRATE_DIR/src/api/simple.rs +++ b/frb_codegen/assets/integration_template/REPLACE_ME_RUST_CRATE_DIR/src/api/simple.rs @@ -2,3 +2,9 @@ pub fn greet(name: String) -> String { format!("Hello, {name}!") } + +#[flutter_rust_bridge::frb(init)] +pub fn init_app() { + // Default utilities - feel free to customize + flutter_rust_bridge::setup_default_user_utils(); +} From 5309ecabc18b4f59ad86cd23a9e64f13ddc34d62 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Tue, 2 Jan 2024 09:32:48 +0800 Subject: [PATCH 07/20] chore: codegen --- Cargo.lock | 53 ++++++++++++++++++- .../flutter_via_create/rust/src/api/simple.rs | 6 +++ .../rust/src/api/simple.rs | 6 +++ 3 files changed, 64 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 12553c1968..3ab5fabdaa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -45,6 +45,24 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" +[[package]] +name = "android_log-sys" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ecc8056bf6ab9892dcd53216c83d1597487d7dacac16c8df6b877d127df9937" + +[[package]] +name = "android_logger" +version = "0.13.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c494134f746c14dc653a35a4ea5aca24ac368529da5370ecf41fe0341c35772f" +dependencies = [ + "android_log-sys", + "env_logger", + "log", + "once_cell", +] + [[package]] name = "android_system_properties" version = "0.1.5" @@ -393,6 +411,16 @@ dependencies = [ "cc", ] +[[package]] +name = "dashmap" +version = "4.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e77a43b28d0668df09411cb0bc9a8c2adc40f9a048afe863e05fd43251e8e39c" +dependencies = [ + "cfg-if", + "num_cpus", +] + [[package]] name = "dashmap" version = "5.5.3" @@ -472,6 +500,16 @@ dependencies = [ "syn 2.0.28", ] +[[package]] +name = "env_logger" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95b3f3e67048839cb0d0781f445682a35113da7121f7c949db0e2be96a4fbece" +dependencies = [ + "log", + "regex", +] + [[package]] name = "errno" version = "0.3.2" @@ -527,6 +565,7 @@ name = "flutter_rust_bridge" version = "2.0.0-dev.9" dependencies = [ "allo-isolate", + "android_logger", "anyhow", "backtrace", "build-target", @@ -544,6 +583,7 @@ dependencies = [ "lazy_static", "libc", "log", + "oslog", "parking_lot", "threadpool", "tokio", @@ -1045,6 +1085,17 @@ version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" +[[package]] +name = "oslog" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8343ce955f18e7e68c0207dd0ea776ec453035685395ababd2ea651c569728b3" +dependencies = [ + "cc", + "dashmap 4.0.2", + "log", +] + [[package]] name = "parking_lot" version = "0.12.1" @@ -1273,7 +1324,7 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0e56dd856803e253c8f298af3f4d7eb0ae5e23a737252cd90bb4f3b435033b2d" dependencies = [ - "dashmap", + "dashmap 5.5.3", "futures", "lazy_static", "log", diff --git a/frb_example/flutter_via_create/rust/src/api/simple.rs b/frb_example/flutter_via_create/rust/src/api/simple.rs index 83207b7cee..4360c82ae0 100644 --- a/frb_example/flutter_via_create/rust/src/api/simple.rs +++ b/frb_example/flutter_via_create/rust/src/api/simple.rs @@ -2,3 +2,9 @@ pub fn greet(name: String) -> String { format!("Hello, {name}!") } + +#[flutter_rust_bridge::frb(init)] +pub fn init_app() { + // Default utilities - feel free to customize + flutter_rust_bridge::setup_default_user_utils(); +} diff --git a/frb_example/flutter_via_integrate/rust/src/api/simple.rs b/frb_example/flutter_via_integrate/rust/src/api/simple.rs index 83207b7cee..4360c82ae0 100644 --- a/frb_example/flutter_via_integrate/rust/src/api/simple.rs +++ b/frb_example/flutter_via_integrate/rust/src/api/simple.rs @@ -2,3 +2,9 @@ pub fn greet(name: String) -> String { format!("Hello, {name}!") } + +#[flutter_rust_bridge::frb(init)] +pub fn init_app() { + // Default utilities - feel free to customize + flutter_rust_bridge::setup_default_user_utils(); +} From 4a255e487f293c2843130fd607b56de0041c1cee Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Tue, 2 Jan 2024 09:34:17 +0800 Subject: [PATCH 08/20] feat: cfg --- frb_rust/Cargo.toml | 3 ++- frb_rust/src/lib.rs | 1 + frb_rust/src/misc/mod.rs | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/frb_rust/Cargo.toml b/frb_rust/Cargo.toml index bdf65455f6..d67ba24907 100644 --- a/frb_rust/Cargo.toml +++ b/frb_rust/Cargo.toml @@ -64,8 +64,9 @@ wasm-bindgen-test = "0.3.32" cool_asserts = "2.0.3" [features] -default = ["chrono", "wasm-start", "rust-async"] +default = ["chrono", "wasm-start", "rust-async", "user-utils"] uuid = ["dep:uuid", "allo-isolate/uuid"] chrono = ["dep:chrono", "allo-isolate/chrono"] wasm-start = ["console_error_panic_hook"] rust-async = ["dep:tokio", "dep:futures"] +user-utils = ["dep:android_logger", "dep:oslog"] diff --git a/frb_rust/src/lib.rs b/frb_rust/src/lib.rs index 125844dcce..bab793ddca 100644 --- a/frb_rust/src/lib.rs +++ b/frb_rust/src/lib.rs @@ -26,6 +26,7 @@ pub use crate::handler::handler::Handler; pub use crate::handler::implementation::handler::DefaultHandler; pub use crate::misc::dart_dynamic::DartDynamic; pub use crate::misc::into_into_dart::IntoIntoDart; +#[cfg(feature = "user-utils")] pub use crate::misc::user_utils::setup_default_user_utils; pub use crate::rust_async::{spawn, spawn_blocking_with, spawn_local, JoinHandle}; pub use crate::rust_opaque::{DartSafe, RustOpaque}; diff --git a/frb_rust/src/misc/mod.rs b/frb_rust/src/misc/mod.rs index 20509951dc..df17134f49 100644 --- a/frb_rust/src/misc/mod.rs +++ b/frb_rust/src/misc/mod.rs @@ -3,6 +3,7 @@ pub(crate) mod into_into_dart; pub(crate) mod manual_impl; pub(crate) mod rust_arc; pub(crate) mod rust_auto_opaque; +#[cfg(feature = "user-utils")] pub(crate) mod user_utils; #[cfg(target_family = "wasm")] pub(crate) mod web_utils; From ad6cd8363b5d83941ebdeda9474c8276a08aff36 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Tue, 2 Jan 2024 09:35:13 +0800 Subject: [PATCH 09/20] fix: err --- frb_rust/Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frb_rust/Cargo.toml b/frb_rust/Cargo.toml index d67ba24907..bf022de907 100644 --- a/frb_rust/Cargo.toml +++ b/frb_rust/Cargo.toml @@ -50,10 +50,10 @@ web-sys = { version = "0.3.58", features = [ ] } [target.'cfg(target_os = "android")'.dependencies] -android_logger = "0.13" +android_logger = { version = "0.13" , optional = true} [target.'cfg(target_os = "ios")'.dependencies] -oslog = "0.1.0" +oslog = { version = "0.1.0" , optional = true} [build-dependencies] cc = "1.0" From dd048190c1c0981bc230c9c61196dcb0c3738fe2 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Tue, 2 Jan 2024 09:36:02 +0800 Subject: [PATCH 10/20] chore: lock --- frb_example/dart_minimal/rust/Cargo.lock | 89 +++++++++++++++++++ frb_example/deliberate_bad/rust/Cargo.lock | 89 +++++++++++++++++++ .../flutter_via_create/rust/Cargo.lock | 89 +++++++++++++++++++ .../flutter_via_integrate/rust/Cargo.lock | 89 +++++++++++++++++++ frb_example/gallery/rust/Cargo.lock | 51 +++++++++++ frb_example/pure_dart/rust/Cargo.lock | 89 +++++++++++++++++++ 6 files changed, 496 insertions(+) diff --git a/frb_example/dart_minimal/rust/Cargo.lock b/frb_example/dart_minimal/rust/Cargo.lock index 77804f13d3..19d7d913b9 100644 --- a/frb_example/dart_minimal/rust/Cargo.lock +++ b/frb_example/dart_minimal/rust/Cargo.lock @@ -17,6 +17,15 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "aho-corasick" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" +dependencies = [ + "memchr", +] + [[package]] name = "allo-isolate" version = "0.1.21" @@ -35,6 +44,24 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" +[[package]] +name = "android_log-sys" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ecc8056bf6ab9892dcd53216c83d1597487d7dacac16c8df6b877d127df9937" + +[[package]] +name = "android_logger" +version = "0.13.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c494134f746c14dc653a35a4ea5aca24ac368529da5370ecf41fe0341c35772f" +dependencies = [ + "android_log-sys", + "env_logger", + "log", + "once_cell", +] + [[package]] name = "android_system_properties" version = "0.1.5" @@ -164,6 +191,16 @@ dependencies = [ "cc", ] +[[package]] +name = "dashmap" +version = "4.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e77a43b28d0668df09411cb0bc9a8c2adc40f9a048afe863e05fd43251e8e39c" +dependencies = [ + "cfg-if", + "num_cpus", +] + [[package]] name = "delegate-attr" version = "0.3.0" @@ -175,11 +212,22 @@ dependencies = [ "syn", ] +[[package]] +name = "env_logger" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95b3f3e67048839cb0d0781f445682a35113da7121f7c949db0e2be96a4fbece" +dependencies = [ + "log", + "regex", +] + [[package]] name = "flutter_rust_bridge" version = "2.0.0-dev.9" dependencies = [ "allo-isolate", + "android_logger", "anyhow", "backtrace", "build-target", @@ -196,6 +244,7 @@ dependencies = [ "lazy_static", "libc", "log", + "oslog", "parking_lot", "threadpool", "tokio", @@ -427,6 +476,17 @@ version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" +[[package]] +name = "oslog" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8343ce955f18e7e68c0207dd0ea776ec453035685395ababd2ea651c569728b3" +dependencies = [ + "cc", + "dashmap", + "log", +] + [[package]] name = "parking_lot" version = "0.12.1" @@ -489,6 +549,35 @@ dependencies = [ "bitflags", ] +[[package]] +name = "regex" +version = "1.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" + [[package]] name = "rustc-demangle" version = "0.1.23" diff --git a/frb_example/deliberate_bad/rust/Cargo.lock b/frb_example/deliberate_bad/rust/Cargo.lock index 6e82258399..8297765e4d 100644 --- a/frb_example/deliberate_bad/rust/Cargo.lock +++ b/frb_example/deliberate_bad/rust/Cargo.lock @@ -17,6 +17,15 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "aho-corasick" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" +dependencies = [ + "memchr", +] + [[package]] name = "allo-isolate" version = "0.1.21" @@ -35,6 +44,24 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" +[[package]] +name = "android_log-sys" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ecc8056bf6ab9892dcd53216c83d1597487d7dacac16c8df6b877d127df9937" + +[[package]] +name = "android_logger" +version = "0.13.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c494134f746c14dc653a35a4ea5aca24ac368529da5370ecf41fe0341c35772f" +dependencies = [ + "android_log-sys", + "env_logger", + "log", + "once_cell", +] + [[package]] name = "android_system_properties" version = "0.1.5" @@ -164,6 +191,16 @@ dependencies = [ "cc", ] +[[package]] +name = "dashmap" +version = "4.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e77a43b28d0668df09411cb0bc9a8c2adc40f9a048afe863e05fd43251e8e39c" +dependencies = [ + "cfg-if", + "num_cpus", +] + [[package]] name = "delegate-attr" version = "0.3.0" @@ -175,11 +212,22 @@ dependencies = [ "syn", ] +[[package]] +name = "env_logger" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95b3f3e67048839cb0d0781f445682a35113da7121f7c949db0e2be96a4fbece" +dependencies = [ + "log", + "regex", +] + [[package]] name = "flutter_rust_bridge" version = "2.0.0-dev.9" dependencies = [ "allo-isolate", + "android_logger", "anyhow", "backtrace", "build-target", @@ -196,6 +244,7 @@ dependencies = [ "lazy_static", "libc", "log", + "oslog", "parking_lot", "threadpool", "tokio", @@ -427,6 +476,17 @@ version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" +[[package]] +name = "oslog" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8343ce955f18e7e68c0207dd0ea776ec453035685395ababd2ea651c569728b3" +dependencies = [ + "cc", + "dashmap", + "log", +] + [[package]] name = "parking_lot" version = "0.12.1" @@ -489,6 +549,35 @@ dependencies = [ "bitflags", ] +[[package]] +name = "regex" +version = "1.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" + [[package]] name = "rustc-demangle" version = "0.1.23" diff --git a/frb_example/flutter_via_create/rust/Cargo.lock b/frb_example/flutter_via_create/rust/Cargo.lock index 4db4904481..c9afa119eb 100644 --- a/frb_example/flutter_via_create/rust/Cargo.lock +++ b/frb_example/flutter_via_create/rust/Cargo.lock @@ -17,6 +17,15 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "aho-corasick" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" +dependencies = [ + "memchr", +] + [[package]] name = "allo-isolate" version = "0.1.21" @@ -35,6 +44,24 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" +[[package]] +name = "android_log-sys" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ecc8056bf6ab9892dcd53216c83d1597487d7dacac16c8df6b877d127df9937" + +[[package]] +name = "android_logger" +version = "0.13.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c494134f746c14dc653a35a4ea5aca24ac368529da5370ecf41fe0341c35772f" +dependencies = [ + "android_log-sys", + "env_logger", + "log", + "once_cell", +] + [[package]] name = "android_system_properties" version = "0.1.5" @@ -161,6 +188,16 @@ dependencies = [ "cc", ] +[[package]] +name = "dashmap" +version = "4.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e77a43b28d0668df09411cb0bc9a8c2adc40f9a048afe863e05fd43251e8e39c" +dependencies = [ + "cfg-if", + "num_cpus", +] + [[package]] name = "delegate-attr" version = "0.3.0" @@ -172,11 +209,22 @@ dependencies = [ "syn", ] +[[package]] +name = "env_logger" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95b3f3e67048839cb0d0781f445682a35113da7121f7c949db0e2be96a4fbece" +dependencies = [ + "log", + "regex", +] + [[package]] name = "flutter_rust_bridge" version = "2.0.0-dev.9" dependencies = [ "allo-isolate", + "android_logger", "anyhow", "backtrace", "build-target", @@ -193,6 +241,7 @@ dependencies = [ "lazy_static", "libc", "log", + "oslog", "parking_lot", "threadpool", "tokio", @@ -415,6 +464,17 @@ version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" +[[package]] +name = "oslog" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8343ce955f18e7e68c0207dd0ea776ec453035685395ababd2ea651c569728b3" +dependencies = [ + "cc", + "dashmap", + "log", +] + [[package]] name = "parking_lot" version = "0.12.1" @@ -477,6 +537,35 @@ dependencies = [ "bitflags", ] +[[package]] +name = "regex" +version = "1.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" + [[package]] name = "rust_lib" version = "0.1.0" diff --git a/frb_example/flutter_via_integrate/rust/Cargo.lock b/frb_example/flutter_via_integrate/rust/Cargo.lock index 4db4904481..c9afa119eb 100644 --- a/frb_example/flutter_via_integrate/rust/Cargo.lock +++ b/frb_example/flutter_via_integrate/rust/Cargo.lock @@ -17,6 +17,15 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "aho-corasick" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" +dependencies = [ + "memchr", +] + [[package]] name = "allo-isolate" version = "0.1.21" @@ -35,6 +44,24 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" +[[package]] +name = "android_log-sys" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ecc8056bf6ab9892dcd53216c83d1597487d7dacac16c8df6b877d127df9937" + +[[package]] +name = "android_logger" +version = "0.13.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c494134f746c14dc653a35a4ea5aca24ac368529da5370ecf41fe0341c35772f" +dependencies = [ + "android_log-sys", + "env_logger", + "log", + "once_cell", +] + [[package]] name = "android_system_properties" version = "0.1.5" @@ -161,6 +188,16 @@ dependencies = [ "cc", ] +[[package]] +name = "dashmap" +version = "4.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e77a43b28d0668df09411cb0bc9a8c2adc40f9a048afe863e05fd43251e8e39c" +dependencies = [ + "cfg-if", + "num_cpus", +] + [[package]] name = "delegate-attr" version = "0.3.0" @@ -172,11 +209,22 @@ dependencies = [ "syn", ] +[[package]] +name = "env_logger" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95b3f3e67048839cb0d0781f445682a35113da7121f7c949db0e2be96a4fbece" +dependencies = [ + "log", + "regex", +] + [[package]] name = "flutter_rust_bridge" version = "2.0.0-dev.9" dependencies = [ "allo-isolate", + "android_logger", "anyhow", "backtrace", "build-target", @@ -193,6 +241,7 @@ dependencies = [ "lazy_static", "libc", "log", + "oslog", "parking_lot", "threadpool", "tokio", @@ -415,6 +464,17 @@ version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" +[[package]] +name = "oslog" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8343ce955f18e7e68c0207dd0ea776ec453035685395ababd2ea651c569728b3" +dependencies = [ + "cc", + "dashmap", + "log", +] + [[package]] name = "parking_lot" version = "0.12.1" @@ -477,6 +537,35 @@ dependencies = [ "bitflags", ] +[[package]] +name = "regex" +version = "1.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" + [[package]] name = "rust_lib" version = "0.1.0" diff --git a/frb_example/gallery/rust/Cargo.lock b/frb_example/gallery/rust/Cargo.lock index 2079e3706f..41fe1eb520 100644 --- a/frb_example/gallery/rust/Cargo.lock +++ b/frb_example/gallery/rust/Cargo.lock @@ -63,6 +63,24 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" +[[package]] +name = "android_log-sys" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ecc8056bf6ab9892dcd53216c83d1597487d7dacac16c8df6b877d127df9937" + +[[package]] +name = "android_logger" +version = "0.13.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c494134f746c14dc653a35a4ea5aca24ac368529da5370ecf41fe0341c35772f" +dependencies = [ + "android_log-sys", + "env_logger", + "log", + "once_cell", +] + [[package]] name = "android_system_properties" version = "0.1.5" @@ -337,6 +355,16 @@ dependencies = [ "cc", ] +[[package]] +name = "dashmap" +version = "4.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e77a43b28d0668df09411cb0bc9a8c2adc40f9a048afe863e05fd43251e8e39c" +dependencies = [ + "cfg-if", + "num_cpus", +] + [[package]] name = "delegate-attr" version = "0.3.0" @@ -360,6 +388,16 @@ version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" +[[package]] +name = "env_logger" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95b3f3e67048839cb0d0781f445682a35113da7121f7c949db0e2be96a4fbece" +dependencies = [ + "log", + "regex", +] + [[package]] name = "equivalent" version = "1.0.1" @@ -427,6 +465,7 @@ name = "flutter_rust_bridge" version = "2.0.0-dev.9" dependencies = [ "allo-isolate", + "android_logger", "anyhow", "backtrace", "build-target", @@ -443,6 +482,7 @@ dependencies = [ "lazy_static", "libc", "log", + "oslog", "parking_lot", "threadpool", "tokio", @@ -900,6 +940,17 @@ version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" +[[package]] +name = "oslog" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8343ce955f18e7e68c0207dd0ea776ec453035685395ababd2ea651c569728b3" +dependencies = [ + "cc", + "dashmap", + "log", +] + [[package]] name = "parking_lot" version = "0.12.1" diff --git a/frb_example/pure_dart/rust/Cargo.lock b/frb_example/pure_dart/rust/Cargo.lock index ac47cc1f3e..062ef8d672 100644 --- a/frb_example/pure_dart/rust/Cargo.lock +++ b/frb_example/pure_dart/rust/Cargo.lock @@ -17,6 +17,15 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "aho-corasick" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" +dependencies = [ + "memchr", +] + [[package]] name = "allo-isolate" version = "0.1.21" @@ -36,6 +45,24 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" +[[package]] +name = "android_log-sys" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ecc8056bf6ab9892dcd53216c83d1597487d7dacac16c8df6b877d127df9937" + +[[package]] +name = "android_logger" +version = "0.13.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c494134f746c14dc653a35a4ea5aca24ac368529da5370ecf41fe0341c35772f" +dependencies = [ + "android_log-sys", + "env_logger", + "log", + "once_cell", +] + [[package]] name = "android_system_properties" version = "0.1.5" @@ -171,6 +198,16 @@ dependencies = [ "cc", ] +[[package]] +name = "dashmap" +version = "4.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e77a43b28d0668df09411cb0bc9a8c2adc40f9a048afe863e05fd43251e8e39c" +dependencies = [ + "cfg-if", + "num_cpus", +] + [[package]] name = "delegate-attr" version = "0.3.0" @@ -182,6 +219,16 @@ dependencies = [ "syn", ] +[[package]] +name = "env_logger" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95b3f3e67048839cb0d0781f445682a35113da7121f7c949db0e2be96a4fbece" +dependencies = [ + "log", + "regex", +] + [[package]] name = "errno" version = "0.3.8" @@ -203,6 +250,7 @@ name = "flutter_rust_bridge" version = "2.0.0-dev.9" dependencies = [ "allo-isolate", + "android_logger", "anyhow", "backtrace", "build-target", @@ -219,6 +267,7 @@ dependencies = [ "lazy_static", "libc", "log", + "oslog", "parking_lot", "threadpool", "tokio", @@ -479,6 +528,17 @@ version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" +[[package]] +name = "oslog" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8343ce955f18e7e68c0207dd0ea776ec453035685395ababd2ea651c569728b3" +dependencies = [ + "cc", + "dashmap", + "log", +] + [[package]] name = "parking_lot" version = "0.12.1" @@ -547,6 +607,35 @@ dependencies = [ "bitflags 1.3.2", ] +[[package]] +name = "regex" +version = "1.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" + [[package]] name = "rustc-demangle" version = "0.1.23" From b3b34c0cdb34ae42ec25bf6918f87d58788f2381 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Tue, 2 Jan 2024 09:36:07 +0800 Subject: [PATCH 11/20] fix: compile --- frb_rust/src/misc/user_utils.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frb_rust/src/misc/user_utils.rs b/frb_rust/src/misc/user_utils.rs index af0e277c2c..b77f873a11 100644 --- a/frb_rust/src/misc/user_utils.rs +++ b/frb_rust/src/misc/user_utils.rs @@ -13,7 +13,7 @@ fn setup_backtrace() { if env::var("RUST_BACKTRACE").err() == Some(VarError::NotPresent) { env::set_var("RUST_BACKTRACE", "1"); } else { - debug!("Skip setup RUST_BACKTRACE because there is already environment variable"); + log::debug!("Skip setup RUST_BACKTRACE because there is already environment variable"); } } From e07486abec759b5bea55674b01027b737603c219 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Tue, 2 Jan 2024 09:36:43 +0800 Subject: [PATCH 12/20] chore: template --- .../Cargo.lock.template | 89 +++++++++++++++++++ 1 file changed, 89 insertions(+) diff --git a/frb_codegen/assets/integration_template/REPLACE_ME_RUST_CRATE_DIR/Cargo.lock.template b/frb_codegen/assets/integration_template/REPLACE_ME_RUST_CRATE_DIR/Cargo.lock.template index 61bfcaa9cf..469aef4d99 100644 --- a/frb_codegen/assets/integration_template/REPLACE_ME_RUST_CRATE_DIR/Cargo.lock.template +++ b/frb_codegen/assets/integration_template/REPLACE_ME_RUST_CRATE_DIR/Cargo.lock.template @@ -17,6 +17,15 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "aho-corasick" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" +dependencies = [ + "memchr", +] + [[package]] name = "allo-isolate" version = "0.1.21" @@ -35,6 +44,24 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" +[[package]] +name = "android_log-sys" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ecc8056bf6ab9892dcd53216c83d1597487d7dacac16c8df6b877d127df9937" + +[[package]] +name = "android_logger" +version = "0.13.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c494134f746c14dc653a35a4ea5aca24ac368529da5370ecf41fe0341c35772f" +dependencies = [ + "android_log-sys", + "env_logger", + "log", + "once_cell", +] + [[package]] name = "android_system_properties" version = "0.1.5" @@ -161,6 +188,16 @@ dependencies = [ "cc", ] +[[package]] +name = "dashmap" +version = "4.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e77a43b28d0668df09411cb0bc9a8c2adc40f9a048afe863e05fd43251e8e39c" +dependencies = [ + "cfg-if", + "num_cpus", +] + [[package]] name = "delegate-attr" version = "0.3.0" @@ -172,11 +209,22 @@ dependencies = [ "syn", ] +[[package]] +name = "env_logger" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95b3f3e67048839cb0d0781f445682a35113da7121f7c949db0e2be96a4fbece" +dependencies = [ + "log", + "regex", +] + [[package]] name = "flutter_rust_bridge" version = "2.0.0-dev.9" dependencies = [ "allo-isolate", + "android_logger", "anyhow", "backtrace", "build-target", @@ -193,6 +241,7 @@ dependencies = [ "lazy_static", "libc", "log", + "oslog", "parking_lot", "threadpool", "tokio", @@ -415,6 +464,17 @@ version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" +[[package]] +name = "oslog" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8343ce955f18e7e68c0207dd0ea776ec453035685395ababd2ea651c569728b3" +dependencies = [ + "cc", + "dashmap", + "log", +] + [[package]] name = "parking_lot" version = "0.12.1" @@ -477,6 +537,35 @@ dependencies = [ "bitflags", ] +[[package]] +name = "regex" +version = "1.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" + [[package]] name = "REPLACE_ME_RUST_CRATE_NAME" version = "0.1.0" From a1aced24c7d4007fa9cdc67d0c9e4940aa2276c3 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Tue, 2 Jan 2024 09:40:15 +0800 Subject: [PATCH 13/20] chore: codegen --- .../src/frb_generated.io.rs | 11 +++++-- .../src/frb_generated.rs | 16 ++++++++++ .../src/frb_generated.web.rs | 5 ++++ .../lib/src/rust/frb_generated.dart | 30 +++++++++++++++++-- .../lib/src/rust/frb_generated.io.dart | 29 +++++++++++++----- .../lib/src/rust/frb_generated.web.dart | 4 +++ frb_example/dart_minimal/frb_generated.h | 3 ++ .../lib/src/rust/api/minimal.dart | 3 ++ .../lib/src/rust/frb_generated.dart | 28 ++++++++++++++++- .../lib/src/rust/frb_generated.io.dart | 14 +++++++++ .../lib/src/rust/frb_generated.web.dart | 4 +++ .../dart_minimal/rust/src/frb_generated.io.rs | 5 ++++ .../dart_minimal/rust/src/frb_generated.rs | 16 ++++++++++ .../rust/src/frb_generated.web.rs | 5 ++++ .../lib/src/rust/api/simple.dart | 3 ++ .../lib/src/rust/frb_generated.dart | 28 ++++++++++++++++- .../lib/src/rust/frb_generated.io.dart | 14 +++++++++ .../lib/src/rust/frb_generated.web.dart | 4 +++ .../rust/src/frb_generated.io.rs | 5 ++++ .../rust/src/frb_generated.rs | 16 ++++++++++ .../rust/src/frb_generated.web.rs | 5 ++++ .../lib/src/rust/api/simple.dart | 3 ++ .../lib/src/rust/frb_generated.dart | 28 ++++++++++++++++- .../lib/src/rust/frb_generated.io.dart | 14 +++++++++ .../lib/src/rust/frb_generated.web.dart | 4 +++ .../rust/src/frb_generated.io.rs | 5 ++++ .../rust/src/frb_generated.rs | 16 ++++++++++ .../rust/src/frb_generated.web.rs | 5 ++++ frb_example/pure_dart/frb_generated.h | 3 ++ .../lib/src/rust/api/customization.dart | 3 ++ .../pure_dart/lib/src/rust/frb_generated.dart | 25 ++++++++++++++++ .../lib/src/rust/frb_generated.io.dart | 14 +++++++++ .../lib/src/rust/frb_generated.web.dart | 4 +++ .../pure_dart/rust/src/frb_generated.io.rs | 5 ++++ .../pure_dart/rust/src/frb_generated.rs | 16 ++++++++++ .../pure_dart/rust/src/frb_generated.web.rs | 5 ++++ 36 files changed, 382 insertions(+), 16 deletions(-) diff --git a/frb_codegen/assets/integration_template/REPLACE_ME_RUST_CRATE_DIR/src/frb_generated.io.rs b/frb_codegen/assets/integration_template/REPLACE_ME_RUST_CRATE_DIR/src/frb_generated.io.rs index 2369ae88aa..1a78e0145e 100644 --- a/frb_codegen/assets/integration_template/REPLACE_ME_RUST_CRATE_DIR/src/frb_generated.io.rs +++ b/frb_codegen/assets/integration_template/REPLACE_ME_RUST_CRATE_DIR/src/frb_generated.io.rs @@ -35,7 +35,7 @@ impl NewWithNullPtr for *mut T { } #[no_mangle] -pub extern "C" fn frbgen_REPLACE_ME_DART_PACKAGE_NAME_dart_fn_deliver_output( +pub extern "C" fn frbgen_flutter_via_create_dart_fn_deliver_output( call_id: i32, ptr_: *mut u8, rust_vec_len_: i32, @@ -52,14 +52,19 @@ pub extern "C" fn frbgen_REPLACE_ME_DART_PACKAGE_NAME_dart_fn_deliver_output( } #[no_mangle] -pub extern "C" fn frbgen_REPLACE_ME_DART_PACKAGE_NAME_wire_greet( +pub extern "C" fn frbgen_flutter_via_create_wire_greet( name: *mut wire_cst_list_prim_u_8, ) -> flutter_rust_bridge::for_generated::WireSyncRust2DartDco { wire_greet_impl(name) } #[no_mangle] -pub extern "C" fn frbgen_REPLACE_ME_DART_PACKAGE_NAME_cst_new_list_prim_u_8( +pub extern "C" fn frbgen_flutter_via_create_wire_init_app(port_: i64) { + wire_init_app_impl(port_) +} + +#[no_mangle] +pub extern "C" fn frbgen_flutter_via_create_cst_new_list_prim_u_8( len: i32, ) -> *mut wire_cst_list_prim_u_8 { let ans = wire_cst_list_prim_u_8 { diff --git a/frb_codegen/assets/integration_template/REPLACE_ME_RUST_CRATE_DIR/src/frb_generated.rs b/frb_codegen/assets/integration_template/REPLACE_ME_RUST_CRATE_DIR/src/frb_generated.rs index 713e1682c2..b7c785431b 100644 --- a/frb_codegen/assets/integration_template/REPLACE_ME_RUST_CRATE_DIR/src/frb_generated.rs +++ b/frb_codegen/assets/integration_template/REPLACE_ME_RUST_CRATE_DIR/src/frb_generated.rs @@ -49,6 +49,22 @@ fn wire_greet_impl( }, ) } +fn wire_init_app_impl(port_: flutter_rust_bridge::for_generated::MessagePort) { + FLUTTER_RUST_BRIDGE_HANDLER.wrap_normal::( + flutter_rust_bridge::for_generated::TaskInfo { + debug_name: "init_app", + port: Some(port_), + mode: flutter_rust_bridge::for_generated::FfiCallMode::Normal, + }, + move || { + move |context| { + transform_result_dco( + (move || Result::<_, ()>::Ok(crate::api::simple::init_app()))(), + ) + } + }, + ) +} // Section: dart2rust diff --git a/frb_codegen/assets/integration_template/REPLACE_ME_RUST_CRATE_DIR/src/frb_generated.web.rs b/frb_codegen/assets/integration_template/REPLACE_ME_RUST_CRATE_DIR/src/frb_generated.web.rs index 29bbb477c1..3be2835aea 100644 --- a/frb_codegen/assets/integration_template/REPLACE_ME_RUST_CRATE_DIR/src/frb_generated.web.rs +++ b/frb_codegen/assets/integration_template/REPLACE_ME_RUST_CRATE_DIR/src/frb_generated.web.rs @@ -69,3 +69,8 @@ pub fn dart_fn_deliver_output( pub fn wire_greet(name: String) -> flutter_rust_bridge::for_generated::WireSyncRust2DartDco { wire_greet_impl(name) } + +#[wasm_bindgen] +pub fn wire_init_app(port_: flutter_rust_bridge::for_generated::MessagePort) { + wire_init_app_impl(port_) +} diff --git a/frb_codegen/assets/integration_template/lib/src/rust/frb_generated.dart b/frb_codegen/assets/integration_template/lib/src/rust/frb_generated.dart index 0ab63132bc..44febb52cf 100644 --- a/frb_codegen/assets/integration_template/lib/src/rust/frb_generated.dart +++ b/frb_codegen/assets/integration_template/lib/src/rust/frb_generated.dart @@ -44,7 +44,9 @@ class RustLib extends BaseEntrypoint { RustLibWire.fromExternalLibrary; @override - Future executeRustInitializers() async {} + Future executeRustInitializers() async { + await api.initApp(); + } @override ExternalLibraryLoaderConfig get defaultExternalLibraryLoaderConfig => @@ -52,7 +54,7 @@ class RustLib extends BaseEntrypoint { static const kDefaultExternalLibraryLoaderConfig = ExternalLibraryLoaderConfig( - stem: 'REPLACE_ME_RUST_CRATE_NAME', + stem: 'rust_lib', ioDirectory: 'rust/target/release/', webPrefix: 'pkg/', ); @@ -60,6 +62,8 @@ class RustLib extends BaseEntrypoint { abstract class RustLibApi extends BaseApi { String greet({required String name, dynamic hint}); + + Future initApp({dynamic hint}); } class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { @@ -93,6 +97,28 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { argNames: ["name"], ); + @override + Future initApp({dynamic hint}) { + return handler.executeNormal(NormalTask( + callFfi: (port_) { + return wire.wire_init_app(port_); + }, + codec: DcoCodec( + decodeSuccessData: dco_decode_unit, + decodeErrorData: null, + ), + constMeta: kInitAppConstMeta, + argValues: [], + apiImpl: this, + hint: hint, + )); + } + + TaskConstMeta get kInitAppConstMeta => const TaskConstMeta( + debugName: "init_app", + argNames: [], + ); + @protected String dco_decode_String(dynamic raw) { return raw as String; diff --git a/frb_codegen/assets/integration_template/lib/src/rust/frb_generated.io.dart b/frb_codegen/assets/integration_template/lib/src/rust/frb_generated.io.dart index ea766561d5..798f253a9c 100644 --- a/frb_codegen/assets/integration_template/lib/src/rust/frb_generated.io.dart +++ b/frb_codegen/assets/integration_template/lib/src/rust/frb_generated.io.dart @@ -127,10 +127,9 @@ class RustLibWire implements BaseWire { } late final _dart_fn_deliver_outputPtr = _lookup< - ffi.NativeFunction< - ffi.Void Function( - ffi.Int32, ffi.Pointer, ffi.Int32, ffi.Int32)>>( - 'frbgen_REPLACE_ME_DART_PACKAGE_NAME_dart_fn_deliver_output'); + ffi.NativeFunction< + ffi.Void Function(ffi.Int32, ffi.Pointer, ffi.Int32, + ffi.Int32)>>('frbgen_flutter_via_create_dart_fn_deliver_output'); late final _dart_fn_deliver_output = _dart_fn_deliver_outputPtr .asFunction, int, int)>(); @@ -146,10 +145,24 @@ class RustLibWire implements BaseWire { ffi.NativeFunction< WireSyncRust2DartDco Function( ffi.Pointer)>>( - 'frbgen_REPLACE_ME_DART_PACKAGE_NAME_wire_greet'); + 'frbgen_flutter_via_create_wire_greet'); late final _wire_greet = _wire_greetPtr.asFunction< WireSyncRust2DartDco Function(ffi.Pointer)>(); + void wire_init_app( + int port_, + ) { + return _wire_init_app( + port_, + ); + } + + late final _wire_init_appPtr = + _lookup>( + 'frbgen_flutter_via_create_wire_init_app'); + late final _wire_init_app = + _wire_init_appPtr.asFunction(); + ffi.Pointer cst_new_list_prim_u_8( int len, ) { @@ -159,9 +172,9 @@ class RustLibWire implements BaseWire { } late final _cst_new_list_prim_u_8Ptr = _lookup< - ffi.NativeFunction< - ffi.Pointer Function(ffi.Int32)>>( - 'frbgen_REPLACE_ME_DART_PACKAGE_NAME_cst_new_list_prim_u_8'); + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Int32)>>('frbgen_flutter_via_create_cst_new_list_prim_u_8'); late final _cst_new_list_prim_u_8 = _cst_new_list_prim_u_8Ptr .asFunction Function(int)>(); diff --git a/frb_codegen/assets/integration_template/lib/src/rust/frb_generated.web.dart b/frb_codegen/assets/integration_template/lib/src/rust/frb_generated.web.dart index 74c567f835..2ac373d2f3 100644 --- a/frb_codegen/assets/integration_template/lib/src/rust/frb_generated.web.dart +++ b/frb_codegen/assets/integration_template/lib/src/rust/frb_generated.web.dart @@ -94,6 +94,8 @@ class RustLibWire extends BaseWire { dynamic /* flutter_rust_bridge::for_generated::WireSyncRust2DartDco */ wire_greet(String name) => wasmModule.wire_greet(name); + + void wire_init_app(NativePortType port_) => wasmModule.wire_init_app(port_); } @JS('wasm_bindgen') @@ -113,4 +115,6 @@ class RustLibWasmModule implements WasmModule { external dynamic /* flutter_rust_bridge::for_generated::WireSyncRust2DartDco */ wire_greet(String name); + + external void wire_init_app(NativePortType port_); } diff --git a/frb_example/dart_minimal/frb_generated.h b/frb_example/dart_minimal/frb_generated.h index 8d31ab3013..629f100abe 100644 --- a/frb_example/dart_minimal/frb_generated.h +++ b/frb_example/dart_minimal/frb_generated.h @@ -15,11 +15,14 @@ void frbgen_frb_example_dart_minimal_dart_fn_deliver_output(int32_t call_id, int32_t rust_vec_len_, int32_t data_len_); +void frbgen_frb_example_dart_minimal_wire_init_app(int64_t port_); + void frbgen_frb_example_dart_minimal_wire_minimal_adder(int64_t port_, int32_t a, int32_t b); static int64_t dummy_method_to_enforce_bundling(void) { int64_t dummy_var = 0; dummy_var ^= ((int64_t) (void*) drop_dart_object); dummy_var ^= ((int64_t) (void*) frbgen_frb_example_dart_minimal_dart_fn_deliver_output); + dummy_var ^= ((int64_t) (void*) frbgen_frb_example_dart_minimal_wire_init_app); dummy_var ^= ((int64_t) (void*) frbgen_frb_example_dart_minimal_wire_minimal_adder); dummy_var ^= ((int64_t) (void*) get_dart_object); dummy_var ^= ((int64_t) (void*) new_dart_opaque); diff --git a/frb_example/dart_minimal/lib/src/rust/api/minimal.dart b/frb_example/dart_minimal/lib/src/rust/api/minimal.dart index 4173ffb73e..60d49864ba 100644 --- a/frb_example/dart_minimal/lib/src/rust/api/minimal.dart +++ b/frb_example/dart_minimal/lib/src/rust/api/minimal.dart @@ -6,5 +6,8 @@ import '../frb_generated.dart'; import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart'; +Future initApp({dynamic hint}) => + RustLib.instance.api.initApp(hint: hint); + Future minimalAdder({required int a, required int b, dynamic hint}) => RustLib.instance.api.minimalAdder(a: a, b: b, hint: hint); diff --git a/frb_example/dart_minimal/lib/src/rust/frb_generated.dart b/frb_example/dart_minimal/lib/src/rust/frb_generated.dart index bfc9934952..1ddf1a9bf2 100644 --- a/frb_example/dart_minimal/lib/src/rust/frb_generated.dart +++ b/frb_example/dart_minimal/lib/src/rust/frb_generated.dart @@ -44,7 +44,9 @@ class RustLib extends BaseEntrypoint { RustLibWire.fromExternalLibrary; @override - Future executeRustInitializers() async {} + Future executeRustInitializers() async { + await api.initApp(); + } @override ExternalLibraryLoaderConfig get defaultExternalLibraryLoaderConfig => @@ -59,6 +61,8 @@ class RustLib extends BaseEntrypoint { } abstract class RustLibApi extends BaseApi { + Future initApp({dynamic hint}); + Future minimalAdder({required int a, required int b, dynamic hint}); } @@ -70,6 +74,28 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { required super.portManager, }); + @override + Future initApp({dynamic hint}) { + return handler.executeNormal(NormalTask( + callFfi: (port_) { + return wire.wire_init_app(port_); + }, + codec: DcoCodec( + decodeSuccessData: dco_decode_unit, + decodeErrorData: null, + ), + constMeta: kInitAppConstMeta, + argValues: [], + apiImpl: this, + hint: hint, + )); + } + + TaskConstMeta get kInitAppConstMeta => const TaskConstMeta( + debugName: "init_app", + argNames: [], + ); + @override Future minimalAdder({required int a, required int b, dynamic hint}) { return handler.executeNormal(NormalTask( diff --git a/frb_example/dart_minimal/lib/src/rust/frb_generated.io.dart b/frb_example/dart_minimal/lib/src/rust/frb_generated.io.dart index 9e3586f3c1..e75a131181 100644 --- a/frb_example/dart_minimal/lib/src/rust/frb_generated.io.dart +++ b/frb_example/dart_minimal/lib/src/rust/frb_generated.io.dart @@ -98,6 +98,20 @@ class RustLibWire implements BaseWire { late final _dart_fn_deliver_output = _dart_fn_deliver_outputPtr .asFunction, int, int)>(); + void wire_init_app( + int port_, + ) { + return _wire_init_app( + port_, + ); + } + + late final _wire_init_appPtr = + _lookup>( + 'frbgen_frb_example_dart_minimal_wire_init_app'); + late final _wire_init_app = + _wire_init_appPtr.asFunction(); + void wire_minimal_adder( int port_, int a, diff --git a/frb_example/dart_minimal/lib/src/rust/frb_generated.web.dart b/frb_example/dart_minimal/lib/src/rust/frb_generated.web.dart index 64d1e26dcb..f8bcb6e0f2 100644 --- a/frb_example/dart_minimal/lib/src/rust/frb_generated.web.dart +++ b/frb_example/dart_minimal/lib/src/rust/frb_generated.web.dart @@ -58,6 +58,8 @@ class RustLibWire extends BaseWire { wasmModule.dart_fn_deliver_output( call_id, ptr_, rust_vec_len_, data_len_); + void wire_init_app(NativePortType port_) => wasmModule.wire_init_app(port_); + void wire_minimal_adder(NativePortType port_, int a, int b) => wasmModule.wire_minimal_adder(port_, a, b); } @@ -77,5 +79,7 @@ class RustLibWasmModule implements WasmModule { external void dart_fn_deliver_output(int call_id, PlatformGeneralizedUint8ListPtr ptr_, int rust_vec_len_, int data_len_); + external void wire_init_app(NativePortType port_); + external void wire_minimal_adder(NativePortType port_, int a, int b); } diff --git a/frb_example/dart_minimal/rust/src/frb_generated.io.rs b/frb_example/dart_minimal/rust/src/frb_generated.io.rs index 96c2e56322..ba8d7ba9d8 100644 --- a/frb_example/dart_minimal/rust/src/frb_generated.io.rs +++ b/frb_example/dart_minimal/rust/src/frb_generated.io.rs @@ -37,6 +37,11 @@ pub extern "C" fn frbgen_frb_example_dart_minimal_dart_fn_deliver_output( FLUTTER_RUST_BRIDGE_HANDLER.dart_fn_handle_output(call_id, message) } +#[no_mangle] +pub extern "C" fn frbgen_frb_example_dart_minimal_wire_init_app(port_: i64) { + wire_init_app_impl(port_) +} + #[no_mangle] pub extern "C" fn frbgen_frb_example_dart_minimal_wire_minimal_adder(port_: i64, a: i32, b: i32) { wire_minimal_adder_impl(port_, a, b) diff --git a/frb_example/dart_minimal/rust/src/frb_generated.rs b/frb_example/dart_minimal/rust/src/frb_generated.rs index 5631a02f39..b2e566cc8d 100644 --- a/frb_example/dart_minimal/rust/src/frb_generated.rs +++ b/frb_example/dart_minimal/rust/src/frb_generated.rs @@ -32,6 +32,22 @@ flutter_rust_bridge::frb_generated_default_handler!(); // Section: wire_funcs +fn wire_init_app_impl(port_: flutter_rust_bridge::for_generated::MessagePort) { + FLUTTER_RUST_BRIDGE_HANDLER.wrap_normal::( + flutter_rust_bridge::for_generated::TaskInfo { + debug_name: "init_app", + port: Some(port_), + mode: flutter_rust_bridge::for_generated::FfiCallMode::Normal, + }, + move || { + move |context| { + transform_result_dco((move || { + Result::<_, ()>::Ok(crate::api::minimal::init_app()) + })()) + } + }, + ) +} fn wire_minimal_adder_impl( port_: flutter_rust_bridge::for_generated::MessagePort, a: impl CstDecode + core::panic::UnwindSafe, diff --git a/frb_example/dart_minimal/rust/src/frb_generated.web.rs b/frb_example/dart_minimal/rust/src/frb_generated.web.rs index b7d4133934..7dd2ce209f 100644 --- a/frb_example/dart_minimal/rust/src/frb_generated.web.rs +++ b/frb_example/dart_minimal/rust/src/frb_generated.web.rs @@ -43,6 +43,11 @@ pub fn dart_fn_deliver_output( FLUTTER_RUST_BRIDGE_HANDLER.dart_fn_handle_output(call_id, message) } +#[wasm_bindgen] +pub fn wire_init_app(port_: flutter_rust_bridge::for_generated::MessagePort) { + wire_init_app_impl(port_) +} + #[wasm_bindgen] pub fn wire_minimal_adder(port_: flutter_rust_bridge::for_generated::MessagePort, a: i32, b: i32) { wire_minimal_adder_impl(port_, a, b) diff --git a/frb_example/flutter_via_create/lib/src/rust/api/simple.dart b/frb_example/flutter_via_create/lib/src/rust/api/simple.dart index af14b3581e..daf8a26922 100644 --- a/frb_example/flutter_via_create/lib/src/rust/api/simple.dart +++ b/frb_example/flutter_via_create/lib/src/rust/api/simple.dart @@ -8,3 +8,6 @@ import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart'; String greet({required String name, dynamic hint}) => RustLib.instance.api.greet(name: name, hint: hint); + +Future initApp({dynamic hint}) => + RustLib.instance.api.initApp(hint: hint); diff --git a/frb_example/flutter_via_create/lib/src/rust/frb_generated.dart b/frb_example/flutter_via_create/lib/src/rust/frb_generated.dart index 4355e4b87f..44febb52cf 100644 --- a/frb_example/flutter_via_create/lib/src/rust/frb_generated.dart +++ b/frb_example/flutter_via_create/lib/src/rust/frb_generated.dart @@ -44,7 +44,9 @@ class RustLib extends BaseEntrypoint { RustLibWire.fromExternalLibrary; @override - Future executeRustInitializers() async {} + Future executeRustInitializers() async { + await api.initApp(); + } @override ExternalLibraryLoaderConfig get defaultExternalLibraryLoaderConfig => @@ -60,6 +62,8 @@ class RustLib extends BaseEntrypoint { abstract class RustLibApi extends BaseApi { String greet({required String name, dynamic hint}); + + Future initApp({dynamic hint}); } class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { @@ -93,6 +97,28 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { argNames: ["name"], ); + @override + Future initApp({dynamic hint}) { + return handler.executeNormal(NormalTask( + callFfi: (port_) { + return wire.wire_init_app(port_); + }, + codec: DcoCodec( + decodeSuccessData: dco_decode_unit, + decodeErrorData: null, + ), + constMeta: kInitAppConstMeta, + argValues: [], + apiImpl: this, + hint: hint, + )); + } + + TaskConstMeta get kInitAppConstMeta => const TaskConstMeta( + debugName: "init_app", + argNames: [], + ); + @protected String dco_decode_String(dynamic raw) { return raw as String; diff --git a/frb_example/flutter_via_create/lib/src/rust/frb_generated.io.dart b/frb_example/flutter_via_create/lib/src/rust/frb_generated.io.dart index 587fbfb5e4..798f253a9c 100644 --- a/frb_example/flutter_via_create/lib/src/rust/frb_generated.io.dart +++ b/frb_example/flutter_via_create/lib/src/rust/frb_generated.io.dart @@ -149,6 +149,20 @@ class RustLibWire implements BaseWire { late final _wire_greet = _wire_greetPtr.asFunction< WireSyncRust2DartDco Function(ffi.Pointer)>(); + void wire_init_app( + int port_, + ) { + return _wire_init_app( + port_, + ); + } + + late final _wire_init_appPtr = + _lookup>( + 'frbgen_flutter_via_create_wire_init_app'); + late final _wire_init_app = + _wire_init_appPtr.asFunction(); + ffi.Pointer cst_new_list_prim_u_8( int len, ) { diff --git a/frb_example/flutter_via_create/lib/src/rust/frb_generated.web.dart b/frb_example/flutter_via_create/lib/src/rust/frb_generated.web.dart index 74c567f835..2ac373d2f3 100644 --- a/frb_example/flutter_via_create/lib/src/rust/frb_generated.web.dart +++ b/frb_example/flutter_via_create/lib/src/rust/frb_generated.web.dart @@ -94,6 +94,8 @@ class RustLibWire extends BaseWire { dynamic /* flutter_rust_bridge::for_generated::WireSyncRust2DartDco */ wire_greet(String name) => wasmModule.wire_greet(name); + + void wire_init_app(NativePortType port_) => wasmModule.wire_init_app(port_); } @JS('wasm_bindgen') @@ -113,4 +115,6 @@ class RustLibWasmModule implements WasmModule { external dynamic /* flutter_rust_bridge::for_generated::WireSyncRust2DartDco */ wire_greet(String name); + + external void wire_init_app(NativePortType port_); } diff --git a/frb_example/flutter_via_create/rust/src/frb_generated.io.rs b/frb_example/flutter_via_create/rust/src/frb_generated.io.rs index 9cbba52667..1a78e0145e 100644 --- a/frb_example/flutter_via_create/rust/src/frb_generated.io.rs +++ b/frb_example/flutter_via_create/rust/src/frb_generated.io.rs @@ -58,6 +58,11 @@ pub extern "C" fn frbgen_flutter_via_create_wire_greet( wire_greet_impl(name) } +#[no_mangle] +pub extern "C" fn frbgen_flutter_via_create_wire_init_app(port_: i64) { + wire_init_app_impl(port_) +} + #[no_mangle] pub extern "C" fn frbgen_flutter_via_create_cst_new_list_prim_u_8( len: i32, diff --git a/frb_example/flutter_via_create/rust/src/frb_generated.rs b/frb_example/flutter_via_create/rust/src/frb_generated.rs index 713e1682c2..b7c785431b 100644 --- a/frb_example/flutter_via_create/rust/src/frb_generated.rs +++ b/frb_example/flutter_via_create/rust/src/frb_generated.rs @@ -49,6 +49,22 @@ fn wire_greet_impl( }, ) } +fn wire_init_app_impl(port_: flutter_rust_bridge::for_generated::MessagePort) { + FLUTTER_RUST_BRIDGE_HANDLER.wrap_normal::( + flutter_rust_bridge::for_generated::TaskInfo { + debug_name: "init_app", + port: Some(port_), + mode: flutter_rust_bridge::for_generated::FfiCallMode::Normal, + }, + move || { + move |context| { + transform_result_dco( + (move || Result::<_, ()>::Ok(crate::api::simple::init_app()))(), + ) + } + }, + ) +} // Section: dart2rust diff --git a/frb_example/flutter_via_create/rust/src/frb_generated.web.rs b/frb_example/flutter_via_create/rust/src/frb_generated.web.rs index 29bbb477c1..3be2835aea 100644 --- a/frb_example/flutter_via_create/rust/src/frb_generated.web.rs +++ b/frb_example/flutter_via_create/rust/src/frb_generated.web.rs @@ -69,3 +69,8 @@ pub fn dart_fn_deliver_output( pub fn wire_greet(name: String) -> flutter_rust_bridge::for_generated::WireSyncRust2DartDco { wire_greet_impl(name) } + +#[wasm_bindgen] +pub fn wire_init_app(port_: flutter_rust_bridge::for_generated::MessagePort) { + wire_init_app_impl(port_) +} diff --git a/frb_example/flutter_via_integrate/lib/src/rust/api/simple.dart b/frb_example/flutter_via_integrate/lib/src/rust/api/simple.dart index af14b3581e..daf8a26922 100644 --- a/frb_example/flutter_via_integrate/lib/src/rust/api/simple.dart +++ b/frb_example/flutter_via_integrate/lib/src/rust/api/simple.dart @@ -8,3 +8,6 @@ import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart'; String greet({required String name, dynamic hint}) => RustLib.instance.api.greet(name: name, hint: hint); + +Future initApp({dynamic hint}) => + RustLib.instance.api.initApp(hint: hint); diff --git a/frb_example/flutter_via_integrate/lib/src/rust/frb_generated.dart b/frb_example/flutter_via_integrate/lib/src/rust/frb_generated.dart index 4355e4b87f..44febb52cf 100644 --- a/frb_example/flutter_via_integrate/lib/src/rust/frb_generated.dart +++ b/frb_example/flutter_via_integrate/lib/src/rust/frb_generated.dart @@ -44,7 +44,9 @@ class RustLib extends BaseEntrypoint { RustLibWire.fromExternalLibrary; @override - Future executeRustInitializers() async {} + Future executeRustInitializers() async { + await api.initApp(); + } @override ExternalLibraryLoaderConfig get defaultExternalLibraryLoaderConfig => @@ -60,6 +62,8 @@ class RustLib extends BaseEntrypoint { abstract class RustLibApi extends BaseApi { String greet({required String name, dynamic hint}); + + Future initApp({dynamic hint}); } class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { @@ -93,6 +97,28 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { argNames: ["name"], ); + @override + Future initApp({dynamic hint}) { + return handler.executeNormal(NormalTask( + callFfi: (port_) { + return wire.wire_init_app(port_); + }, + codec: DcoCodec( + decodeSuccessData: dco_decode_unit, + decodeErrorData: null, + ), + constMeta: kInitAppConstMeta, + argValues: [], + apiImpl: this, + hint: hint, + )); + } + + TaskConstMeta get kInitAppConstMeta => const TaskConstMeta( + debugName: "init_app", + argNames: [], + ); + @protected String dco_decode_String(dynamic raw) { return raw as String; diff --git a/frb_example/flutter_via_integrate/lib/src/rust/frb_generated.io.dart b/frb_example/flutter_via_integrate/lib/src/rust/frb_generated.io.dart index c1c85a3e4e..c4db1d39cb 100644 --- a/frb_example/flutter_via_integrate/lib/src/rust/frb_generated.io.dart +++ b/frb_example/flutter_via_integrate/lib/src/rust/frb_generated.io.dart @@ -150,6 +150,20 @@ class RustLibWire implements BaseWire { late final _wire_greet = _wire_greetPtr.asFunction< WireSyncRust2DartDco Function(ffi.Pointer)>(); + void wire_init_app( + int port_, + ) { + return _wire_init_app( + port_, + ); + } + + late final _wire_init_appPtr = + _lookup>( + 'frbgen_flutter_via_integrate_wire_init_app'); + late final _wire_init_app = + _wire_init_appPtr.asFunction(); + ffi.Pointer cst_new_list_prim_u_8( int len, ) { diff --git a/frb_example/flutter_via_integrate/lib/src/rust/frb_generated.web.dart b/frb_example/flutter_via_integrate/lib/src/rust/frb_generated.web.dart index 74c567f835..2ac373d2f3 100644 --- a/frb_example/flutter_via_integrate/lib/src/rust/frb_generated.web.dart +++ b/frb_example/flutter_via_integrate/lib/src/rust/frb_generated.web.dart @@ -94,6 +94,8 @@ class RustLibWire extends BaseWire { dynamic /* flutter_rust_bridge::for_generated::WireSyncRust2DartDco */ wire_greet(String name) => wasmModule.wire_greet(name); + + void wire_init_app(NativePortType port_) => wasmModule.wire_init_app(port_); } @JS('wasm_bindgen') @@ -113,4 +115,6 @@ class RustLibWasmModule implements WasmModule { external dynamic /* flutter_rust_bridge::for_generated::WireSyncRust2DartDco */ wire_greet(String name); + + external void wire_init_app(NativePortType port_); } diff --git a/frb_example/flutter_via_integrate/rust/src/frb_generated.io.rs b/frb_example/flutter_via_integrate/rust/src/frb_generated.io.rs index 6bfe7bebe9..fee423ac85 100644 --- a/frb_example/flutter_via_integrate/rust/src/frb_generated.io.rs +++ b/frb_example/flutter_via_integrate/rust/src/frb_generated.io.rs @@ -58,6 +58,11 @@ pub extern "C" fn frbgen_flutter_via_integrate_wire_greet( wire_greet_impl(name) } +#[no_mangle] +pub extern "C" fn frbgen_flutter_via_integrate_wire_init_app(port_: i64) { + wire_init_app_impl(port_) +} + #[no_mangle] pub extern "C" fn frbgen_flutter_via_integrate_cst_new_list_prim_u_8( len: i32, diff --git a/frb_example/flutter_via_integrate/rust/src/frb_generated.rs b/frb_example/flutter_via_integrate/rust/src/frb_generated.rs index 713e1682c2..b7c785431b 100644 --- a/frb_example/flutter_via_integrate/rust/src/frb_generated.rs +++ b/frb_example/flutter_via_integrate/rust/src/frb_generated.rs @@ -49,6 +49,22 @@ fn wire_greet_impl( }, ) } +fn wire_init_app_impl(port_: flutter_rust_bridge::for_generated::MessagePort) { + FLUTTER_RUST_BRIDGE_HANDLER.wrap_normal::( + flutter_rust_bridge::for_generated::TaskInfo { + debug_name: "init_app", + port: Some(port_), + mode: flutter_rust_bridge::for_generated::FfiCallMode::Normal, + }, + move || { + move |context| { + transform_result_dco( + (move || Result::<_, ()>::Ok(crate::api::simple::init_app()))(), + ) + } + }, + ) +} // Section: dart2rust diff --git a/frb_example/flutter_via_integrate/rust/src/frb_generated.web.rs b/frb_example/flutter_via_integrate/rust/src/frb_generated.web.rs index 29bbb477c1..3be2835aea 100644 --- a/frb_example/flutter_via_integrate/rust/src/frb_generated.web.rs +++ b/frb_example/flutter_via_integrate/rust/src/frb_generated.web.rs @@ -69,3 +69,8 @@ pub fn dart_fn_deliver_output( pub fn wire_greet(name: String) -> flutter_rust_bridge::for_generated::WireSyncRust2DartDco { wire_greet_impl(name) } + +#[wasm_bindgen] +pub fn wire_init_app(port_: flutter_rust_bridge::for_generated::MessagePort) { + wire_init_app_impl(port_) +} diff --git a/frb_example/pure_dart/frb_generated.h b/frb_example/pure_dart/frb_generated.h index a0204076bf..faa9e26812 100644 --- a/frb_example/pure_dart/frb_generated.h +++ b/frb_example/pure_dart/frb_generated.h @@ -4180,6 +4180,8 @@ void frbgen_frb_example_pure_dart_wire_function_with_comments_triple_slash_singl void frbgen_frb_example_pure_dart_wire_check_init_done(int64_t port_); +void frbgen_frb_example_pure_dart_wire_init_app(int64_t port_); + void frbgen_frb_example_pure_dart_wire_my_init_one(int64_t port_); void frbgen_frb_example_pure_dart_wire_my_init_two(int64_t port_); @@ -12137,6 +12139,7 @@ static int64_t dummy_method_to_enforce_bundling(void) { dummy_var ^= ((int64_t) (void*) frbgen_frb_example_pure_dart_wire_how_long_does_it_take_twin_normal); dummy_var ^= ((int64_t) (void*) frbgen_frb_example_pure_dart_wire_how_long_does_it_take_twin_rust_async); dummy_var ^= ((int64_t) (void*) frbgen_frb_example_pure_dart_wire_how_long_does_it_take_twin_sync); + dummy_var ^= ((int64_t) (void*) frbgen_frb_example_pure_dart_wire_init_app); dummy_var ^= ((int64_t) (void*) frbgen_frb_example_pure_dart_wire_is_app_embedded_twin_normal); dummy_var ^= ((int64_t) (void*) frbgen_frb_example_pure_dart_wire_is_app_embedded_twin_rust_async); dummy_var ^= ((int64_t) (void*) frbgen_frb_example_pure_dart_wire_is_app_embedded_twin_rust_async_sse); diff --git a/frb_example/pure_dart/lib/src/rust/api/customization.dart b/frb_example/pure_dart/lib/src/rust/api/customization.dart index 94e13307bb..758ed20055 100644 --- a/frb_example/pure_dart/lib/src/rust/api/customization.dart +++ b/frb_example/pure_dart/lib/src/rust/api/customization.dart @@ -6,6 +6,9 @@ import '../frb_generated.dart'; import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart'; +Future initApp({dynamic hint}) => + RustLib.instance.api.initApp(hint: hint); + Future myInitOne({dynamic hint}) => RustLib.instance.api.myInitOne(hint: hint); diff --git a/frb_example/pure_dart/lib/src/rust/frb_generated.dart b/frb_example/pure_dart/lib/src/rust/frb_generated.dart index 4f982cd2e5..678765b2cc 100644 --- a/frb_example/pure_dart/lib/src/rust/frb_generated.dart +++ b/frb_example/pure_dart/lib/src/rust/frb_generated.dart @@ -242,6 +242,7 @@ class RustLib extends BaseEntrypoint { @override Future executeRustInitializers() async { + await api.initApp(); await api.myInitOne(); await api.myInitTwo(); } @@ -352,6 +353,8 @@ abstract class RustLibApi extends BaseApi { Future checkInitDone({dynamic hint}); + Future initApp({dynamic hint}); + Future myInitOne({dynamic hint}); Future myInitTwo({dynamic hint}); @@ -5749,6 +5752,28 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { argNames: [], ); + @override + Future initApp({dynamic hint}) { + return handler.executeNormal(NormalTask( + callFfi: (port_) { + return wire.wire_init_app(port_); + }, + codec: DcoCodec( + decodeSuccessData: dco_decode_unit, + decodeErrorData: null, + ), + constMeta: kInitAppConstMeta, + argValues: [], + apiImpl: this, + hint: hint, + )); + } + + TaskConstMeta get kInitAppConstMeta => const TaskConstMeta( + debugName: "init_app", + argNames: [], + ); + @override Future myInitOne({dynamic hint}) { return handler.executeNormal(NormalTask( diff --git a/frb_example/pure_dart/lib/src/rust/frb_generated.io.dart b/frb_example/pure_dart/lib/src/rust/frb_generated.io.dart index 2b4cac5c7f..77187e1f47 100644 --- a/frb_example/pure_dart/lib/src/rust/frb_generated.io.dart +++ b/frb_example/pure_dart/lib/src/rust/frb_generated.io.dart @@ -26405,6 +26405,20 @@ class RustLibWire implements BaseWire { late final _wire_check_init_done = _wire_check_init_donePtr.asFunction(); + void wire_init_app( + int port_, + ) { + return _wire_init_app( + port_, + ); + } + + late final _wire_init_appPtr = + _lookup>( + 'frbgen_frb_example_pure_dart_wire_init_app'); + late final _wire_init_app = + _wire_init_appPtr.asFunction(); + void wire_my_init_one( int port_, ) { diff --git a/frb_example/pure_dart/lib/src/rust/frb_generated.web.dart b/frb_example/pure_dart/lib/src/rust/frb_generated.web.dart index 5e8b7d2dc2..2cd70dd5c0 100644 --- a/frb_example/pure_dart/lib/src/rust/frb_generated.web.dart +++ b/frb_example/pure_dart/lib/src/rust/frb_generated.web.dart @@ -21320,6 +21320,8 @@ class RustLibWire extends BaseWire { void wire_check_init_done(NativePortType port_) => wasmModule.wire_check_init_done(port_); + void wire_init_app(NativePortType port_) => wasmModule.wire_init_app(port_); + void wire_my_init_one(NativePortType port_) => wasmModule.wire_my_init_one(port_); @@ -30806,6 +30808,8 @@ class RustLibWasmModule implements WasmModule { external void wire_check_init_done(NativePortType port_); + external void wire_init_app(NativePortType port_); + external void wire_my_init_one(NativePortType port_); external void wire_my_init_two(NativePortType port_); diff --git a/frb_example/pure_dart/rust/src/frb_generated.io.rs b/frb_example/pure_dart/rust/src/frb_generated.io.rs index c19fd6642c..71bd88fe16 100644 --- a/frb_example/pure_dart/rust/src/frb_generated.io.rs +++ b/frb_example/pure_dart/rust/src/frb_generated.io.rs @@ -16288,6 +16288,11 @@ pub extern "C" fn frbgen_frb_example_pure_dart_wire_check_init_done(port_: i64) wire_check_init_done_impl(port_) } +#[no_mangle] +pub extern "C" fn frbgen_frb_example_pure_dart_wire_init_app(port_: i64) { + wire_init_app_impl(port_) +} + #[no_mangle] pub extern "C" fn frbgen_frb_example_pure_dart_wire_my_init_one(port_: i64) { wire_my_init_one_impl(port_) diff --git a/frb_example/pure_dart/rust/src/frb_generated.rs b/frb_example/pure_dart/rust/src/frb_generated.rs index 8e2d09d452..6ec033ca08 100644 --- a/frb_example/pure_dart/rust/src/frb_generated.rs +++ b/frb_example/pure_dart/rust/src/frb_generated.rs @@ -694,6 +694,22 @@ fn wire_check_init_done_impl(port_: flutter_rust_bridge::for_generated::MessageP }, ) } +fn wire_init_app_impl(port_: flutter_rust_bridge::for_generated::MessagePort) { + FLUTTER_RUST_BRIDGE_HANDLER.wrap_normal::( + flutter_rust_bridge::for_generated::TaskInfo { + debug_name: "init_app", + port: Some(port_), + mode: flutter_rust_bridge::for_generated::FfiCallMode::Normal, + }, + move || { + move |context| { + transform_result_dco((move || { + Result::<_, ()>::Ok(crate::api::customization::init_app()) + })()) + } + }, + ) +} fn wire_my_init_one_impl(port_: flutter_rust_bridge::for_generated::MessagePort) { FLUTTER_RUST_BRIDGE_HANDLER.wrap_normal::(flutter_rust_bridge::for_generated::TaskInfo{ debug_name: "my_init_one", port: Some(port_), mode: flutter_rust_bridge::for_generated::FfiCallMode::Normal }, move || { move |context| { transform_result_dco((move || { diff --git a/frb_example/pure_dart/rust/src/frb_generated.web.rs b/frb_example/pure_dart/rust/src/frb_generated.web.rs index ca376cc05d..720f47ced9 100644 --- a/frb_example/pure_dart/rust/src/frb_generated.web.rs +++ b/frb_example/pure_dart/rust/src/frb_generated.web.rs @@ -10491,6 +10491,11 @@ pub fn wire_check_init_done(port_: flutter_rust_bridge::for_generated::MessagePo wire_check_init_done_impl(port_) } +#[wasm_bindgen] +pub fn wire_init_app(port_: flutter_rust_bridge::for_generated::MessagePort) { + wire_init_app_impl(port_) +} + #[wasm_bindgen] pub fn wire_my_init_one(port_: flutter_rust_bridge::for_generated::MessagePort) { wire_my_init_one_impl(port_) From a6fbb89b7d198420f8b3b2686515c2ec250e19a9 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Tue, 2 Jan 2024 09:43:16 +0800 Subject: [PATCH 14/20] feat: do not gen api func for initializer --- .../library/codegen/generator/api_dart/spec_generator/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frb_codegen/src/library/codegen/generator/api_dart/spec_generator/mod.rs b/frb_codegen/src/library/codegen/generator/api_dart/spec_generator/mod.rs index 651a25ad85..271f6086d4 100644 --- a/frb_codegen/src/library/codegen/generator/api_dart/spec_generator/mod.rs +++ b/frb_codegen/src/library/codegen/generator/api_dart/spec_generator/mod.rs @@ -103,7 +103,7 @@ fn generate_item( .map(|funcs| { funcs .iter() - .filter(|f| f.owner == IrFuncOwnerInfo::Function) + .filter(|f| (f.owner == IrFuncOwnerInfo::Function) && !f.initializer) .map(|f| function::generate(f, context)) .collect::>>() }) From 2e6459bb7c76819c8be250067d0f09352ad97889 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Tue, 2 Jan 2024 09:44:10 +0800 Subject: [PATCH 15/20] chore: codegen --- frb_example/dart_minimal/lib/src/rust/api/minimal.dart | 3 --- .../flutter_via_create/lib/src/rust/api/simple.dart | 3 --- .../flutter_via_integrate/lib/src/rust/api/simple.dart | 3 --- .../pure_dart/lib/src/rust/api/customization.dart | 9 --------- 4 files changed, 18 deletions(-) diff --git a/frb_example/dart_minimal/lib/src/rust/api/minimal.dart b/frb_example/dart_minimal/lib/src/rust/api/minimal.dart index 60d49864ba..4173ffb73e 100644 --- a/frb_example/dart_minimal/lib/src/rust/api/minimal.dart +++ b/frb_example/dart_minimal/lib/src/rust/api/minimal.dart @@ -6,8 +6,5 @@ import '../frb_generated.dart'; import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart'; -Future initApp({dynamic hint}) => - RustLib.instance.api.initApp(hint: hint); - Future minimalAdder({required int a, required int b, dynamic hint}) => RustLib.instance.api.minimalAdder(a: a, b: b, hint: hint); diff --git a/frb_example/flutter_via_create/lib/src/rust/api/simple.dart b/frb_example/flutter_via_create/lib/src/rust/api/simple.dart index daf8a26922..af14b3581e 100644 --- a/frb_example/flutter_via_create/lib/src/rust/api/simple.dart +++ b/frb_example/flutter_via_create/lib/src/rust/api/simple.dart @@ -8,6 +8,3 @@ import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart'; String greet({required String name, dynamic hint}) => RustLib.instance.api.greet(name: name, hint: hint); - -Future initApp({dynamic hint}) => - RustLib.instance.api.initApp(hint: hint); diff --git a/frb_example/flutter_via_integrate/lib/src/rust/api/simple.dart b/frb_example/flutter_via_integrate/lib/src/rust/api/simple.dart index daf8a26922..af14b3581e 100644 --- a/frb_example/flutter_via_integrate/lib/src/rust/api/simple.dart +++ b/frb_example/flutter_via_integrate/lib/src/rust/api/simple.dart @@ -8,6 +8,3 @@ import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart'; String greet({required String name, dynamic hint}) => RustLib.instance.api.greet(name: name, hint: hint); - -Future initApp({dynamic hint}) => - RustLib.instance.api.initApp(hint: hint); diff --git a/frb_example/pure_dart/lib/src/rust/api/customization.dart b/frb_example/pure_dart/lib/src/rust/api/customization.dart index 758ed20055..9c48e4adc6 100644 --- a/frb_example/pure_dart/lib/src/rust/api/customization.dart +++ b/frb_example/pure_dart/lib/src/rust/api/customization.dart @@ -6,14 +6,5 @@ import '../frb_generated.dart'; import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart'; -Future initApp({dynamic hint}) => - RustLib.instance.api.initApp(hint: hint); - -Future myInitOne({dynamic hint}) => - RustLib.instance.api.myInitOne(hint: hint); - -Future myInitTwo({dynamic hint}) => - RustLib.instance.api.myInitTwo(hint: hint); - Future checkInitDone({dynamic hint}) => RustLib.instance.api.checkInitDone(hint: hint); From 0a164c55d64fc6a30345259f8b06c09cb6777674 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Tue, 2 Jan 2024 09:58:48 +0800 Subject: [PATCH 16/20] fix: err --- .../REPLACE_ME_RUST_CRATE_DIR/src/frb_generated.io.rs | 8 ++++---- .../lib/src/rust/frb_generated.io.dart | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/frb_codegen/assets/integration_template/REPLACE_ME_RUST_CRATE_DIR/src/frb_generated.io.rs b/frb_codegen/assets/integration_template/REPLACE_ME_RUST_CRATE_DIR/src/frb_generated.io.rs index 1a78e0145e..46d61a5b71 100644 --- a/frb_codegen/assets/integration_template/REPLACE_ME_RUST_CRATE_DIR/src/frb_generated.io.rs +++ b/frb_codegen/assets/integration_template/REPLACE_ME_RUST_CRATE_DIR/src/frb_generated.io.rs @@ -35,7 +35,7 @@ impl NewWithNullPtr for *mut T { } #[no_mangle] -pub extern "C" fn frbgen_flutter_via_create_dart_fn_deliver_output( +pub extern "C" fn frbgen_REPLACE_ME_DART_PACKAGE_NAME_dart_fn_deliver_output( call_id: i32, ptr_: *mut u8, rust_vec_len_: i32, @@ -52,19 +52,19 @@ pub extern "C" fn frbgen_flutter_via_create_dart_fn_deliver_output( } #[no_mangle] -pub extern "C" fn frbgen_flutter_via_create_wire_greet( +pub extern "C" fn frbgen_REPLACE_ME_DART_PACKAGE_NAME_wire_greet( name: *mut wire_cst_list_prim_u_8, ) -> flutter_rust_bridge::for_generated::WireSyncRust2DartDco { wire_greet_impl(name) } #[no_mangle] -pub extern "C" fn frbgen_flutter_via_create_wire_init_app(port_: i64) { +pub extern "C" fn frbgen_REPLACE_ME_DART_PACKAGE_NAME_wire_init_app(port_: i64) { wire_init_app_impl(port_) } #[no_mangle] -pub extern "C" fn frbgen_flutter_via_create_cst_new_list_prim_u_8( +pub extern "C" fn frbgen_REPLACE_ME_DART_PACKAGE_NAME_cst_new_list_prim_u_8( len: i32, ) -> *mut wire_cst_list_prim_u_8 { let ans = wire_cst_list_prim_u_8 { diff --git a/frb_codegen/assets/integration_template/lib/src/rust/frb_generated.io.dart b/frb_codegen/assets/integration_template/lib/src/rust/frb_generated.io.dart index 798f253a9c..ae768e541c 100644 --- a/frb_codegen/assets/integration_template/lib/src/rust/frb_generated.io.dart +++ b/frb_codegen/assets/integration_template/lib/src/rust/frb_generated.io.dart @@ -129,7 +129,7 @@ class RustLibWire implements BaseWire { late final _dart_fn_deliver_outputPtr = _lookup< ffi.NativeFunction< ffi.Void Function(ffi.Int32, ffi.Pointer, ffi.Int32, - ffi.Int32)>>('frbgen_flutter_via_create_dart_fn_deliver_output'); + ffi.Int32)>>('frbgen_REPLACE_ME_DART_PACKAGE_NAME_dart_fn_deliver_output'); late final _dart_fn_deliver_output = _dart_fn_deliver_outputPtr .asFunction, int, int)>(); @@ -145,7 +145,7 @@ class RustLibWire implements BaseWire { ffi.NativeFunction< WireSyncRust2DartDco Function( ffi.Pointer)>>( - 'frbgen_flutter_via_create_wire_greet'); + 'frbgen_REPLACE_ME_DART_PACKAGE_NAME_wire_greet'); late final _wire_greet = _wire_greetPtr.asFunction< WireSyncRust2DartDco Function(ffi.Pointer)>(); @@ -159,7 +159,7 @@ class RustLibWire implements BaseWire { late final _wire_init_appPtr = _lookup>( - 'frbgen_flutter_via_create_wire_init_app'); + 'frbgen_REPLACE_ME_DART_PACKAGE_NAME_wire_init_app'); late final _wire_init_app = _wire_init_appPtr.asFunction(); @@ -174,7 +174,7 @@ class RustLibWire implements BaseWire { late final _cst_new_list_prim_u_8Ptr = _lookup< ffi.NativeFunction< ffi.Pointer Function( - ffi.Int32)>>('frbgen_flutter_via_create_cst_new_list_prim_u_8'); + ffi.Int32)>>('frbgen_REPLACE_ME_DART_PACKAGE_NAME_cst_new_list_prim_u_8'); late final _cst_new_list_prim_u_8 = _cst_new_list_prim_u_8Ptr .asFunction Function(int)>(); From 11ce4e9f666d26d279fb0741461981239105e08c Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Tue, 2 Jan 2024 12:40:40 +0800 Subject: [PATCH 17/20] fix: err --- frb_rust/src/misc/user_utils.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frb_rust/src/misc/user_utils.rs b/frb_rust/src/misc/user_utils.rs index b77f873a11..9ac1d6cd39 100644 --- a/frb_rust/src/misc/user_utils.rs +++ b/frb_rust/src/misc/user_utils.rs @@ -20,12 +20,12 @@ fn setup_backtrace() { fn setup_log_to_console() { #[cfg(target_os = "android")] let _ = android_logger::init_once( - android_logger::Config::default().with_max_level(LevelFilter::Trace), + android_logger::Config::default().with_max_level(log::LevelFilter::Trace), ); #[cfg(target_os = "ios")] let _ = oslog::OsLogger::new("frb_user") - .level_filter(LevelFilter::Trace) + .level_filter(log::LevelFilter::Trace) .init(); // TODO add more platforms, e.g. web, ... From 2465eba9852ece6e398af910d39599df66d30e2c Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Tue, 2 Jan 2024 12:41:45 +0800 Subject: [PATCH 18/20] fix: test err --- frb_example/pure_dart/test/custom_handler_test.dart | 2 ++ frb_example/pure_dart/test/mockability_test.dart | 1 + 2 files changed, 3 insertions(+) diff --git a/frb_example/pure_dart/test/custom_handler_test.dart b/frb_example/pure_dart/test/custom_handler_test.dart index 1dc9c6742b..951f4694e2 100644 --- a/frb_example/pure_dart/test/custom_handler_test.dart +++ b/frb_example/pure_dart/test/custom_handler_test.dart @@ -9,11 +9,13 @@ Future main() async { test('can use custom handler', () async { expect(customHandler.logs, [ + 'executeNormal init_app', 'executeNormal my_init_one', 'executeNormal my_init_two', ]); expect(await simpleAdderTwinNormal(a: 1, b: 2), 3); expect(customHandler.logs, [ + 'executeNormal init_app', 'executeNormal my_init_one', 'executeNormal my_init_two', 'executeNormal simple_adder_twin_normal', diff --git a/frb_example/pure_dart/test/mockability_test.dart b/frb_example/pure_dart/test/mockability_test.dart index 323cf3fd46..4c10f4ef2d 100644 --- a/frb_example/pure_dart/test/mockability_test.dart +++ b/frb_example/pure_dart/test/mockability_test.dart @@ -8,6 +8,7 @@ class MockRustLibApi extends Mock implements RustLibApi {} Future main() async { final mockApi = MockRustLibApi(); + when(() => mockApi.initApp()).thenAnswer((_) async => null); when(() => mockApi.myInitOne()).thenAnswer((_) async => null); when(() => mockApi.myInitTwo()).thenAnswer((_) async => null); From b03da25e6e7e019f02aec060740b1eec819c6c80 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Tue, 2 Jan 2024 13:46:50 +0800 Subject: [PATCH 19/20] chore: more --- .../lib/src/makefile_dart/test.dart | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/tools/frb_internal/lib/src/makefile_dart/test.dart b/tools/frb_internal/lib/src/makefile_dart/test.dart index 63c1ae6893..cdb3d9530d 100644 --- a/tools/frb_internal/lib/src/makefile_dart/test.dart +++ b/tools/frb_internal/lib/src/makefile_dart/test.dart @@ -302,7 +302,8 @@ Future testDartNative(TestDartNativeConfig config) async { '${dartMode.name} $extraFlags test ${config.coverage ? ' --coverage="coverage"' : ""}', relativePwd: config.package, extraEnv: { - ...kEnvEnableRustBacktrace, + // Deliberately do not provide backtrace env to see whether the test_utils work + // ...kEnvEnableRustBacktrace, ...rustEnvMap, }, ); @@ -381,13 +382,17 @@ Future testDartWeb(TestDartConfig config) async { final package = config.package; if (package == 'frb_dart') { - await exec('dart test -p chrome', - relativePwd: package, extraEnv: kEnvEnableRustBacktrace); + await exec( + 'dart test -p chrome', + relativePwd: package, + // extraEnv: kEnvEnableRustBacktrace, + ); } else { await exec( - 'dart run flutter_rust_bridge_utils test-web --entrypoint ../$package/test/dart_web_test_entrypoint.dart', - relativePwd: 'frb_utils', - extraEnv: kEnvEnableRustBacktrace); + 'dart run flutter_rust_bridge_utils test-web --entrypoint ../$package/test/dart_web_test_entrypoint.dart', + relativePwd: 'frb_utils', + // extraEnv: kEnvEnableRustBacktrace, + ); } } From 83b26a4cee0f6cb524d19503acb4440257fb6c42 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Tue, 2 Jan 2024 14:03:01 +0800 Subject: [PATCH 20/20] feat: doc --- README.md | 1 + website/docs/guides/how-to/init.md | 24 +++++++++++++++++++++-- website/docs/guides/how-to/logging.md | 5 +++++ website/docs/guides/how-to/stack-trace.md | 5 +++-- website/docs/index.md | 1 + 5 files changed, 32 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 4c78851d2e..a4fee80ac9 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,7 @@ This package is [officially Flutter Favorite](https://docs.flutter.dev/packages- * **Rapid setup**: Only a one-liner command to integrate into your project. * **Write your code naturally**: Use your intuition and write the code you want. The bridge understands many advanced grammars (see below), allowing seamless calling Rust from Dart. * **Use libraries/tools in Flutter/Rust**: All existing libraries, Flutter debuggers, ... Nothing to stop you from using them. +* **Battery included**: Even small things like logging and enable backtraces are configured in the starter kit. ### 3. Powerfulness diff --git a/website/docs/guides/how-to/init.md b/website/docs/guides/how-to/init.md index 3c997f5505..e8e6bb5123 100644 --- a/website/docs/guides/how-to/init.md +++ b/website/docs/guides/how-to/init.md @@ -1,7 +1,27 @@ # Initialization -Suppose you want to initialize the Rust side during Flutter/Dart startup, -then just simply call arbitrary Rust function as you like. +## Use `#[frb(init)]` + +If you want to initialize the Rust side during Flutter/Dart startup, +just use `#[frb(init)]` annotation on functions. + +For example: + +```rust +#[frb(init)] +pub fn lets_init_app_here() { + // ... +} +``` + +Indeed, the `flutter_rust_bridge_codegen create` already creates an init function, `init_app`, for you. + +Remark: The function needs to be inside your Rust input folder, otherwise it is simply ignored. + +## Alternative approach + +Alternatively, if you do not want to use the annotation above, +just simply call arbitrary Rust function as you like. There is nothing special about initialization compared to normal execution. For example: diff --git a/website/docs/guides/how-to/logging.md b/website/docs/guides/how-to/logging.md index 679c1e32dc..9f3451f791 100644 --- a/website/docs/guides/how-to/logging.md +++ b/website/docs/guides/how-to/logging.md @@ -1,5 +1,10 @@ # Logging +:::tip +If using the template by `flutter_rust_bridge_codegen create/integrate`, the "print logs to console" is configured by default, +via the auto-generated call to `flutter_rust_bridge::setup_default_user_utils()`. +::: + Since I have seen some questions asking how logging can be implemented with a Flutter + Rust application, here are some examples. ## Example 1: Print logs to console diff --git a/website/docs/guides/how-to/stack-trace.md b/website/docs/guides/how-to/stack-trace.md index 4df7cf3e11..4989d1663f 100644 --- a/website/docs/guides/how-to/stack-trace.md +++ b/website/docs/guides/how-to/stack-trace.md @@ -1,7 +1,8 @@ # Stack Traces -:::info -This is a Rust langauge feature, and flutter_rust_bridge just keeps the default configuration by default. +:::tip +If using the template by `flutter_rust_bridge_codegen create/integrate`, this is already configured by default, +via the auto-generated call to `flutter_rust_bridge::setup_default_user_utils()`. ::: To pass Rust stack traces to flutter, you need to set `RUST_BACKTRACE` in the running application. For that simply add `env::set_var("RUST_BACKTRACE", "1");` before initialising the bridge. diff --git a/website/docs/index.md b/website/docs/index.md index 24acf46117..253f547d68 100644 --- a/website/docs/index.md +++ b/website/docs/index.md @@ -73,6 +73,7 @@ This package is [officially Flutter Favorite](https://docs.flutter.dev/packages- * **Rapid setup**: Only a one-liner command to integrate into your project. * **Write your code naturally**: Use your intuition and write the code you want. The bridge understands many advanced grammars (see below), allowing seamless calling Rust from Dart. * **Use libraries/tools in Flutter/Rust**: All existing libraries, Flutter debuggers, ... Nothing to stop you from using them. +* **Battery included**: Even small things like logging and enable backtraces are configured in the starter kit. ### 3. Powerfulness