diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f918f29571..8d16d608192 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,35 +1,7 @@ # Changelog -## 2.12.0 - * Please refer to https://fzyzcjy.github.io/flutter_rust_bridge/guides/miscellaneous/whats-new for what's changed in V2. -* Add `no_dart_fix`, `no_dart_format` and `no_write_lib` to `flutter_rust_bridge_codegen integrate` #2790 (thanks @xuxiaocheng0201) -* Check for target dependencies when auto upgrading in codegen #2805 (thanks @turtletongue) -* Update troubleshooting.md #2806 -* Run scheduled CIs only when the repo owner is correct #2817 (thanks @AlexV525) -* Use `fvm install` to prevent `flutter_rust_bridge_codegen generate` from hanging #2834 (thanks @ethicnology) -* Support having a different crate name than the Flutter plugin #2859 (thanks @NathanKolbas) -* Update GitHub CI workflow to use new iOS simulators #2866 (thanks @NathanKolbas) -* Add resolution in yaml struct and workspace root resolution logic #2872 (thanks @AadamZ5) -* Update actions versions of all workflows #2876 (thanks @h3x4d3c1m4l) -* Add support for optional publish tag in release workflow #2877 (thanks @h3x4d3c1m4l) -* Support multiple flutter_rust_bridge packages on web #2903 (thanks @dt-iohk) -* Add encoded types DCO support #2905 (thanks @SilverMira) -* Fix Windows 10 `flutter_rust_bridge_codegen build-web` failure #2906 (thanks @marcmcd) -* Use `Vec::with_capacity` instead of `vec![]` in SSE vector decode #2926 (thanks @Shadowcat650) -* Fix unhandled error in dart_fn_handle_output when sending message #2941 (thanks @khangah) -* Upgrade versions and CI #2951 #2934 #2810 #2918 #2932 #2811 -* Added suggestion to update cargo in troubleshooting.md #2955 (thanks @dgasparri) -* Regenerate tests #2973 #2982 (thanks @TrackerSB) -* Add DevContainer and Dockerfile #2981 -* Add Claude skills and enhance development guidance #2983 -* Add upgrade notice to V1 documentation pages #2984 -* Add web test support to skills and Dockerfile #2986 -* Update PR template and tips #2989 -* Revise troubleshooting steps for Cargokit and Flutter #2994 (thanks @liruohrh) -* Fix web build with latest wasm-bindgen/js-sys versions #3010 -* Create docker image for development #3025 -* Add configurable log levels to setup functions #3026 (thanks @futpib) +* Overhaul of the logging implementation, from an opinionated approach to a configurable one. Please consult the [documentation](https://fzyzcjy.github.io/flutter_rust_bridge/guides/logging) for more information. If you implemented logging yourself you might have to migrate your changes. ## 2.11.1 diff --git a/Cargo.lock b/Cargo.lock index c59070a2a17..4988442382b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -45,23 +45,6 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" -[[package]] -name = "android_log-sys" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84521a3cf562bc62942e294181d9eef17eb38ceb8c68677bc49f144e4c3d4f8d" - -[[package]] -name = "android_logger" -version = "0.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f39be698127218cca460cb624878c9aa4e2b47dba3b277963d2bf00bad263b" -dependencies = [ - "android_log-sys", - "env_filter", - "log", -] - [[package]] name = "android_system_properties" version = "0.1.5" @@ -533,16 +516,6 @@ dependencies = [ "syn 2.0.85", ] -[[package]] -name = "env_filter" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "186e05a59d4c50738528153b83b0b0194d3a29507dfec16eccd4b342903397d0" -dependencies = [ - "log", - "regex", -] - [[package]] name = "equivalent" version = "1.0.1" @@ -604,7 +577,6 @@ name = "flutter_rust_bridge" version = "2.12.0" dependencies = [ "allo-isolate", - "android_logger", "anyhow", "backtrace", "build-target", @@ -620,7 +592,6 @@ dependencies = [ "js-sys", "lazy_static", "log", - "oslog", "portable-atomic", "threadpool", "tokio", @@ -1035,9 +1006,9 @@ dependencies = [ [[package]] name = "log" -version = "0.4.19" +version = "0.4.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b06a4cde4c0f271a446782e3eff8de789548ce57dbc8eca9292c27f4a42004b4" +checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94" [[package]] name = "md-5" @@ -1140,17 +1111,6 @@ version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" -[[package]] -name = "oslog" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80d2043d1f61d77cb2f4b1f7b7b2295f40507f5f8e9d1c8bf10a1ca5f97a3969" -dependencies = [ - "cc", - "dashmap", - "log", -] - [[package]] name = "parking_lot" version = "0.12.1" diff --git a/Cargo.toml b/Cargo.toml index e9f6802518e..421af868234 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,6 +4,7 @@ exclude = [ # Exclude example packages to ensure the example mimics how a typical user will use it. # For example, the `target` directory is different with and without workspaces. "frb_example/dart_minimal/rust", + "frb_example/dart_logging/rust", "frb_example/deliberate_bad/rust", "frb_example/flutter_via_create/rust", "frb_example/flutter_via_integrate/rust", diff --git a/frb_codegen/assets/integration_template/shared/REPLACE_ME_RUST_CRATE_DIR/Cargo.lock.template b/frb_codegen/assets/integration_template/shared/REPLACE_ME_RUST_CRATE_DIR/Cargo.lock.template index 6b8092eecf3..bd7e3b903a7 100644 --- a/frb_codegen/assets/integration_template/shared/REPLACE_ME_RUST_CRATE_DIR/Cargo.lock.template +++ b/frb_codegen/assets/integration_template/shared/REPLACE_ME_RUST_CRATE_DIR/Cargo.lock.template @@ -468,30 +468,6 @@ version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" -[[package]] -name = "oslog" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80d2043d1f61d77cb2f4b1f7b7b2295f40507f5f8e9d1c8bf10a1ca5f97a3969" -dependencies = [ - "cc", - "dashmap", - "log", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2621685985a2ebf1c516881c026032ac7deafcda1a2c9b7850dc81e3dfcb64c1" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-link", -] - [[package]] name = "pin-project-lite" version = "0.2.13" @@ -566,6 +542,14 @@ 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" +dependencies = [ + "flutter_rust_bridge", + "log", +] + [[package]] name = "rustc-demangle" version = "0.1.23" @@ -716,10 +700,4 @@ checksum = "50c24a44ec86bb68fbecd1b3efed7e85ea5621b39b35ef2766b66cd984f8010f" dependencies = [ "js-sys", "wasm-bindgen", -] - -[[package]] -name = "windows-link" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" +] \ No newline at end of file diff --git a/frb_codegen/assets/integration_template/shared/REPLACE_ME_RUST_CRATE_DIR/Cargo.toml.template b/frb_codegen/assets/integration_template/shared/REPLACE_ME_RUST_CRATE_DIR/Cargo.toml.template index d40635ceced..775be4704cd 100644 --- a/frb_codegen/assets/integration_template/shared/REPLACE_ME_RUST_CRATE_DIR/Cargo.toml.template +++ b/frb_codegen/assets/integration_template/shared/REPLACE_ME_RUST_CRATE_DIR/Cargo.toml.template @@ -8,6 +8,8 @@ crate-type = ["cdylib", "staticlib"] [dependencies] flutter_rust_bridge = REPLACE_ME_RUST_FRB_DEPENDENCY +# Optional - can be removed if you do not want logging +log = "^0.4.20" [lints.rust] unexpected_cfgs = { level = "warn", check-cfg = ['cfg(frb_expand)'] } diff --git a/frb_codegen/assets/integration_template/shared/REPLACE_ME_RUST_CRATE_DIR/src/lib.rs b/frb_codegen/assets/integration_template/shared/REPLACE_ME_RUST_CRATE_DIR/src/lib.rs index cbb071f8bf2..598f05181c4 100644 --- a/frb_codegen/assets/integration_template/shared/REPLACE_ME_RUST_CRATE_DIR/src/lib.rs +++ b/frb_codegen/assets/integration_template/shared/REPLACE_ME_RUST_CRATE_DIR/src/lib.rs @@ -1,2 +1,6 @@ -pub mod api; +// AUTO INJECTED BY flutter_rust_bridge. +// The following lines may not be accurate; change them according to your needs. mod frb_generated; +// END of AUTO INJECTED code + +pub mod api; diff --git a/frb_codegen/src/binary/commands_parser.rs b/frb_codegen/src/binary/commands_parser.rs index 27d77980fb9..c646fc6346d 100644 --- a/frb_codegen/src/binary/commands_parser.rs +++ b/frb_codegen/src/binary/commands_parser.rs @@ -80,7 +80,6 @@ mod tests { use crate::binary::test_utils::set_cwd_test_fixture; use clap::Parser; use itertools::concat; - use lib_flutter_rust_bridge_codegen::utils::logs::configure_opinionated_test_logging; use lib_flutter_rust_bridge_codegen::{codegen, if_then_some}; use serial_test::serial; @@ -89,7 +88,6 @@ mod tests { #[serial] fn test_compute_codegen_config_mode_from_files_auto_flutter_rust_bridge_yaml( ) -> anyhow::Result<()> { - configure_opinionated_test_logging(); set_cwd_test_fixture("binary/commands_parser/flutter_rust_bridge_yaml")?; let config = run_command_line(vec!["", "generate"])?; @@ -102,7 +100,6 @@ mod tests { #[test] #[serial] fn test_compute_codegen_config_mode_from_files_auto_pubspec_yaml() -> anyhow::Result<()> { - configure_opinionated_test_logging(); set_cwd_test_fixture("binary/commands_parser/pubspec_yaml")?; let config = run_command_line(vec!["", "generate"])?; @@ -116,7 +113,6 @@ mod tests { #[serial] fn test_compute_codegen_config_mode_from_files_auto_pubspec_yaml_faulty() -> anyhow::Result<()> { - configure_opinionated_test_logging(); set_cwd_test_fixture("binary/commands_parser/faulty_pubspec_yaml")?; let result = run_command_line(vec!["", "generate"]); @@ -134,7 +130,6 @@ mod tests { #[test] #[serial] fn test_compute_codegen_config_mode_config_file() -> anyhow::Result<()> { - configure_opinionated_test_logging(); set_cwd_test_fixture("binary/commands_parser/config_file")?; let config = run_command_line(vec!["", "generate", "--config-file", "hello.yaml"])?; @@ -147,7 +142,6 @@ mod tests { #[test] #[serial] fn test_compute_codegen_config_mode_config_file_faulty_file() -> anyhow::Result<()> { - configure_opinionated_test_logging(); set_cwd_test_fixture("binary/commands_parser/flutter_rust_bridge_yaml")?; let result = run_command_line(vec![ "", @@ -168,7 +162,6 @@ mod tests { #[test] #[serial] fn test_compute_codegen_config_mode_from_naive_generate_command_args() { - configure_opinionated_test_logging(); set_cwd_test_fixture("binary/commands_parser").unwrap(); // use whatever folder without config file // bool flags @@ -196,7 +189,6 @@ mod tests { #[test] #[serial] fn test_compute_codegen_config_from_both_file_and_command_line() -> anyhow::Result<()> { - configure_opinionated_test_logging(); set_cwd_test_fixture("binary/commands_parser/flutter_rust_bridge_yaml")?; let config = run_command_line(vec!["", "generate", "--llvm-path", "/my/path"])?; diff --git a/frb_codegen/src/library/codegen/config/internal_config_parser/mod.rs b/frb_codegen/src/library/codegen/config/internal_config_parser/mod.rs index 2163dede21b..00384c8111d 100644 --- a/frb_codegen/src/library/codegen/config/internal_config_parser/mod.rs +++ b/frb_codegen/src/library/codegen/config/internal_config_parser/mod.rs @@ -206,7 +206,6 @@ mod tests { use crate::codegen::config::config::MetaConfig; use crate::codegen::config::internal_config::InternalConfig; use crate::codegen::Config; - use crate::utils::logs::configure_opinionated_test_logging; use crate::utils::test_utils::{ create_path_sanitizers, get_test_fixture_dir, json_golden_test, }; @@ -229,7 +228,6 @@ mod tests { } fn body(fixture_name: &str) -> anyhow::Result<()> { - configure_opinionated_test_logging(); let test_fixture_dir = get_test_fixture_dir(fixture_name); env::set_current_dir(&test_fixture_dir)?; info!("test_fixture_dir={test_fixture_dir:?}"); diff --git a/frb_codegen/src/library/codegen/generator/api_dart/mod.rs b/frb_codegen/src/library/codegen/generator/api_dart/mod.rs index 073617becdb..c9e7ec4e2a3 100644 --- a/frb_codegen/src/library/codegen/generator/api_dart/mod.rs +++ b/frb_codegen/src/library/codegen/generator/api_dart/mod.rs @@ -50,7 +50,6 @@ mod tests { use crate::codegen::generator::api_dart::generate; use crate::codegen::misc::GeneratorProgressBarPack; use crate::codegen::Config; - use crate::utils::logs::configure_opinionated_test_logging; use crate::utils::test_utils::{get_test_fixture_dir, text_golden_test}; use serial_test::serial; use std::collections::HashMap; @@ -82,7 +81,6 @@ mod tests { } fn body(fixture_name: &str, expect_outputs: HashMap<&str, &str>) -> anyhow::Result<()> { - configure_opinionated_test_logging(); let test_fixture_dir = get_test_fixture_dir(fixture_name); env::set_current_dir(&test_fixture_dir)?; diff --git a/frb_codegen/src/library/codegen/generator/api_dart/spec_generator/sanity_checker.rs b/frb_codegen/src/library/codegen/generator/api_dart/spec_generator/sanity_checker.rs index 93403939a37..88b2a188b0d 100644 --- a/frb_codegen/src/library/codegen/generator/api_dart/spec_generator/sanity_checker.rs +++ b/frb_codegen/src/library/codegen/generator/api_dart/spec_generator/sanity_checker.rs @@ -21,7 +21,7 @@ pub(crate) fn sanity_check_class_name_duplicates( ); if std::env::var(SKIP_ENV_VAR).is_ok() { - warn!("{}", message); + warn!("{message}",); } else { bail!( "{}Another way to debug is to temporarily set environment variable `{}=1` and check the generated code.", diff --git a/frb_codegen/src/library/codegen/parser/hir/tree/transformer/pub_use_transformer.rs b/frb_codegen/src/library/codegen/parser/hir/tree/transformer/pub_use_transformer.rs index f8fc0b5a1b1..485aebb507a 100644 --- a/frb_codegen/src/library/codegen/parser/hir/tree/transformer/pub_use_transformer.rs +++ b/frb_codegen/src/library/codegen/parser/hir/tree/transformer/pub_use_transformer.rs @@ -123,10 +123,7 @@ fn transform_module_by_pub_use_single( if let Some(src_mod) = module.get_module_nested(&pub_use_info.namespace.path()) { // Codecov seems to be buggy by saying this line is not covered (while lines above/below) are // frb-coverage:ignore-start - log::debug!( - "transform_module_by_pub_use_single pub_use_info={:?}", - pub_use_info - ); + log::debug!("transform_module_by_pub_use_single pub_use_info={pub_use_info:?}"); // frb-coverage:ignore-end if src_mod.meta.is_public() { diff --git a/frb_codegen/src/library/codegen/parser/mod.rs b/frb_codegen/src/library/codegen/parser/mod.rs index 225d0ca854c..76f166719df 100644 --- a/frb_codegen/src/library/codegen/parser/mod.rs +++ b/frb_codegen/src/library/codegen/parser/mod.rs @@ -71,7 +71,6 @@ mod tests { ParserMirInternalConfig, RustInputNamespacePack, }; use crate::codegen::parser::{parse_inner, MirPack}; - use crate::utils::logs::configure_opinionated_test_logging; use crate::utils::namespace::Namespace; use crate::utils::test_utils::{ create_path_sanitizers, get_test_fixture_dir, json_golden_test, @@ -157,7 +156,6 @@ mod tests { fixture_name: &str, rust_input_namespace_pack: Option RustInputNamespacePack>>, ) -> anyhow::Result<(MirPack, PathBuf)> { - configure_opinionated_test_logging(); let test_fixture_dir = get_test_fixture_dir(fixture_name); let rust_crate_dir = test_fixture_dir.clone(); info!("test_fixture_dir={test_fixture_dir:?}"); diff --git a/frb_codegen/src/library/codegen/polisher/add_mod_to_lib.rs b/frb_codegen/src/library/codegen/polisher/add_mod_to_lib.rs index bba3745c2df..dc6e8df98df 100644 --- a/frb_codegen/src/library/codegen/polisher/add_mod_to_lib.rs +++ b/frb_codegen/src/library/codegen/polisher/add_mod_to_lib.rs @@ -1,8 +1,8 @@ use anyhow::*; -use log::{info, warn}; +use log::{debug, info, warn}; use pathdiff::diff_paths; use std::fs; -use std::path::Path; +use std::path::{Component, Path}; // the function signature is not covered while the whole body is covered - looks like a bug in coverage tool // frb-coverage:ignore-start @@ -14,8 +14,7 @@ pub(super) fn try_add_mod_to_lib(rust_crate_dir: &Path, rust_output_path: &Path) warn!( "add_mod_to_lib fail, the generated code may or may not have problems. \ Please ensure you have add code like `mod the_generated_bridge_code;` to your `lib.rs`. \ - Details: {}", - e + Details: {e}" ); // frb-coverage:ignore-end } @@ -24,35 +23,604 @@ pub(super) fn try_add_mod_to_lib(rust_crate_dir: &Path, rust_output_path: &Path) fn auto_add_mod_to_lib_core(rust_crate_dir: &Path, rust_output_path: &Path) -> Result<()> { let path_src_folder = rust_crate_dir.join("src"); let rust_output_path_relative_to_src_folder = - diff_paths(rust_output_path, path_src_folder.clone()).with_context(|| { - // This will stop the whole generator and tell the users, so we do not care about testing it - // frb-coverage:ignore-start - format!( - "rust_output_path={rust_output_path:?} is unrelated to path_src_folder={path_src_folder:?}", - ) - // frb-coverage:ignore-end - })?; - - let mod_name = rust_output_path_relative_to_src_folder - .file_stem() - .context("No file_stem")? - .to_str() - .context("Not a UTF-8 path")? - .to_string() - .replace('/', "::"); - let expect_code = format!("mod {mod_name};"); + diff_paths(rust_output_path, path_src_folder.clone()).with_context(|| { + format!( + "rust_output_path={rust_output_path:?} is unrelated to path_src_folder={path_src_folder:?}", + ) + })?; let path_lib_rs = path_src_folder.join("lib.rs"); + let raw_content_lib_rs = fs::read_to_string(&path_lib_rs)?; + let lib_rs_content_normalized = raw_content_lib_rs.replace("\r\n", "\n"); - let raw_content_lib_rs = fs::read_to_string(path_lib_rs.clone())?; - if !raw_content_lib_rs.contains(&expect_code) { - info!("Inject `{}` into {:?}", &expect_code, &path_lib_rs); - - let comments = " /* AUTO INJECTED BY flutter_rust_bridge. This line may not be accurate, and you can change it according to your needs. */"; - let modified_content_lib_rs = format!("{expect_code}{comments}\n{raw_content_lib_rs}"); + let final_content = process_lib_rs_content( + &lib_rs_content_normalized, + &rust_output_path_relative_to_src_folder, + )?; - fs::write(&path_lib_rs, modified_content_lib_rs).unwrap(); + // --- Write back only if content actually changed from the original normalized state, ignoring white spaces --- + if final_content.replace("/n", "") != lib_rs_content_normalized.replace("/n", "") { + fs::write(&path_lib_rs, final_content.as_bytes()).unwrap(); // Write as bytes to preserve LF newlines + } else { + info!("No changes needed to lib.rs. Skipping write."); } Ok(()) } + +fn process_lib_rs_content(initial_content: &str, relative_path: &Path) -> Result { + const CODE_INJECT_BLOCK_MARKER_START: &str = "// AUTO INJECTED BY flutter_rust_bridge."; + const CODE_INJECT_BLOCK_MARKER_END: &str = "// END of AUTO INJECTED code"; + + let relative_path = &relative_path.with_extension(""); + + let (mod_name, path) = if relative_path + .parent() + // test is path is just "" + .is_some_and(|parents| parents.parent().is_some()) + { + // Path has a parent, meaning it's not just a filename + // mod_name: first component of the original relative_path (e.g., "bridge" from "bridge/gen/frb_generated.rs") + let mod_name_first_component = relative_path + .components() + .next() // Get the first component of the *original* relative_path + .and_then(|component| match component { + Component::Normal(s) => s.to_str(), + _ => { + unreachable!("The path should be relative!") + } + }) + .context("First component of path is not valid UTF-8 or could not be extracted")? + .to_string(); + + // path: the full parent path, without the filename, with "::" separators + let path_string_with_colons = relative_path + .to_str() + .context("the path is not valid UTF-8")? + .replace(std::path::MAIN_SEPARATOR, "::"); + + Ok((mod_name_first_component, Some(path_string_with_colons))) + } else { + // Path has no parent, meaning it's a filename only (e.g., "frb_generated.rs") + // mod_name: the file_stem (filename without extension) + Ok(( + relative_path + .to_str() + .context("File stem is not valid UTF-8")? + .to_string(), + None, + )) + }?; + + let code_to_inject = format!( + "// The following lines may not be accurate; change them according to your needs.\n\ + pub mod {mod_name};{}", + path.map_or_else( + || "".to_string(), + |path| { + format!( + "\n\ + use crate::{path};" + ) + } + ) + ); + + let code_to_inject_full_block = format!( + "{CODE_INJECT_BLOCK_MARKER_START}\n{code_to_inject}\n{CODE_INJECT_BLOCK_MARKER_END}\n\n" + ); + + // TODO remove this lines after a migration period + // remove FRB's per-v2.10.0 injectedd code + let legacy_frb_injected_code = format!("mod {}; /* AUTO INJECTED BY flutter_rust_bridge. This line may not be accurate, and you can change it according to your needs. */" + , relative_path.to_str().context("File stem is not valid UTF-8")?); + let mut in_injected_block = false; + let mut new_code_injected = false; + let mut pre_code_injection_text = String::new(); + let mut output = String::new(); + let mut last_line_was_empty = true; + + debug!("injecting code to lib.rs"); + for line in initial_content.lines() { + // trace!("line is: '{line}'"); + match line.trim() { + "" => { + // Only add empty line if the last line wasn't empty (collapse multiple empty lines) + if !last_line_was_empty { + output.push('\n'); // normalises \r\n to \n + last_line_was_empty = true; + } + } + // Keep config lines (e.g. `#![allow(clippy::new_without_default)]`) on top of the file + trimmed_line if trimmed_line.starts_with("#!") => { + pre_code_injection_text.push_str(trimmed_line); + pre_code_injection_text.push('\n'); + } + trimmed_line if trimmed_line == legacy_frb_injected_code => { + debug!("legacy code, removing"); + last_line_was_empty = false; + } + trimmed_line if trimmed_line == CODE_INJECT_BLOCK_MARKER_START => { + if !in_injected_block { + in_injected_block = true; + } + } + trimmed_line if trimmed_line == CODE_INJECT_BLOCK_MARKER_END => { + if in_injected_block { + if !new_code_injected { + // overwriter old injected code with new one + output.push_str(&_inject_code( + &pre_code_injection_text, + &code_to_inject_full_block, + )); + debug!("INJECT code"); + new_code_injected = true; + } + in_injected_block = false; + last_line_was_empty = true; + } else { + panic!("\nCould not generate code for lib.rs, as the content is wrong (missing injected code start marker '{CODE_INJECT_BLOCK_MARKER_START}'.\nThis is the content:\n'\n{initial_content}\n'"); + } + } + trimmed_line if !in_injected_block => { + // take line outside of injected code and trim it + output.push_str(&format!("{trimmed_line}\n")); + last_line_was_empty = false; + } + _ if in_injected_block => { + // drop the old injected line + } + _ => { + unreachable!() + } + } + // debug!("output is: '{output}'"); + } + if in_injected_block { + panic!("\nCould not generate code for lib.rs, as the content is wrong (missing injected code end marker '{CODE_INJECT_BLOCK_MARKER_END}'.\nThis is the content:\n'\n{initial_content}\n'"); + } + + if !new_code_injected { + output = format!( + "{}{output}", + _inject_code(&pre_code_injection_text, &code_to_inject_full_block) + ); + }; + // have only one neline in the very end + output = format!("{}\n", output.trim_end_matches('\n')); + Ok(output) +} + +fn _inject_code(pre_code_injection_text: &str, code_to_inject: &str) -> String { + format!( + "{pre_code_injection_text}{}{code_to_inject}", + if pre_code_injection_text.is_empty() { + "" + } else { + "\n" + } + ) +} + +#[cfg(test)] +mod tests { + use super::*; + + // Helper to get the expected new injected block for tests + fn get_expected_new_block_filename_only(mod_name: &Path) -> String { + format!( + "// AUTO INJECTED BY flutter_rust_bridge.\n\ + // The following lines may not be accurate; change them according to your needs.\n\ + pub mod {};\n\ + // END of AUTO INJECTED code\n", + mod_name.with_extension("").to_str().unwrap() + ) + } + fn get_expected_new_block_with_path(mod_name: &Path, path: &Path) -> String { + format!( + "// AUTO INJECTED BY flutter_rust_bridge.\n\ + // The following lines may not be accurate; change them according to your needs.\n\ + pub mod {};\n\ + use crate::{};\n\ + // END of AUTO INJECTED code\n", + mod_name.to_str().unwrap(), + path.to_str() + .unwrap() + .replace(std::path::MAIN_SEPARATOR, "::") + ) + } + + fn get_expected_full_file_filename_only(mod_name: &Path) -> String { + format!( + "{}\npub mod api;\n", + get_expected_new_block_filename_only(mod_name) + ) + } + fn get_expected_full_file_with_path(mod_name: &Path, path: &Path) -> String { + format!( + "{}\npub mod api;\n", + get_expected_new_block_with_path(mod_name, path) + ) + } + + // --- Test Cases --- + + #[test] + fn test_inject_into_empty_lib_rs() { + let initial_content = ""; + let path = Path::new("frb_generated.rs"); + let result_content = process_lib_rs_content(initial_content, path).unwrap(); + assert_eq!(result_content, get_expected_new_block_filename_only(path)); + } + + #[test] + fn test_inject_into_existing_lib_rs_without_newline_at_end() { + let initial_content = "pub mod api;"; // No trailing newline + let path = Path::new("frb_generated"); + let result_content = process_lib_rs_content(initial_content, path).unwrap(); + assert_eq!(result_content, get_expected_full_file_filename_only(path)); + } + + #[test] + fn test_inject_into_existing_lib_rs_with_path() { + let initial_content = "pub mod api;"; // No trailing newline + let path = Path::new("bridge/gen/frb_generated.rs"); + let result_content = process_lib_rs_content(initial_content, path).unwrap(); + assert_eq!( + result_content, + get_expected_full_file_with_path( + Path::new("bridge"), + path.with_extension("").as_path() + ) + ); + } + #[test] + fn test_inject_into_existing_lib_rs_with_one_path() { + let initial_content = "pub mod api;"; // No trailing newline + let path = Path::new("gen/frb_generated.rs"); + let result_content = process_lib_rs_content(initial_content, path).unwrap(); + assert_eq!( + result_content, + get_expected_full_file_with_path(Path::new("gen"), path.with_extension("").as_path()) + ); + } + + #[test] + fn test_inject_into_existing_lib_rs_with_newline_at_end() { + let initial_content = "pub mod api;\n"; // With trailing newline + let path = Path::new("frb_generated"); + let result_content = process_lib_rs_content(initial_content, path).unwrap(); + assert_eq!(result_content, get_expected_full_file_filename_only(path)); + } + #[test] + fn test_inject_into_existing_lib_rs_with_multiple_newlines_at_end() { + let initial_content = "pub mod api;\n\n\n"; // With trailing newline + let path = Path::new("frb_generated"); + let result_content = process_lib_rs_content(initial_content, path).unwrap(); + assert_eq!(result_content, get_expected_full_file_filename_only(path)); + } + #[test] + fn test_inject_into_existing_lib_rs_with_multiple_newlines() { + let initial_content = "\n\n\npub mod api;\n\n\n"; // With trailing newline + let path = Path::new("frb_generated"); + let result_content = process_lib_rs_content(initial_content, path).unwrap(); + assert_eq!(result_content, get_expected_full_file_filename_only(path)); + } + + #[test] + fn test_no_change_if_already_up_to_date_new_format() { + let path = Path::new("frb_generated"); + let initial_content = get_expected_full_file_filename_only(path); + let result_content = process_lib_rs_content(&initial_content, path).unwrap(); + assert_eq!(result_content, initial_content); // Should remain unchanged + } + + #[test] + fn test_leave_at_top() { + let path = Path::new("frb_generated"); + let result_content = + process_lib_rs_content(&get_expected_full_file_filename_only(path), path).unwrap(); + assert_eq!(result_content, get_expected_full_file_filename_only(path)); // Should remain unchanged + } + + #[test] + fn test_replace_old_format_with_new_format() { + let path = Path::new("frb_generated"); + let old_injected_line = format!( + "mod {}; /* AUTO INJECTED BY flutter_rust_bridge. This line may not be accurate, and you can change it according to your needs. */" + , path.to_str().unwrap() + ); + let initial_content = format!( + "pub mod api;\n{old_injected_line}\nother code;" // Old format embedded + ); + let result_content = process_lib_rs_content(&initial_content, path).unwrap(); + + let expected_code = format!( + "{}\npub mod api;\nother code;\n", // Old format removed, new prepended, remaining code at end + get_expected_new_block_filename_only(path) + ); + assert_eq!(result_content, expected_code); + } + + #[test] + fn test_replace_only_old_format_file() { + let path = Path::new("frb_generated"); + let old_injected_line = format!( + "mod {}; /* AUTO INJECTED BY flutter_rust_bridge. This line may not be accurate, and you can change it according to your needs. */" + , path.to_str().unwrap() + ); + let initial_content = format!("{old_injected_line}\n"); // File contains only the old format + let result_content = process_lib_rs_content(&initial_content, path).unwrap(); + + // Should be replaced by only the new block + assert_eq!(result_content, get_expected_new_block_filename_only(path)); // Should remain unchanged + } + + #[test] + fn test_idempotent_after_replacement() { + let path = Path::new("frb_generated"); + let old_injected_line = format!( + "mod {}; /* AUTO INJECTED BY flutter_rust_bridge. This line may not be accurate, and you can change it according to your needs. */" + , path.to_str().unwrap() + ); + let initial_content = format!("pub mod api;\n{old_injected_line}\n"); + + let content_after_first_run = process_lib_rs_content(&initial_content, path).unwrap(); // First run: replace old with new + let content_after_second_run = + process_lib_rs_content(&content_after_first_run, path).unwrap(); // Second run: should not change + + assert_eq!(content_after_first_run, content_after_second_run); + assert_eq!( + content_after_second_run, + get_expected_full_file_filename_only(path) + ); + } + + #[test] + fn test_multiple_old_formats() { + let path = Path::new("frb_generated"); + + let old_injected_line = format!( + "mod {}; /* AUTO INJECTED BY flutter_rust_bridge. This line may not be accurate, and you can change it according to your needs. */" + , path.to_str().unwrap() + ); + let initial_content = format!( + "{old_injected_line}\npub mod api;\n{old_injected_line}\n" // Multiple old formats + ); + let result_content = process_lib_rs_content(&initial_content, path).unwrap(); + assert_eq!(result_content, get_expected_full_file_filename_only(path)); + } + + #[test] + fn test_multpipe_code_markers() { + let path = Path::new("frb_generated"); + let path_str = path.to_str().unwrap(); + let initial_content = format!( + "// AUTO INJECTED BY flutter_rust_bridge.\n\ + The following lines may not be accurate; change them according to your needs.\n\ + mod {path_str};\n\ + // this export is needed for logging\n\ + use crate::{path_str}::StreamSink as __FrbStreamSinkForLogging;\n\ + // END of AUTO INJECTED code\n\ + pub mod api;\n + // AUTO INJECTED BY flutter_rust_bridge.\n\ + The following lines may not be accurate; change them according to your needs.\n\ + mod {path_str};\n\ + // this export is needed for logging\n\ + use crate::{path_str}::StreamSink as __FrbStreamSinkForLogging;\n\ + // END of AUTO INJECTED code\n" + ); + let result_content = process_lib_rs_content(&initial_content, path).unwrap(); + assert_eq!(result_content, get_expected_full_file_filename_only(path)); + } + + #[test] + #[should_panic( + expected = "\nCould not generate code for lib.rs, as the content is wrong (missing injected code end marker '// END of AUTO INJECTED code'.\nThis is the content:\n" + )] + fn test_incomplete_code_markers_only_start() { + let path = Path::new("frb_generated"); + let path_str = path.to_str().unwrap(); + let initial_content = format!( + "// AUTO INJECTED BY flutter_rust_bridge.\n\ + The following lines may not be accurate; change them according to your needs.\n\ + mod {path_str};\n\ + // this export is needed for logging\n\ + use crate::{path_str}::StreamSink as __FrbStreamSinkForLogging;\n\ + pub mod api;\n" + ); + let result_content = process_lib_rs_content(&initial_content, path).unwrap(); + assert_eq!(result_content, get_expected_full_file_filename_only(path)); + } + + #[test] + #[should_panic( + expected = "\nCould not generate code for lib.rs, as the content is wrong (missing injected code start marker '// AUTO INJECTED BY flutter_rust_bridge.'.\nThis is the content:\n" + )] + fn test_incomplete_code_markers_only_end() { + let path = Path::new("frb_generated"); + let path_str = path.to_str().unwrap(); + let initial_content = format!( + "mod {path_str};\n\ + // this export is needed for logging\n\ + use crate::{path_str}::StreamSink as __FrbStreamSinkForLogging;\n\ + // END of AUTO INJECTED code\n\ + pub mod api;\n" + ); + let _ = process_lib_rs_content(&initial_content, path).unwrap(); + } + + #[test] + #[should_panic( + expected = "\nCould not generate code for lib.rs, as the content is wrong (missing injected code end marker '// END of AUTO INJECTED code'.\nThis is the content:\n" + )] + fn test_multiple_start_code_markers_without_end() { + let path = Path::new("frb_generated"); + let path_str = path.to_str().unwrap(); + let initial_content = format!( + "// AUTO INJECTED BY flutter_rust_bridge.\n\ + The following lines may not be accurate; change them according to your needs.\n\ + mod {path_str};\n\ + // this export is needed for logging\n\ + use crate::{path_str}::StreamSink as __FrbStreamSinkForLogging;\n\ + pub mod api;\n + // AUTO INJECTED BY flutter_rust_bridge.\n\ + The following lines may not be accurate; change them according to your needs.\n\ + mod {path_str};\n\ + // this export is needed for logging\n\ + use crate::{path_str}::StreamSink as __FrbStreamSinkForLogging;\n" + ); + let result_content = process_lib_rs_content(&initial_content, path).unwrap(); + assert_eq!(result_content, get_expected_full_file_filename_only(path)); + } + #[test] + #[should_panic( + expected = "\nCould not generate code for lib.rs, as the content is wrong (missing injected code start marker '// AUTO INJECTED BY flutter_rust_bridge.'.\nThis is the content:\n" + )] + fn test_multiple_end_code_markers_without_start() { + let path = Path::new("frb_generated"); + let path_str = path.to_str().unwrap(); + let initial_content = format!( + "mod {path_str};\n\ + // this export is needed for logging\n\ + use crate::{path_str}::StreamSink as __FrbStreamSinkForLogging;\n\ + // END of AUTO INJECTED code\n\ + pub mod api;\n + mod {path_str};\n\ + // this export is needed for logging\n\ + use crate::{path_str}::StreamSink as __FrbStreamSinkForLogging;\n\ + // END of AUTO INJECTED code\n" + ); + let result_content = process_lib_rs_content(&initial_content, path).unwrap(); + assert_eq!(result_content, get_expected_full_file_filename_only(path)); + } + + #[test] + fn test_new_format_old_content() { + let path = Path::new("frb_generated"); + let path_str = path.to_str().unwrap(); + let initial_content = format!( + "// AUTO INJECTED BY flutter_rust_bridge.\n\ + The following lines may not be accurate; change them according to your needs.\n\ + mod {path_str};\n\ + // this export is needed for logging\n\ + use crate::{path_str}::StreamSink as __FrbStreamSinkForLogging;\n\ + // END of AUTO INJECTED code\n\ + pub mod api;\n" + ); + let result_content = process_lib_rs_content(&initial_content, path).unwrap(); + assert_eq!(result_content, get_expected_full_file_filename_only(path)); + } + + #[test] + fn test_replace_old_generated_content_with_new() { + let path = Path::new("frb_generated"); + let initial_content = "// AUTO INJECTED BY flutter_rust_bridge.\n\ + This are outdated lines, to be replaced!\n\ + And another old line.\n\ + If these are still inside, the test fails!\n\ + // END of AUTO INJECTED code\n\ + pub mod api;\n"; + let result_content = process_lib_rs_content(initial_content, path).unwrap(); + assert_eq!(result_content, get_expected_full_file_filename_only(path)); + } + + #[test] + fn test_mixed_formats_and_other_content_replace_at_place() { + let path = Path::new("frb_generated"); + let old_injected_line = format!( "mod {}; /* AUTO INJECTED BY flutter_rust_bridge. This line may not be accurate, and you can change it according to your needs. */" + , path.to_str().unwrap() + ); + let existing_new_block = get_expected_new_block_filename_only(path); + + let initial_content = format!( + "// Some header comments\n\ + {existing_new_block}\n\ + \n\ + pub mod feature_a;\n\ + {old_injected_line}\n\n\ + pub mod feature_b;\n\n\ + {old_injected_line}\n\ + // Some footer comments\n" + ); + let result_content = process_lib_rs_content(&initial_content, path).unwrap(); + + let expected_code = format!( + "// Some header comments\n\ + {existing_new_block}\n\ + pub mod feature_a;\n\n\ + pub mod feature_b;\n\n\ + // Some footer comments\n" + ); + assert_eq!(result_content, expected_code); + } + + #[test] + fn test_only_empty_lines_differ() { + let path = Path::new("frb_generated"); + let path_str = path.to_str().unwrap(); + let initial_content = format!( + "// AUTO INJECTED BY flutter_rust_bridge.\n\ + // The following lines may not be accurate; change them according to your needs.\n\ + pub mod {path_str};\n\ + // END of AUTO INJECTED code\n\ + \n\ + // AUTO-GENERATED FROM frb_example/pure_dart, DO NOT EDIT\n\ + pub mod api;\n\ + mod auxiliary;\n\ + mod deliberate_name_conflict;\n\ + pub fn function_at_lib_rs()\n\ + \n" + ); + let result_content = process_lib_rs_content(&initial_content, path).unwrap(); + + assert_eq!( + result_content.replace("\n", ""), + initial_content.replace("\n", "") + ); + } + #[test] + fn test_keep_directive_on_top() { + let path = Path::new("frb_generated"); + let initial_content = " + #![allow(clippy::new_without_default)] + pub mod app; + " + .to_string(); + let result_content = process_lib_rs_content(&initial_content, path).unwrap(); + let expected_code = "#![allow(clippy::new_without_default)]\n\ + \n\ + // AUTO INJECTED BY flutter_rust_bridge.\n\ + // The following lines may not be accurate; change them according to your needs.\n\ + pub mod frb_generated;\n\ + // END of AUTO INJECTED code\n\ + \n\ + pub mod app;\n"; + assert_eq!(result_content, expected_code); + } + #[test] + fn test_remove_top_newline() { + let path = Path::new("frb_generated"); + let initial_content = "\n\ + #![allow(clippy::new_without_default)]\n\ + \n\ + // AUTO INJECTED BY flutter_rust_bridge.\n\ + // The following lines may not be accurate; change them according to your needs.\n\ + pub mod frb_generated;\n\ + // this export is needed for logging\n\ + use crate::frb_generated::StreamSink as __FrbStreamSinkForLogging;\n\ + // END of AUTO INJECTED code\n\ + \n\ + pub mod app;\n"; + let result_content = process_lib_rs_content(initial_content, path).unwrap(); + let expected_code = "#![allow(clippy::new_without_default)]\n\ + \n\ + // AUTO INJECTED BY flutter_rust_bridge.\n\ + // The following lines may not be accurate; change them according to your needs.\n\ + pub mod frb_generated;\n\ + // END of AUTO INJECTED code\n\ + \n\ + pub mod app;\n"; + assert_eq!(result_content, expected_code); + } +} diff --git a/frb_codegen/src/library/commands/cbindgen.rs b/frb_codegen/src/library/commands/cbindgen.rs index b10146940b4..9af6093b813 100644 --- a/frb_codegen/src/library/commands/cbindgen.rs +++ b/frb_codegen/src/library/commands/cbindgen.rs @@ -43,7 +43,7 @@ fn cbindgen_to_file(args: CbindgenArgs, c_output_path: &Path) -> anyhow::Result< ), ..default_cbindgen_config }; - debug!("cbindgen config: {:#?}", config); + debug!("cbindgen config: {config:#?}"); cbindgen_raw(config, args.rust_crate_dir, c_output_path) } @@ -70,7 +70,7 @@ pub(crate) fn cbindgen_raw( c_output_path: &Path, ) -> anyhow::Result<()> { let parsed_crate_dir = parse_crate_dir(rust_crate_dir)?; - debug!("cbindgen parsed_crate_dir={}", parsed_crate_dir); + debug!("cbindgen parsed_crate_dir={parsed_crate_dir}"); #[allow(clippy::manual_inspect)] let bindings = cbindgen::generate_with_config(parsed_crate_dir, config).map_err(|e| { diff --git a/frb_codegen/src/library/commands/command_runner.rs b/frb_codegen/src/library/commands/command_runner.rs index 5892bb9754b..fb02509f7d4 100644 --- a/frb_codegen/src/library/commands/command_runner.rs +++ b/frb_codegen/src/library/commands/command_runner.rs @@ -191,8 +191,7 @@ pub(crate) fn execute_command<'a>( } debug!( - "execute command: bin={} args={:?} current_dir={:?} cmd={:?}", - bin, args_display, current_dir, cmd + "execute command: bin={bin} args={args_display:?} current_dir={current_dir:?} cmd={cmd:?}" ); let result = cmd @@ -210,7 +209,7 @@ pub(crate) fn execute_command<'a>( if stdout.contains("fatal error") { // We do not care about details of this message // frb-coverage:ignore-start - warn!("See keywords such as `error` in command output. Maybe there is a problem? command={:?} stdout={:?}", cmd, stdout); + warn!("See keywords such as `error` in command output. Maybe there is a problem? command={cmd:?} stdout={stdout:?}"); // frb-coverage:ignore-end } } else if options.log_when_error.unwrap_or(true) { diff --git a/frb_codegen/src/library/commands/ffigen.rs b/frb_codegen/src/library/commands/ffigen.rs index 8ac5be68111..66062929cc6 100644 --- a/frb_codegen/src/library/commands/ffigen.rs +++ b/frb_codegen/src/library/commands/ffigen.rs @@ -96,7 +96,7 @@ pub(crate) fn ffigen_raw(config: &FfigenCommandConfig, dart_root: &Path) -> anyh &String::from_utf8_lossy(&res.stdout), &String::from_utf8_lossy(&res.stderr), )? { - warn!("{}", warning); + warn!("{warning}"); } Ok(()) diff --git a/frb_codegen/src/library/utils/logs.rs b/frb_codegen/src/library/utils/logs.rs deleted file mode 100644 index 647052c60a7..00000000000 --- a/frb_codegen/src/library/utils/logs.rs +++ /dev/null @@ -1,140 +0,0 @@ -//! Utilities related to logging - -use crate::utils::console::MULTI_PROGRESS; -use fern::colors::{Color, ColoredLevelConfig}; -use log::LevelFilter; -use std::io::IsTerminal; - -/// Configure an opinionated way of logging. -/// -/// This is just one way of outputing logs, and users are free to use this function -/// or choose their own way of outputing logs. That's why this function is "opinionated". -/// -/// It will log to file and standard output. -/// All logs with level `debug`(with parameter `verbose`=true or system variable `RUST_LOG`="debug") or above -/// will be recorded in `./logs/.log`. -/// Logs with level `info` and above will be output to standard output, with colored tag. -/// -/// # Example -/// -/// ``` -/// use lib_flutter_rust_bridge_codegen::utils::logs::configure_opinionated_logging; -/// configure_opinionated_logging("./logs/", false).expect("failed to initialize log"); -/// ``` -pub fn configure_opinionated_logging(path: &str, verbose: bool) -> Result<(), fern::InitError> { - let level_filter = log_level_from_env_var().unwrap_or_else(|| verbose_to_level_filter(verbose)); - - if level_filter == LevelFilter::Debug { - std::fs::create_dir_all(path).unwrap(); - } - - let mut fern_logger = fern::Dispatch::new(); - fern_logger = log_format_simple(fern_logger); - fern_logger = match level_filter { - LevelFilter::Debug => fern_logger - .level(LevelFilter::Debug) - .chain(fern::DateBased::new(path, "%Y-%m-%d.log")) - .chain(std::io::stdout()), - LevelFilter::Info => fern_logger - .level(LevelFilter::Info) - .level_for("cbindgen", LevelFilter::Error) - .chain(std::io::stdout()), - _ => fern_logger.level(level_filter).chain(std::io::stdout()), - }; - - let (max_level, fern_logger) = fern_logger.into_log(); - let log_wrapper = indicatif_log_bridge::LogWrapper::new(MULTI_PROGRESS.clone(), fern_logger); - - // ref: fern.apply / LogWrapper.try_init - log::set_boxed_logger(Box::new(log_wrapper))?; - log::set_max_level(max_level); - - let prev = std::panic::take_hook(); - std::panic::set_hook(Box::new(move |info| { - log::error!("{}", info); - prev(info); - })); - - Ok(()) -} - -fn log_level_from_env_var() -> Option { - (std::env::var("RUST_LOG").ok()).map(|value| log_level_from_str(&value)) -} - -fn log_level_from_str(value: &str) -> LevelFilter { - match value { - "trace" => LevelFilter::Trace, - "debug" => LevelFilter::Debug, - "info" => LevelFilter::Info, - "warn" => LevelFilter::Warn, - "error" => LevelFilter::Error, - "off" => LevelFilter::Off, - // frb-coverage:ignore-start - _ => panic!("{}", "unknown RUST_LOG level: {value}"), - // frb-coverage:ignore-end - } -} - -fn verbose_to_level_filter(verbose: bool) -> LevelFilter { - if verbose { - LevelFilter::Debug - } else { - LevelFilter::Info - } -} - -fn log_format_simple(d: fern::Dispatch) -> fern::Dispatch { - let colored_output = ColoredLevelConfig::new() - .error(Color::Red) - .warn(Color::Yellow) - .info(Color::Green) - .debug(Color::Blue) - .trace(Color::BrightBlack); - - d.format(move |out, message, record| { - let time = chrono::Utc::now().format("%Y-%m-%dT%H:%M:%S%.3fZ"); - - let level = record.level(); - let level = if std::io::stdout().is_terminal() { - colored_output.color(level).to_string() - } else { - level.to_string() - }; - - out.finish(format_args!( - "[{} {} {}:{}] {}", - time, - level, - record.file().unwrap_or(""), - record.line().unwrap_or(0), - message - )) - }) -} - -/// Configure an opinionated way of logging, useful in tests. -pub fn configure_opinionated_test_logging() { - // https://github.com/daboross/fern/issues/54 - // This will fail if called twice; don't worry. - let _ = log_format_simple(fern::Dispatch::new()) - .level(log_level_from_env_var().unwrap_or(LevelFilter::Debug)) - .chain(fern::Output::call(|record| println!("{}", record.args()))) - .apply(); -} - -#[cfg(test)] -mod tests { - use crate::utils::logs::log_level_from_str; - use log::LevelFilter; - - #[test] - pub fn test_log_level_from_str() { - assert_eq!(log_level_from_str("trace"), LevelFilter::Trace); - assert_eq!(log_level_from_str("debug"), LevelFilter::Debug); - assert_eq!(log_level_from_str("info"), LevelFilter::Info); - assert_eq!(log_level_from_str("warn"), LevelFilter::Warn); - assert_eq!(log_level_from_str("error"), LevelFilter::Error); - assert_eq!(log_level_from_str("off"), LevelFilter::Off); - } -} diff --git a/frb_codegen/src/library/utils/mod.rs b/frb_codegen/src/library/utils/mod.rs index 0dcdc4ee130..837480a11ea 100644 --- a/frb_codegen/src/library/utils/mod.rs +++ b/frb_codegen/src/library/utils/mod.rs @@ -9,7 +9,6 @@ pub(crate) mod dart_keywords; pub(crate) mod dart_repository; mod enum_map; pub(crate) mod file_utils; -pub mod logs; pub(crate) mod namespace; pub(crate) mod path_utils; pub(crate) mod rust_project_utils; diff --git a/frb_codegen/src/main.rs b/frb_codegen/src/main.rs index 97765913ca9..eef57754b55 100644 --- a/frb_codegen/src/main.rs +++ b/frb_codegen/src/main.rs @@ -9,14 +9,12 @@ use crate::binary::commands::{Cli, Commands, CreateOrIntegrateCommandCommonArgs} use crate::binary::commands_parser::{compute_codegen_config, compute_codegen_meta_config}; use clap::Parser; use lib_flutter_rust_bridge_codegen::integration::{CreateConfig, IntegrateConfig}; -use lib_flutter_rust_bridge_codegen::utils::logs::configure_opinionated_logging; use lib_flutter_rust_bridge_codegen::*; use log::{debug, warn}; use std::path::Path; fn main() -> anyhow::Result<()> { let cli = Cli::parse(); - configure_opinionated_logging("./logs/", cli.verbose)?; main_given_cli(cli) } @@ -88,9 +86,6 @@ mod tests { // we do not care about coverage of test themselves // frb-coverage:ignore-start fn body_execute_generate(name: &str) -> anyhow::Result<()> { - // if want verbose log, enable it - // configure_opinionated_test_logging(); - if env::var("FRB_SKIP_GENERATE_FRB_EXAMPLE_TEST").unwrap_or_default() == "1" { return Ok(()); } diff --git a/frb_dart/lib/flutter_rust_bridge_for_generated_common.dart b/frb_dart/lib/flutter_rust_bridge_for_generated_common.dart index a335de74256..8f365e7c5c9 100644 --- a/frb_dart/lib/flutter_rust_bridge_for_generated_common.dart +++ b/frb_dart/lib/flutter_rust_bridge_for_generated_common.dart @@ -29,3 +29,4 @@ export 'src/misc/simple_disposable.dart'; export 'src/rust_arc/_common.dart'; export 'src/stream/stream_sink.dart'; export 'src/task.dart'; +export 'src/utils/frb_logger.dart'; diff --git a/frb_dart/lib/src/utils/frb_logger.dart b/frb_dart/lib/src/utils/frb_logger.dart new file mode 100644 index 00000000000..b1a071da2fe --- /dev/null +++ b/frb_dart/lib/src/utils/frb_logger.dart @@ -0,0 +1,307 @@ +// ignore_for_file: avoid_print + +import 'dart:io'; + +import 'package:logging/logging.dart'; + +/// FRB normalized LogLevels +/// Keeps the more fine granular log levels of the logging.dart package while overwriting +/// the unusual ones with the log level names from the rust log crate. +/// +/// This enum also handles the conversion between +/// its own levels and integer numbers to `logging.dart` package's `Level` enum. +enum LogLevel { + /// Maps to `Level.ALL` and integer levels >= 0. + all( + levelNumberThreshold: 0, + ), + + /// Maps to `Level.FINEST` and integer levels >= 300. + finest( + levelNumberThreshold: 300, + ), + + /// Maps to `Level.FINER` and integer levels >= 400. + finer( + levelNumberThreshold: 400, + ), + + /// Maps to `Level.FINE` and integer levels >= 500. This is typically used for Trace. + trace( + levelNumberThreshold: 500, + ), + + /// Maps to `Level.CONFIG` and integer levels >= 700. This is typically used for Debug. + debug( + levelNumberThreshold: 700, + ), + + /// Maps to `Level.INFO` and integer levels >= 800. + info( + levelNumberThreshold: 800, + ), + + /// Maps to `Level.WARNING` and integer levels >= 900. This is typically used for Warn. + warn( + levelNumberThreshold: 900, + ), + + /// Maps to `Level.SEVERE` and integer levels >= 1000. This is typically used for Error. + /// Maps to `Level.SHOUT` and integer levels >= 1200. This is typically used for Fatal/Shout. + error( + levelNumberThreshold: 1999, + ), + + /// Maps to `Level.OFF` and integer levels >= 2000. + off( + levelNumberThreshold: 2000, // Or any value that signifies 'Off' + ); + + /// threshold up to which number mapps to which level + final int levelNumberThreshold; + + const LogLevel({ + required this.levelNumberThreshold, + }); + + /// Converts an integer level number to a [LogLevel] enum. + /// The conversion is based on predefined thresholds and the enum's declaration order. + static LogLevel fromNumber(int levelNumber) { + // The first level whose threshold is greater or equal than the given levelNumber is the correct one. + // This assumes the enum values are declared in ascending order of their thresholds. + for (final level in LogLevel.values) { + if (levelNumber <= level.levelNumberThreshold) { + return level; + } + } + // If no specific level is matched (e.g., if levelNumber is very high but doesn't explicitly hit Off's threshold), + // default to Off. This can happen if the last regular level's threshold is passed. + return LogLevel.off; + } + + /// Maps a string log level name to a `logging.Level`. + /// This is used for parsing initial configuration from strings (e.g., environment variables). + static LogLevel fromString(String levelStr) { + switch (levelStr.toUpperCase()) { + case 'ALL': + return LogLevel.all; + case 'FINEST': + return LogLevel.finest; + case 'FINER': + return LogLevel.finer; + case 'TRACE': + return LogLevel.trace; + case 'DEBUG': + return LogLevel.debug; + case 'INFO': + return LogLevel.info; + case 'WARN': + return LogLevel.warn; + case 'ERROR': + return LogLevel.error; + case 'OFF': + return LogLevel.off; + default: + print( + 'Unknown LOG_LEVEL: "$levelStr". For potential values, refer to LogLevel enum definition.'); + exit(1); // Exit, as this is a critical configuration error + } + } + + /// converts a LogLevel to a logging package's level + Level toLoggingLevel() { + switch (this) { + case LogLevel.all: + return Level.ALL; + case LogLevel.finest: + return Level.FINEST; + case LogLevel.finer: + return Level.FINER; + case LogLevel.trace: + return Level.FINE; + case LogLevel.debug: + return Level.CONFIG; + case LogLevel.info: + return Level.INFO; + case LogLevel.warn: + return Level.WARNING; + case LogLevel.error: + return Level.SHOUT; + case LogLevel.off: + return Level.OFF; + } + } + + /// converts a LogLevel to a logging package's level + static LogLevel fromLoggingLevel(Level level) { + switch (level) { + case Level.ALL: + return LogLevel.all; + case Level.FINEST: + return LogLevel.finest; + case Level.FINER: + return LogLevel.finer; + case Level.FINE: + return LogLevel.trace; + case Level.CONFIG: + return LogLevel.debug; + case Level.INFO: + return LogLevel.info; + case Level.WARNING: + return LogLevel.warn; + case Level.SEVERE: + return LogLevel.error; + case Level.SHOUT: + return LogLevel.error; + case Level.OFF: + return LogLevel.off; + default: + throw Exception("Unknown Dart logging level: $level"); + } + } +} + +/// Call Log functions from the Dart side +/// to be instantiated with FRBLogger.initLogger() +/// NOT initAndGetSingleton directly! +class FRBDartLogger { + /// stream to receive log records from rust code + final Stream streamSink; + + /// default log function + final Function({required MirLogRecord record}) logFn; + + /// function to convert intermediate Log records to Dart LogRecords + final MirLogRecord Function(LogRecord record) fromDartLogRecord; + + // Private constructor to enforce singleton pattern and ensure initialization + const FRBDartLogger._({ + required this.streamSink, + required this.logFn, + required this.fromDartLogRecord, + }); + + // This static field is typed as FRBDartLogger because `frb_logger.dart` cannot + // know the concrete MirLogRecord type from the generated code (in 'frb_rust/misc/logging.rs') at compile time. + static FRBDartLogger? _singleton; + static late String _currentLoggerName; + + /// Initializes the logging system, including the Rust logger. + /// + /// This method is designed to be called **once** from the generated dart file. + /// It takes the concrete `MirLogRecord` type's parameters as `dynamic` arguments, + /// then creates and stores the strongly-typed singleton. + static FRBDartLogger initAndGetSingleton({ + required Stream streamSink, + required void Function({required dynamic record}) logFn, + required MirLogRecordType Function(LogRecord record) fromDartLogRecord, + String name = 'FRBLogger', + LogLevel maxLogLevel = LogLevel.info, + void Function({required dynamic record})? customLogFunction, + }) { + if (_singleton != null) { + throw Exception( + 'Called FRBLogger.initLogger() twice or after FRBLogger.getLogger()!'); + } + + // Assign the singleton directly using a private constructor. + // The type `dynamic` acts as a placeholder here, but the actual functions + // passed in `streamSink`, `logFn`, `fromDartLogRecord` will be correctly typed + // from the calling side (generated dart code). + _singleton = FRBDartLogger._( + streamSink: streamSink, + logFn: logFn, + fromDartLogRecord: fromDartLogRecord, + ); + + Logger(name); + _currentLoggerName = name; + + String? envLogLevel; + try { + envLogLevel = Platform.environment['LOG_LEVEL']; + } on UnsupportedError { + envLogLevel = null; + } + if (envLogLevel != null) { + print( + 'Taking log level from env: $envLogLevel instead of the one given by code: $maxLogLevel'); + maxLogLevel = LogLevel.fromString(envLogLevel); + } + Logger.root.level = maxLogLevel.toLoggingLevel(); + + final Function({required dynamic record}) usedlogFn = + customLogFunction ?? _singleton!.logFn; + + // logs from Rust + _singleton!.streamSink.listen((record) { + usedlogFn(record: record); + }); + + // logs from Dart + Logger.root.onRecord.listen((record) { + usedlogFn(record: _singleton!.fromDartLogRecord(record)); + }); + + return _singleton! as FRBDartLogger; + } + + /// Gets the initialized singleton logger. + /// It returns `FRBDartLogger` as `frb_logger.dart` doesn't know the concrete type. + static FRBDartLogger getLogger([String? name]) { + if (_singleton == null) { + throw Exception( + "This exception should not happen - please file a bug ticket!"); + } + var loggerName = name ?? _currentLoggerName; + Logger(loggerName); + _currentLoggerName = loggerName; + return _singleton!; + } + + // These logging methods use the MirLogRecord type from the instance they are called on. + /// finest level logging output + finest(String message) { + Logger(_currentLoggerName).log(LogLevel.finest.toLoggingLevel(), message); + } + + /// finer level logging output + finer(String message) { + Logger(_currentLoggerName).log(LogLevel.finer.toLoggingLevel(), message); + } + + /// trace level logging output + trace(String message) { + Logger(_currentLoggerName).log(LogLevel.trace.toLoggingLevel(), message); + } + + /// debug level logging output + debug(String message) { + Logger(_currentLoggerName).log(LogLevel.debug.toLoggingLevel(), message); + } + + /// info level logging output + info(String message) { + Logger(_currentLoggerName).log(LogLevel.info.toLoggingLevel(), message); + } + + /// warn level logging output + warn(String message) { + Logger(_currentLoggerName).log(LogLevel.warn.toLoggingLevel(), message); + } + + /// error level logging output + error(String message) { + Logger(_currentLoggerName).log(LogLevel.error.toLoggingLevel(), message); + } + + @override + int get hashCode => streamSink.hashCode; + + @override + bool operator ==(Object other) => + identical(this, other) || + other is FRBDartLogger && + runtimeType == other.runtimeType && + streamSink == other.streamSink; +} diff --git a/frb_dart/pubspec.yaml b/frb_dart/pubspec.yaml index fa0e433ca3f..750776adccc 100644 --- a/frb_dart/pubspec.yaml +++ b/frb_dart/pubspec.yaml @@ -11,6 +11,7 @@ dependencies: meta: ^1.3.0 path: ^1.8.1 web: '>=0.5.0 <2.0.0' + logging: ^1.3.0 dev_dependencies: # Temporarily remove before https://github.com/kevmoo/build_cli/issues/168 is fixed # build_cli: ^2.2.4 diff --git a/frb_example/dart_build_rs/pubspec.lock b/frb_example/dart_build_rs/pubspec.lock index 07da1e18d37..7a6101e94ce 100644 --- a/frb_example/dart_build_rs/pubspec.lock +++ b/frb_example/dart_build_rs/pubspec.lock @@ -359,6 +359,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.3.0" + macros: + dependency: transitive + description: + name: macros + sha256: "1d9e801cd66f7ea3663c45fc708450db1fa57f988142c64289142c9b7ee80656" + url: "https://pub.dev" + source: hosted + version: "0.1.3-main.0" matcher: dependency: transitive description: diff --git a/frb_example/dart_build_rs/rust/Cargo.lock b/frb_example/dart_build_rs/rust/Cargo.lock index 354ac880422..706f3f59fe5 100644 --- a/frb_example/dart_build_rs/rust/Cargo.lock +++ b/frb_example/dart_build_rs/rust/Cargo.lock @@ -43,23 +43,6 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" -[[package]] -name = "android_log-sys" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84521a3cf562bc62942e294181d9eef17eb38ceb8c68677bc49f144e4c3d4f8d" - -[[package]] -name = "android_logger" -version = "0.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f39be698127218cca460cb624878c9aa4e2b47dba3b277963d2bf00bad263b" -dependencies = [ - "android_log-sys", - "env_filter", - "log", -] - [[package]] name = "android_system_properties" version = "0.1.5" @@ -510,16 +493,6 @@ dependencies = [ "syn 2.0.87", ] -[[package]] -name = "env_filter" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "186e05a59d4c50738528153b83b0b0194d3a29507dfec16eccd4b342903397d0" -dependencies = [ - "log", - "regex", -] - [[package]] name = "equivalent" version = "1.0.1" @@ -570,11 +543,11 @@ name = "flutter_rust_bridge" version = "2.12.0" dependencies = [ "allo-isolate", - "android_logger", "anyhow", "build-target", "bytemuck", "byteorder", + "chrono", "console_error_panic_hook", "dart-sys", "delegate-attr", @@ -583,7 +556,6 @@ dependencies = [ "js-sys", "lazy_static", "log", - "oslog", "portable-atomic", "threadpool", "tokio", @@ -1097,17 +1069,6 @@ version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" -[[package]] -name = "oslog" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80d2043d1f61d77cb2f4b1f7b7b2295f40507f5f8e9d1c8bf10a1ca5f97a3969" -dependencies = [ - "cc", - "dashmap", - "log", -] - [[package]] name = "parking_lot" version = "0.12.1" diff --git a/frb_example/dart_build_rs/rust/build.rs b/frb_example/dart_build_rs/rust/build.rs index 150d5f3acf3..87352269c16 100644 --- a/frb_example/dart_build_rs/rust/build.rs +++ b/frb_example/dart_build_rs/rust/build.rs @@ -1,6 +1,5 @@ use lib_flutter_rust_bridge_codegen::codegen; use lib_flutter_rust_bridge_codegen::codegen::Config; -use lib_flutter_rust_bridge_codegen::utils::logs::configure_opinionated_logging; fn main() -> anyhow::Result<()> { // Uncomment the line below, if you only want to generate bindings on api directory change. @@ -11,10 +10,6 @@ fn main() -> anyhow::Result<()> { // // println!("cargo:rerun-if-changed=src/api"); - // If you want to see logs - // Alternatively, use `cargo build -vvv` (instead of `cargo build`) to see logs on screen - configure_opinionated_logging("./logs/", true)?; - // Execute code generator with auto-detected config codegen::generate( Config::from_config_file("../flutter_rust_bridge.yaml")?.unwrap(), diff --git a/frb_example/dart_build_rs/rust/src/lib.rs b/frb_example/dart_build_rs/rust/src/lib.rs index 9360602722d..598f05181c4 100644 --- a/frb_example/dart_build_rs/rust/src/lib.rs +++ b/frb_example/dart_build_rs/rust/src/lib.rs @@ -1,2 +1,6 @@ +// AUTO INJECTED BY flutter_rust_bridge. +// The following lines may not be accurate; change them according to your needs. +mod frb_generated; +// END of AUTO INJECTED code + pub mod api; -mod frb_generated; /* AUTO INJECTED BY flutter_rust_bridge. This line may not be accurate, and you can change it according to your needs. */ diff --git a/frb_example/dart_logging/.gitignore b/frb_example/dart_logging/.gitignore new file mode 100644 index 00000000000..24476c5d1eb --- /dev/null +++ b/frb_example/dart_logging/.gitignore @@ -0,0 +1,44 @@ +# Miscellaneous +*.class +*.log +*.pyc +*.swp +.DS_Store +.atom/ +.buildlog/ +.history +.svn/ +migrate_working_dir/ + +# IntelliJ related +*.iml +*.ipr +*.iws +.idea/ + +# The .vscode folder contains launch configuration and tasks you configure in +# VS Code which you may wish to be included in version control, so this line +# is commented out by default. +#.vscode/ + +# Flutter/Dart/Pub related +**/doc/api/ +**/ios/Flutter/.last_build_id +.dart_tool/ +.flutter-plugins +.flutter-plugins-dependencies +.packages +.pub-cache/ +.pub/ +/build/ + +# Symbolication related +app.*.symbols + +# Obfuscation related +app.*.map.json + +# Android Studio will place build artifacts here +/android/app/debug +/android/app/profile +/android/app/release diff --git a/frb_example/dart_logging/README.md b/frb_example/dart_logging/README.md new file mode 100644 index 00000000000..e67e94a370e --- /dev/null +++ b/frb_example/dart_logging/README.md @@ -0,0 +1,3 @@ +## Dart minimal logging example for `flutter_rust_bridge` + +Please visit the main documentation or open an issue for more information. diff --git a/frb_example/dart_logging/analysis_options.yaml b/frb_example/dart_logging/analysis_options.yaml new file mode 100644 index 00000000000..e6e61117cac --- /dev/null +++ b/frb_example/dart_logging/analysis_options.yaml @@ -0,0 +1,3 @@ +analyzer: + exclude: + - rust/target/**.dart # contains dumped debug info, instead of normal code \ No newline at end of file diff --git a/frb_example/dart_logging/build.dart b/frb_example/dart_logging/build.dart new file mode 100644 index 00000000000..1df95807a05 --- /dev/null +++ b/frb_example/dart_logging/build.dart @@ -0,0 +1,3 @@ +import 'package:flutter_rust_bridge_utils/flutter_rust_bridge_utils.dart'; + +void main(List args) async => simpleBuild(args); diff --git a/frb_example/dart_logging/flutter_rust_bridge.yaml b/frb_example/dart_logging/flutter_rust_bridge.yaml new file mode 100644 index 00000000000..d72e727b403 --- /dev/null +++ b/frb_example/dart_logging/flutter_rust_bridge.yaml @@ -0,0 +1,13 @@ +# See `pure_dart` example for comments on the configs +rust_input: rust/src/api/**/*.rs +# rust_output: 'rust/src/bridge/gen/frb_generated.rs' +rust_output: 'rust/src/bridge/frb_generated.rs' +dart_output: lib/src/rust +c_output: frb_generated.h +dump_all: true +local: true + +# TODO temp +#full_dep: true +#enable_lifetime: true +#stop_on_error: true diff --git a/frb_example/dart_logging/frb_generated.h b/frb_example/dart_logging/frb_generated.h new file mode 100644 index 00000000000..ad87ade833f --- /dev/null +++ b/frb_example/dart_logging/frb_generated.h @@ -0,0 +1 @@ +// Nothing when using full_dep=false mode \ No newline at end of file diff --git a/frb_example/dart_logging/lib/main.dart b/frb_example/dart_logging/lib/main.dart new file mode 100644 index 00000000000..a4ffc5d72a0 --- /dev/null +++ b/frb_example/dart_logging/lib/main.dart @@ -0,0 +1,15 @@ +import 'dart:io'; + +import 'package:frb_example_dart_logging/src/rust/api/minimal_logging.dart'; +import 'package:frb_example_dart_logging/src/rust/frb_generated.dart'; + +// final LOGGER = FRBLogger.initLogger(maxLogLevel: LogLevel.trace); +final LOGGER = FRBLogger.getLogger(); + +// If you are developing a binary program, you may want to put it in `bin/something.dart` +Future main() async { + await RustLib.init(); + LOGGER.info( + 'Call Rust and get: 100+200 = ${await minimalAdder(a: 100, b: 200)}'); + exit(0); +} diff --git a/frb_example/dart_logging/lib/src/rust/api/minimal_logging.dart b/frb_example/dart_logging/lib/src/rust/api/minimal_logging.dart new file mode 100644 index 00000000000..082ef6b74a0 --- /dev/null +++ b/frb_example/dart_logging/lib/src/rust/api/minimal_logging.dart @@ -0,0 +1,176 @@ +// This file is automatically generated, so please do not edit it. +// @generated by `flutter_rust_bridge`@ 2.11.1. + +// ignore_for_file: invalid_use_of_internal_member, unused_import, unnecessary_import + +import '../frb_generated.dart'; +import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart'; +import 'package:logging/logging.dart'; + +// These functions are ignored because they are not marked as `pub`: `_construct_default_message`, `_default_log_fn`, `_default_logger_name`, `_default_max_log_level`, `from_u16`, `to_u16` +// These function are ignored because they are on traits that is not defined in current crate (put an empty `#[frb]` on it to unignore): `clone`, `enabled`, `flush`, `from`, `log` + +String rootLoggerName() => + RustLib.instance.api.crateApiMinimalLoggingRootLoggerName(); + +String maxLogLevel() => + RustLib.instance.api.crateApiMinimalLoggingMaxLogLevel(); + +/// this is the call for logging (from Rust and Dart (as logFn)) +void logFn({required MirLogRecord record}) => + RustLib.instance.api.crateApiMinimalLoggingLogFn(record: record); + +/// uses custom type translation to translate between log::LogLevel and Dart:logging::Level +/// loglevel is represented by a number, so that we don't need to put \import `import 'package:logging/logging.dart';` +/// into the dart preamble in flutter_rust_bridge.yaml +Stream initializeLog2Dart({required int maxLogLevel}) => + RustLib.instance.api + .crateApiMinimalLoggingInitializeLog2Dart(maxLogLevel: maxLogLevel); + +Future minimalAdder({required int a, required int b}) => + RustLib.instance.api.crateApiMinimalLoggingMinimalAdder(a: a, b: b); + +class FRBLogger { + final RustStreamSink streamSink; + + const FRBLogger({ + required this.streamSink, + }); + + // HINT: Make it `#[frb(sync)]` to let it become the default constructor of Dart class. + static Future newInstance() => + RustLib.instance.api.crateApiMinimalLoggingFrbLoggerNew(); + + static FRBDartLogger initLogger( + {String? name = 'FRBLogger', + LogLevel maxLogLevel = LogLevel.info, + Function({required MirLogRecord record}) customLogFunction = logFn}) { + //initialize the rust side + int maxLogLevelNumber = maxLogLevel.levelNumberThreshold; + Stream stream = + initializeLog2Dart(maxLogLevel: maxLogLevelNumber); + + // Functions for type conversion for interaction with frb_dart/utils/frb_logging.dart + // Wrap logFn to match `void Function({required dynamic record})` + void Function({required dynamic record}) wrappedLogFn = + ({required dynamic record}) { + // Safely cast `dynamic` record back to `MirLogRecord` for the original `logFn` + logFn(record: record as MirLogRecord); + }; + // Wrap fromDartLogRecord to match `dynamic Function(LogRecord record)` + MirLogRecord Function(LogRecord record) wrappedFromDartLogRecord = + (LogRecord record) { + return MirLogRecord.fromDartLogRecord(record); + }; + // Wrap customLogFunction if provided, to match `void Function({required dynamic record})?` + void Function({required dynamic record})? wrappedCustomLogFunction; + wrappedCustomLogFunction = ({required dynamic record}) { + customLogFunction(record: record as MirLogRecord); + }; + + return FRBDartLogger.initAndGetSingleton( + streamSink: stream, + name: name ?? 'FRBLogger', + logFn: wrappedLogFn, + fromDartLogRecord: wrappedFromDartLogRecord, + maxLogLevel: maxLogLevel, + customLogFunction: wrappedCustomLogFunction, + ); + } + + static FRBDartLogger getLogger([String? name]) { + FRBDartLogger logger; + try { + logger = FRBDartLogger.getLogger(name); + } catch (e) { + logger = FRBLogger.initLogger(name: name); + } + return logger; + } + + @override + int get hashCode => streamSink.hashCode; + + @override + bool operator ==(Object other) => + identical(this, other) || + other is FRBLogger && + runtimeType == other.runtimeType && + streamSink == other.streamSink; +} + +/// mapping log crate's [Record](https://docs.rs/log/latest/log/struct.Record.html) to dart's Logger [LogRecord](https://pub.dev/documentation/logging/latest/logging/LogRecord-class.html). +/// intermediary struct to avoid Record's lifetimes +class MirLogRecord { + final int levelNumber; + final String levelName; + final String message; + final String loggerName; + final String timestamp; + final bool rustLog; + final String? modulePath; + final String? fileName; + final int? lineNumber; + + const MirLogRecord({ + required this.levelNumber, + required this.levelName, + required this.message, + required this.loggerName, + required this.timestamp, + required this.rustLog, + this.modulePath, + this.fileName, + this.lineNumber, + }); + + static MirLogRecord fromDartLogRecord(LogRecord record) { + return MirLogRecord( + message: record.message, + levelNumber: record.level.value, + levelName: LogLevel.fromLoggingLevel(record.level).name.toUpperCase(), + timestamp: record.time.toString(), + loggerName: record.loggerName, + rustLog: false, + ); + } + + static LogRecord toDartLogRecordFromMir(MirLogRecord record) { + return LogRecord( + LogLevel.fromString(record.levelName).toLoggingLevel(), + record.message, + record.loggerName, + ); + } + + LogRecord toDartLogRecord() { + return toDartLogRecordFromMir(this); + } + + @override + int get hashCode => + levelNumber.hashCode ^ + levelName.hashCode ^ + message.hashCode ^ + loggerName.hashCode ^ + timestamp.hashCode ^ + rustLog.hashCode ^ + modulePath.hashCode ^ + fileName.hashCode ^ + lineNumber.hashCode; + + @override + bool operator ==(Object other) => + identical(this, other) || + other is MirLogRecord && + runtimeType == other.runtimeType && + levelNumber == other.levelNumber && + levelName == other.levelName && + message == other.message && + loggerName == other.loggerName && + timestamp == other.timestamp && + rustLog == other.rustLog && + modulePath == other.modulePath && + fileName == other.fileName && + lineNumber == other.lineNumber; +} diff --git a/frb_example/dart_logging/lib/src/rust/frb_generated.dart b/frb_example/dart_logging/lib/src/rust/frb_generated.dart new file mode 100644 index 00000000000..5f505baa621 --- /dev/null +++ b/frb_example/dart_logging/lib/src/rust/frb_generated.dart @@ -0,0 +1,648 @@ +// This file is automatically generated, so please do not edit it. +// @generated by `flutter_rust_bridge`@ 2.11.1. + +// ignore_for_file: unused_import, unused_element, unnecessary_import, duplicate_ignore, invalid_use_of_internal_member, annotate_overrides, non_constant_identifier_names, curly_braces_in_flow_control_structures, prefer_const_literals_to_create_immutables, unused_field + +import 'api/minimal_logging.dart'; +import 'dart:async'; +import 'dart:convert'; +import 'frb_generated.dart'; +import 'frb_generated.io.dart' + if (dart.library.js_interop) 'frb_generated.web.dart'; +import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart'; + +/// Main entrypoint of the Rust API +class RustLib extends BaseEntrypoint { + @internal + static final instance = RustLib._(); + + RustLib._(); + + /// Initialize flutter_rust_bridge + static Future init({ + RustLibApi? api, + BaseHandler? handler, + ExternalLibrary? externalLibrary, + bool forceSameCodegenVersion = true, + }) async { + await instance.initImpl( + api: api, + handler: handler, + externalLibrary: externalLibrary, + forceSameCodegenVersion: forceSameCodegenVersion, + ); + } + + /// Initialize flutter_rust_bridge in mock mode. + /// No libraries for FFI are loaded. + static void initMock({ + required RustLibApi api, + }) { + instance.initMockImpl( + api: api, + ); + } + + /// Dispose flutter_rust_bridge + /// + /// The call to this function is optional, since flutter_rust_bridge (and everything else) + /// is automatically disposed when the app stops. + static void dispose() => instance.disposeImpl(); + + @override + ApiImplConstructor get apiImplConstructor => + RustLibApiImpl.new; + + @override + WireConstructor get wireConstructor => + RustLibWire.fromExternalLibrary; + + @override + Future executeRustInitializers() async { + await api.crateApiMinimalLoggingInitApp(); + } + + @override + ExternalLibraryLoaderConfig get defaultExternalLibraryLoaderConfig => + kDefaultExternalLibraryLoaderConfig; + + @override + String get codegenVersion => '2.11.1'; + + @override + int get rustContentHash => 1044248026; + + static const kDefaultExternalLibraryLoaderConfig = + ExternalLibraryLoaderConfig( + stem: 'frb_example_dart_logging', + ioDirectory: 'rust/target/release/', + webPrefix: 'pkg/', + ); +} + +abstract class RustLibApi extends BaseApi { + Future crateApiMinimalLoggingFrbLoggerNew(); + + Future crateApiMinimalLoggingInitApp(); + + Stream crateApiMinimalLoggingInitializeLog2Dart( + {required int maxLogLevel}); + + void crateApiMinimalLoggingLogFn({required MirLogRecord record}); + + String crateApiMinimalLoggingMaxLogLevel(); + + Future crateApiMinimalLoggingMinimalAdder( + {required int a, required int b}); + + String crateApiMinimalLoggingRootLoggerName(); +} + +class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { + RustLibApiImpl({ + required super.handler, + required super.wire, + required super.generalizedFrbRustBinding, + required super.portManager, + }); + + @override + Future crateApiMinimalLoggingFrbLoggerNew() { + return handler.executeNormal(NormalTask( + callFfi: (port_) { + final serializer = SseSerializer(generalizedFrbRustBinding); + pdeCallFfi(generalizedFrbRustBinding, serializer, + funcId: 1, port: port_); + }, + codec: SseCodec( + decodeSuccessData: sse_decode_frb_logger, + decodeErrorData: null, + ), + constMeta: kCrateApiMinimalLoggingFrbLoggerNewConstMeta, + argValues: [], + apiImpl: this, + )); + } + + TaskConstMeta get kCrateApiMinimalLoggingFrbLoggerNewConstMeta => + const TaskConstMeta( + debugName: "frb_logger_new", + argNames: [], + ); + + @override + Future crateApiMinimalLoggingInitApp() { + return handler.executeNormal(NormalTask( + callFfi: (port_) { + final serializer = SseSerializer(generalizedFrbRustBinding); + pdeCallFfi(generalizedFrbRustBinding, serializer, + funcId: 2, port: port_); + }, + codec: SseCodec( + decodeSuccessData: sse_decode_unit, + decodeErrorData: null, + ), + constMeta: kCrateApiMinimalLoggingInitAppConstMeta, + argValues: [], + apiImpl: this, + )); + } + + TaskConstMeta get kCrateApiMinimalLoggingInitAppConstMeta => + const TaskConstMeta( + debugName: "init_app", + argNames: [], + ); + + @override + Stream crateApiMinimalLoggingInitializeLog2Dart( + {required int maxLogLevel}) { + final logStream = RustStreamSink(); + unawaited(handler.executeNormal(NormalTask( + callFfi: (port_) { + final serializer = SseSerializer(generalizedFrbRustBinding); + sse_encode_StreamSink_mir_log_record_Sse(logStream, serializer); + sse_encode_u_16(maxLogLevel, serializer); + pdeCallFfi(generalizedFrbRustBinding, serializer, + funcId: 3, port: port_); + }, + codec: SseCodec( + decodeSuccessData: sse_decode_unit, + decodeErrorData: null, + ), + constMeta: kCrateApiMinimalLoggingInitializeLog2DartConstMeta, + argValues: [logStream, maxLogLevel], + apiImpl: this, + ))); + return logStream.stream; + } + + TaskConstMeta get kCrateApiMinimalLoggingInitializeLog2DartConstMeta => + const TaskConstMeta( + debugName: "initialize_log_2_dart", + argNames: ["logStream", "maxLogLevel"], + ); + + @override + void crateApiMinimalLoggingLogFn({required MirLogRecord record}) { + return handler.executeSync(SyncTask( + callFfi: () { + final serializer = SseSerializer(generalizedFrbRustBinding); + sse_encode_box_autoadd_mir_log_record(record, serializer); + return pdeCallFfi(generalizedFrbRustBinding, serializer, funcId: 4)!; + }, + codec: SseCodec( + decodeSuccessData: sse_decode_unit, + decodeErrorData: null, + ), + constMeta: kCrateApiMinimalLoggingLogFnConstMeta, + argValues: [record], + apiImpl: this, + )); + } + + TaskConstMeta get kCrateApiMinimalLoggingLogFnConstMeta => + const TaskConstMeta( + debugName: "log_fn", + argNames: ["record"], + ); + + @override + String crateApiMinimalLoggingMaxLogLevel() { + return handler.executeSync(SyncTask( + callFfi: () { + final serializer = SseSerializer(generalizedFrbRustBinding); + return pdeCallFfi(generalizedFrbRustBinding, serializer, funcId: 5)!; + }, + codec: SseCodec( + decodeSuccessData: sse_decode_String, + decodeErrorData: null, + ), + constMeta: kCrateApiMinimalLoggingMaxLogLevelConstMeta, + argValues: [], + apiImpl: this, + )); + } + + TaskConstMeta get kCrateApiMinimalLoggingMaxLogLevelConstMeta => + const TaskConstMeta( + debugName: "max_log_level", + argNames: [], + ); + + @override + Future crateApiMinimalLoggingMinimalAdder( + {required int a, required int b}) { + return handler.executeNormal(NormalTask( + callFfi: (port_) { + final serializer = SseSerializer(generalizedFrbRustBinding); + sse_encode_i_32(a, serializer); + sse_encode_i_32(b, serializer); + pdeCallFfi(generalizedFrbRustBinding, serializer, + funcId: 6, port: port_); + }, + codec: SseCodec( + decodeSuccessData: sse_decode_i_32, + decodeErrorData: null, + ), + constMeta: kCrateApiMinimalLoggingMinimalAdderConstMeta, + argValues: [a, b], + apiImpl: this, + )); + } + + TaskConstMeta get kCrateApiMinimalLoggingMinimalAdderConstMeta => + const TaskConstMeta( + debugName: "minimal_adder", + argNames: ["a", "b"], + ); + + @override + String crateApiMinimalLoggingRootLoggerName() { + return handler.executeSync(SyncTask( + callFfi: () { + final serializer = SseSerializer(generalizedFrbRustBinding); + return pdeCallFfi(generalizedFrbRustBinding, serializer, funcId: 7)!; + }, + codec: SseCodec( + decodeSuccessData: sse_decode_String, + decodeErrorData: null, + ), + constMeta: kCrateApiMinimalLoggingRootLoggerNameConstMeta, + argValues: [], + apiImpl: this, + )); + } + + TaskConstMeta get kCrateApiMinimalLoggingRootLoggerNameConstMeta => + const TaskConstMeta( + debugName: "root_logger_name", + argNames: [], + ); + + @protected + AnyhowException dco_decode_AnyhowException(dynamic raw) { + // Codec=Dco (DartCObject based), see doc to use other codecs + return AnyhowException(raw as String); + } + + @protected + RustStreamSink dco_decode_StreamSink_mir_log_record_Sse( + dynamic raw) { + // Codec=Dco (DartCObject based), see doc to use other codecs + throw UnimplementedError(); + } + + @protected + String dco_decode_String(dynamic raw) { + // Codec=Dco (DartCObject based), see doc to use other codecs + return raw as String; + } + + @protected + bool dco_decode_bool(dynamic raw) { + // Codec=Dco (DartCObject based), see doc to use other codecs + return raw as bool; + } + + @protected + MirLogRecord dco_decode_box_autoadd_mir_log_record(dynamic raw) { + // Codec=Dco (DartCObject based), see doc to use other codecs + return dco_decode_mir_log_record(raw); + } + + @protected + int dco_decode_box_autoadd_u_32(dynamic raw) { + // Codec=Dco (DartCObject based), see doc to use other codecs + return raw as int; + } + + @protected + FRBLogger dco_decode_frb_logger(dynamic raw) { + // Codec=Dco (DartCObject based), see doc to use other codecs + final arr = raw as List; + if (arr.length != 1) + throw Exception('unexpected arr length: expect 1 but see ${arr.length}'); + return FRBLogger( + streamSink: dco_decode_StreamSink_mir_log_record_Sse(arr[0]), + ); + } + + @protected + int dco_decode_i_32(dynamic raw) { + // Codec=Dco (DartCObject based), see doc to use other codecs + return raw as int; + } + + @protected + Uint8List dco_decode_list_prim_u_8_strict(dynamic raw) { + // Codec=Dco (DartCObject based), see doc to use other codecs + return raw as Uint8List; + } + + @protected + MirLogRecord dco_decode_mir_log_record(dynamic raw) { + // Codec=Dco (DartCObject based), see doc to use other codecs + final arr = raw as List; + if (arr.length != 9) + throw Exception('unexpected arr length: expect 9 but see ${arr.length}'); + return MirLogRecord( + levelNumber: dco_decode_u_16(arr[0]), + levelName: dco_decode_String(arr[1]), + message: dco_decode_String(arr[2]), + loggerName: dco_decode_String(arr[3]), + timestamp: dco_decode_String(arr[4]), + rustLog: dco_decode_bool(arr[5]), + modulePath: dco_decode_opt_String(arr[6]), + fileName: dco_decode_opt_String(arr[7]), + lineNumber: dco_decode_opt_box_autoadd_u_32(arr[8]), + ); + } + + @protected + String? dco_decode_opt_String(dynamic raw) { + // Codec=Dco (DartCObject based), see doc to use other codecs + return raw == null ? null : dco_decode_String(raw); + } + + @protected + int? dco_decode_opt_box_autoadd_u_32(dynamic raw) { + // Codec=Dco (DartCObject based), see doc to use other codecs + return raw == null ? null : dco_decode_box_autoadd_u_32(raw); + } + + @protected + int dco_decode_u_16(dynamic raw) { + // Codec=Dco (DartCObject based), see doc to use other codecs + return raw as int; + } + + @protected + int dco_decode_u_32(dynamic raw) { + // Codec=Dco (DartCObject based), see doc to use other codecs + return raw as int; + } + + @protected + int dco_decode_u_8(dynamic raw) { + // Codec=Dco (DartCObject based), see doc to use other codecs + return raw as int; + } + + @protected + void dco_decode_unit(dynamic raw) { + // Codec=Dco (DartCObject based), see doc to use other codecs + return; + } + + @protected + AnyhowException sse_decode_AnyhowException(SseDeserializer deserializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + var inner = sse_decode_String(deserializer); + return AnyhowException(inner); + } + + @protected + RustStreamSink sse_decode_StreamSink_mir_log_record_Sse( + SseDeserializer deserializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + throw UnimplementedError('Unreachable ()'); + } + + @protected + String sse_decode_String(SseDeserializer deserializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + var inner = sse_decode_list_prim_u_8_strict(deserializer); + return utf8.decoder.convert(inner); + } + + @protected + bool sse_decode_bool(SseDeserializer deserializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + return deserializer.buffer.getUint8() != 0; + } + + @protected + MirLogRecord sse_decode_box_autoadd_mir_log_record( + SseDeserializer deserializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + return (sse_decode_mir_log_record(deserializer)); + } + + @protected + int sse_decode_box_autoadd_u_32(SseDeserializer deserializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + return (sse_decode_u_32(deserializer)); + } + + @protected + FRBLogger sse_decode_frb_logger(SseDeserializer deserializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + var var_streamSink = sse_decode_StreamSink_mir_log_record_Sse(deserializer); + return FRBLogger(streamSink: var_streamSink); + } + + @protected + int sse_decode_i_32(SseDeserializer deserializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + return deserializer.buffer.getInt32(); + } + + @protected + Uint8List sse_decode_list_prim_u_8_strict(SseDeserializer deserializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + var len_ = sse_decode_i_32(deserializer); + return deserializer.buffer.getUint8List(len_); + } + + @protected + MirLogRecord sse_decode_mir_log_record(SseDeserializer deserializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + var var_levelNumber = sse_decode_u_16(deserializer); + var var_levelName = sse_decode_String(deserializer); + var var_message = sse_decode_String(deserializer); + var var_loggerName = sse_decode_String(deserializer); + var var_timestamp = sse_decode_String(deserializer); + var var_rustLog = sse_decode_bool(deserializer); + var var_modulePath = sse_decode_opt_String(deserializer); + var var_fileName = sse_decode_opt_String(deserializer); + var var_lineNumber = sse_decode_opt_box_autoadd_u_32(deserializer); + return MirLogRecord( + levelNumber: var_levelNumber, + levelName: var_levelName, + message: var_message, + loggerName: var_loggerName, + timestamp: var_timestamp, + rustLog: var_rustLog, + modulePath: var_modulePath, + fileName: var_fileName, + lineNumber: var_lineNumber); + } + + @protected + String? sse_decode_opt_String(SseDeserializer deserializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + + if (sse_decode_bool(deserializer)) { + return (sse_decode_String(deserializer)); + } else { + return null; + } + } + + @protected + int? sse_decode_opt_box_autoadd_u_32(SseDeserializer deserializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + + if (sse_decode_bool(deserializer)) { + return (sse_decode_box_autoadd_u_32(deserializer)); + } else { + return null; + } + } + + @protected + int sse_decode_u_16(SseDeserializer deserializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + return deserializer.buffer.getUint16(); + } + + @protected + int sse_decode_u_32(SseDeserializer deserializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + return deserializer.buffer.getUint32(); + } + + @protected + int sse_decode_u_8(SseDeserializer deserializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + return deserializer.buffer.getUint8(); + } + + @protected + void sse_decode_unit(SseDeserializer deserializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + } + + @protected + void sse_encode_AnyhowException( + AnyhowException self, SseSerializer serializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + sse_encode_String(self.message, serializer); + } + + @protected + void sse_encode_StreamSink_mir_log_record_Sse( + RustStreamSink self, SseSerializer serializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + sse_encode_String( + self.setupAndSerialize( + codec: SseCodec( + decodeSuccessData: sse_decode_mir_log_record, + decodeErrorData: sse_decode_AnyhowException, + )), + serializer); + } + + @protected + void sse_encode_String(String self, SseSerializer serializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + sse_encode_list_prim_u_8_strict(utf8.encoder.convert(self), serializer); + } + + @protected + void sse_encode_bool(bool self, SseSerializer serializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + serializer.buffer.putUint8(self ? 1 : 0); + } + + @protected + void sse_encode_box_autoadd_mir_log_record( + MirLogRecord self, SseSerializer serializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + sse_encode_mir_log_record(self, serializer); + } + + @protected + void sse_encode_box_autoadd_u_32(int self, SseSerializer serializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + sse_encode_u_32(self, serializer); + } + + @protected + void sse_encode_frb_logger(FRBLogger self, SseSerializer serializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + sse_encode_StreamSink_mir_log_record_Sse(self.streamSink, serializer); + } + + @protected + void sse_encode_i_32(int self, SseSerializer serializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + serializer.buffer.putInt32(self); + } + + @protected + void sse_encode_list_prim_u_8_strict( + Uint8List self, SseSerializer serializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + sse_encode_i_32(self.length, serializer); + serializer.buffer.putUint8List(self); + } + + @protected + void sse_encode_mir_log_record(MirLogRecord self, SseSerializer serializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + sse_encode_u_16(self.levelNumber, serializer); + sse_encode_String(self.levelName, serializer); + sse_encode_String(self.message, serializer); + sse_encode_String(self.loggerName, serializer); + sse_encode_String(self.timestamp, serializer); + sse_encode_bool(self.rustLog, serializer); + sse_encode_opt_String(self.modulePath, serializer); + sse_encode_opt_String(self.fileName, serializer); + sse_encode_opt_box_autoadd_u_32(self.lineNumber, serializer); + } + + @protected + void sse_encode_opt_String(String? self, SseSerializer serializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + + sse_encode_bool(self != null, serializer); + if (self != null) { + sse_encode_String(self, serializer); + } + } + + @protected + void sse_encode_opt_box_autoadd_u_32(int? self, SseSerializer serializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + + sse_encode_bool(self != null, serializer); + if (self != null) { + sse_encode_box_autoadd_u_32(self, serializer); + } + } + + @protected + void sse_encode_u_16(int self, SseSerializer serializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + serializer.buffer.putUint16(self); + } + + @protected + void sse_encode_u_32(int self, SseSerializer serializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + serializer.buffer.putUint32(self); + } + + @protected + void sse_encode_u_8(int self, SseSerializer serializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + serializer.buffer.putUint8(self); + } + + @protected + void sse_encode_unit(void self, SseSerializer serializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + } +} diff --git a/frb_example/dart_logging/lib/src/rust/frb_generated.io.dart b/frb_example/dart_logging/lib/src/rust/frb_generated.io.dart new file mode 100644 index 00000000000..359aa12ee09 --- /dev/null +++ b/frb_example/dart_logging/lib/src/rust/frb_generated.io.dart @@ -0,0 +1,186 @@ +// This file is automatically generated, so please do not edit it. +// @generated by `flutter_rust_bridge`@ 2.11.1. + +// ignore_for_file: unused_import, unused_element, unnecessary_import, duplicate_ignore, invalid_use_of_internal_member, annotate_overrides, non_constant_identifier_names, curly_braces_in_flow_control_structures, prefer_const_literals_to_create_immutables, unused_field + +import 'api/minimal_logging.dart'; +import 'dart:async'; +import 'dart:convert'; +import 'dart:ffi' as ffi; +import 'frb_generated.dart'; +import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated_io.dart'; + +abstract class RustLibApiImplPlatform extends BaseApiImpl { + RustLibApiImplPlatform({ + required super.handler, + required super.wire, + required super.generalizedFrbRustBinding, + required super.portManager, + }); + + @protected + AnyhowException dco_decode_AnyhowException(dynamic raw); + + @protected + RustStreamSink dco_decode_StreamSink_mir_log_record_Sse( + dynamic raw); + + @protected + String dco_decode_String(dynamic raw); + + @protected + bool dco_decode_bool(dynamic raw); + + @protected + MirLogRecord dco_decode_box_autoadd_mir_log_record(dynamic raw); + + @protected + int dco_decode_box_autoadd_u_32(dynamic raw); + + @protected + FRBLogger dco_decode_frb_logger(dynamic raw); + + @protected + int dco_decode_i_32(dynamic raw); + + @protected + Uint8List dco_decode_list_prim_u_8_strict(dynamic raw); + + @protected + MirLogRecord dco_decode_mir_log_record(dynamic raw); + + @protected + String? dco_decode_opt_String(dynamic raw); + + @protected + int? dco_decode_opt_box_autoadd_u_32(dynamic raw); + + @protected + int dco_decode_u_16(dynamic raw); + + @protected + int dco_decode_u_32(dynamic raw); + + @protected + int dco_decode_u_8(dynamic raw); + + @protected + void dco_decode_unit(dynamic raw); + + @protected + AnyhowException sse_decode_AnyhowException(SseDeserializer deserializer); + + @protected + RustStreamSink sse_decode_StreamSink_mir_log_record_Sse( + SseDeserializer deserializer); + + @protected + String sse_decode_String(SseDeserializer deserializer); + + @protected + bool sse_decode_bool(SseDeserializer deserializer); + + @protected + MirLogRecord sse_decode_box_autoadd_mir_log_record( + SseDeserializer deserializer); + + @protected + int sse_decode_box_autoadd_u_32(SseDeserializer deserializer); + + @protected + FRBLogger sse_decode_frb_logger(SseDeserializer deserializer); + + @protected + int sse_decode_i_32(SseDeserializer deserializer); + + @protected + Uint8List sse_decode_list_prim_u_8_strict(SseDeserializer deserializer); + + @protected + MirLogRecord sse_decode_mir_log_record(SseDeserializer deserializer); + + @protected + String? sse_decode_opt_String(SseDeserializer deserializer); + + @protected + int? sse_decode_opt_box_autoadd_u_32(SseDeserializer deserializer); + + @protected + int sse_decode_u_16(SseDeserializer deserializer); + + @protected + int sse_decode_u_32(SseDeserializer deserializer); + + @protected + int sse_decode_u_8(SseDeserializer deserializer); + + @protected + void sse_decode_unit(SseDeserializer deserializer); + + @protected + void sse_encode_AnyhowException( + AnyhowException self, SseSerializer serializer); + + @protected + void sse_encode_StreamSink_mir_log_record_Sse( + RustStreamSink self, SseSerializer serializer); + + @protected + void sse_encode_String(String self, SseSerializer serializer); + + @protected + void sse_encode_bool(bool self, SseSerializer serializer); + + @protected + void sse_encode_box_autoadd_mir_log_record( + MirLogRecord self, SseSerializer serializer); + + @protected + void sse_encode_box_autoadd_u_32(int self, SseSerializer serializer); + + @protected + void sse_encode_frb_logger(FRBLogger self, SseSerializer serializer); + + @protected + void sse_encode_i_32(int self, SseSerializer serializer); + + @protected + void sse_encode_list_prim_u_8_strict( + Uint8List self, SseSerializer serializer); + + @protected + void sse_encode_mir_log_record(MirLogRecord self, SseSerializer serializer); + + @protected + void sse_encode_opt_String(String? self, SseSerializer serializer); + + @protected + void sse_encode_opt_box_autoadd_u_32(int? self, SseSerializer serializer); + + @protected + void sse_encode_u_16(int self, SseSerializer serializer); + + @protected + void sse_encode_u_32(int self, SseSerializer serializer); + + @protected + void sse_encode_u_8(int self, SseSerializer serializer); + + @protected + void sse_encode_unit(void self, SseSerializer serializer); +} + +// Section: wire_class + +class RustLibWire implements BaseWire { + factory RustLibWire.fromExternalLibrary(ExternalLibrary lib) => + RustLibWire(lib.ffiDynamicLibrary); + + /// Holds the symbol lookup function. + final ffi.Pointer Function(String symbolName) + _lookup; + + /// The symbols are looked up in [dynamicLibrary]. + RustLibWire(ffi.DynamicLibrary dynamicLibrary) + : _lookup = dynamicLibrary.lookup; +} diff --git a/frb_example/dart_logging/lib/src/rust/frb_generated.web.dart b/frb_example/dart_logging/lib/src/rust/frb_generated.web.dart new file mode 100644 index 00000000000..b7cc2dc090b --- /dev/null +++ b/frb_example/dart_logging/lib/src/rust/frb_generated.web.dart @@ -0,0 +1,186 @@ +// This file is automatically generated, so please do not edit it. +// @generated by `flutter_rust_bridge`@ 2.11.1. + +// ignore_for_file: unused_import, unused_element, unnecessary_import, duplicate_ignore, invalid_use_of_internal_member, annotate_overrides, non_constant_identifier_names, curly_braces_in_flow_control_structures, prefer_const_literals_to_create_immutables, unused_field + +// Static analysis wrongly picks the IO variant, thus ignore this +// ignore_for_file: argument_type_not_assignable + +import 'api/minimal_logging.dart'; +import 'dart:async'; +import 'dart:convert'; +import 'frb_generated.dart'; +import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated_web.dart'; + +abstract class RustLibApiImplPlatform extends BaseApiImpl { + RustLibApiImplPlatform({ + required super.handler, + required super.wire, + required super.generalizedFrbRustBinding, + required super.portManager, + }); + + @protected + AnyhowException dco_decode_AnyhowException(dynamic raw); + + @protected + RustStreamSink dco_decode_StreamSink_mir_log_record_Sse( + dynamic raw); + + @protected + String dco_decode_String(dynamic raw); + + @protected + bool dco_decode_bool(dynamic raw); + + @protected + MirLogRecord dco_decode_box_autoadd_mir_log_record(dynamic raw); + + @protected + int dco_decode_box_autoadd_u_32(dynamic raw); + + @protected + FRBLogger dco_decode_frb_logger(dynamic raw); + + @protected + int dco_decode_i_32(dynamic raw); + + @protected + Uint8List dco_decode_list_prim_u_8_strict(dynamic raw); + + @protected + MirLogRecord dco_decode_mir_log_record(dynamic raw); + + @protected + String? dco_decode_opt_String(dynamic raw); + + @protected + int? dco_decode_opt_box_autoadd_u_32(dynamic raw); + + @protected + int dco_decode_u_16(dynamic raw); + + @protected + int dco_decode_u_32(dynamic raw); + + @protected + int dco_decode_u_8(dynamic raw); + + @protected + void dco_decode_unit(dynamic raw); + + @protected + AnyhowException sse_decode_AnyhowException(SseDeserializer deserializer); + + @protected + RustStreamSink sse_decode_StreamSink_mir_log_record_Sse( + SseDeserializer deserializer); + + @protected + String sse_decode_String(SseDeserializer deserializer); + + @protected + bool sse_decode_bool(SseDeserializer deserializer); + + @protected + MirLogRecord sse_decode_box_autoadd_mir_log_record( + SseDeserializer deserializer); + + @protected + int sse_decode_box_autoadd_u_32(SseDeserializer deserializer); + + @protected + FRBLogger sse_decode_frb_logger(SseDeserializer deserializer); + + @protected + int sse_decode_i_32(SseDeserializer deserializer); + + @protected + Uint8List sse_decode_list_prim_u_8_strict(SseDeserializer deserializer); + + @protected + MirLogRecord sse_decode_mir_log_record(SseDeserializer deserializer); + + @protected + String? sse_decode_opt_String(SseDeserializer deserializer); + + @protected + int? sse_decode_opt_box_autoadd_u_32(SseDeserializer deserializer); + + @protected + int sse_decode_u_16(SseDeserializer deserializer); + + @protected + int sse_decode_u_32(SseDeserializer deserializer); + + @protected + int sse_decode_u_8(SseDeserializer deserializer); + + @protected + void sse_decode_unit(SseDeserializer deserializer); + + @protected + void sse_encode_AnyhowException( + AnyhowException self, SseSerializer serializer); + + @protected + void sse_encode_StreamSink_mir_log_record_Sse( + RustStreamSink self, SseSerializer serializer); + + @protected + void sse_encode_String(String self, SseSerializer serializer); + + @protected + void sse_encode_bool(bool self, SseSerializer serializer); + + @protected + void sse_encode_box_autoadd_mir_log_record( + MirLogRecord self, SseSerializer serializer); + + @protected + void sse_encode_box_autoadd_u_32(int self, SseSerializer serializer); + + @protected + void sse_encode_frb_logger(FRBLogger self, SseSerializer serializer); + + @protected + void sse_encode_i_32(int self, SseSerializer serializer); + + @protected + void sse_encode_list_prim_u_8_strict( + Uint8List self, SseSerializer serializer); + + @protected + void sse_encode_mir_log_record(MirLogRecord self, SseSerializer serializer); + + @protected + void sse_encode_opt_String(String? self, SseSerializer serializer); + + @protected + void sse_encode_opt_box_autoadd_u_32(int? self, SseSerializer serializer); + + @protected + void sse_encode_u_16(int self, SseSerializer serializer); + + @protected + void sse_encode_u_32(int self, SseSerializer serializer); + + @protected + void sse_encode_u_8(int self, SseSerializer serializer); + + @protected + void sse_encode_unit(void self, SseSerializer serializer); +} + +// Section: wire_class + +class RustLibWire implements BaseWire { + RustLibWire.fromExternalLibrary(ExternalLibrary lib); +} + +@JS('wasm_bindgen') +external RustLibWasmModule get wasmModule; + +@JS() +@anonymous +extension type RustLibWasmModule._(JSObject _) implements JSObject {} diff --git a/frb_example/dart_logging/pubspec.lock b/frb_example/dart_logging/pubspec.lock new file mode 100644 index 00000000000..e5ce3e2e2c4 --- /dev/null +++ b/frb_example/dart_logging/pubspec.lock @@ -0,0 +1,688 @@ +# Generated by pub +# See https://dart.dev/tools/pub/glossary#lockfile +packages: + _fe_analyzer_shared: + dependency: transitive + description: + name: _fe_analyzer_shared + sha256: "16e298750b6d0af7ce8a3ba7c18c69c3785d11b15ec83f6dcd0ad2a0009b3cab" + url: "https://pub.dev" + source: hosted + version: "76.0.0" + _macros: + dependency: transitive + description: dart + source: sdk + version: "0.3.3" + analyzer: + dependency: transitive + description: + name: analyzer + sha256: "1f14db053a8c23e260789e9b0980fa27f2680dd640932cae5e1137cce0e46e1e" + url: "https://pub.dev" + source: hosted + version: "6.11.0" + archive: + dependency: transitive + description: + name: archive + sha256: cb6a278ef2dbb298455e1a713bda08524a175630ec643a242c399c932a0a1f7d + url: "https://pub.dev" + source: hosted + version: "3.6.1" + args: + dependency: transitive + description: + name: args + sha256: bf9f5caeea8d8fe6721a9c358dd8a5c1947b27f1cfaa18b39c301273594919e6 + url: "https://pub.dev" + source: hosted + version: "2.6.0" + async: + dependency: transitive + description: + name: async + sha256: d2872f9c19731c2e5f10444b14686eb7cc85c76274bd6c16e1816bff9a3bab63 + url: "https://pub.dev" + source: hosted + version: "2.12.0" + boolean_selector: + dependency: transitive + description: + name: boolean_selector + sha256: "8aab1771e1243a5063b8b0ff68042d67334e3feab9e95b9490f9a6ebf73b42ea" + url: "https://pub.dev" + source: hosted + version: "2.1.2" + build: + dependency: transitive + description: + name: build + sha256: cef23f1eda9b57566c81e2133d196f8e3df48f244b317368d65c5943d91148f0 + url: "https://pub.dev" + source: hosted + version: "2.4.2" + build_cli_annotations: + dependency: transitive + description: + name: build_cli_annotations + sha256: b59d2769769efd6c9ff6d4c4cede0be115a566afc591705c2040b707534b1172 + url: "https://pub.dev" + source: hosted + version: "2.1.0" + build_config: + dependency: transitive + description: + name: build_config + sha256: "4ae2de3e1e67ea270081eaee972e1bd8f027d459f249e0f1186730784c2e7e33" + url: "https://pub.dev" + source: hosted + version: "1.1.2" + build_daemon: + dependency: transitive + description: + name: build_daemon + sha256: "294a2edaf4814a378725bfe6358210196f5ea37af89ecd81bfa32960113d4948" + url: "https://pub.dev" + source: hosted + version: "4.0.3" + build_resolvers: + dependency: transitive + description: + name: build_resolvers + sha256: "99d3980049739a985cf9b21f30881f46db3ebc62c5b8d5e60e27440876b1ba1e" + url: "https://pub.dev" + source: hosted + version: "2.4.3" + build_runner: + dependency: "direct dev" + description: + name: build_runner + sha256: "74691599a5bc750dc96a6b4bfd48f7d9d66453eab04c7f4063134800d6a5c573" + url: "https://pub.dev" + source: hosted + version: "2.4.14" + build_runner_core: + dependency: transitive + description: + name: build_runner_core + sha256: "22e3aa1c80e0ada3722fe5b63fd43d9c8990759d0a2cf489c8c5d7b2bdebc021" + url: "https://pub.dev" + source: hosted + version: "8.0.0" + built_collection: + dependency: transitive + description: + name: built_collection + sha256: "376e3dd27b51ea877c28d525560790aee2e6fbb5f20e2f85d5081027d94e2100" + url: "https://pub.dev" + source: hosted + version: "5.1.1" + built_value: + dependency: transitive + description: + name: built_value + sha256: "28a712df2576b63c6c005c465989a348604960c0958d28be5303ba9baa841ac2" + url: "https://pub.dev" + source: hosted + version: "8.9.3" + checked_yaml: + dependency: transitive + description: + name: checked_yaml + sha256: feb6bed21949061731a7a75fc5d2aa727cf160b91af9a3e464c5e3a32e28b5ff + url: "https://pub.dev" + source: hosted + version: "2.0.3" + cli_config: + dependency: transitive + description: + name: cli_config + sha256: "65c7830649e1f8247660f1b783effb460255d6e2c1ac94eb823cf1f84e59b288" + url: "https://pub.dev" + source: hosted + version: "0.1.2" + cli_util: + dependency: transitive + description: + name: cli_util + sha256: ff6785f7e9e3c38ac98b2fb035701789de90154024a75b6cb926445e83197d1c + url: "https://pub.dev" + source: hosted + version: "0.4.2" + code_builder: + dependency: transitive + description: + name: code_builder + sha256: "0ec10bf4a89e4c613960bf1e8b42c64127021740fb21640c29c909826a5eea3e" + url: "https://pub.dev" + source: hosted + version: "4.10.1" + collection: + dependency: transitive + description: + name: collection + sha256: "2f5709ae4d3d59dd8f7cd309b4e023046b57d8a6c82130785d2b0e5868084e76" + url: "https://pub.dev" + source: hosted + version: "1.19.1" + convert: + dependency: transitive + description: + name: convert + sha256: b30acd5944035672bc15c6b7a8b47d773e41e2f17de064350988c5d02adb1c68 + url: "https://pub.dev" + source: hosted + version: "3.1.2" + coverage: + dependency: transitive + description: + name: coverage + sha256: e3493833ea012784c740e341952298f1cc77f1f01b1bbc3eb4eecf6984fb7f43 + url: "https://pub.dev" + source: hosted + version: "1.11.1" + crypto: + dependency: transitive + description: + name: crypto + sha256: "1e445881f28f22d6140f181e07737b22f1e099a5e1ff94b0af2f9e4a463f4855" + url: "https://pub.dev" + source: hosted + version: "3.0.6" + dart_style: + dependency: transitive + description: + name: dart_style + sha256: "7856d364b589d1f08986e140938578ed36ed948581fbc3bc9aef1805039ac5ab" + url: "https://pub.dev" + source: hosted + version: "2.3.7" + ffi: + dependency: transitive + description: + name: ffi + sha256: "16ed7b077ef01ad6170a3d0c57caa4a112a38d7a2ed5602e0aca9ca6f3d98da6" + url: "https://pub.dev" + source: hosted + version: "2.1.3" + ffigen: + dependency: "direct dev" + description: + name: ffigen + sha256: "2119b4fe3aad0db94dc9531b90283c4640a6231070e613c400b426a4da08c704" + url: "https://pub.dev" + source: hosted + version: "16.1.0" + file: + dependency: transitive + description: + name: file + sha256: a3b4f84adafef897088c160faf7dfffb7696046cb13ae90b508c2cbc95d3b8d4 + url: "https://pub.dev" + source: hosted + version: "7.0.1" + fixnum: + dependency: transitive + description: + name: fixnum + sha256: b6dc7065e46c974bc7c5f143080a6764ec7a4be6da1285ececdc37be96de53be + url: "https://pub.dev" + source: hosted + version: "1.1.1" + flutter_rust_bridge: + dependency: "direct main" + description: + path: "../../frb_dart" + relative: true + source: path + version: "2.11.1" + flutter_rust_bridge_utils: + dependency: "direct main" + description: + path: "../../frb_utils" + relative: true + source: path + version: "1.0.0" + freezed: + dependency: "direct dev" + description: + name: freezed + sha256: "6022db4c7bfa626841b2a10f34dd1e1b68e8f8f9650db6112dcdeeca45ca793c" + url: "https://pub.dev" + source: hosted + version: "3.0.6" + freezed_annotation: + dependency: "direct main" + description: + name: freezed_annotation + sha256: c87ff004c8aa6af2d531668b46a4ea379f7191dc6dfa066acd53d506da6e044b + url: "https://pub.dev" + source: hosted + version: "3.0.0" + frontend_server_client: + dependency: transitive + description: + name: frontend_server_client + sha256: f64a0333a82f30b0cca061bc3d143813a486dc086b574bfb233b7c1372427694 + url: "https://pub.dev" + source: hosted + version: "4.0.0" + glob: + dependency: transitive + description: + name: glob + sha256: "0e7014b3b7d4dac1ca4d6114f82bf1782ee86745b9b42a92c9289c23d8a0ab63" + url: "https://pub.dev" + source: hosted + version: "2.1.2" + graphs: + dependency: transitive + description: + name: graphs + sha256: "741bbf84165310a68ff28fe9e727332eef1407342fca52759cb21ad8177bb8d0" + url: "https://pub.dev" + source: hosted + version: "2.3.2" + http: + dependency: transitive + description: + name: http + sha256: b9c29a161230ee03d3ccf545097fccd9b87a5264228c5d348202e0f0c28f9010 + url: "https://pub.dev" + source: hosted + version: "1.2.2" + http_multi_server: + dependency: transitive + description: + name: http_multi_server + sha256: aa6199f908078bb1c5efb8d8638d4ae191aac11b311132c3ef48ce352fb52ef8 + url: "https://pub.dev" + source: hosted + version: "3.2.2" + http_parser: + dependency: transitive + description: + name: http_parser + sha256: "178d74305e7866013777bab2c3d8726205dc5a4dd935297175b19a23a2e66571" + url: "https://pub.dev" + source: hosted + version: "4.1.2" + io: + dependency: transitive + description: + name: io + sha256: dfd5a80599cf0165756e3181807ed3e77daf6dd4137caaad72d0b7931597650b + url: "https://pub.dev" + source: hosted + version: "1.0.5" + js: + dependency: transitive + description: + name: js + sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3 + url: "https://pub.dev" + source: hosted + version: "0.6.7" + json_annotation: + dependency: "direct main" + description: + name: json_annotation + sha256: "1ce844379ca14835a50d2f019a3099f419082cfdd231cd86a142af94dd5c6bb1" + url: "https://pub.dev" + source: hosted + version: "4.9.0" + json_serializable: + dependency: "direct dev" + description: + name: json_serializable + sha256: c50ef5fc083d5b5e12eef489503ba3bf5ccc899e487d691584699b4bdefeea8c + url: "https://pub.dev" + source: hosted + version: "6.9.5" + lints: + dependency: "direct main" + description: + name: lints + sha256: c35bb79562d980e9a453fc715854e1ed39e24e7d0297a880ef54e17f9874a9d7 + url: "https://pub.dev" + source: hosted + version: "5.1.1" + logging: + dependency: transitive + description: + name: logging + sha256: c8245ada5f1717ed44271ed1c26b8ce85ca3228fd2ffdb75468ab01979309d61 + url: "https://pub.dev" + source: hosted + version: "1.3.0" + macros: + dependency: transitive + description: + name: macros + sha256: "1d9e801cd66f7ea3663c45fc708450db1fa57f988142c64289142c9b7ee80656" + url: "https://pub.dev" + source: hosted + version: "0.1.3-main.0" + matcher: + dependency: transitive + description: + name: matcher + sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb + url: "https://pub.dev" + source: hosted + version: "0.12.16+1" + meta: + dependency: transitive + description: + name: meta + sha256: e3641ec5d63ebf0d9b41bd43201a66e3fc79a65db5f61fc181f04cd27aab950c + url: "https://pub.dev" + source: hosted + version: "1.16.0" + mime: + dependency: transitive + description: + name: mime + sha256: "41a20518f0cb1256669420fdba0cd90d21561e560ac240f26ef8322e45bb7ed6" + url: "https://pub.dev" + source: hosted + version: "2.0.0" + native_assets_cli: + dependency: transitive + description: + name: native_assets_cli + sha256: "51d1af3ebc2437f5883ed749f1877cb82d6a569b0712dad02c8370e6e4f2b5e3" + url: "https://pub.dev" + source: hosted + version: "0.2.0" + node_preamble: + dependency: transitive + description: + name: node_preamble + sha256: "6e7eac89047ab8a8d26cf16127b5ed26de65209847630400f9aefd7cd5c730db" + url: "https://pub.dev" + source: hosted + version: "2.0.2" + package_config: + dependency: transitive + description: + name: package_config + sha256: "92d4488434b520a62570293fbd33bb556c7d49230791c1b4bbd973baf6d2dc67" + url: "https://pub.dev" + source: hosted + version: "2.1.1" + path: + dependency: transitive + description: + name: path + sha256: "75cca69d1490965be98c73ceaea117e8a04dd21217b37b292c9ddbec0d955bc5" + url: "https://pub.dev" + source: hosted + version: "1.9.1" + petitparser: + dependency: transitive + description: + name: petitparser + sha256: "07c8f0b1913bcde1ff0d26e57ace2f3012ccbf2b204e070290dad3bb22797646" + url: "https://pub.dev" + source: hosted + version: "6.1.0" + pool: + dependency: transitive + description: + name: pool + sha256: "20fe868b6314b322ea036ba325e6fc0711a22948856475e2c2b6306e8ab39c2a" + url: "https://pub.dev" + source: hosted + version: "1.5.1" + pub_semver: + dependency: transitive + description: + name: pub_semver + sha256: "7b3cfbf654f3edd0c6298ecd5be782ce997ddf0e00531b9464b55245185bbbbd" + url: "https://pub.dev" + source: hosted + version: "2.1.5" + pubspec_parse: + dependency: transitive + description: + name: pubspec_parse + sha256: "0560ba233314abbed0a48a2956f7f022cce7c3e1e73df540277da7544cad4082" + url: "https://pub.dev" + source: hosted + version: "1.5.0" + puppeteer: + dependency: transitive + description: + name: puppeteer + sha256: "7a990c68d33882b642214c351f66492d9a738afa4226a098ab70642357337fa2" + url: "https://pub.dev" + source: hosted + version: "3.16.0" + quiver: + dependency: transitive + description: + name: quiver + sha256: ea0b925899e64ecdfbf9c7becb60d5b50e706ade44a85b2363be2a22d88117d2 + url: "https://pub.dev" + source: hosted + version: "3.2.2" + recase: + dependency: transitive + description: + name: recase + sha256: e4eb4ec2dcdee52dcf99cb4ceabaffc631d7424ee55e56f280bc039737f89213 + url: "https://pub.dev" + source: hosted + version: "4.1.0" + shelf: + dependency: transitive + description: + name: shelf + sha256: e7dd780a7ffb623c57850b33f43309312fc863fb6aa3d276a754bb299839ef12 + url: "https://pub.dev" + source: hosted + version: "1.4.2" + shelf_packages_handler: + dependency: transitive + description: + name: shelf_packages_handler + sha256: "89f967eca29607c933ba9571d838be31d67f53f6e4ee15147d5dc2934fee1b1e" + url: "https://pub.dev" + source: hosted + version: "3.0.2" + shelf_static: + dependency: transitive + description: + name: shelf_static + sha256: c87c3875f91262785dade62d135760c2c69cb217ac759485334c5857ad89f6e3 + url: "https://pub.dev" + source: hosted + version: "1.1.3" + shelf_web_socket: + dependency: transitive + description: + name: shelf_web_socket + sha256: "9ca081be41c60190ebcb4766b2486a7d50261db7bd0f5d9615f2d653637a84c1" + url: "https://pub.dev" + source: hosted + version: "1.0.4" + source_gen: + dependency: transitive + description: + name: source_gen + sha256: "35c8150ece9e8c8d263337a265153c3329667640850b9304861faea59fc98f6b" + url: "https://pub.dev" + source: hosted + version: "2.0.0" + source_helper: + dependency: transitive + description: + name: source_helper + sha256: "86d247119aedce8e63f4751bd9626fc9613255935558447569ad42f9f5b48b3c" + url: "https://pub.dev" + source: hosted + version: "1.3.5" + source_map_stack_trace: + dependency: transitive + description: + name: source_map_stack_trace + sha256: c0713a43e323c3302c2abe2a1cc89aa057a387101ebd280371d6a6c9fa68516b + url: "https://pub.dev" + source: hosted + version: "2.1.2" + source_maps: + dependency: transitive + description: + name: source_maps + sha256: "190222579a448b03896e0ca6eca5998fa810fda630c1d65e2f78b3f638f54812" + url: "https://pub.dev" + source: hosted + version: "0.10.13" + source_span: + dependency: transitive + description: + name: source_span + sha256: "254ee5351d6cb365c859e20ee823c3bb479bf4a293c22d17a9f1bf144ce86f7c" + url: "https://pub.dev" + source: hosted + version: "1.10.1" + stack_trace: + dependency: transitive + description: + name: stack_trace + sha256: "8b27215b45d22309b5cddda1aa2b19bdfec9df0e765f2de506401c071d38d1b1" + url: "https://pub.dev" + source: hosted + version: "1.12.1" + stream_channel: + dependency: transitive + description: + name: stream_channel + sha256: "969e04c80b8bcdf826f8f16579c7b14d780458bd97f56d107d3950fdbeef059d" + url: "https://pub.dev" + source: hosted + version: "2.1.4" + stream_transform: + dependency: transitive + description: + name: stream_transform + sha256: ad47125e588cfd37a9a7f86c7d6356dde8dfe89d071d293f80ca9e9273a33871 + url: "https://pub.dev" + source: hosted + version: "2.1.1" + string_scanner: + dependency: transitive + description: + name: string_scanner + sha256: "921cd31725b72fe181906c6a94d987c78e3b98c2e205b397ea399d4054872b43" + url: "https://pub.dev" + source: hosted + version: "1.4.1" + term_glyph: + dependency: transitive + description: + name: term_glyph + sha256: "7f554798625ea768a7518313e58f83891c7f5024f88e46e7182a4558850a4b8e" + url: "https://pub.dev" + source: hosted + version: "1.2.2" + test: + dependency: "direct dev" + description: + name: test + sha256: "301b213cd241ca982e9ba50266bd3f5bd1ea33f1455554c5abb85d1be0e2d87e" + url: "https://pub.dev" + source: hosted + version: "1.25.15" + test_api: + dependency: transitive + description: + name: test_api + sha256: fb31f383e2ee25fbbfe06b40fe21e1e458d14080e3c67e7ba0acfde4df4e0bbd + url: "https://pub.dev" + source: hosted + version: "0.7.4" + test_core: + dependency: transitive + description: + name: test_core + sha256: "84d17c3486c8dfdbe5e12a50c8ae176d15e2a771b96909a9442b40173649ccaa" + url: "https://pub.dev" + source: hosted + version: "0.6.8" + timing: + dependency: transitive + description: + name: timing + sha256: "62ee18aca144e4a9f29d212f5a4c6a053be252b895ab14b5821996cff4ed90fe" + url: "https://pub.dev" + source: hosted + version: "1.0.2" + typed_data: + dependency: transitive + description: + name: typed_data + sha256: f9049c039ebfeb4cf7a7104a675823cd72dba8297f264b6637062516699fa006 + url: "https://pub.dev" + source: hosted + version: "1.4.0" + vm_service: + dependency: transitive + description: + name: vm_service + sha256: b3d56ff4341b8f182b96aceb2fa20e3dcb336b9f867bc0eafc0de10f1048e957 + url: "https://pub.dev" + source: hosted + version: "13.0.0" + watcher: + dependency: transitive + description: + name: watcher + sha256: "69da27e49efa56a15f8afe8f4438c4ec02eff0a117df1b22ea4aad194fe1c104" + url: "https://pub.dev" + source: hosted + version: "1.1.1" + web: + dependency: transitive + description: + name: web + sha256: cd3543bd5798f6ad290ea73d210f423502e71900302dde696f8bff84bf89a1cb + url: "https://pub.dev" + source: hosted + version: "1.1.0" + web_socket_channel: + dependency: transitive + description: + name: web_socket_channel + sha256: d88238e5eac9a42bb43ca4e721edba3c08c6354d4a53063afaa568516217621b + url: "https://pub.dev" + source: hosted + version: "2.4.0" + webkit_inspection_protocol: + dependency: transitive + description: + name: webkit_inspection_protocol + sha256: "87d3f2333bb240704cd3f1c6b5b7acd8a10e7f0bc28c28dcf14e782014f4a572" + url: "https://pub.dev" + source: hosted + version: "1.2.1" + yaml: + dependency: transitive + description: + name: yaml + sha256: b9da305ac7c39faa3f030eccd175340f968459dae4af175130b3fc47e40d76ce + url: "https://pub.dev" + source: hosted + version: "3.1.3" + yaml_edit: + dependency: transitive + description: + name: yaml_edit + sha256: fb38626579fb345ad00e674e2af3a5c9b0cc4b9bfb8fd7f7ff322c7c9e62aef5 + url: "https://pub.dev" + source: hosted + version: "2.2.2" +sdks: + dart: ">=3.6.0 <4.0.0" diff --git a/frb_example/dart_logging/pubspec.yaml b/frb_example/dart_logging/pubspec.yaml new file mode 100644 index 00000000000..66e3891749d --- /dev/null +++ b/frb_example/dart_logging/pubspec.yaml @@ -0,0 +1,20 @@ +name: frb_example_dart_logging +description: flutter rust bridge example +version: 1.0.0 +publish_to: none +environment: + sdk: ">=3.3.0 <4.0.0" +dependencies: + lints: ^5.1.1 + flutter_rust_bridge: + path: ../../frb_dart + flutter_rust_bridge_utils: + path: ../../frb_utils + freezed_annotation: ^3.0.0 + json_annotation: ^4.9.0 +dev_dependencies: + test: ^1.21.4 + freezed: ^3.0.6 + build_runner: ^2.4.4 + ffigen: ^16.1.0 + json_serializable: ^6.9.0 diff --git a/frb_example/dart_logging/rust/Cargo.lock b/frb_example/dart_logging/rust/Cargo.lock new file mode 100644 index 00000000000..becb57f0425 --- /dev/null +++ b/frb_example/dart_logging/rust/Cargo.lock @@ -0,0 +1,827 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "addr2line" +version = "0.24.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfbe277e56a376000877090da837660b4427aad530e3028d44e0bffe4f89a1c1" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler2" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa" + +[[package]] +name = "allo-isolate" +version = "0.1.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "449e356a4864c017286dbbec0e12767ea07efba29e3b7d984194c2a7ff3c4550" +dependencies = [ + "anyhow", + "atomic", + "backtrace", +] + +[[package]] +name = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + +[[package]] +name = "anyhow" +version = "1.0.98" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e16d2d3311acee920a9eb8d33b8cbc1787ce4a264e85f964c2404b969bdcd487" + +[[package]] +name = "atomic" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c59bdb34bc650a32731b31bd8f0829cc15d24a708ee31559e0bb34f2bc320cba" + +[[package]] +name = "autocfg" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" + +[[package]] +name = "backtrace" +version = "0.3.75" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6806a6321ec58106fea15becdad98371e28d92ccbc7c8f1b3b6dd724fe8f1002" +dependencies = [ + "addr2line", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", + "windows-targets", +] + +[[package]] +name = "bitflags" +version = "2.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b8e56985ec62d17e9c1001dc89c88ecd7dc08e47eba5ec7c29c7b5eeecde967" + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "build-target" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "832133bbabbbaa9fbdba793456a2827627a7d2b8fb96032fa1e7666d7895832b" + +[[package]] +name = "bumpalo" +version = "3.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46c5e41b57b8bba42a04676d81cb89e9ee8e859a1a66f80a5a72e1cb76b34d43" + +[[package]] +name = "bytemuck" +version = "1.23.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c76a5792e44e4abe34d3abf15636779261d45a7450612059293d1d2cfc63422" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "cc" +version = "1.2.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c1599538de2394445747c8cf7935946e3cc27e9625f889d979bfb2aaf569362" +dependencies = [ + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9555578bc9e57714c812a1f84e4fc5b4d21fcb063490c624de019f7464c91268" + +[[package]] +name = "chrono" +version = "0.4.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c469d952047f47f91b68d1cba3f10d63c11d73e4636f24f08daf0278abf01c4d" +dependencies = [ + "android-tzdata", + "iana-time-zone", + "js-sys", + "num-traits", + "wasm-bindgen", + "windows-link", +] + +[[package]] +name = "console_error_panic_hook" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a06aeb73f470f66dcdbf7223caeebb85984942f22f1adb2a088cf9668146bbbc" +dependencies = [ + "cfg-if", + "wasm-bindgen", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "dart-sys" +version = "4.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57967e4b200d767d091b961d6ab42cc7d0cc14fe9e052e75d0d3cf9eb732d895" +dependencies = [ + "cc", +] + +[[package]] +name = "delegate-attr" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51aac4c99b2e6775164b412ea33ae8441b2fde2dbf05a20bc0052a63d08c475b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "crypto-common", +] + +[[package]] +name = "flutter_rust_bridge" +version = "2.11.1" +dependencies = [ + "allo-isolate", + "anyhow", + "build-target", + "bytemuck", + "byteorder", + "chrono", + "console_error_panic_hook", + "dart-sys", + "delegate-attr", + "flutter_rust_bridge_macros", + "futures", + "js-sys", + "lazy_static", + "log", + "portable-atomic", + "threadpool", + "tokio", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", +] + +[[package]] +name = "flutter_rust_bridge_macros" +version = "2.11.1" +dependencies = [ + "hex", + "md-5", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "frb_example_dart_logging" +version = "0.1.0" +dependencies = [ + "flutter_rust_bridge", + "log", +] + +[[package]] +name = "futures" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65bc07b1a8bc7c85c5f2e110c476c7389b4554ba72af57d8445ea63a576b0876" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" + +[[package]] +name = "futures-executor" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e28d1d997f585e54aebc3f97d39e72338912123a67330d723fdbb564d646c9f" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6" + +[[package]] +name = "futures-macro" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e575fab7d1e0dcb8d0c7bcf9a63ee213816ab51902e6d244a95819acacf1d4f7" + +[[package]] +name = "futures-task" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f90f7dce0722e95104fcb095585910c0977252f286e354b5e3bd38902cd99988" + +[[package]] +name = "futures-util" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "gimli" +version = "0.31.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" + +[[package]] +name = "hermit-abi" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc0fef456e4baa96da950455cd02c081ca953b141298e41db3fc7e36b1da849c" + +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "iana-time-zone" +version = "0.1.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0c919e5debc312ad217002b8048a17b7d83f80703865bbfcfebb0458b0b27d8" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "log", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + +[[package]] +name = "io-uring" +version = "0.7.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b86e202f00093dcba4275d4636b93ef9dd75d025ae560d2521b45ea28ab49013" +dependencies = [ + "bitflags", + "cfg-if", + "libc", +] + +[[package]] +name = "js-sys" +version = "0.3.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cfaf33c695fc6e08064efbc1f72ec937429614f25eef83af942d0e227c3a28f" +dependencies = [ + "once_cell", + "wasm-bindgen", +] + +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + +[[package]] +name = "libc" +version = "0.2.174" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1171693293099992e19cddea4e8b849964e9846f4acee11b3948bcc337be8776" + +[[package]] +name = "log" +version = "0.4.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94" + +[[package]] +name = "md-5" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d89e7ee0cfbedfc4da3340218492196241d89eefb6dab27de5df917a6d2e78cf" +dependencies = [ + "cfg-if", + "digest", +] + +[[package]] +name = "memchr" +version = "2.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a282da65faaf38286cf3be983213fcf1d2e2a58700e808f83f4ea9a4804bc0" + +[[package]] +name = "miniz_oxide" +version = "0.8.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fa76a2c86f704bdb222d66965fb3d63269ce38518b83cb0575fca855ebb6316" +dependencies = [ + "adler2", +] + +[[package]] +name = "mio" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78bed444cc8a2160f01cbcf811ef18cac863ad68ae8ca62092e8db51d51c761c" +dependencies = [ + "libc", + "wasi", + "windows-sys", +] + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "num_cpus" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91df4bbde75afed763b708b7eee1e8e7651e02d97f6d5dd763e89367e957b23b" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.36.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62948e14d923ea95ea2c7c86c71013138b66525b86bdc08d2dcc262bdb497b87" +dependencies = [ + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.21.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" + +[[package]] +name = "pin-project-lite" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "portable-atomic" +version = "1.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f84267b20a16ea918e43c6a88433c2d54fa145c92a811b5b047ccbe153674483" + +[[package]] +name = "proc-macro2" +version = "1.0.95" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "989e6739f80c4ad5b13e0fd7fe89531180375b18520cc8c82080e4dc4035b84f" + +[[package]] +name = "rustversion" +version = "1.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a0d197bd2c9dc6e53b84da9556a69ba4cdfab8619eb41a8bd1cc2027a0f6b1d" + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "slab" +version = "0.4.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04dc19736151f35336d325007ac991178d504a119863a2fcb3758cdb5e52c50d" + +[[package]] +name = "syn" +version = "2.0.104" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17b6f705963418cdb9927482fa304bc562ece2fdd4f616084c50b7023b435a40" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "threadpool" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d050e60b33d41c19108b32cea32164033a9013fe3b46cbd4457559bfbf77afaa" +dependencies = [ + "num_cpus", +] + +[[package]] +name = "tokio" +version = "1.46.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0cc3a2344dafbe23a245241fe8b09735b521110d30fcefbbd5feb1797ca35d17" +dependencies = [ + "backtrace", + "io-uring", + "libc", + "mio", + "pin-project-lite", + "slab", +] + +[[package]] +name = "typenum" +version = "1.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1dccffe3ce07af9386bfd29e80c0ab1a8205a2fc34e4bcd40364df902cfa8f3f" + +[[package]] +name = "unicode-ident" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "wasi" +version = "0.11.1+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" + +[[package]] +name = "wasm-bindgen" +version = "0.2.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1edc8929d7499fc4e8f0be2262a241556cfc54a0bea223790e71446f2aab1ef5" +dependencies = [ + "cfg-if", + "once_cell", + "rustversion", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f0a0651a5c2bc21487bde11ee802ccaf4c51935d0d3d42a6101f98161700bc6" +dependencies = [ + "bumpalo", + "log", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.50" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "555d470ec0bc3bb57890405e5d4322cc9ea83cebb085523ced7be4144dac1e61" +dependencies = [ + "cfg-if", + "js-sys", + "once_cell", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fe63fc6d09ed3792bd0897b314f53de8e16568c2b3f7982f468c0bf9bd0b407" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ae87ea40c9f689fc23f209965b6fb8a99ad69aeeb0231408be24920604395de" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a05d73b933a847d6cccdda8f838a22ff101ad9bf93e33684f39c1f5f0eece3d" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "web-sys" +version = "0.3.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33b6dd2ef9186f1f2072e409e99cd22a975331a6b3591b12c764e0e55c60d5d2" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "windows-core" +version = "0.61.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0fdd3ddb90610c7638aa2b3a3ab2904fb9e5cdbecc643ddb3647212781c4ae3" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-link", + "windows-result", + "windows-strings", +] + +[[package]] +name = "windows-implement" +version = "0.60.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a47fddd13af08290e67f4acabf4b459f647552718f683a7b415d290ac744a836" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "windows-interface" +version = "0.59.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd9211b69f8dcdfa817bfd14bf1c97c9188afa36f4750130fcdf3f400eca9fa8" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "windows-link" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e6ad25900d524eaabdbbb96d20b4311e1e7ae1699af4fb28c17ae66c80d798a" + +[[package]] +name = "windows-result" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56f42bd332cc6c8eac5af113fc0c1fd6a8fd2aa08a0119358686e5160d0586c6" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-strings" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56e6c93f3a0c3b36176cb1327a4958a0353d5d166c2a35cb268ace15e91d3b57" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" diff --git a/frb_example/dart_logging/rust/Cargo.toml b/frb_example/dart_logging/rust/Cargo.toml new file mode 100644 index 00000000000..52596a57922 --- /dev/null +++ b/frb_example/dart_logging/rust/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "frb_example_dart_logging" +version = "0.1.0" +edition = "2021" + +[lib] +crate-type = ["cdylib"] + +[dependencies] +flutter_rust_bridge = { path = "../../../frb_rust" } +# Optional - can be removed if you do not want logging +log = "^0.4.20" + +[lints.rust] +unexpected_cfgs = { level = "warn", check-cfg = ['cfg(frb_expand)'] } diff --git a/frb_example/dart_logging/rust/src/api/minimal_logging.rs b/frb_example/dart_logging/rust/src/api/minimal_logging.rs new file mode 100644 index 00000000000..4dca1aaefbf --- /dev/null +++ b/frb_example/dart_logging/rust/src/api/minimal_logging.rs @@ -0,0 +1,13 @@ +use flutter_rust_bridge::enable_frb_logging; + +enable_frb_logging!(); + +#[frb(init)] +pub fn init_app() { + flutter_rust_bridge::setup_default_user_utils(); +} + +pub fn minimal_adder(a: i32, b: i32) -> i32 { + log::info!("adding {} and {}", a, b); + a + b +} diff --git a/frb_example/dart_logging/rust/src/api/mod.rs b/frb_example/dart_logging/rust/src/api/mod.rs new file mode 100644 index 00000000000..23e6c541949 --- /dev/null +++ b/frb_example/dart_logging/rust/src/api/mod.rs @@ -0,0 +1 @@ +pub mod minimal_logging; diff --git a/frb_example/dart_logging/rust/src/bridge/frb_generated.rs b/frb_example/dart_logging/rust/src/bridge/frb_generated.rs new file mode 100644 index 00000000000..78020ec3551 --- /dev/null +++ b/frb_example/dart_logging/rust/src/bridge/frb_generated.rs @@ -0,0 +1,686 @@ +// This file is automatically generated, so please do not edit it. +// @generated by `flutter_rust_bridge`@ 2.11.1. + +#![allow( + non_camel_case_types, + unused, + non_snake_case, + clippy::needless_return, + clippy::redundant_closure_call, + clippy::redundant_closure, + clippy::useless_conversion, + clippy::unit_arg, + clippy::unused_unit, + clippy::double_parens, + clippy::let_and_return, + clippy::too_many_arguments, + clippy::match_single_binding, + clippy::clone_on_copy, + clippy::let_unit_value, + clippy::deref_addrof, + clippy::explicit_auto_deref, + clippy::borrow_deref_ref, + clippy::needless_borrow +)] + +// Section: imports + +use flutter_rust_bridge::for_generated::byteorder::{NativeEndian, ReadBytesExt, WriteBytesExt}; +use flutter_rust_bridge::for_generated::{transform_result_dco, Lifetimeable, Lockable}; +use flutter_rust_bridge::{Handler, IntoIntoDart}; + +// Section: boilerplate + +flutter_rust_bridge::frb_generated_boilerplate!( + default_stream_sink_codec = SseCodec, + default_rust_opaque = RustOpaqueMoi, + default_rust_auto_opaque = RustAutoOpaqueMoi, +); +pub(crate) const FLUTTER_RUST_BRIDGE_CODEGEN_VERSION: &str = "2.11.1"; +pub(crate) const FLUTTER_RUST_BRIDGE_CODEGEN_CONTENT_HASH: i32 = 1044248026; + +// Section: executor + +flutter_rust_bridge::frb_generated_default_handler!(); + +// Section: wire_funcs + +fn wire__crate__api__minimal_logging__frb_logger_new_impl( + port_: flutter_rust_bridge::for_generated::MessagePort, + ptr_: flutter_rust_bridge::for_generated::PlatformGeneralizedUint8ListPtr, + rust_vec_len_: i32, + data_len_: i32, +) { + FLUTTER_RUST_BRIDGE_HANDLER.wrap_normal::( + flutter_rust_bridge::for_generated::TaskInfo { + debug_name: "frb_logger_new", + port: Some(port_), + mode: flutter_rust_bridge::for_generated::FfiCallMode::Normal, + }, + move || { + let message = unsafe { + flutter_rust_bridge::for_generated::Dart2RustMessageSse::from_wire( + ptr_, + rust_vec_len_, + data_len_, + ) + }; + let mut deserializer = + flutter_rust_bridge::for_generated::SseDeserializer::new(message); + deserializer.end(); + move |context| { + transform_result_sse::<_, ()>((move || { + let output_ok = + Result::<_, ()>::Ok(crate::api::minimal_logging::FRBLogger::new())?; + Ok(output_ok) + })()) + } + }, + ) +} +fn wire__crate__api__minimal_logging__init_app_impl( + port_: flutter_rust_bridge::for_generated::MessagePort, + ptr_: flutter_rust_bridge::for_generated::PlatformGeneralizedUint8ListPtr, + rust_vec_len_: i32, + data_len_: i32, +) { + 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 || { + let message = unsafe { + flutter_rust_bridge::for_generated::Dart2RustMessageSse::from_wire( + ptr_, + rust_vec_len_, + data_len_, + ) + }; + let mut deserializer = + flutter_rust_bridge::for_generated::SseDeserializer::new(message); + deserializer.end(); + move |context| { + transform_result_sse::<_, ()>((move || { + let output_ok = Result::<_, ()>::Ok({ + crate::api::minimal_logging::init_app(); + })?; + Ok(output_ok) + })()) + } + }, + ) +} +fn wire__crate__api__minimal_logging__initialize_log_2_dart_impl( + port_: flutter_rust_bridge::for_generated::MessagePort, + ptr_: flutter_rust_bridge::for_generated::PlatformGeneralizedUint8ListPtr, + rust_vec_len_: i32, + data_len_: i32, +) { + FLUTTER_RUST_BRIDGE_HANDLER.wrap_normal::( + flutter_rust_bridge::for_generated::TaskInfo { + debug_name: "initialize_log_2_dart", + port: Some(port_), + mode: flutter_rust_bridge::for_generated::FfiCallMode::Normal, + }, + move || { + let message = unsafe { + flutter_rust_bridge::for_generated::Dart2RustMessageSse::from_wire( + ptr_, + rust_vec_len_, + data_len_, + ) + }; + let mut deserializer = + flutter_rust_bridge::for_generated::SseDeserializer::new(message); + let api_log_stream = >::sse_decode(&mut deserializer); + let api_max_log_level = ::sse_decode(&mut deserializer); + deserializer.end(); + move |context| { + transform_result_sse::<_, ()>((move || { + let output_ok = Result::<_, ()>::Ok({ + crate::api::minimal_logging::initialize_log_2_dart( + api_log_stream, + api_max_log_level, + ); + })?; + Ok(output_ok) + })()) + } + }, + ) +} +fn wire__crate__api__minimal_logging__log_fn_impl( + ptr_: flutter_rust_bridge::for_generated::PlatformGeneralizedUint8ListPtr, + rust_vec_len_: i32, + data_len_: i32, +) -> flutter_rust_bridge::for_generated::WireSyncRust2DartSse { + FLUTTER_RUST_BRIDGE_HANDLER.wrap_sync::( + flutter_rust_bridge::for_generated::TaskInfo { + debug_name: "log_fn", + port: None, + mode: flutter_rust_bridge::for_generated::FfiCallMode::Sync, + }, + move || { + let message = unsafe { + flutter_rust_bridge::for_generated::Dart2RustMessageSse::from_wire( + ptr_, + rust_vec_len_, + data_len_, + ) + }; + let mut deserializer = + flutter_rust_bridge::for_generated::SseDeserializer::new(message); + let api_record = + ::sse_decode(&mut deserializer); + deserializer.end(); + transform_result_sse::<_, ()>((move || { + let output_ok = Result::<_, ()>::Ok({ + crate::api::minimal_logging::log_fn(api_record); + })?; + Ok(output_ok) + })()) + }, + ) +} +fn wire__crate__api__minimal_logging__max_log_level_impl( + ptr_: flutter_rust_bridge::for_generated::PlatformGeneralizedUint8ListPtr, + rust_vec_len_: i32, + data_len_: i32, +) -> flutter_rust_bridge::for_generated::WireSyncRust2DartSse { + FLUTTER_RUST_BRIDGE_HANDLER.wrap_sync::( + flutter_rust_bridge::for_generated::TaskInfo { + debug_name: "max_log_level", + port: None, + mode: flutter_rust_bridge::for_generated::FfiCallMode::Sync, + }, + move || { + let message = unsafe { + flutter_rust_bridge::for_generated::Dart2RustMessageSse::from_wire( + ptr_, + rust_vec_len_, + data_len_, + ) + }; + let mut deserializer = + flutter_rust_bridge::for_generated::SseDeserializer::new(message); + deserializer.end(); + transform_result_sse::<_, ()>((move || { + let output_ok = Result::<_, ()>::Ok(crate::api::minimal_logging::max_log_level())?; + Ok(output_ok) + })()) + }, + ) +} +fn wire__crate__api__minimal_logging__minimal_adder_impl( + port_: flutter_rust_bridge::for_generated::MessagePort, + ptr_: flutter_rust_bridge::for_generated::PlatformGeneralizedUint8ListPtr, + rust_vec_len_: i32, + data_len_: i32, +) { + FLUTTER_RUST_BRIDGE_HANDLER.wrap_normal::( + flutter_rust_bridge::for_generated::TaskInfo { + debug_name: "minimal_adder", + port: Some(port_), + mode: flutter_rust_bridge::for_generated::FfiCallMode::Normal, + }, + move || { + let message = unsafe { + flutter_rust_bridge::for_generated::Dart2RustMessageSse::from_wire( + ptr_, + rust_vec_len_, + data_len_, + ) + }; + let mut deserializer = + flutter_rust_bridge::for_generated::SseDeserializer::new(message); + let api_a = ::sse_decode(&mut deserializer); + let api_b = ::sse_decode(&mut deserializer); + deserializer.end(); + move |context| { + transform_result_sse::<_, ()>((move || { + let output_ok = Result::<_, ()>::Ok( + crate::api::minimal_logging::minimal_adder(api_a, api_b), + )?; + Ok(output_ok) + })()) + } + }, + ) +} +fn wire__crate__api__minimal_logging__root_logger_name_impl( + ptr_: flutter_rust_bridge::for_generated::PlatformGeneralizedUint8ListPtr, + rust_vec_len_: i32, + data_len_: i32, +) -> flutter_rust_bridge::for_generated::WireSyncRust2DartSse { + FLUTTER_RUST_BRIDGE_HANDLER.wrap_sync::( + flutter_rust_bridge::for_generated::TaskInfo { + debug_name: "root_logger_name", + port: None, + mode: flutter_rust_bridge::for_generated::FfiCallMode::Sync, + }, + move || { + let message = unsafe { + flutter_rust_bridge::for_generated::Dart2RustMessageSse::from_wire( + ptr_, + rust_vec_len_, + data_len_, + ) + }; + let mut deserializer = + flutter_rust_bridge::for_generated::SseDeserializer::new(message); + deserializer.end(); + transform_result_sse::<_, ()>((move || { + let output_ok = + Result::<_, ()>::Ok(crate::api::minimal_logging::root_logger_name())?; + Ok(output_ok) + })()) + }, + ) +} + +// Section: dart2rust + +impl SseDecode for flutter_rust_bridge::for_generated::anyhow::Error { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { + let mut inner = ::sse_decode(deserializer); + return flutter_rust_bridge::for_generated::anyhow::anyhow!("{}", inner); + } +} + +impl SseDecode + for StreamSink< + crate::api::minimal_logging::MirLogRecord, + flutter_rust_bridge::for_generated::SseCodec, + > +{ + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { + let mut inner = ::sse_decode(deserializer); + return StreamSink::deserialize(inner); + } +} + +impl SseDecode for String { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { + let mut inner = >::sse_decode(deserializer); + return String::from_utf8(inner).unwrap(); + } +} + +impl SseDecode for bool { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { + deserializer.cursor.read_u8().unwrap() != 0 + } +} + +impl SseDecode for crate::api::minimal_logging::FRBLogger { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { + let mut var_streamSink = >::sse_decode(deserializer); + return crate::api::minimal_logging::FRBLogger { + stream_sink: var_streamSink, + }; + } +} + +impl SseDecode for i32 { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { + deserializer.cursor.read_i32::().unwrap() + } +} + +impl SseDecode for Vec { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { + let mut len_ = ::sse_decode(deserializer); + let mut ans_ = vec![]; + for idx_ in 0..len_ { + ans_.push(::sse_decode(deserializer)); + } + return ans_; + } +} + +impl SseDecode for crate::api::minimal_logging::MirLogRecord { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { + let mut var_levelNumber = ::sse_decode(deserializer); + let mut var_levelName = ::sse_decode(deserializer); + let mut var_message = ::sse_decode(deserializer); + let mut var_loggerName = ::sse_decode(deserializer); + let mut var_timestamp = ::sse_decode(deserializer); + let mut var_rustLog = ::sse_decode(deserializer); + let mut var_modulePath = >::sse_decode(deserializer); + let mut var_fileName = >::sse_decode(deserializer); + let mut var_lineNumber = >::sse_decode(deserializer); + return crate::api::minimal_logging::MirLogRecord { + level_number: var_levelNumber, + level_name: var_levelName, + message: var_message, + logger_name: var_loggerName, + timestamp: var_timestamp, + rust_log: var_rustLog, + module_path: var_modulePath, + file_name: var_fileName, + line_number: var_lineNumber, + }; + } +} + +impl SseDecode for Option { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { + if (::sse_decode(deserializer)) { + return Some(::sse_decode(deserializer)); + } else { + return None; + } + } +} + +impl SseDecode for Option { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { + if (::sse_decode(deserializer)) { + return Some(::sse_decode(deserializer)); + } else { + return None; + } + } +} + +impl SseDecode for u16 { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { + deserializer.cursor.read_u16::().unwrap() + } +} + +impl SseDecode for u32 { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { + deserializer.cursor.read_u32::().unwrap() + } +} + +impl SseDecode for u8 { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { + deserializer.cursor.read_u8().unwrap() + } +} + +impl SseDecode for () { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self {} +} + +fn pde_ffi_dispatcher_primary_impl( + func_id: i32, + port: flutter_rust_bridge::for_generated::MessagePort, + ptr: flutter_rust_bridge::for_generated::PlatformGeneralizedUint8ListPtr, + rust_vec_len: i32, + data_len: i32, +) { + // Codec=Pde (Serialization + dispatch), see doc to use other codecs + match func_id { + 1 => wire__crate__api__minimal_logging__frb_logger_new_impl( + port, + ptr, + rust_vec_len, + data_len, + ), + 2 => wire__crate__api__minimal_logging__init_app_impl(port, ptr, rust_vec_len, data_len), + 3 => wire__crate__api__minimal_logging__initialize_log_2_dart_impl( + port, + ptr, + rust_vec_len, + data_len, + ), + 6 => { + wire__crate__api__minimal_logging__minimal_adder_impl(port, ptr, rust_vec_len, data_len) + } + _ => unreachable!(), + } +} + +fn pde_ffi_dispatcher_sync_impl( + func_id: i32, + ptr: flutter_rust_bridge::for_generated::PlatformGeneralizedUint8ListPtr, + rust_vec_len: i32, + data_len: i32, +) -> flutter_rust_bridge::for_generated::WireSyncRust2DartSse { + // Codec=Pde (Serialization + dispatch), see doc to use other codecs + match func_id { + 4 => wire__crate__api__minimal_logging__log_fn_impl(ptr, rust_vec_len, data_len), + 5 => wire__crate__api__minimal_logging__max_log_level_impl(ptr, rust_vec_len, data_len), + 7 => wire__crate__api__minimal_logging__root_logger_name_impl(ptr, rust_vec_len, data_len), + _ => unreachable!(), + } +} + +// Section: rust2dart + +// Codec=Dco (DartCObject based), see doc to use other codecs +impl flutter_rust_bridge::IntoDart for crate::api::minimal_logging::FRBLogger { + fn into_dart(self) -> flutter_rust_bridge::for_generated::DartAbi { + [self.stream_sink.into_into_dart().into_dart()].into_dart() + } +} +impl flutter_rust_bridge::for_generated::IntoDartExceptPrimitive + for crate::api::minimal_logging::FRBLogger +{ +} +impl flutter_rust_bridge::IntoIntoDart + for crate::api::minimal_logging::FRBLogger +{ + fn into_into_dart(self) -> crate::api::minimal_logging::FRBLogger { + self + } +} +// Codec=Dco (DartCObject based), see doc to use other codecs +impl flutter_rust_bridge::IntoDart for crate::api::minimal_logging::MirLogRecord { + fn into_dart(self) -> flutter_rust_bridge::for_generated::DartAbi { + [ + self.level_number.into_into_dart().into_dart(), + self.level_name.into_into_dart().into_dart(), + self.message.into_into_dart().into_dart(), + self.logger_name.into_into_dart().into_dart(), + self.timestamp.into_into_dart().into_dart(), + self.rust_log.into_into_dart().into_dart(), + self.module_path.into_into_dart().into_dart(), + self.file_name.into_into_dart().into_dart(), + self.line_number.into_into_dart().into_dart(), + ] + .into_dart() + } +} +impl flutter_rust_bridge::for_generated::IntoDartExceptPrimitive + for crate::api::minimal_logging::MirLogRecord +{ +} +impl flutter_rust_bridge::IntoIntoDart + for crate::api::minimal_logging::MirLogRecord +{ + fn into_into_dart(self) -> crate::api::minimal_logging::MirLogRecord { + self + } +} + +impl SseEncode for flutter_rust_bridge::for_generated::anyhow::Error { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) { + ::sse_encode(format!("{:?}", self), serializer); + } +} + +impl SseEncode + for StreamSink< + crate::api::minimal_logging::MirLogRecord, + flutter_rust_bridge::for_generated::SseCodec, + > +{ + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) { + unimplemented!("") + } +} + +impl SseEncode for String { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) { + >::sse_encode(self.into_bytes(), serializer); + } +} + +impl SseEncode for bool { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) { + serializer.cursor.write_u8(self as _).unwrap(); + } +} + +impl SseEncode for crate::api::minimal_logging::FRBLogger { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) { + >::sse_encode(self.stream_sink, serializer); + } +} + +impl SseEncode for i32 { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) { + serializer.cursor.write_i32::(self).unwrap(); + } +} + +impl SseEncode for Vec { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) { + ::sse_encode(self.len() as _, serializer); + for item in self { + ::sse_encode(item, serializer); + } + } +} + +impl SseEncode for crate::api::minimal_logging::MirLogRecord { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) { + ::sse_encode(self.level_number, serializer); + ::sse_encode(self.level_name, serializer); + ::sse_encode(self.message, serializer); + ::sse_encode(self.logger_name, serializer); + ::sse_encode(self.timestamp, serializer); + ::sse_encode(self.rust_log, serializer); + >::sse_encode(self.module_path, serializer); + >::sse_encode(self.file_name, serializer); + >::sse_encode(self.line_number, serializer); + } +} + +impl SseEncode for Option { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) { + ::sse_encode(self.is_some(), serializer); + if let Some(value) = self { + ::sse_encode(value, serializer); + } + } +} + +impl SseEncode for Option { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) { + ::sse_encode(self.is_some(), serializer); + if let Some(value) = self { + ::sse_encode(value, serializer); + } + } +} + +impl SseEncode for u16 { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) { + serializer.cursor.write_u16::(self).unwrap(); + } +} + +impl SseEncode for u32 { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) { + serializer.cursor.write_u32::(self).unwrap(); + } +} + +impl SseEncode for u8 { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) { + serializer.cursor.write_u8(self).unwrap(); + } +} + +impl SseEncode for () { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) {} +} + +#[cfg(not(target_family = "wasm"))] +mod io { + // This file is automatically generated, so please do not edit it. + // @generated by `flutter_rust_bridge`@ 2.11.1. + + // Section: imports + + use super::*; + use flutter_rust_bridge::for_generated::byteorder::{ + NativeEndian, ReadBytesExt, WriteBytesExt, + }; + use flutter_rust_bridge::for_generated::{transform_result_dco, Lifetimeable, Lockable}; + use flutter_rust_bridge::{Handler, IntoIntoDart}; + + // Section: boilerplate + + flutter_rust_bridge::frb_generated_boilerplate_io!(); +} +#[cfg(not(target_family = "wasm"))] +pub use io::*; + +/// cbindgen:ignore +#[cfg(target_family = "wasm")] +mod web { + // This file is automatically generated, so please do not edit it. + // @generated by `flutter_rust_bridge`@ 2.11.1. + + // Section: imports + + use super::*; + use flutter_rust_bridge::for_generated::byteorder::{ + NativeEndian, ReadBytesExt, WriteBytesExt, + }; + use flutter_rust_bridge::for_generated::wasm_bindgen; + use flutter_rust_bridge::for_generated::wasm_bindgen::prelude::*; + use flutter_rust_bridge::for_generated::{transform_result_dco, Lifetimeable, Lockable}; + use flutter_rust_bridge::{Handler, IntoIntoDart}; + + // Section: boilerplate + + flutter_rust_bridge::frb_generated_boilerplate_web!(); +} +#[cfg(target_family = "wasm")] +pub use web::*; diff --git a/frb_example/dart_logging/rust/src/bridge/mod.rs b/frb_example/dart_logging/rust/src/bridge/mod.rs new file mode 100644 index 00000000000..56ecf8eed3e --- /dev/null +++ b/frb_example/dart_logging/rust/src/bridge/mod.rs @@ -0,0 +1 @@ +pub mod frb_generated; diff --git a/frb_example/dart_logging/rust/src/lib.rs b/frb_example/dart_logging/rust/src/lib.rs new file mode 100644 index 00000000000..87c9ab70949 --- /dev/null +++ b/frb_example/dart_logging/rust/src/lib.rs @@ -0,0 +1,7 @@ +// AUTO INJECTED BY flutter_rust_bridge. +// The following lines may not be accurate; change them according to your needs. +mod bridge; +use crate::bridge::frb_generated; +// END of AUTO INJECTED code + +pub mod api; diff --git a/frb_example/dart_logging/test/dart_valgrind_test_entrypoint.dart b/frb_example/dart_logging/test/dart_valgrind_test_entrypoint.dart new file mode 100644 index 00000000000..09c05d7a2d3 --- /dev/null +++ b/frb_example/dart_logging/test/dart_valgrind_test_entrypoint.dart @@ -0,0 +1,5 @@ +import 'logging_test.dart' as minimal_test; + +Future main() async { + await minimal_test.main(); +} diff --git a/frb_example/dart_logging/test/dart_web_test_entrypoint.dart b/frb_example/dart_logging/test/dart_web_test_entrypoint.dart new file mode 100644 index 00000000000..fc428d81da5 --- /dev/null +++ b/frb_example/dart_logging/test/dart_web_test_entrypoint.dart @@ -0,0 +1,9 @@ +import 'package:flutter_rust_bridge_utils/flutter_rust_bridge_utils_web.dart'; + +import 'logging_test.dart' as minimal_test; + +Future main() async { + await dartWebTestEntrypoint(() async { + await minimal_test.main(); + }); +} diff --git a/frb_example/dart_logging/test/empty_entrypoint.dart b/frb_example/dart_logging/test/empty_entrypoint.dart new file mode 100644 index 00000000000..ab73b3a234a --- /dev/null +++ b/frb_example/dart_logging/test/empty_entrypoint.dart @@ -0,0 +1 @@ +void main() {} diff --git a/frb_example/dart_logging/test/logging_test.dart b/frb_example/dart_logging/test/logging_test.dart new file mode 100644 index 00000000000..4a49db0671c --- /dev/null +++ b/frb_example/dart_logging/test/logging_test.dart @@ -0,0 +1,19 @@ +import 'dart:async'; + +import 'package:frb_example_dart_logging/src/rust/api/minimal_logging.dart'; +import 'package:frb_example_dart_logging/src/rust/frb_generated.dart'; +import 'package:test/test.dart'; + +Future main() async { + print('Action: Init rust (before)'); + await RustLib.init(); + print('Action: Init rust (after)'); + + print('Action: Configure tests (before)'); + test('dart call minimalAdder', () async { + print('Action: Call rust (before)'); + expect(await minimalAdder(a: 100, b: 200), 300); + print('Action: Call rust (after)'); + }); + print('Action: Configure tests (end)'); +} diff --git a/frb_example/dart_logging/web/.gitignore b/frb_example/dart_logging/web/.gitignore new file mode 100644 index 00000000000..ab4772b91e7 --- /dev/null +++ b/frb_example/dart_logging/web/.gitignore @@ -0,0 +1 @@ +main.dart.js* \ No newline at end of file diff --git a/frb_example/dart_logging/web/experiment_call_wasm_from_js.html b/frb_example/dart_logging/web/experiment_call_wasm_from_js.html new file mode 100644 index 00000000000..6552f8e1db0 --- /dev/null +++ b/frb_example/dart_logging/web/experiment_call_wasm_from_js.html @@ -0,0 +1,30 @@ + + + +Experiment (not directly related to flutter_rust_bridge): +Call Rust WASM from JavaScript. + +NOTE: Please open this html using *different* origin from where the JS/WASM is hosted to test CORS + policy + + + + + \ No newline at end of file diff --git a/frb_example/dart_minimal/pubspec.lock b/frb_example/dart_minimal/pubspec.lock index 76146e8c1ac..4d5e456f09b 100644 --- a/frb_example/dart_minimal/pubspec.lock +++ b/frb_example/dart_minimal/pubspec.lock @@ -21,26 +21,26 @@ packages: dependency: transitive description: name: archive - sha256: cb6a278ef2dbb298455e1a713bda08524a175630ec643a242c399c932a0a1f7d + sha256: "2fde1607386ab523f7a36bb3e7edb43bd58e6edaf2ffb29d8a6d578b297fdbbd" url: "https://pub.dev" source: hosted - version: "3.6.1" + version: "4.0.7" args: dependency: transitive description: name: args - sha256: bf9f5caeea8d8fe6721a9c358dd8a5c1947b27f1cfaa18b39c301273594919e6 + sha256: d0481093c50b1da8910eb0bb301626d4d8eb7284aa739614d2b394ee09e3ea04 url: "https://pub.dev" source: hosted - version: "2.6.0" + version: "2.7.0" async: dependency: transitive description: name: async - sha256: d2872f9c19731c2e5f10444b14686eb7cc85c76274bd6c16e1816bff9a3bab63 + sha256: "758e6d74e971c3e5aceb4110bfd6698efc7f501675bcfe0c775459a8140750eb" url: "https://pub.dev" source: hosted - version: "2.12.0" + version: "2.13.0" boolean_selector: dependency: transitive description: @@ -77,26 +77,26 @@ packages: dependency: transitive description: name: build_daemon - sha256: "294a2edaf4814a378725bfe6358210196f5ea37af89ecd81bfa32960113d4948" + sha256: "8e928697a82be082206edb0b9c99c5a4ad6bc31c9e9b8b2f291ae65cd4a25daa" url: "https://pub.dev" source: hosted - version: "4.0.3" + version: "4.0.4" build_resolvers: dependency: transitive description: name: build_resolvers - sha256: "99d3980049739a985cf9b21f30881f46db3ebc62c5b8d5e60e27440876b1ba1e" + sha256: b9e4fda21d846e192628e7a4f6deda6888c36b5b69ba02ff291a01fd529140f0 url: "https://pub.dev" source: hosted - version: "2.4.3" + version: "2.4.4" build_runner: dependency: "direct dev" description: name: build_runner - sha256: "74691599a5bc750dc96a6b4bfd48f7d9d66453eab04c7f4063134800d6a5c573" + sha256: "058fe9dce1de7d69c4b84fada934df3e0153dd000758c4d65964d0166779aa99" url: "https://pub.dev" source: hosted - version: "2.4.14" + version: "2.4.15" build_runner_core: dependency: transitive description: @@ -117,10 +117,10 @@ packages: dependency: transitive description: name: built_value - sha256: "28a712df2576b63c6c005c465989a348604960c0958d28be5303ba9baa841ac2" + sha256: "082001b5c3dc495d4a42f1d5789990505df20d8547d42507c29050af6933ee27" url: "https://pub.dev" source: hosted - version: "8.9.3" + version: "8.10.1" checked_yaml: dependency: transitive description: @@ -189,10 +189,10 @@ packages: dependency: transitive description: name: dart_style - sha256: "8a0e5fba27e8ee025d2ffb4ee820b4e6e2cf5e4246a6b1a477eb66866947e0bb" + sha256: "7306ab8a2359a48d22310ad823521d723acfed60ee1f7e37388e8986853b6820" url: "https://pub.dev" source: hosted - version: "3.1.1" + version: "2.3.8" ffi: dependency: transitive description: @@ -267,10 +267,10 @@ packages: dependency: transitive description: name: glob - sha256: "0e7014b3b7d4dac1ca4d6114f82bf1782ee86745b9b42a92c9289c23d8a0ab63" + sha256: c3f1ee72c96f8f78935e18aa8cecced9ab132419e8625dc187e1c2408efc20de url: "https://pub.dev" source: hosted - version: "2.1.2" + version: "2.1.3" graphs: dependency: transitive description: @@ -291,10 +291,10 @@ packages: dependency: transitive description: name: http - sha256: b9c29a161230ee03d3ccf545097fccd9b87a5264228c5d348202e0f0c28f9010 + sha256: "2c11f3f94c687ee9bad77c171151672986360b2b001d109814ee7140b2cf261b" url: "https://pub.dev" source: hosted - version: "1.2.2" + version: "1.4.0" http_multi_server: dependency: transitive description: @@ -363,18 +363,18 @@ packages: dependency: transitive description: name: matcher - sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb + sha256: dc58c723c3c24bf8d3e2d3ad3f2f9d7bd9cf43ec6feaa64181775e60190153f2 url: "https://pub.dev" source: hosted - version: "0.12.16+1" + version: "0.12.17" meta: dependency: transitive description: name: meta - sha256: e3641ec5d63ebf0d9b41bd43201a66e3fc79a65db5f61fc181f04cd27aab950c + sha256: "23f08335362185a5ea2ad3a4e597f1375e78bce8a040df5c600c8d3552ef2394" url: "https://pub.dev" source: hosted - version: "1.16.0" + version: "1.17.0" mime: dependency: transitive description: @@ -395,10 +395,10 @@ packages: dependency: transitive description: name: package_config - sha256: "92d4488434b520a62570293fbd33bb556c7d49230791c1b4bbd973baf6d2dc67" + sha256: f096c55ebb7deb7e384101542bfba8c52696c1b56fca2eb62827989ef2353bbc url: "https://pub.dev" source: hosted - version: "2.1.1" + version: "2.2.0" path: dependency: transitive description: @@ -423,6 +423,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.5.1" + posix: + dependency: transitive + description: + name: posix + sha256: f0d7856b6ca1887cfa6d1d394056a296ae33489db914e365e2044fdada449e62 + url: "https://pub.dev" + source: hosted + version: "6.0.2" pub_semver: dependency: transitive description: @@ -443,10 +451,10 @@ packages: dependency: transitive description: name: puppeteer - sha256: "7a990c68d33882b642214c351f66492d9a738afa4226a098ab70642357337fa2" + sha256: ac8cf90a3202b4658b7a7ba6fb17f1e255905773cd0741108334a93c034ffe76 url: "https://pub.dev" source: hosted - version: "3.16.0" + version: "3.18.0" quiver: dependency: transitive description: @@ -579,26 +587,26 @@ packages: dependency: "direct dev" description: name: test - sha256: "301b213cd241ca982e9ba50266bd3f5bd1ea33f1455554c5abb85d1be0e2d87e" + sha256: "65e29d831719be0591f7b3b1a32a3cda258ec98c58c7b25f7b84241bc31215bb" url: "https://pub.dev" source: hosted - version: "1.25.15" + version: "1.26.2" test_api: dependency: transitive description: name: test_api - sha256: fb31f383e2ee25fbbfe06b40fe21e1e458d14080e3c67e7ba0acfde4df4e0bbd + sha256: "522f00f556e73044315fa4585ec3270f1808a4b186c936e612cab0b565ff1e00" url: "https://pub.dev" source: hosted - version: "0.7.4" + version: "0.7.6" test_core: dependency: transitive description: name: test_core - sha256: "84d17c3486c8dfdbe5e12a50c8ae176d15e2a771b96909a9442b40173649ccaa" + sha256: "80bf5a02b60af04b09e14f6fe68b921aad119493e26e490deaca5993fef1b05a" url: "https://pub.dev" source: hosted - version: "0.6.8" + version: "0.6.11" timing: dependency: transitive description: @@ -619,26 +627,26 @@ packages: dependency: transitive description: name: vm_service - sha256: b3d56ff4341b8f182b96aceb2fa20e3dcb336b9f867bc0eafc0de10f1048e957 + sha256: "45caa6c5917fa127b5dbcfbd1fa60b14e583afdc08bfc96dda38886ca252eb60" url: "https://pub.dev" source: hosted - version: "13.0.0" + version: "15.0.2" watcher: dependency: transitive description: name: watcher - sha256: "69da27e49efa56a15f8afe8f4438c4ec02eff0a117df1b22ea4aad194fe1c104" + sha256: "0b7fd4a0bbc4b92641dbf20adfd7e3fd1398fe17102d94b674234563e110088a" url: "https://pub.dev" source: hosted - version: "1.1.1" + version: "1.1.2" web: dependency: transitive description: name: web - sha256: cd3543bd5798f6ad290ea73d210f423502e71900302dde696f8bff84bf89a1cb + sha256: "868d88a33d8a87b18ffc05f9f030ba328ffefba92d6c127917a2ba740f9cfe4a" url: "https://pub.dev" source: hosted - version: "1.1.0" + version: "1.1.1" web_socket_channel: dependency: transitive description: diff --git a/frb_example/dart_minimal/rust/Cargo.lock b/frb_example/dart_minimal/rust/Cargo.lock index bbff787d371..15167d2f6a9 100644 --- a/frb_example/dart_minimal/rust/Cargo.lock +++ b/frb_example/dart_minimal/rust/Cargo.lock @@ -17,15 +17,6 @@ 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.26" @@ -38,20 +29,18 @@ dependencies = [ ] [[package]] -name = "android_log-sys" -version = "0.3.2" +name = "android-tzdata" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84521a3cf562bc62942e294181d9eef17eb38ceb8c68677bc49f144e4c3d4f8d" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" [[package]] -name = "android_logger" -version = "0.15.0" +name = "android_system_properties" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f39be698127218cca460cb624878c9aa4e2b47dba3b277963d2bf00bad263b" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" dependencies = [ - "android_log-sys", - "env_filter", - "log", + "libc", ] [[package]] @@ -87,12 +76,6 @@ dependencies = [ "rustc-demangle", ] -[[package]] -name = "bitflags" -version = "2.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b8e56985ec62d17e9c1001dc89c88ecd7dc08e47eba5ec7c29c7b5eeecde967" - [[package]] name = "block-buffer" version = "0.10.4" @@ -141,6 +124,20 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "chrono" +version = "0.4.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c469d952047f47f91b68d1cba3f10d63c11d73e4636f24f08daf0278abf01c4d" +dependencies = [ + "android-tzdata", + "iana-time-zone", + "js-sys", + "num-traits", + "wasm-bindgen", + "windows-link", +] + [[package]] name = "console_error_panic_hook" version = "0.1.7" @@ -151,6 +148,12 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + [[package]] name = "crypto-common" version = "0.1.6" @@ -170,19 +173,6 @@ dependencies = [ "cc", ] -[[package]] -name = "dashmap" -version = "5.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "978747c1d849a7d2ee5e8adc0159961c48fb7e5db2f06af6723b80123bb53856" -dependencies = [ - "cfg-if", - "hashbrown", - "lock_api", - "once_cell", - "parking_lot_core", -] - [[package]] name = "delegate-attr" version = "0.3.0" @@ -204,26 +194,16 @@ dependencies = [ "crypto-common", ] -[[package]] -name = "env_filter" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "186e05a59d4c50738528153b83b0b0194d3a29507dfec16eccd4b342903397d0" -dependencies = [ - "log", - "regex", -] - [[package]] name = "flutter_rust_bridge" version = "2.12.0" dependencies = [ "allo-isolate", - "android_logger", "anyhow", "build-target", "bytemuck", "byteorder", + "chrono", "console_error_panic_hook", "dart-sys", "delegate-attr", @@ -232,7 +212,6 @@ dependencies = [ "js-sys", "lazy_static", "log", - "oslog", "portable-atomic", "threadpool", "tokio", @@ -364,12 +343,6 @@ version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" -[[package]] -name = "hashbrown" -version = "0.14.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" - [[package]] name = "hermit-abi" version = "0.3.3" @@ -382,6 +355,30 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +[[package]] +name = "iana-time-zone" +version = "0.1.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0c919e5debc312ad217002b8048a17b7d83f80703865bbfcfebb0458b0b27d8" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "log", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + [[package]] name = "js-sys" version = "0.3.69" @@ -403,16 +400,6 @@ version = "0.2.150" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c" -[[package]] -name = "lock_api" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" -dependencies = [ - "autocfg", - "scopeguard", -] - [[package]] name = "log" version = "0.4.20" @@ -444,6 +431,15 @@ dependencies = [ "adler", ] +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + [[package]] name = "num_cpus" version = "1.16.0" @@ -469,30 +465,6 @@ version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" -[[package]] -name = "oslog" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80d2043d1f61d77cb2f4b1f7b7b2295f40507f5f8e9d1c8bf10a1ca5f97a3969" -dependencies = [ - "cc", - "dashmap", - "log", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-targets", -] - [[package]] name = "pin-project-lite" version = "0.2.13" @@ -529,44 +501,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "redox_syscall" -version = "0.5.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "928fca9cf2aa042393a8325b9ead81d2f0df4cb12e1e24cef072922ccd99c5af" -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" @@ -579,12 +513,6 @@ version = "1.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eded382c5f5f786b989652c49544c4877d9f015cc22e145a5ea8ea66c2921cd2" -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - [[package]] name = "slab" version = "0.4.9" @@ -594,12 +522,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "smallvec" -version = "1.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8917285742e9f3e1683f0a9c4e6b57960b7314d0b08d30d1ecd426713ee2eee9" - [[package]] name = "syn" version = "2.0.48" @@ -730,65 +652,60 @@ dependencies = [ ] [[package]] -name = "windows-targets" -version = "0.52.6" +name = "windows-core" +version = "0.61.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +checksum = "c0fdd3ddb90610c7638aa2b3a3ab2904fb9e5cdbecc643ddb3647212781c4ae3" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_gnullvm", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows-implement", + "windows-interface", + "windows-link", + "windows-result", + "windows-strings", ] [[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.6" +name = "windows-implement" +version = "0.60.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" +checksum = "a47fddd13af08290e67f4acabf4b459f647552718f683a7b415d290ac744a836" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] [[package]] -name = "windows_i686_msvc" -version = "0.52.6" +name = "windows-interface" +version = "0.59.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" +checksum = "bd9211b69f8dcdfa817bfd14bf1c97c9188afa36f4750130fcdf3f400eca9fa8" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] [[package]] -name = "windows_x86_64_gnu" -version = "0.52.6" +name = "windows-link" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" +checksum = "5e6ad25900d524eaabdbbb96d20b4311e1e7ae1699af4fb28c17ae66c80d798a" [[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.6" +name = "windows-result" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" +checksum = "56f42bd332cc6c8eac5af113fc0c1fd6a8fd2aa08a0119358686e5160d0586c6" +dependencies = [ + "windows-link", +] [[package]] -name = "windows_x86_64_msvc" -version = "0.52.6" +name = "windows-strings" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" +checksum = "56e6c93f3a0c3b36176cb1327a4958a0353d5d166c2a35cb268ace15e91d3b57" +dependencies = [ + "windows-link", +] diff --git a/frb_example/dart_minimal/rust/src/lib.rs b/frb_example/dart_minimal/rust/src/lib.rs index 9360602722d..598f05181c4 100644 --- a/frb_example/dart_minimal/rust/src/lib.rs +++ b/frb_example/dart_minimal/rust/src/lib.rs @@ -1,2 +1,6 @@ +// AUTO INJECTED BY flutter_rust_bridge. +// The following lines may not be accurate; change them according to your needs. +mod frb_generated; +// END of AUTO INJECTED code + pub mod api; -mod frb_generated; /* AUTO INJECTED BY flutter_rust_bridge. This line may not be accurate, and you can change it according to your needs. */ diff --git a/frb_example/deliberate_bad/rust/Cargo.lock b/frb_example/deliberate_bad/rust/Cargo.lock index 916fbd3a15f..a9b64ef98ec 100644 --- a/frb_example/deliberate_bad/rust/Cargo.lock +++ b/frb_example/deliberate_bad/rust/Cargo.lock @@ -17,15 +17,6 @@ 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.26" @@ -38,20 +29,18 @@ dependencies = [ ] [[package]] -name = "android_log-sys" -version = "0.3.2" +name = "android-tzdata" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84521a3cf562bc62942e294181d9eef17eb38ceb8c68677bc49f144e4c3d4f8d" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" [[package]] -name = "android_logger" -version = "0.15.0" +name = "android_system_properties" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f39be698127218cca460cb624878c9aa4e2b47dba3b277963d2bf00bad263b" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" dependencies = [ - "android_log-sys", - "env_filter", - "log", + "libc", ] [[package]] @@ -90,12 +79,6 @@ dependencies = [ "rustc-demangle", ] -[[package]] -name = "bitflags" -version = "2.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b8e56985ec62d17e9c1001dc89c88ecd7dc08e47eba5ec7c29c7b5eeecde967" - [[package]] name = "block-buffer" version = "0.10.4" @@ -144,6 +127,20 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "chrono" +version = "0.4.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c469d952047f47f91b68d1cba3f10d63c11d73e4636f24f08daf0278abf01c4d" +dependencies = [ + "android-tzdata", + "iana-time-zone", + "js-sys", + "num-traits", + "wasm-bindgen", + "windows-link", +] + [[package]] name = "console_error_panic_hook" version = "0.1.7" @@ -154,6 +151,12 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + [[package]] name = "crypto-common" version = "0.1.6" @@ -173,19 +176,6 @@ dependencies = [ "cc", ] -[[package]] -name = "dashmap" -version = "5.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "978747c1d849a7d2ee5e8adc0159961c48fb7e5db2f06af6723b80123bb53856" -dependencies = [ - "cfg-if", - "hashbrown", - "lock_api", - "once_cell", - "parking_lot_core", -] - [[package]] name = "delegate-attr" version = "0.3.0" @@ -207,26 +197,16 @@ dependencies = [ "crypto-common", ] -[[package]] -name = "env_filter" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "186e05a59d4c50738528153b83b0b0194d3a29507dfec16eccd4b342903397d0" -dependencies = [ - "log", - "regex", -] - [[package]] name = "flutter_rust_bridge" version = "2.12.0" dependencies = [ "allo-isolate", - "android_logger", "anyhow", "build-target", "bytemuck", "byteorder", + "chrono", "console_error_panic_hook", "dart-sys", "delegate-attr", @@ -235,7 +215,6 @@ dependencies = [ "js-sys", "lazy_static", "log", - "oslog", "portable-atomic", "threadpool", "tokio", @@ -369,12 +348,6 @@ version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" -[[package]] -name = "hashbrown" -version = "0.14.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" - [[package]] name = "hermit-abi" version = "0.3.3" @@ -387,6 +360,30 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +[[package]] +name = "iana-time-zone" +version = "0.1.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0c919e5debc312ad217002b8048a17b7d83f80703865bbfcfebb0458b0b27d8" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "log", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + [[package]] name = "js-sys" version = "0.3.69" @@ -408,16 +405,6 @@ version = "0.2.150" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c" -[[package]] -name = "lock_api" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" -dependencies = [ - "autocfg", - "scopeguard", -] - [[package]] name = "log" version = "0.4.20" @@ -449,6 +436,15 @@ dependencies = [ "adler", ] +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + [[package]] name = "num_cpus" version = "1.16.0" @@ -474,30 +470,6 @@ version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" -[[package]] -name = "oslog" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80d2043d1f61d77cb2f4b1f7b7b2295f40507f5f8e9d1c8bf10a1ca5f97a3969" -dependencies = [ - "cc", - "dashmap", - "log", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-targets", -] - [[package]] name = "pin-project-lite" version = "0.2.13" @@ -534,44 +506,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "redox_syscall" -version = "0.5.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "928fca9cf2aa042393a8325b9ead81d2f0df4cb12e1e24cef072922ccd99c5af" -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" @@ -584,12 +518,6 @@ version = "1.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eded382c5f5f786b989652c49544c4877d9f015cc22e145a5ea8ea66c2921cd2" -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - [[package]] name = "slab" version = "0.4.9" @@ -599,12 +527,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "smallvec" -version = "1.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8917285742e9f3e1683f0a9c4e6b57960b7314d0b08d30d1ecd426713ee2eee9" - [[package]] name = "syn" version = "2.0.39" @@ -735,65 +657,60 @@ dependencies = [ ] [[package]] -name = "windows-targets" -version = "0.52.6" +name = "windows-core" +version = "0.61.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +checksum = "c0fdd3ddb90610c7638aa2b3a3ab2904fb9e5cdbecc643ddb3647212781c4ae3" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_gnullvm", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows-implement", + "windows-interface", + "windows-link", + "windows-result", + "windows-strings", ] [[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.6" +name = "windows-implement" +version = "0.60.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" +checksum = "a47fddd13af08290e67f4acabf4b459f647552718f683a7b415d290ac744a836" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] [[package]] -name = "windows_i686_msvc" -version = "0.52.6" +name = "windows-interface" +version = "0.59.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" +checksum = "bd9211b69f8dcdfa817bfd14bf1c97c9188afa36f4750130fcdf3f400eca9fa8" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] [[package]] -name = "windows_x86_64_gnu" -version = "0.52.6" +name = "windows-link" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" +checksum = "5e6ad25900d524eaabdbbb96d20b4311e1e7ae1699af4fb28c17ae66c80d798a" [[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.6" +name = "windows-result" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" +checksum = "56f42bd332cc6c8eac5af113fc0c1fd6a8fd2aa08a0119358686e5160d0586c6" +dependencies = [ + "windows-link", +] [[package]] -name = "windows_x86_64_msvc" -version = "0.52.6" +name = "windows-strings" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" +checksum = "56e6c93f3a0c3b36176cb1327a4958a0353d5d166c2a35cb268ace15e91d3b57" +dependencies = [ + "windows-link", +] diff --git a/frb_example/deliberate_bad/rust/src/lib.rs b/frb_example/deliberate_bad/rust/src/lib.rs index 9360602722d..598f05181c4 100644 --- a/frb_example/deliberate_bad/rust/src/lib.rs +++ b/frb_example/deliberate_bad/rust/src/lib.rs @@ -1,2 +1,6 @@ +// AUTO INJECTED BY flutter_rust_bridge. +// The following lines may not be accurate; change them according to your needs. +mod frb_generated; +// END of AUTO INJECTED code + pub mod api; -mod frb_generated; /* AUTO INJECTED BY flutter_rust_bridge. This line may not be accurate, and you can change it according to your needs. */ diff --git a/frb_example/flutter_package/example/pubspec.lock b/frb_example/flutter_package/example/pubspec.lock index 03c88c5500f..23d9d78a69e 100644 --- a/frb_example/flutter_package/example/pubspec.lock +++ b/frb_example/flutter_package/example/pubspec.lock @@ -159,7 +159,15 @@ packages: sha256: "12f842a479589fea194fe5c5a3095abc7be0c1f2ddfa9a0e76aed1dbd26a87df" url: "https://pub.dev" source: hosted - version: "6.1.0" + version: "5.1.1" + logging: + dependency: transitive + description: + name: logging + sha256: c8245ada5f1717ed44271ed1c26b8ce85ca3228fd2ffdb75468ab01979309d61 + url: "https://pub.dev" + source: hosted + version: "1.3.0" matcher: dependency: transitive description: diff --git a/frb_example/flutter_package/rust/Cargo.lock b/frb_example/flutter_package/rust/Cargo.lock index 6256585d4f1..d8308c25038 100644 --- a/frb_example/flutter_package/rust/Cargo.lock +++ b/frb_example/flutter_package/rust/Cargo.lock @@ -17,15 +17,6 @@ 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.27" @@ -38,20 +29,18 @@ dependencies = [ ] [[package]] -name = "android_log-sys" -version = "0.3.2" +name = "android-tzdata" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84521a3cf562bc62942e294181d9eef17eb38ceb8c68677bc49f144e4c3d4f8d" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" [[package]] -name = "android_logger" -version = "0.15.1" +name = "android_system_properties" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbb4e440d04be07da1f1bf44fb4495ebd58669372fe0cffa6e48595ac5bd88a3" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" dependencies = [ - "android_log-sys", - "env_filter", - "log", + "libc", ] [[package]] @@ -87,12 +76,6 @@ dependencies = [ "rustc-demangle", ] -[[package]] -name = "bitflags" -version = "2.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "843867be96c8daad0d758b57df9392b6d8d271134fce549de6ce169ff98a92af" - [[package]] name = "block-buffer" version = "0.10.4" @@ -141,6 +124,20 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "chrono" +version = "0.4.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c469d952047f47f91b68d1cba3f10d63c11d73e4636f24f08daf0278abf01c4d" +dependencies = [ + "android-tzdata", + "iana-time-zone", + "js-sys", + "num-traits", + "wasm-bindgen", + "windows-link", +] + [[package]] name = "console_error_panic_hook" version = "0.1.7" @@ -151,6 +148,12 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + [[package]] name = "crypto-common" version = "0.1.6" @@ -170,19 +173,6 @@ dependencies = [ "cc", ] -[[package]] -name = "dashmap" -version = "5.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "978747c1d849a7d2ee5e8adc0159961c48fb7e5db2f06af6723b80123bb53856" -dependencies = [ - "cfg-if", - "hashbrown", - "lock_api", - "once_cell", - "parking_lot_core", -] - [[package]] name = "delegate-attr" version = "0.3.0" @@ -204,21 +194,12 @@ dependencies = [ "crypto-common", ] -[[package]] -name = "env_filter" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bf3c259d255ca70051b30e2e95b5446cdb8949ac4cd22c0d7fd634d89f568e2" -dependencies = [ - "log", - "regex", -] - [[package]] name = "flutter_package" version = "0.1.0" dependencies = [ "flutter_rust_bridge", + "log", ] [[package]] @@ -226,11 +207,11 @@ name = "flutter_rust_bridge" version = "2.12.0" dependencies = [ "allo-isolate", - "android_logger", "anyhow", "build-target", "bytemuck", "byteorder", + "chrono", "console_error_panic_hook", "dart-sys", "delegate-attr", @@ -239,7 +220,6 @@ dependencies = [ "js-sys", "lazy_static", "log", - "oslog", "portable-atomic", "threadpool", "tokio", @@ -364,12 +344,6 @@ version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" -[[package]] -name = "hashbrown" -version = "0.14.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" - [[package]] name = "hermit-abi" version = "0.3.3" @@ -382,6 +356,30 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +[[package]] +name = "iana-time-zone" +version = "0.1.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0c919e5debc312ad217002b8048a17b7d83f80703865bbfcfebb0458b0b27d8" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "log", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + [[package]] name = "js-sys" version = "0.3.69" @@ -403,15 +401,6 @@ version = "0.2.150" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c" -[[package]] -name = "lock_api" -version = "0.4.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965" -dependencies = [ - "scopeguard", -] - [[package]] name = "log" version = "0.4.20" @@ -443,6 +432,15 @@ dependencies = [ "adler", ] +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + [[package]] name = "num_cpus" version = "1.16.0" @@ -468,30 +466,6 @@ version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" -[[package]] -name = "oslog" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80d2043d1f61d77cb2f4b1f7b7b2295f40507f5f8e9d1c8bf10a1ca5f97a3969" -dependencies = [ - "cc", - "dashmap", - "log", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2621685985a2ebf1c516881c026032ac7deafcda1a2c9b7850dc81e3dfcb64c1" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-link", -] - [[package]] name = "pin-project-lite" version = "0.2.13" @@ -528,56 +502,12 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "redox_syscall" -version = "0.5.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d" -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" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - [[package]] name = "slab" version = "0.4.9" @@ -587,12 +517,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "smallvec" -version = "1.15.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" - [[package]] name = "syn" version = "2.0.39" @@ -718,8 +642,61 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "windows-core" +version = "0.61.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0fdd3ddb90610c7638aa2b3a3ab2904fb9e5cdbecc643ddb3647212781c4ae3" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-link", + "windows-result", + "windows-strings", +] + +[[package]] +name = "windows-implement" +version = "0.60.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a47fddd13af08290e67f4acabf4b459f647552718f683a7b415d290ac744a836" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "windows-interface" +version = "0.59.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd9211b69f8dcdfa817bfd14bf1c97c9188afa36f4750130fcdf3f400eca9fa8" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "windows-link" -version = "0.2.1" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" +checksum = "5e6ad25900d524eaabdbbb96d20b4311e1e7ae1699af4fb28c17ae66c80d798a" + +[[package]] +name = "windows-result" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56f42bd332cc6c8eac5af113fc0c1fd6a8fd2aa08a0119358686e5160d0586c6" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-strings" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56e6c93f3a0c3b36176cb1327a4958a0353d5d166c2a35cb268ace15e91d3b57" +dependencies = [ + "windows-link", +] diff --git a/frb_example/flutter_package/rust/Cargo.toml b/frb_example/flutter_package/rust/Cargo.toml index bb992aab412..ce36a49d243 100644 --- a/frb_example/flutter_package/rust/Cargo.toml +++ b/frb_example/flutter_package/rust/Cargo.toml @@ -8,6 +8,8 @@ crate-type = ["cdylib", "staticlib"] [dependencies] flutter_rust_bridge = { path = "../../../frb_rust" } +# Optional - can be removed if you do not want logging +log = "^0.4.20" [lints.rust] unexpected_cfgs = { level = "warn", check-cfg = ['cfg(frb_expand)'] } diff --git a/frb_example/flutter_package/rust/src/lib.rs b/frb_example/flutter_package/rust/src/lib.rs index cbb071f8bf2..598f05181c4 100644 --- a/frb_example/flutter_package/rust/src/lib.rs +++ b/frb_example/flutter_package/rust/src/lib.rs @@ -1,2 +1,6 @@ -pub mod api; +// AUTO INJECTED BY flutter_rust_bridge. +// The following lines may not be accurate; change them according to your needs. mod frb_generated; +// END of AUTO INJECTED code + +pub mod api; diff --git a/frb_example/flutter_via_create/pubspec.lock b/frb_example/flutter_via_create/pubspec.lock index c27a4781f14..509f38ceb49 100644 --- a/frb_example/flutter_via_create/pubspec.lock +++ b/frb_example/flutter_via_create/pubspec.lock @@ -152,7 +152,15 @@ packages: sha256: "12f842a479589fea194fe5c5a3095abc7be0c1f2ddfa9a0e76aed1dbd26a87df" url: "https://pub.dev" source: hosted - version: "6.1.0" + version: "5.1.1" + logging: + dependency: transitive + description: + name: logging + sha256: c8245ada5f1717ed44271ed1c26b8ce85ca3228fd2ffdb75468ab01979309d61 + url: "https://pub.dev" + source: hosted + version: "1.3.0" matcher: dependency: transitive description: diff --git a/frb_example/flutter_via_create/rust/Cargo.lock b/frb_example/flutter_via_create/rust/Cargo.lock index 5440ccce2ce..87be61525a0 100644 --- a/frb_example/flutter_via_create/rust/Cargo.lock +++ b/frb_example/flutter_via_create/rust/Cargo.lock @@ -17,15 +17,6 @@ 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.27" @@ -38,20 +29,18 @@ dependencies = [ ] [[package]] -name = "android_log-sys" -version = "0.3.2" +name = "android-tzdata" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84521a3cf562bc62942e294181d9eef17eb38ceb8c68677bc49f144e4c3d4f8d" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" [[package]] -name = "android_logger" -version = "0.15.1" +name = "android_system_properties" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbb4e440d04be07da1f1bf44fb4495ebd58669372fe0cffa6e48595ac5bd88a3" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" dependencies = [ - "android_log-sys", - "env_filter", - "log", + "libc", ] [[package]] @@ -87,12 +76,6 @@ dependencies = [ "rustc-demangle", ] -[[package]] -name = "bitflags" -version = "2.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "843867be96c8daad0d758b57df9392b6d8d271134fce549de6ce169ff98a92af" - [[package]] name = "block-buffer" version = "0.10.4" @@ -141,6 +124,20 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "chrono" +version = "0.4.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c469d952047f47f91b68d1cba3f10d63c11d73e4636f24f08daf0278abf01c4d" +dependencies = [ + "android-tzdata", + "iana-time-zone", + "js-sys", + "num-traits", + "wasm-bindgen", + "windows-link", +] + [[package]] name = "console_error_panic_hook" version = "0.1.7" @@ -151,6 +148,12 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + [[package]] name = "crypto-common" version = "0.1.6" @@ -170,19 +173,6 @@ dependencies = [ "cc", ] -[[package]] -name = "dashmap" -version = "5.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "978747c1d849a7d2ee5e8adc0159961c48fb7e5db2f06af6723b80123bb53856" -dependencies = [ - "cfg-if", - "hashbrown", - "lock_api", - "once_cell", - "parking_lot_core", -] - [[package]] name = "delegate-attr" version = "0.3.0" @@ -204,26 +194,16 @@ dependencies = [ "crypto-common", ] -[[package]] -name = "env_filter" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bf3c259d255ca70051b30e2e95b5446cdb8949ac4cd22c0d7fd634d89f568e2" -dependencies = [ - "log", - "regex", -] - [[package]] name = "flutter_rust_bridge" version = "2.12.0" dependencies = [ "allo-isolate", - "android_logger", "anyhow", "build-target", "bytemuck", "byteorder", + "chrono", "console_error_panic_hook", "dart-sys", "delegate-attr", @@ -232,7 +212,6 @@ dependencies = [ "js-sys", "lazy_static", "log", - "oslog", "portable-atomic", "threadpool", "tokio", @@ -357,12 +336,6 @@ version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" -[[package]] -name = "hashbrown" -version = "0.14.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" - [[package]] name = "hermit-abi" version = "0.3.3" @@ -375,6 +348,30 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +[[package]] +name = "iana-time-zone" +version = "0.1.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0c919e5debc312ad217002b8048a17b7d83f80703865bbfcfebb0458b0b27d8" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "log", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + [[package]] name = "js-sys" version = "0.3.69" @@ -396,15 +393,6 @@ version = "0.2.150" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c" -[[package]] -name = "lock_api" -version = "0.4.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965" -dependencies = [ - "scopeguard", -] - [[package]] name = "log" version = "0.4.20" @@ -436,6 +424,15 @@ dependencies = [ "adler", ] +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + [[package]] name = "num_cpus" version = "1.16.0" @@ -461,30 +458,6 @@ version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" -[[package]] -name = "oslog" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80d2043d1f61d77cb2f4b1f7b7b2295f40507f5f8e9d1c8bf10a1ca5f97a3969" -dependencies = [ - "cc", - "dashmap", - "log", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2621685985a2ebf1c516881c026032ac7deafcda1a2c9b7850dc81e3dfcb64c1" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-link", -] - [[package]] name = "pin-project-lite" version = "0.2.13" @@ -521,49 +494,12 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "redox_syscall" -version = "0.5.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d" -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_flutter_via_create" version = "0.1.0" dependencies = [ "flutter_rust_bridge", + "log", ] [[package]] @@ -572,12 +508,6 @@ version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - [[package]] name = "slab" version = "0.4.9" @@ -587,12 +517,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "smallvec" -version = "1.15.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" - [[package]] name = "syn" version = "2.0.39" @@ -718,8 +642,61 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "windows-core" +version = "0.61.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0fdd3ddb90610c7638aa2b3a3ab2904fb9e5cdbecc643ddb3647212781c4ae3" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-link", + "windows-result", + "windows-strings", +] + +[[package]] +name = "windows-implement" +version = "0.60.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a47fddd13af08290e67f4acabf4b459f647552718f683a7b415d290ac744a836" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "windows-interface" +version = "0.59.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd9211b69f8dcdfa817bfd14bf1c97c9188afa36f4750130fcdf3f400eca9fa8" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "windows-link" -version = "0.2.1" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" +checksum = "5e6ad25900d524eaabdbbb96d20b4311e1e7ae1699af4fb28c17ae66c80d798a" + +[[package]] +name = "windows-result" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56f42bd332cc6c8eac5af113fc0c1fd6a8fd2aa08a0119358686e5160d0586c6" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-strings" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56e6c93f3a0c3b36176cb1327a4958a0353d5d166c2a35cb268ace15e91d3b57" +dependencies = [ + "windows-link", +] diff --git a/frb_example/flutter_via_create/rust/Cargo.toml b/frb_example/flutter_via_create/rust/Cargo.toml index 80548a59f88..f69b266bbff 100644 --- a/frb_example/flutter_via_create/rust/Cargo.toml +++ b/frb_example/flutter_via_create/rust/Cargo.toml @@ -8,6 +8,8 @@ crate-type = ["cdylib", "staticlib"] [dependencies] flutter_rust_bridge = { path = "../../../frb_rust" } +# Optional - can be removed if you do not want logging +log = "^0.4.20" [lints.rust] unexpected_cfgs = { level = "warn", check-cfg = ['cfg(frb_expand)'] } diff --git a/frb_example/flutter_via_create/rust/src/lib.rs b/frb_example/flutter_via_create/rust/src/lib.rs index cbb071f8bf2..598f05181c4 100644 --- a/frb_example/flutter_via_create/rust/src/lib.rs +++ b/frb_example/flutter_via_create/rust/src/lib.rs @@ -1,2 +1,6 @@ -pub mod api; +// AUTO INJECTED BY flutter_rust_bridge. +// The following lines may not be accurate; change them according to your needs. mod frb_generated; +// END of AUTO INJECTED code + +pub mod api; diff --git a/frb_example/flutter_via_integrate/pubspec.lock b/frb_example/flutter_via_integrate/pubspec.lock index 9d87f9aafb6..a83ba4cef07 100644 --- a/frb_example/flutter_via_integrate/pubspec.lock +++ b/frb_example/flutter_via_integrate/pubspec.lock @@ -152,7 +152,15 @@ packages: sha256: "12f842a479589fea194fe5c5a3095abc7be0c1f2ddfa9a0e76aed1dbd26a87df" url: "https://pub.dev" source: hosted - version: "6.1.0" + version: "5.1.1" + logging: + dependency: transitive + description: + name: logging + sha256: c8245ada5f1717ed44271ed1c26b8ce85ca3228fd2ffdb75468ab01979309d61 + url: "https://pub.dev" + source: hosted + version: "1.3.0" matcher: dependency: transitive description: diff --git a/frb_example/flutter_via_integrate/rust/Cargo.lock b/frb_example/flutter_via_integrate/rust/Cargo.lock index bb4840bb47f..e05061ad573 100644 --- a/frb_example/flutter_via_integrate/rust/Cargo.lock +++ b/frb_example/flutter_via_integrate/rust/Cargo.lock @@ -17,15 +17,6 @@ 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.27" @@ -38,20 +29,18 @@ dependencies = [ ] [[package]] -name = "android_log-sys" -version = "0.3.2" +name = "android-tzdata" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84521a3cf562bc62942e294181d9eef17eb38ceb8c68677bc49f144e4c3d4f8d" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" [[package]] -name = "android_logger" -version = "0.15.1" +name = "android_system_properties" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbb4e440d04be07da1f1bf44fb4495ebd58669372fe0cffa6e48595ac5bd88a3" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" dependencies = [ - "android_log-sys", - "env_filter", - "log", + "libc", ] [[package]] @@ -87,12 +76,6 @@ dependencies = [ "rustc-demangle", ] -[[package]] -name = "bitflags" -version = "2.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "843867be96c8daad0d758b57df9392b6d8d271134fce549de6ce169ff98a92af" - [[package]] name = "block-buffer" version = "0.10.4" @@ -141,6 +124,20 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "chrono" +version = "0.4.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c469d952047f47f91b68d1cba3f10d63c11d73e4636f24f08daf0278abf01c4d" +dependencies = [ + "android-tzdata", + "iana-time-zone", + "js-sys", + "num-traits", + "wasm-bindgen", + "windows-link", +] + [[package]] name = "console_error_panic_hook" version = "0.1.7" @@ -151,6 +148,12 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + [[package]] name = "crypto-common" version = "0.1.6" @@ -170,19 +173,6 @@ dependencies = [ "cc", ] -[[package]] -name = "dashmap" -version = "5.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "978747c1d849a7d2ee5e8adc0159961c48fb7e5db2f06af6723b80123bb53856" -dependencies = [ - "cfg-if", - "hashbrown", - "lock_api", - "once_cell", - "parking_lot_core", -] - [[package]] name = "delegate-attr" version = "0.3.0" @@ -204,26 +194,16 @@ dependencies = [ "crypto-common", ] -[[package]] -name = "env_filter" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bf3c259d255ca70051b30e2e95b5446cdb8949ac4cd22c0d7fd634d89f568e2" -dependencies = [ - "log", - "regex", -] - [[package]] name = "flutter_rust_bridge" version = "2.12.0" dependencies = [ "allo-isolate", - "android_logger", "anyhow", "build-target", "bytemuck", "byteorder", + "chrono", "console_error_panic_hook", "dart-sys", "delegate-attr", @@ -232,7 +212,6 @@ dependencies = [ "js-sys", "lazy_static", "log", - "oslog", "portable-atomic", "threadpool", "tokio", @@ -357,12 +336,6 @@ version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" -[[package]] -name = "hashbrown" -version = "0.14.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" - [[package]] name = "hermit-abi" version = "0.3.3" @@ -375,6 +348,30 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +[[package]] +name = "iana-time-zone" +version = "0.1.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0c919e5debc312ad217002b8048a17b7d83f80703865bbfcfebb0458b0b27d8" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "log", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + [[package]] name = "js-sys" version = "0.3.69" @@ -396,15 +393,6 @@ version = "0.2.150" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c" -[[package]] -name = "lock_api" -version = "0.4.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965" -dependencies = [ - "scopeguard", -] - [[package]] name = "log" version = "0.4.20" @@ -436,6 +424,15 @@ dependencies = [ "adler", ] +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + [[package]] name = "num_cpus" version = "1.16.0" @@ -461,30 +458,6 @@ version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" -[[package]] -name = "oslog" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80d2043d1f61d77cb2f4b1f7b7b2295f40507f5f8e9d1c8bf10a1ca5f97a3969" -dependencies = [ - "cc", - "dashmap", - "log", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2621685985a2ebf1c516881c026032ac7deafcda1a2c9b7850dc81e3dfcb64c1" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-link", -] - [[package]] name = "pin-project-lite" version = "0.2.13" @@ -521,49 +494,12 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "redox_syscall" -version = "0.5.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d" -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_flutter_via_integrate" version = "0.1.0" dependencies = [ "flutter_rust_bridge", + "log", ] [[package]] @@ -572,12 +508,6 @@ version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - [[package]] name = "slab" version = "0.4.9" @@ -587,12 +517,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "smallvec" -version = "1.15.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" - [[package]] name = "syn" version = "2.0.39" @@ -718,8 +642,61 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "windows-core" +version = "0.61.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0fdd3ddb90610c7638aa2b3a3ab2904fb9e5cdbecc643ddb3647212781c4ae3" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-link", + "windows-result", + "windows-strings", +] + +[[package]] +name = "windows-implement" +version = "0.60.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a47fddd13af08290e67f4acabf4b459f647552718f683a7b415d290ac744a836" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "windows-interface" +version = "0.59.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd9211b69f8dcdfa817bfd14bf1c97c9188afa36f4750130fcdf3f400eca9fa8" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "windows-link" -version = "0.2.1" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" +checksum = "5e6ad25900d524eaabdbbb96d20b4311e1e7ae1699af4fb28c17ae66c80d798a" + +[[package]] +name = "windows-result" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56f42bd332cc6c8eac5af113fc0c1fd6a8fd2aa08a0119358686e5160d0586c6" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-strings" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56e6c93f3a0c3b36176cb1327a4958a0353d5d166c2a35cb268ace15e91d3b57" +dependencies = [ + "windows-link", +] diff --git a/frb_example/flutter_via_integrate/rust/Cargo.toml b/frb_example/flutter_via_integrate/rust/Cargo.toml index c04910591b5..b3baa86253f 100644 --- a/frb_example/flutter_via_integrate/rust/Cargo.toml +++ b/frb_example/flutter_via_integrate/rust/Cargo.toml @@ -8,6 +8,8 @@ crate-type = ["cdylib", "staticlib"] [dependencies] flutter_rust_bridge = { path = "../../../frb_rust" } +# Optional - can be removed if you do not want logging +log = "^0.4.20" [lints.rust] unexpected_cfgs = { level = "warn", check-cfg = ['cfg(frb_expand)'] } diff --git a/frb_example/flutter_via_integrate/rust/src/lib.rs b/frb_example/flutter_via_integrate/rust/src/lib.rs index cbb071f8bf2..598f05181c4 100644 --- a/frb_example/flutter_via_integrate/rust/src/lib.rs +++ b/frb_example/flutter_via_integrate/rust/src/lib.rs @@ -1,2 +1,6 @@ -pub mod api; +// AUTO INJECTED BY flutter_rust_bridge. +// The following lines may not be accurate; change them according to your needs. mod frb_generated; +// END of AUTO INJECTED code + +pub mod api; diff --git a/frb_example/gallery/rust/Cargo.lock b/frb_example/gallery/rust/Cargo.lock index 1b41396754a..4ce21e6e100 100644 --- a/frb_example/gallery/rust/Cargo.lock +++ b/frb_example/gallery/rust/Cargo.lock @@ -17,15 +17,6 @@ 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.26" @@ -38,20 +29,18 @@ dependencies = [ ] [[package]] -name = "android_log-sys" -version = "0.3.2" +name = "android-tzdata" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84521a3cf562bc62942e294181d9eef17eb38ceb8c68677bc49f144e4c3d4f8d" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" [[package]] -name = "android_logger" -version = "0.15.0" +name = "android_system_properties" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f39be698127218cca460cb624878c9aa4e2b47dba3b277963d2bf00bad263b" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" dependencies = [ - "android_log-sys", - "env_filter", - "log", + "libc", ] [[package]] @@ -102,12 +91,6 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" -[[package]] -name = "bitflags" -version = "2.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b8e56985ec62d17e9c1001dc89c88ecd7dc08e47eba5ec7c29c7b5eeecde967" - [[package]] name = "block-buffer" version = "0.10.4" @@ -156,6 +139,20 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "chrono" +version = "0.4.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c469d952047f47f91b68d1cba3f10d63c11d73e4636f24f08daf0278abf01c4d" +dependencies = [ + "android-tzdata", + "iana-time-zone", + "js-sys", + "num-traits", + "wasm-bindgen", + "windows-link", +] + [[package]] name = "color_quant" version = "1.1.0" @@ -172,6 +169,12 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + [[package]] name = "crc32fast" version = "1.3.2" @@ -272,19 +275,6 @@ dependencies = [ "cc", ] -[[package]] -name = "dashmap" -version = "5.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "978747c1d849a7d2ee5e8adc0159961c48fb7e5db2f06af6723b80123bb53856" -dependencies = [ - "cfg-if", - "hashbrown", - "lock_api", - "once_cell", - "parking_lot_core", -] - [[package]] name = "delegate-attr" version = "0.3.0" @@ -312,16 +302,6 @@ version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" -[[package]] -name = "env_filter" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "186e05a59d4c50738528153b83b0b0194d3a29507dfec16eccd4b342903397d0" -dependencies = [ - "log", - "regex", -] - [[package]] name = "exr" version = "1.71.0" @@ -371,11 +351,11 @@ name = "flutter_rust_bridge" version = "2.12.0" dependencies = [ "allo-isolate", - "android_logger", "anyhow", "build-target", "bytemuck", "byteorder", + "chrono", "console_error_panic_hook", "dart-sys", "delegate-attr", @@ -384,7 +364,6 @@ dependencies = [ "js-sys", "lazy_static", "log", - "oslog", "portable-atomic", "threadpool", "tokio", @@ -528,12 +507,6 @@ dependencies = [ "crunchy", ] -[[package]] -name = "hashbrown" -version = "0.14.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" - [[package]] name = "hermit-abi" version = "0.3.3" @@ -546,6 +519,30 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +[[package]] +name = "iana-time-zone" +version = "0.1.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0c919e5debc312ad217002b8048a17b7d83f80703865bbfcfebb0458b0b27d8" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "log", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + [[package]] name = "image" version = "0.24.7" @@ -753,30 +750,6 @@ version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" -[[package]] -name = "oslog" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80d2043d1f61d77cb2f4b1f7b7b2295f40507f5f8e9d1c8bf10a1ca5f97a3969" -dependencies = [ - "cc", - "dashmap", - "log", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-targets", -] - [[package]] name = "pin-project-lite" version = "0.2.13" @@ -795,7 +768,7 @@ version = "0.17.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd75bf2d8dd3702b9707cdbc56a5b9ef42cec752eb8b3bafc01234558442aa64" dependencies = [ - "bitflags 1.3.2", + "bitflags", "crc32fast", "fdeflate", "flate2", @@ -855,44 +828,6 @@ dependencies = [ "crossbeam-utils", ] -[[package]] -name = "redox_syscall" -version = "0.5.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "928fca9cf2aa042393a8325b9ead81d2f0df4cb12e1e24cef072922ccd99c5af" -dependencies = [ - "bitflags 2.9.1", -] - -[[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" @@ -1099,68 +1034,63 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9193164d4de03a926d909d3bc7c30543cecb35400c02114792c2cae20d5e2dbb" [[package]] -name = "windows-targets" -version = "0.52.6" +name = "windows-core" +version = "0.61.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +checksum = "c0fdd3ddb90610c7638aa2b3a3ab2904fb9e5cdbecc643ddb3647212781c4ae3" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_gnullvm", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows-implement", + "windows-interface", + "windows-link", + "windows-result", + "windows-strings", ] [[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.6" +name = "windows-implement" +version = "0.60.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" +checksum = "a47fddd13af08290e67f4acabf4b459f647552718f683a7b415d290ac744a836" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] [[package]] -name = "windows_i686_msvc" -version = "0.52.6" +name = "windows-interface" +version = "0.59.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" +checksum = "bd9211b69f8dcdfa817bfd14bf1c97c9188afa36f4750130fcdf3f400eca9fa8" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] [[package]] -name = "windows_x86_64_gnu" -version = "0.52.6" +name = "windows-link" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" +checksum = "5e6ad25900d524eaabdbbb96d20b4311e1e7ae1699af4fb28c17ae66c80d798a" [[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.6" +name = "windows-result" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" +checksum = "56f42bd332cc6c8eac5af113fc0c1fd6a8fd2aa08a0119358686e5160d0586c6" +dependencies = [ + "windows-link", +] [[package]] -name = "windows_x86_64_msvc" -version = "0.52.6" +name = "windows-strings" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" +checksum = "56e6c93f3a0c3b36176cb1327a4958a0353d5d166c2a35cb268ace15e91d3b57" +dependencies = [ + "windows-link", +] [[package]] name = "zune-inflate" diff --git a/frb_example/gallery/rust/src/lib.rs b/frb_example/gallery/rust/src/lib.rs index bd0019a2ede..739902678c6 100644 --- a/frb_example/gallery/rust/src/lib.rs +++ b/frb_example/gallery/rust/src/lib.rs @@ -1,3 +1,7 @@ -pub mod api; +// AUTO INJECTED BY flutter_rust_bridge. +// The following lines may not be accurate; change them according to your needs. mod frb_generated; +// END of AUTO INJECTED code + +pub mod api; pub mod ignore_me; /* AUTO INJECTED BY flutter_rust_bridge. This line may not be accurate, and you can change it according to your needs. */ diff --git a/frb_example/integrate_third_party/pubspec.lock b/frb_example/integrate_third_party/pubspec.lock index d16de1dc867..f40d1c1ac9c 100644 --- a/frb_example/integrate_third_party/pubspec.lock +++ b/frb_example/integrate_third_party/pubspec.lock @@ -373,10 +373,18 @@ packages: dependency: transitive description: name: logging - sha256: "623a88c9594aa774443aa3eb2d41807a48486b5613e67599fb4c41c0ad47c340" + sha256: c8245ada5f1717ed44271ed1c26b8ce85ca3228fd2ffdb75468ab01979309d61 url: "https://pub.dev" source: hosted - version: "1.2.0" + version: "1.3.0" + macros: + dependency: transitive + description: + name: macros + sha256: "1d9e801cd66f7ea3663c45fc708450db1fa57f988142c64289142c9b7ee80656" + url: "https://pub.dev" + source: hosted + version: "0.1.3-main.0" matcher: dependency: transitive description: diff --git a/frb_example/integrate_third_party/rust/Cargo.lock b/frb_example/integrate_third_party/rust/Cargo.lock index f2848477e73..3f4698c4b35 100644 --- a/frb_example/integrate_third_party/rust/Cargo.lock +++ b/frb_example/integrate_third_party/rust/Cargo.lock @@ -17,15 +17,6 @@ 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.26" @@ -38,20 +29,18 @@ dependencies = [ ] [[package]] -name = "android_log-sys" -version = "0.3.2" +name = "android-tzdata" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84521a3cf562bc62942e294181d9eef17eb38ceb8c68677bc49f144e4c3d4f8d" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" [[package]] -name = "android_logger" -version = "0.15.0" +name = "android_system_properties" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f39be698127218cca460cb624878c9aa4e2b47dba3b277963d2bf00bad263b" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" dependencies = [ - "android_log-sys", - "env_filter", - "log", + "libc", ] [[package]] @@ -105,12 +94,6 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" -[[package]] -name = "bitflags" -version = "2.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b8e56985ec62d17e9c1001dc89c88ecd7dc08e47eba5ec7c29c7b5eeecde967" - [[package]] name = "block-buffer" version = "0.10.4" @@ -165,6 +148,20 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "chrono" +version = "0.4.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c469d952047f47f91b68d1cba3f10d63c11d73e4636f24f08daf0278abf01c4d" +dependencies = [ + "android-tzdata", + "iana-time-zone", + "js-sys", + "num-traits", + "wasm-bindgen", + "windows-link", +] + [[package]] name = "console_error_panic_hook" version = "0.1.7" @@ -175,6 +172,12 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + [[package]] name = "creek" version = "1.2.2" @@ -250,19 +253,6 @@ dependencies = [ "cc", ] -[[package]] -name = "dashmap" -version = "5.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "978747c1d849a7d2ee5e8adc0159961c48fb7e5db2f06af6723b80123bb53856" -dependencies = [ - "cfg-if", - "hashbrown", - "lock_api", - "once_cell", - "parking_lot_core", -] - [[package]] name = "dasp_sample" version = "0.11.0" @@ -299,16 +289,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "env_filter" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "186e05a59d4c50738528153b83b0b0194d3a29507dfec16eccd4b342903397d0" -dependencies = [ - "log", - "regex", -] - [[package]] name = "extend" version = "1.2.0" @@ -337,11 +317,11 @@ name = "flutter_rust_bridge" version = "2.12.0" dependencies = [ "allo-isolate", - "android_logger", "anyhow", "build-target", "bytemuck", "byteorder", + "chrono", "console_error_panic_hook", "dart-sys", "delegate-attr", @@ -350,7 +330,6 @@ dependencies = [ "js-sys", "lazy_static", "log", - "oslog", "portable-atomic", "threadpool", "tokio", @@ -475,12 +454,6 @@ version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" -[[package]] -name = "hashbrown" -version = "0.14.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" - [[package]] name = "hermit-abi" version = "0.3.3" @@ -510,6 +483,30 @@ dependencies = [ "rustfft", ] +[[package]] +name = "iana-time-zone" +version = "0.1.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0c919e5debc312ad217002b8048a17b7d83f80703865bbfcfebb0458b0b27d8" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "log", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + [[package]] name = "js-sys" version = "0.3.69" @@ -537,16 +534,6 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "22edcb39a6fc7e511be7ba578a719af09125391ecde44e0bd61ad3c8e003a4a3" -[[package]] -name = "lock_api" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" -dependencies = [ - "autocfg", - "scopeguard", -] - [[package]] name = "log" version = "0.4.20" @@ -636,30 +623,6 @@ version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" -[[package]] -name = "oslog" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80d2043d1f61d77cb2f4b1f7b7b2295f40507f5f8e9d1c8bf10a1ca5f97a3969" -dependencies = [ - "cc", - "dashmap", - "log", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-targets", -] - [[package]] name = "paste" version = "1.0.15" @@ -726,44 +689,6 @@ dependencies = [ "rustfft", ] -[[package]] -name = "redox_syscall" -version = "0.5.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "928fca9cf2aa042393a8325b9ead81d2f0df4cb12e1e24cef072922ccd99c5af" -dependencies = [ - "bitflags 2.9.1", -] - -[[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 = "rtrb" version = "0.3.1" @@ -833,12 +758,6 @@ version = "1.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eded382c5f5f786b989652c49544c4877d9f015cc22e145a5ea8ea66c2921cd2" -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - [[package]] name = "slab" version = "0.4.9" @@ -928,7 +847,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "798306779e3dc7d5231bd5691f5a813496dc79d3f56bf82e25789f2094e022c3" dependencies = [ "arrayvec", - "bitflags 1.3.2", + "bitflags", "bytemuck", "lazy_static", "log", @@ -1170,65 +1089,60 @@ dependencies = [ ] [[package]] -name = "windows-targets" -version = "0.52.6" +name = "windows-core" +version = "0.61.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +checksum = "c0fdd3ddb90610c7638aa2b3a3ab2904fb9e5cdbecc643ddb3647212781c4ae3" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_gnullvm", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows-implement", + "windows-interface", + "windows-link", + "windows-result", + "windows-strings", ] [[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.6" +name = "windows-implement" +version = "0.60.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" +checksum = "a47fddd13af08290e67f4acabf4b459f647552718f683a7b415d290ac744a836" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] [[package]] -name = "windows_i686_msvc" -version = "0.52.6" +name = "windows-interface" +version = "0.59.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" +checksum = "bd9211b69f8dcdfa817bfd14bf1c97c9188afa36f4750130fcdf3f400eca9fa8" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] [[package]] -name = "windows_x86_64_gnu" -version = "0.52.6" +name = "windows-link" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" +checksum = "5e6ad25900d524eaabdbbb96d20b4311e1e7ae1699af4fb28c17ae66c80d798a" [[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.6" +name = "windows-result" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" +checksum = "56f42bd332cc6c8eac5af113fc0c1fd6a8fd2aa08a0119358686e5160d0586c6" +dependencies = [ + "windows-link", +] [[package]] -name = "windows_x86_64_msvc" -version = "0.52.6" +name = "windows-strings" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" +checksum = "56e6c93f3a0c3b36176cb1327a4958a0353d5d166c2a35cb268ace15e91d3b57" +dependencies = [ + "windows-link", +] diff --git a/frb_example/integrate_third_party/rust/src/lib.rs b/frb_example/integrate_third_party/rust/src/lib.rs index b464c85de89..322b9611499 100644 --- a/frb_example/integrate_third_party/rust/src/lib.rs +++ b/frb_example/integrate_third_party/rust/src/lib.rs @@ -1,3 +1,7 @@ +// AUTO INJECTED BY flutter_rust_bridge. +// The following lines may not be accurate; change them according to your needs. +mod frb_generated; +// END of AUTO INJECTED code + pub mod api; -mod frb_generated; /* AUTO INJECTED BY flutter_rust_bridge. This line may not be accurate, and you can change it according to your needs. */ pub mod third_party; diff --git a/frb_example/pure_dart/frb_generated.h b/frb_example/pure_dart/frb_generated.h index fd4fda24067..f73ee78f563 100644 --- a/frb_example/pure_dart/frb_generated.h +++ b/frb_example/pure_dart/frb_generated.h @@ -18,11 +18,6 @@ typedef struct _Dart_Handle* Dart_Handle; #define CONST_WITH_EXPLICIT_IGNORE_SHOULD_IGNORE 42 -typedef struct benchmark_raw_list_prim_u_8 { - uint8_t *ptr; - int32_t len; -} benchmark_raw_list_prim_u_8; - typedef struct wire_cst_list_prim_u_8_strict { uint8_t *ptr; int32_t len; @@ -2960,6 +2955,11 @@ typedef struct wire_cst_list_sum_with_twin_sync { int32_t len; } wire_cst_list_sum_with_twin_sync; +typedef struct benchmark_raw_list_prim_u_8 { + uint8_t *ptr; + int32_t len; +} benchmark_raw_list_prim_u_8; + typedef struct wire_cst_another_macro_struct_twin_normal { int32_t data; int32_t non_final_data; @@ -3534,14 +3534,6 @@ typedef struct wire_cst_vec_of_primitive_pack_twin_sync { struct wire_cst_list_bool *bool_list; } wire_cst_vec_of_primitive_pack_twin_sync; -void benchmark_raw_void_sync(void); - -struct benchmark_raw_list_prim_u_8 benchmark_raw_new_list_prim_u_8(int32_t len); - -int32_t benchmark_raw_input_bytes(struct benchmark_raw_list_prim_u_8 bytes); - -void benchmark_raw_output_bytes(int64_t port, int32_t message_id, int32_t size); - WireSyncRust2DartDco frbgen_frb_example_pure_dart_wire__crate__api__misc_no_twin_example_a__CONST_ARRAY_TWIN_NORMAL(void); WireSyncRust2DartDco frbgen_frb_example_pure_dart_wire__crate__api__misc_no_twin_example_a__CONST_INT_TWIN_NORMAL(void); @@ -15513,6 +15505,14 @@ struct wire_cst_list_weekdays_twin_normal *frbgen_frb_example_pure_dart_cst_new_ struct wire_cst_list_weekdays_twin_rust_async *frbgen_frb_example_pure_dart_cst_new_list_weekdays_twin_rust_async(int32_t len); struct wire_cst_list_weekdays_twin_sync *frbgen_frb_example_pure_dart_cst_new_list_weekdays_twin_sync(int32_t len); + +void benchmark_raw_void_sync(void); + +struct benchmark_raw_list_prim_u_8 benchmark_raw_new_list_prim_u_8(int32_t len); + +int32_t benchmark_raw_input_bytes(struct benchmark_raw_list_prim_u_8 bytes); + +void benchmark_raw_output_bytes(int64_t port, int32_t message_id, int32_t size); static int64_t dummy_method_to_enforce_bundling(void) { int64_t dummy_var = 0; dummy_var ^= ((int64_t) (void*) frbgen_frb_example_pure_dart_cst_new_box_application_env); 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 59dfa6698f6..b931b46fb7e 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 @@ -43607,49 +43607,6 @@ class RustLibWire implements BaseWire { late final _store_dart_post_cobject = _store_dart_post_cobjectPtr .asFunction(); - void benchmark_raw_void_sync() { - return _benchmark_raw_void_sync(); - } - - late final _benchmark_raw_void_syncPtr = - _lookup>( - 'benchmark_raw_void_sync', - ); - late final _benchmark_raw_void_sync = - _benchmark_raw_void_syncPtr.asFunction(); - - benchmark_raw_list_prim_u_8 benchmark_raw_new_list_prim_u_8(int len) { - return _benchmark_raw_new_list_prim_u_8(len); - } - - late final _benchmark_raw_new_list_prim_u_8Ptr = _lookup< - ffi.NativeFunction>( - 'benchmark_raw_new_list_prim_u_8'); - late final _benchmark_raw_new_list_prim_u_8 = - _benchmark_raw_new_list_prim_u_8Ptr - .asFunction(); - - int benchmark_raw_input_bytes(benchmark_raw_list_prim_u_8 bytes) { - return _benchmark_raw_input_bytes(bytes); - } - - late final _benchmark_raw_input_bytesPtr = _lookup< - ffi.NativeFunction>( - 'benchmark_raw_input_bytes'); - late final _benchmark_raw_input_bytes = _benchmark_raw_input_bytesPtr - .asFunction(); - - void benchmark_raw_output_bytes(int port, int message_id, int size) { - return _benchmark_raw_output_bytes(port, message_id, size); - } - - late final _benchmark_raw_output_bytesPtr = _lookup< - ffi - .NativeFunction>( - 'benchmark_raw_output_bytes'); - late final _benchmark_raw_output_bytes = - _benchmark_raw_output_bytesPtr.asFunction(); - WireSyncRust2DartDco wire__crate__api__misc_no_twin_example_a__CONST_ARRAY_TWIN_NORMAL() { return _wire__crate__api__misc_no_twin_example_a__CONST_ARRAY_TWIN_NORMAL(); @@ -128685,6 +128642,64 @@ class RustLibWire implements BaseWire { _cst_new_list_weekdays_twin_syncPtr.asFunction< ffi.Pointer Function(int)>(); + void benchmark_raw_void_sync() { + return _benchmark_raw_void_sync(); + } + + late final _benchmark_raw_void_syncPtr = + _lookup>( + 'benchmark_raw_void_sync'); + late final _benchmark_raw_void_sync = + _benchmark_raw_void_syncPtr.asFunction(); + + benchmark_raw_list_prim_u_8 benchmark_raw_new_list_prim_u_8( + int len, + ) { + return _benchmark_raw_new_list_prim_u_8( + len, + ); + } + + late final _benchmark_raw_new_list_prim_u_8Ptr = _lookup< + ffi.NativeFunction>( + 'benchmark_raw_new_list_prim_u_8'); + late final _benchmark_raw_new_list_prim_u_8 = + _benchmark_raw_new_list_prim_u_8Ptr + .asFunction(); + + int benchmark_raw_input_bytes( + benchmark_raw_list_prim_u_8 bytes, + ) { + return _benchmark_raw_input_bytes( + bytes, + ); + } + + late final _benchmark_raw_input_bytesPtr = _lookup< + ffi.NativeFunction>( + 'benchmark_raw_input_bytes'); + late final _benchmark_raw_input_bytes = _benchmark_raw_input_bytesPtr + .asFunction(); + + void benchmark_raw_output_bytes( + int port, + int message_id, + int size, + ) { + return _benchmark_raw_output_bytes( + port, + message_id, + size, + ); + } + + late final _benchmark_raw_output_bytesPtr = _lookup< + ffi + .NativeFunction>( + 'benchmark_raw_output_bytes'); + late final _benchmark_raw_output_bytes = + _benchmark_raw_output_bytesPtr.asFunction(); + int dummy_method_to_enforce_bundling() { return _dummy_method_to_enforce_bundling(); } @@ -128706,13 +128721,6 @@ typedef DartDartPostCObjectFnTypeFunction = bool Function( typedef DartPort = ffi.Int64; typedef DartDartPort = int; -final class benchmark_raw_list_prim_u_8 extends ffi.Struct { - external ffi.Pointer ptr; - - @ffi.Int32() - external int len; -} - final class wire_cst_list_prim_u_8_strict extends ffi.Struct { external ffi.Pointer ptr; @@ -132697,6 +132705,13 @@ final class wire_cst_list_sum_with_twin_sync extends ffi.Struct { external int len; } +final class benchmark_raw_list_prim_u_8 extends ffi.Struct { + external ffi.Pointer ptr; + + @ffi.Int32() + external int len; +} + final class wire_cst_another_macro_struct_twin_normal extends ffi.Struct { @ffi.Int32() external int data; diff --git a/frb_example/pure_dart/rust/Cargo.lock b/frb_example/pure_dart/rust/Cargo.lock index 722b062ec70..6da05d17a4a 100644 --- a/frb_example/pure_dart/rust/Cargo.lock +++ b/frb_example/pure_dart/rust/Cargo.lock @@ -17,15 +17,6 @@ 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.26" @@ -45,23 +36,6 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" -[[package]] -name = "android_log-sys" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84521a3cf562bc62942e294181d9eef17eb38ceb8c68677bc49f144e4c3d4f8d" - -[[package]] -name = "android_logger" -version = "0.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f39be698127218cca460cb624878c9aa4e2b47dba3b277963d2bf00bad263b" -dependencies = [ - "android_log-sys", - "env_filter", - "log", -] - [[package]] name = "android_system_properties" version = "0.1.5" @@ -216,19 +190,6 @@ dependencies = [ "cc", ] -[[package]] -name = "dashmap" -version = "5.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "978747c1d849a7d2ee5e8adc0159961c48fb7e5db2f06af6723b80123bb53856" -dependencies = [ - "cfg-if", - "hashbrown", - "lock_api", - "once_cell", - "parking_lot_core", -] - [[package]] name = "delegate-attr" version = "0.3.0" @@ -250,16 +211,6 @@ dependencies = [ "crypto-common", ] -[[package]] -name = "env_filter" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "186e05a59d4c50738528153b83b0b0194d3a29507dfec16eccd4b342903397d0" -dependencies = [ - "log", - "regex", -] - [[package]] name = "errno" version = "0.3.8" @@ -281,7 +232,6 @@ name = "flutter_rust_bridge" version = "2.12.0" dependencies = [ "allo-isolate", - "android_logger", "anyhow", "backtrace", "build-target", @@ -296,7 +246,6 @@ dependencies = [ "js-sys", "lazy_static", "log", - "oslog", "portable-atomic", "threadpool", "tokio", @@ -448,12 +397,6 @@ version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" -[[package]] -name = "hashbrown" -version = "0.14.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" - [[package]] name = "hermit-abi" version = "0.3.3" @@ -522,16 +465,6 @@ version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4cd1a83af159aa67994778be9070f0ae1bd732942279cabb14f86f986a21456" -[[package]] -name = "lock_api" -version = "0.4.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96936507f153605bddfcda068dd804796c84324ed2510809e5b2a624c81da765" -dependencies = [ - "autocfg", - "scopeguard", -] - [[package]] name = "log" version = "0.4.20" @@ -597,30 +530,6 @@ version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" -[[package]] -name = "oslog" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80d2043d1f61d77cb2f4b1f7b7b2295f40507f5f8e9d1c8bf10a1ca5f97a3969" -dependencies = [ - "cc", - "dashmap", - "log", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc838d2a56b5b1a6c25f55575dfc605fabb63bb2365f6c2353ef9159aa69e4a5" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall 0.5.12", - "smallvec", - "windows-targets 0.52.0", -] - [[package]] name = "pin-project-lite" version = "0.2.13" @@ -672,44 +581,6 @@ dependencies = [ "bitflags 1.3.2", ] -[[package]] -name = "redox_syscall" -version = "0.5.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "928fca9cf2aa042393a8325b9ead81d2f0df4cb12e1e24cef072922ccd99c5af" -dependencies = [ - "bitflags 2.4.1", -] - -[[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" @@ -741,12 +612,6 @@ version = "1.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c" -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - [[package]] name = "serde" version = "1.0.193" @@ -787,12 +652,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "smallvec" -version = "1.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8917285742e9f3e1683f0a9c4e6b57960b7314d0b08d30d1ecd426713ee2eee9" - [[package]] name = "syn" version = "2.0.39" @@ -812,7 +671,7 @@ checksum = "7ef1adac450ad7f4b3c28589471ade84f25f731a7a0fe30d71dfa9f60fd808e5" dependencies = [ "cfg-if", "fastrand", - "redox_syscall 0.4.1", + "redox_syscall", "rustix", "windows-sys 0.48.0", ] diff --git a/frb_example/pure_dart/rust/src/lib.rs b/frb_example/pure_dart/rust/src/lib.rs index a94f0a8caf6..bb7ca527f22 100644 --- a/frb_example/pure_dart/rust/src/lib.rs +++ b/frb_example/pure_dart/rust/src/lib.rs @@ -1,6 +1,9 @@ +// AUTO INJECTED BY flutter_rust_bridge. +// The following lines may not be accurate; change them according to your needs. +mod frb_generated; +// END of AUTO INJECTED code + pub mod api; mod auxiliary; mod deliberate_name_conflict; -mod frb_generated; /* AUTO INJECTED BY flutter_rust_bridge. This line may not be accurate, and you can change it according to your needs. */ - pub fn function_at_lib_rs() {} diff --git a/frb_example/pure_dart_pde/rust/Cargo.lock b/frb_example/pure_dart_pde/rust/Cargo.lock index 3f9b2264b7b..0a541863355 100644 --- a/frb_example/pure_dart_pde/rust/Cargo.lock +++ b/frb_example/pure_dart_pde/rust/Cargo.lock @@ -17,15 +17,6 @@ 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.26" @@ -45,23 +36,6 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" -[[package]] -name = "android_log-sys" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84521a3cf562bc62942e294181d9eef17eb38ceb8c68677bc49f144e4c3d4f8d" - -[[package]] -name = "android_logger" -version = "0.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f39be698127218cca460cb624878c9aa4e2b47dba3b277963d2bf00bad263b" -dependencies = [ - "android_log-sys", - "env_filter", - "log", -] - [[package]] name = "android_system_properties" version = "0.1.5" @@ -216,19 +190,6 @@ dependencies = [ "cc", ] -[[package]] -name = "dashmap" -version = "5.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "978747c1d849a7d2ee5e8adc0159961c48fb7e5db2f06af6723b80123bb53856" -dependencies = [ - "cfg-if", - "hashbrown", - "lock_api", - "once_cell", - "parking_lot_core", -] - [[package]] name = "delegate-attr" version = "0.3.0" @@ -250,16 +211,6 @@ dependencies = [ "crypto-common", ] -[[package]] -name = "env_filter" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "186e05a59d4c50738528153b83b0b0194d3a29507dfec16eccd4b342903397d0" -dependencies = [ - "log", - "regex", -] - [[package]] name = "errno" version = "0.3.8" @@ -281,7 +232,6 @@ name = "flutter_rust_bridge" version = "2.12.0" dependencies = [ "allo-isolate", - "android_logger", "anyhow", "backtrace", "build-target", @@ -296,7 +246,6 @@ dependencies = [ "js-sys", "lazy_static", "log", - "oslog", "portable-atomic", "threadpool", "tokio", @@ -448,12 +397,6 @@ version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" -[[package]] -name = "hashbrown" -version = "0.14.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" - [[package]] name = "hermit-abi" version = "0.3.3" @@ -522,16 +465,6 @@ version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4cd1a83af159aa67994778be9070f0ae1bd732942279cabb14f86f986a21456" -[[package]] -name = "lock_api" -version = "0.4.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96936507f153605bddfcda068dd804796c84324ed2510809e5b2a624c81da765" -dependencies = [ - "autocfg", - "scopeguard", -] - [[package]] name = "log" version = "0.4.20" @@ -597,30 +530,6 @@ version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" -[[package]] -name = "oslog" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80d2043d1f61d77cb2f4b1f7b7b2295f40507f5f8e9d1c8bf10a1ca5f97a3969" -dependencies = [ - "cc", - "dashmap", - "log", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc838d2a56b5b1a6c25f55575dfc605fabb63bb2365f6c2353ef9159aa69e4a5" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall 0.5.12", - "smallvec", - "windows-targets 0.52.0", -] - [[package]] name = "pin-project-lite" version = "0.2.13" @@ -672,44 +581,6 @@ dependencies = [ "bitflags 1.3.2", ] -[[package]] -name = "redox_syscall" -version = "0.5.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "928fca9cf2aa042393a8325b9ead81d2f0df4cb12e1e24cef072922ccd99c5af" -dependencies = [ - "bitflags 2.4.1", -] - -[[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" @@ -741,12 +612,6 @@ version = "1.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c" -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - [[package]] name = "serde" version = "1.0.193" @@ -787,12 +652,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "smallvec" -version = "1.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8917285742e9f3e1683f0a9c4e6b57960b7314d0b08d30d1ecd426713ee2eee9" - [[package]] name = "syn" version = "2.0.39" @@ -812,7 +671,7 @@ checksum = "7ef1adac450ad7f4b3c28589471ade84f25f731a7a0fe30d71dfa9f60fd808e5" dependencies = [ "cfg-if", "fastrand", - "redox_syscall 0.4.1", + "redox_syscall", "rustix", "windows-sys 0.48.0", ] diff --git a/frb_example/pure_dart_pde/rust/src/lib.rs b/frb_example/pure_dart_pde/rust/src/lib.rs index 0df02943985..2f696b60092 100644 --- a/frb_example/pure_dart_pde/rust/src/lib.rs +++ b/frb_example/pure_dart_pde/rust/src/lib.rs @@ -1,8 +1,11 @@ // AUTO-GENERATED FROM frb_example/pure_dart, DO NOT EDIT +// AUTO INJECTED BY flutter_rust_bridge. +// The following lines may not be accurate; change them according to your needs. +mod frb_generated; +// END of AUTO INJECTED code + pub mod api; mod auxiliary; mod deliberate_name_conflict; -mod frb_generated; /* AUTO INJECTED BY flutter_rust_bridge. This line may not be accurate, and you can change it according to your needs. */ - pub fn function_at_lib_rs() {} diff --git a/frb_example/rust_ui_counter/Cargo.lock b/frb_example/rust_ui_counter/Cargo.lock index c9866d10e17..e8318663e0d 100644 --- a/frb_example/rust_ui_counter/Cargo.lock +++ b/frb_example/rust_ui_counter/Cargo.lock @@ -17,15 +17,6 @@ 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.26" @@ -38,20 +29,18 @@ dependencies = [ ] [[package]] -name = "android_log-sys" -version = "0.3.2" +name = "android-tzdata" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84521a3cf562bc62942e294181d9eef17eb38ceb8c68677bc49f144e4c3d4f8d" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" [[package]] -name = "android_logger" -version = "0.15.0" +name = "android_system_properties" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f39be698127218cca460cb624878c9aa4e2b47dba3b277963d2bf00bad263b" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" dependencies = [ - "android_log-sys", - "env_filter", - "log", + "libc", ] [[package]] @@ -87,12 +76,6 @@ dependencies = [ "rustc-demangle", ] -[[package]] -name = "bitflags" -version = "2.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b8e56985ec62d17e9c1001dc89c88ecd7dc08e47eba5ec7c29c7b5eeecde967" - [[package]] name = "block-buffer" version = "0.10.4" @@ -141,6 +124,20 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "chrono" +version = "0.4.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c469d952047f47f91b68d1cba3f10d63c11d73e4636f24f08daf0278abf01c4d" +dependencies = [ + "android-tzdata", + "iana-time-zone", + "js-sys", + "num-traits", + "wasm-bindgen", + "windows-link", +] + [[package]] name = "console_error_panic_hook" version = "0.1.7" @@ -151,6 +148,12 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + [[package]] name = "crypto-common" version = "0.1.6" @@ -170,19 +173,6 @@ dependencies = [ "cc", ] -[[package]] -name = "dashmap" -version = "5.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "978747c1d849a7d2ee5e8adc0159961c48fb7e5db2f06af6723b80123bb53856" -dependencies = [ - "cfg-if", - "hashbrown", - "lock_api", - "once_cell", - "parking_lot_core", -] - [[package]] name = "delegate-attr" version = "0.3.0" @@ -204,26 +194,16 @@ dependencies = [ "crypto-common", ] -[[package]] -name = "env_filter" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "186e05a59d4c50738528153b83b0b0194d3a29507dfec16eccd4b342903397d0" -dependencies = [ - "log", - "regex", -] - [[package]] name = "flutter_rust_bridge" version = "2.12.0" dependencies = [ "allo-isolate", - "android_logger", "anyhow", "build-target", "bytemuck", "byteorder", + "chrono", "console_error_panic_hook", "dart-sys", "delegate-attr", @@ -232,7 +212,6 @@ dependencies = [ "js-sys", "lazy_static", "log", - "oslog", "portable-atomic", "threadpool", "tokio", @@ -357,12 +336,6 @@ version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" -[[package]] -name = "hashbrown" -version = "0.14.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" - [[package]] name = "hermit-abi" version = "0.3.3" @@ -407,16 +380,6 @@ version = "0.2.174" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1171693293099992e19cddea4e8b849964e9846f4acee11b3948bcc337be8776" -[[package]] -name = "lock_api" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" -dependencies = [ - "autocfg", - "scopeguard", -] - [[package]] name = "log" version = "0.4.20" @@ -484,30 +447,6 @@ version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" -[[package]] -name = "oslog" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80d2043d1f61d77cb2f4b1f7b7b2295f40507f5f8e9d1c8bf10a1ca5f97a3969" -dependencies = [ - "cc", - "dashmap", - "log", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-targets", -] - [[package]] name = "pin-project-lite" version = "0.2.13" @@ -544,44 +483,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "redox_syscall" -version = "0.5.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "928fca9cf2aa042393a8325b9ead81d2f0df4cb12e1e24cef072922ccd99c5af" -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_frb_example_rust_ui_counter" version = "0.1.0" @@ -601,12 +502,6 @@ version = "1.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eded382c5f5f786b989652c49544c4877d9f015cc22e145a5ea8ea66c2921cd2" -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - [[package]] name = "slab" version = "0.4.9" @@ -616,12 +511,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "smallvec" -version = "1.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8917285742e9f3e1683f0a9c4e6b57960b7314d0b08d30d1ecd426713ee2eee9" - [[package]] name = "syn" version = "2.0.39" @@ -773,62 +662,57 @@ dependencies = [ name = "windows-targets" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +checksum = "c0fdd3ddb90610c7638aa2b3a3ab2904fb9e5cdbecc643ddb3647212781c4ae3" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_gnullvm", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows-implement", + "windows-interface", + "windows-link", + "windows-result", + "windows-strings", ] [[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.6" +name = "windows-implement" +version = "0.60.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" +checksum = "a47fddd13af08290e67f4acabf4b459f647552718f683a7b415d290ac744a836" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] [[package]] -name = "windows_i686_gnullvm" -version = "0.52.6" +name = "windows-interface" +version = "0.59.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" +checksum = "bd9211b69f8dcdfa817bfd14bf1c97c9188afa36f4750130fcdf3f400eca9fa8" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] [[package]] -name = "windows_x86_64_gnu" -version = "0.52.6" +name = "windows-link" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" +checksum = "5e6ad25900d524eaabdbbb96d20b4311e1e7ae1699af4fb28c17ae66c80d798a" [[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.6" +name = "windows-result" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" +checksum = "56f42bd332cc6c8eac5af113fc0c1fd6a8fd2aa08a0119358686e5160d0586c6" +dependencies = [ + "windows-link", +] [[package]] -name = "windows_x86_64_msvc" -version = "0.52.6" +name = "windows-strings" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" +checksum = "56e6c93f3a0c3b36176cb1327a4958a0353d5d166c2a35cb268ace15e91d3b57" +dependencies = [ + "windows-link", +] diff --git a/frb_example/rust_ui_counter/src/lib.rs b/frb_example/rust_ui_counter/src/lib.rs index 028e2a6043f..e3630c0eb0a 100644 --- a/frb_example/rust_ui_counter/src/lib.rs +++ b/frb_example/rust_ui_counter/src/lib.rs @@ -1,4 +1,8 @@ #![allow(clippy::new_without_default)] -pub mod app; +// AUTO INJECTED BY flutter_rust_bridge. +// The following lines may not be accurate; change them according to your needs. mod frb_generated; +// END of AUTO INJECTED code + +pub mod app; diff --git a/frb_example/rust_ui_counter/ui/pubspec.lock b/frb_example/rust_ui_counter/ui/pubspec.lock index d734dcd6c94..d9229f2cde3 100644 --- a/frb_example/rust_ui_counter/ui/pubspec.lock +++ b/frb_example/rust_ui_counter/ui/pubspec.lock @@ -161,6 +161,14 @@ packages: url: "https://pub.dev" source: hosted version: "3.0.0" + logging: + dependency: transitive + description: + name: logging + sha256: c8245ada5f1717ed44271ed1c26b8ce85ca3228fd2ffdb75468ab01979309d61 + url: "https://pub.dev" + source: hosted + version: "1.3.0" matcher: dependency: transitive description: diff --git a/frb_example/rust_ui_todo_list/Cargo.lock b/frb_example/rust_ui_todo_list/Cargo.lock index 3002f69a9b0..abf8772a4fc 100644 --- a/frb_example/rust_ui_todo_list/Cargo.lock +++ b/frb_example/rust_ui_todo_list/Cargo.lock @@ -17,15 +17,6 @@ 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.26" @@ -38,20 +29,18 @@ dependencies = [ ] [[package]] -name = "android_log-sys" -version = "0.3.2" +name = "android-tzdata" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84521a3cf562bc62942e294181d9eef17eb38ceb8c68677bc49f144e4c3d4f8d" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" [[package]] -name = "android_logger" -version = "0.15.0" +name = "android_system_properties" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f39be698127218cca460cb624878c9aa4e2b47dba3b277963d2bf00bad263b" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" dependencies = [ - "android_log-sys", - "env_filter", - "log", + "libc", ] [[package]] @@ -87,12 +76,6 @@ dependencies = [ "rustc-demangle", ] -[[package]] -name = "bitflags" -version = "2.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b8e56985ec62d17e9c1001dc89c88ecd7dc08e47eba5ec7c29c7b5eeecde967" - [[package]] name = "block-buffer" version = "0.10.4" @@ -141,6 +124,20 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "chrono" +version = "0.4.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c469d952047f47f91b68d1cba3f10d63c11d73e4636f24f08daf0278abf01c4d" +dependencies = [ + "android-tzdata", + "iana-time-zone", + "js-sys", + "num-traits", + "wasm-bindgen", + "windows-link", +] + [[package]] name = "console_error_panic_hook" version = "0.1.7" @@ -151,6 +148,12 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + [[package]] name = "crypto-common" version = "0.1.6" @@ -170,19 +173,6 @@ dependencies = [ "cc", ] -[[package]] -name = "dashmap" -version = "5.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "978747c1d849a7d2ee5e8adc0159961c48fb7e5db2f06af6723b80123bb53856" -dependencies = [ - "cfg-if", - "hashbrown", - "lock_api", - "once_cell", - "parking_lot_core", -] - [[package]] name = "delegate-attr" version = "0.3.0" @@ -204,26 +194,16 @@ dependencies = [ "crypto-common", ] -[[package]] -name = "env_filter" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "186e05a59d4c50738528153b83b0b0194d3a29507dfec16eccd4b342903397d0" -dependencies = [ - "log", - "regex", -] - [[package]] name = "flutter_rust_bridge" version = "2.12.0" dependencies = [ "allo-isolate", - "android_logger", "anyhow", "build-target", "bytemuck", "byteorder", + "chrono", "console_error_panic_hook", "dart-sys", "delegate-attr", @@ -232,7 +212,6 @@ dependencies = [ "js-sys", "lazy_static", "log", - "oslog", "portable-atomic", "threadpool", "tokio", @@ -357,12 +336,6 @@ version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" -[[package]] -name = "hashbrown" -version = "0.14.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" - [[package]] name = "hermit-abi" version = "0.3.3" @@ -375,6 +348,30 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +[[package]] +name = "iana-time-zone" +version = "0.1.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0c919e5debc312ad217002b8048a17b7d83f80703865bbfcfebb0458b0b27d8" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "log", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + [[package]] name = "js-sys" version = "0.3.69" @@ -396,16 +393,6 @@ version = "0.2.150" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c" -[[package]] -name = "lock_api" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" -dependencies = [ - "autocfg", - "scopeguard", -] - [[package]] name = "log" version = "0.4.20" @@ -437,6 +424,15 @@ dependencies = [ "adler", ] +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + [[package]] name = "num_cpus" version = "1.16.0" @@ -462,30 +458,6 @@ version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" -[[package]] -name = "oslog" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80d2043d1f61d77cb2f4b1f7b7b2295f40507f5f8e9d1c8bf10a1ca5f97a3969" -dependencies = [ - "cc", - "dashmap", - "log", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-targets", -] - [[package]] name = "pin-project-lite" version = "0.2.13" @@ -522,44 +494,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "redox_syscall" -version = "0.5.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "928fca9cf2aa042393a8325b9ead81d2f0df4cb12e1e24cef072922ccd99c5af" -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_frb_example_rust_ui_todo_list" version = "0.1.0" @@ -579,12 +513,6 @@ version = "1.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eded382c5f5f786b989652c49544c4877d9f015cc22e145a5ea8ea66c2921cd2" -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - [[package]] name = "slab" version = "0.4.9" @@ -594,12 +522,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "smallvec" -version = "1.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8917285742e9f3e1683f0a9c4e6b57960b7314d0b08d30d1ecd426713ee2eee9" - [[package]] name = "syn" version = "2.0.39" @@ -730,65 +652,60 @@ dependencies = [ ] [[package]] -name = "windows-targets" -version = "0.52.6" +name = "windows-core" +version = "0.61.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +checksum = "c0fdd3ddb90610c7638aa2b3a3ab2904fb9e5cdbecc643ddb3647212781c4ae3" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_gnullvm", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows-implement", + "windows-interface", + "windows-link", + "windows-result", + "windows-strings", ] [[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.6" +name = "windows-implement" +version = "0.60.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" +checksum = "a47fddd13af08290e67f4acabf4b459f647552718f683a7b415d290ac744a836" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] [[package]] -name = "windows_i686_msvc" -version = "0.52.6" +name = "windows-interface" +version = "0.59.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" +checksum = "bd9211b69f8dcdfa817bfd14bf1c97c9188afa36f4750130fcdf3f400eca9fa8" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] [[package]] -name = "windows_x86_64_gnu" -version = "0.52.6" +name = "windows-link" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" +checksum = "5e6ad25900d524eaabdbbb96d20b4311e1e7ae1699af4fb28c17ae66c80d798a" [[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.6" +name = "windows-result" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" +checksum = "56f42bd332cc6c8eac5af113fc0c1fd6a8fd2aa08a0119358686e5160d0586c6" +dependencies = [ + "windows-link", +] [[package]] -name = "windows_x86_64_msvc" -version = "0.52.6" +name = "windows-strings" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" +checksum = "56e6c93f3a0c3b36176cb1327a4958a0353d5d166c2a35cb268ace15e91d3b57" +dependencies = [ + "windows-link", +] diff --git a/frb_example/rust_ui_todo_list/src/lib.rs b/frb_example/rust_ui_todo_list/src/lib.rs index 028e2a6043f..e3630c0eb0a 100644 --- a/frb_example/rust_ui_todo_list/src/lib.rs +++ b/frb_example/rust_ui_todo_list/src/lib.rs @@ -1,4 +1,8 @@ #![allow(clippy::new_without_default)] -pub mod app; +// AUTO INJECTED BY flutter_rust_bridge. +// The following lines may not be accurate; change them according to your needs. mod frb_generated; +// END of AUTO INJECTED code + +pub mod app; diff --git a/frb_example/rust_ui_todo_list/ui/pubspec.lock b/frb_example/rust_ui_todo_list/ui/pubspec.lock index f1e9dea0d77..2267d026d3a 100644 --- a/frb_example/rust_ui_todo_list/ui/pubspec.lock +++ b/frb_example/rust_ui_todo_list/ui/pubspec.lock @@ -161,6 +161,14 @@ packages: url: "https://pub.dev" source: hosted version: "3.0.0" + logging: + dependency: transitive + description: + name: logging + sha256: c8245ada5f1717ed44271ed1c26b8ce85ca3228fd2ffdb75468ab01979309d61 + url: "https://pub.dev" + source: hosted + version: "1.3.0" matcher: dependency: transitive description: diff --git a/frb_rust/Cargo.toml b/frb_rust/Cargo.toml index b5a9fdd03cb..45b3b3e2fd9 100644 --- a/frb_rust/Cargo.toml +++ b/frb_rust/Cargo.toml @@ -18,15 +18,22 @@ delegate-attr = "0.3.0" flutter_rust_bridge_macros = { workspace = true } futures = { version = "0.3.29", optional = true } lazy_static = { workspace = true } -log = { version = "0.4", optional = true } +log = { version = "0.4.20", optional = true, features = ["std"] } portable-atomic = { version = "1.8.0", optional = true } uuid = { workspace = true, optional = true } [target.'cfg(not(target_family = "wasm"))'.dependencies] -allo-isolate = { workspace = true, features = ["anyhow", "backtrace", "zero-copy"] } +allo-isolate = { workspace = true, features = [ + "anyhow", + "backtrace", + "zero-copy", +] } dart-sys = { version = "4.1.5", optional = true } threadpool = { version = "1.8.1", optional = true } -tokio = { version = "1.34.0", optional = true, features = ["rt-multi-thread", "sync"] } +tokio = { version = "1.34.0", optional = true, features = [ + "rt-multi-thread", + "sync", +] } [target.'cfg(target_family = "wasm")'.dependencies] bytemuck = "1.11.0" @@ -47,12 +54,6 @@ web-sys = { version = "0.3.58", features = [ "BroadcastChannel", ] } -[target.'cfg(target_os = "android")'.dependencies] -android_logger = { version = "0.15", optional = true } - -[target.'cfg(any(target_os = "ios", target_os = "macos"))'.dependencies] -oslog = { version = "0.2.0", optional = true } - [build-dependencies] build-target = "0.4.0" @@ -75,12 +76,13 @@ default = [ "wasm-start", ] backtrace = ["dep:backtrace", "allo-isolate/backtrace"] +log = ["dep:log", "dep:chrono"] chrono = ["dep:chrono", "allo-isolate/chrono"] dart-opaque = ["dep:dart-sys"] portable-atomic = ["dep:portable-atomic"] rust-async = ["dep:tokio", "dep:futures", "dep:wasm-bindgen-futures"] thread-pool = ["dep:threadpool"] -user-utils = ["dep:android_logger", "dep:oslog"] +user-utils = [] uuid = ["dep:uuid", "allo-isolate/uuid"] wasm-start = ["console_error_panic_hook"] diff --git a/frb_rust/src/for_generated/mod.rs b/frb_rust/src/for_generated/mod.rs index 83d48562338..d7c45a06583 100644 --- a/frb_rust/src/for_generated/mod.rs +++ b/frb_rust/src/for_generated/mod.rs @@ -70,6 +70,8 @@ pub use anyhow; pub use byteorder; #[cfg(target_family = "wasm")] pub use cast::slice_from_byte_buffer; +#[cfg(feature = "log")] +pub use chrono; #[cfg(feature = "rust-async")] pub use futures; #[cfg(target_family = "wasm")] diff --git a/frb_rust/src/lib.rs b/frb_rust/src/lib.rs index 0ce10729448..ae319e0125e 100644 --- a/frb_rust/src/lib.rs +++ b/frb_rust/src/lib.rs @@ -40,6 +40,11 @@ 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; +// needed for testing the logging feature +// in a consuming project's lib.rs this would be +// pub use crate::path_as_specified_by_rust_output::frb_generated; +#[cfg(test)] +use crate::misc::logging::test::mock_frb_generated as frb_generated; pub use crate::misc::panic_backtrace::{CatchUnwindWithBacktrace, PanicBacktrace}; #[cfg(feature = "user-utils")] pub use crate::misc::user_utils::setup_backtrace; diff --git a/frb_rust/src/misc/logging.rs b/frb_rust/src/misc/logging.rs new file mode 100644 index 00000000000..ba118cffdc4 --- /dev/null +++ b/frb_rust/src/misc/logging.rs @@ -0,0 +1,595 @@ +#[allow(clippy::crate_in_macro_def)] +#[macro_export] +macro_rules! enable_frb_logging { + () => { + enable_frb_logging!(name = _default_logger_name(), maxLoglevel = _default_max_log_level(), customLogFunction = _default_log_fn); + }; + (name = $RootLoggerName:expr) => { + enable_frb_logging!(name = $RootLoggerName, maxLoglevel = _default_max_log_level(), customLogFunction = _default_log_fn); + }; + (maxLoglevel = $maxLogLevel:expr) => { + enable_frb_logging!(name = _default_logger_name(), maxLoglevel = $maxLogLevel, customLogFunction = _default_log_fn); + }; + (customLogFunction = $log_fn:expr) => { + enable_frb_logging!(name = _default_logger_name(), maxLoglevel = _default_max_log_level(), customLogFunction = $log_fn); + }; + (name = $RootLoggerName:expr, maxLoglevel = $maxLogLevel:expr) => { + enable_frb_logging!(name = $RootLoggerName, maxLoglevel = $maxLogLevel, customLogFunction = _default_log_fn); + }; + (name = $RootLoggerName:expr, customLogFunction = $log_fn:expr) => { + enable_frb_logging!(name = $RootLoggerName, maxLoglevel = _default_log_fn(), customLogFunction = $log_fn); + }; + (maxLoglevel = $maxLogLevel:expr, customLogFunction = $log_fn:expr) => { + enable_frb_logging!(name = _default_logger_name(), maxLoglevel = $maxLogLevel, customLogFunction = $log_fn); + }; + (name = $RootLoggerName:expr, maxLoglevel = $maxLogLevel:expr, customLogFunction = $log_fn:expr) => { + + fn _default_log_fn (record: MirLogRecord) { + println!("{}", _construct_default_message(record)); + } + fn _construct_default_message(record: MirLogRecord) -> String { + let lang = if record.rust_log {"Rust"} else {"Dart"}; + let line_number = record.line_number.map_or("".to_string(), |number| format!(":{}", number)); + format!("[{} {} @{lang} {}{line_number}] {})", record.timestamp, record.level_name.to_uppercase(), record.logger_name, record.message) + } + + fn _default_logger_name () -> String { + "FRBLogger".to_string() + } + fn _default_max_log_level () -> String { + "INFO".to_string() + } + + #[flutter_rust_bridge::frb(sync)] + #[allow(dead_code)] // used by generated dart code + pub fn root_logger_name() -> String { + $RootLoggerName.to_string() + } + #[flutter_rust_bridge::frb(sync)] + #[allow(dead_code)] // used by generated dart code + pub fn max_log_level() -> String { + $maxLogLevel.to_string() + } + + /// this is the call for logging (from Rust and Dart (as logFn)) + #[flutter_rust_bridge::frb(sync)] + #[allow(dead_code)] // used by generated dart code + pub fn log_fn(record: MirLogRecord) { + ($log_fn(record)); + } + + use flutter_rust_bridge::frb; + use crate::frb_generated::StreamSink; + use $crate::for_generated::chrono; + + #[flutter_rust_bridge::frb(dart_code = " + import 'package:logging/logging.dart'; + + static FRBDartLogger initLogger( + {String? name = 'FRBLogger', + LogLevel maxLogLevel = LogLevel.info, + Function({required MirLogRecord record}) customLogFunction = logFn}) { + //initialize the rust side + int maxLogLevelNumber = maxLogLevel.levelNumberThreshold; + Stream stream = + initializeLog2Dart(maxLogLevel: maxLogLevelNumber); + + // Functions for type conversion for interaction with frb_dart/utils/frb_logging.dart + // Wrap logFn to match `void Function({required dynamic record})` + void Function({required dynamic record}) wrappedLogFn = + ({required dynamic record}) { + // Safely cast `dynamic` record back to `MirLogRecord` for the original `logFn` + logFn(record: record as MirLogRecord); + }; + // Wrap fromDartLogRecord to match `dynamic Function(LogRecord record)` + MirLogRecord Function(LogRecord record) wrappedFromDartLogRecord = + (LogRecord record) { + return MirLogRecord.fromDartLogRecord(record); + }; + // Wrap customLogFunction if provided, to match `void Function({required dynamic record})?` + void Function({required dynamic record})? wrappedCustomLogFunction; + wrappedCustomLogFunction = ({required dynamic record}) { + customLogFunction(record: record as MirLogRecord); + }; + + return FRBDartLogger.initAndGetSingleton( + streamSink: stream, + name: name ?? 'FRBLogger', + logFn: wrappedLogFn, + fromDartLogRecord: wrappedFromDartLogRecord, + maxLogLevel: maxLogLevel, + customLogFunction: wrappedCustomLogFunction, + ); + } + + static FRBDartLogger getLogger([String? name]) { + FRBDartLogger logger; + try { + logger = FRBDartLogger.getLogger(name); + } catch (e) { + logger = FRBLogger.initLogger(name: name); + } + return logger; + } + ")] + pub struct FRBLogger { + #[allow(clippy::crate_in_macro_def)] + pub stream_sink: StreamSink, + } + + impl FRBLogger { + #[allow(clippy::new_without_default)] + #[allow(dead_code)] // needed for frb_code generation, even though it shouldn't be used! + pub fn new() -> FRBLogger { + panic!("Initialize with `final LOGGER = FRBLogger.getLogger();` or `final LOGGER = FRBLogger.initLogger();`"); + } + } + /// uses custom type translation to translate between log::LogLevel and Dart:logging::Level + /// loglevel is represented by a number, so that we don't need to put \import `import 'package:logging/logging.dart';` + /// into the dart preamble in flutter_rust_bridge.yaml + #[allow(dead_code)] // used by generated dart code + pub fn initialize_log_2_dart(log_stream: StreamSink, max_log_level: u16) { + log::set_boxed_logger(Box::new(FRBLogger { + stream_sink: log_stream, + })) + .map(|()| log::set_max_level(from_u16(max_log_level))) + .expect("initialize_log_2_dart is called only once!"); + + // log panics + let prev = std::panic::take_hook(); + std::panic::set_hook(Box::new(move |info| { + log::error!("{}", info); + prev(info); + })); + } + + impl log::Log for FRBLogger { + fn enabled(&self, metadata: &log::Metadata) -> bool { + metadata.level() <= log::max_level() + } + + fn log(&self, record: &log::Record) { + if self.enabled(record.metadata()) { + self.stream_sink + .add(record.into()) + .expect("could not add to stream while sending to dart "); + } + } + + fn flush(&self) { + //no need to flush the StreamSink + } + } + + fn from_u16(level: u16) -> log::LevelFilter { + match level{ + // Level('ALL', 0); + // Level('OFF', 2000); + // Level('FINEST', 300); + // Level('FINER', 400); + // Level('FINE', 500); + 0..=500 => log::LevelFilter::Trace, + // Level('CONFIG', 700); + 501..=700 => log::LevelFilter::Debug, + // Level('INFO', 800); + 701..=800 => log::LevelFilter::Info, + // Level('WARNING', 900); + 801..=900 => log::LevelFilter::Warn, + // Level('SEVERE', 1000); + // Level('SHOUT', 1200); + 901..2000 => log::LevelFilter::Error, + // Level('OFF', 2000); + 2000.. => log::LevelFilter::Off, + } + } + + fn to_u16(value: log::LevelFilter) -> u16 { + match value { + // ALL → value = 0 + log::LevelFilter::Trace => 0, + // FINEST → value = 300. + // FINER → value = 400. + // FINE → value = 500. + // CONFIG → value = 700. + log::LevelFilter::Debug => 700, + // INFO → value = 800. + log::LevelFilter::Info => 800, + // WARNING → value = 900. + log::LevelFilter::Warn => 900, + // SEVERE → value = 1000. + log::LevelFilter::Error => 1000, + // SHOUT → value = 1200. + // OFF → value = 2000. + log::LevelFilter::Off => 2000, + } + } + + /// custom coders for log::LogLevel <-> Dart:logging::Level + #[frb(rust2dart(dart_type = "Level", dart_code = "LogLevel.fromNumber({}).toLoggingLevel()"))] + #[allow(dead_code)] // used by generated dart code + pub fn encode_log_level_filter(level: log::LevelFilter) -> u16 { + to_u16(level) + } + #[frb(dart2rust(dart_type = "Level", dart_code = "{}.value"))] + #[allow(dead_code)] // used by generated dart code + pub fn decode_log_level_filter(level_number: u16) -> log::LevelFilter { + from_u16(level_number) + } + + /// mapping log crate's [Record](https://docs.rs/log/latest/log/struct.Record.html) to dart's Logger [LogRecord](https://pub.dev/documentation/logging/latest/logging/LogRecord-class.html). + /// intermediary struct to avoid Record's lifetimes + #[derive(Clone)] + #[flutter_rust_bridge::frb(dart_code = " + static MirLogRecord fromDartLogRecord(LogRecord record) { + return MirLogRecord( + message: record.message, + levelNumber: record.level.value, + levelName: LogLevel.fromLoggingLevel(record.level).name.toUpperCase(), + timestamp: record.time.toString(), + loggerName: record.loggerName, + rustLog: false, + ); + } + static LogRecord toDartLogRecordFromMir(MirLogRecord record) { + return LogRecord( + LogLevel.fromString(record.levelName).toLoggingLevel(), + record.message, + record.loggerName, + ); + } + LogRecord toDartLogRecord() { + return toDartLogRecordFromMir(this); + } + ")] + pub struct MirLogRecord { + #[allow(dead_code)] // not used, but there for completeness. A custom log function might want to use this. + pub level_number: u16, // The log level encoded. Decode with `LogLevel.fromNumber(x).toLoggingLevel()` in Dart or `from_u16(x) in Rust. : Rust::log::Recod::Level, Dart::Logger::LogRecord::Level + pub level_name: String, // The log level name in upper case. Rust::log::Recod::Level.level().to_string(), Dart::Logger::LogRecord::Level.name + pub message: String, // The String given to the log statement: Rust::log::Recod::args, Dart::Logger::LogRecord::message + pub logger_name: String, // The name of the logger given by `FRBLogger.initLogger(name: "MyClass");`, Rust::log::Recod::target, Dart::Logger::LogRecord::loggerName + pub timestamp: String, // Dart::Logger::LogRecord::time, Rust: chrono::Local::now(), as there is no time record in the log crate's Record + pub rust_log: bool, // true, if the log statement originates from Rust code + #[allow(dead_code)] // not used, but there for completeness. A custom log function might want to use this. + pub module_path: Option, // Rust::log::Recod::module_path, None for Dart + #[allow(dead_code)] // not used, but there for completeness. A custom log function might want to use this. + pub file_name: Option, // Rust::log::Recod::file_name, None for Dart + #[allow(dead_code)] // not used, but there for completeness. A custom log function might want to use this. + pub line_number: Option, // Rust::log::Recod::line_number, None for Dart + } + + impl From<&log::Record<'_>> for MirLogRecord { + fn from(record: &log::Record) -> Self { + Self { + level_number: to_u16(record.level().to_level_filter()), + level_name: record.level().to_string(), + timestamp: chrono::Local::now().to_string(), + message: record.args().to_string(), + logger_name: record.target().into(), + rust_log: true, + module_path: (record.module_path().or_else(|| record.module_path_static())) + .map(|s| s.into()), + file_name: (record.file().or_else(|| record.file_static())).map(|s| s.into()), + line_number: record.line(), + } + } + } + }; +} + +#[cfg(test)] +pub(crate) mod test { + use flutter_rust_bridge_macros as flutter_rust_bridge; + use log::{Level, Log, Metadata, Record}; + + pub mod mock_frb_generated { + use std::sync::{Arc, Mutex}; + // A simple mock for StreamSink for testing + #[derive(Debug, Clone)] + pub struct StreamSink { + pub sent_records: Arc>>, + } + + impl StreamSink { + pub fn new() -> Self { + Self { + sent_records: Arc::new(Mutex::new(Vec::new())), + } + } + + pub fn add(&self, item: T) -> Result<(), crate::Rust2DartSendError> { + self.sent_records.lock().unwrap().push(item); + Ok(()) + } + } + } + #[test] + fn test_default_logger_name() { + enable_frb_logging!(); + assert_eq!(_default_logger_name(), "FRBLogger".to_string()); + } + + #[test] + fn test_default_max_log_level() { + enable_frb_logging!(); + assert_eq!(_default_max_log_level(), "INFO".to_string()); + } + + #[test] + fn test_default_log_fn() { + enable_frb_logging!(); + + let record = MirLogRecord { + level_number: to_u16(log::LevelFilter::Debug), + level_name: "debug".to_string(), + timestamp: chrono::Local::now().to_string(), + message: "Test message".to_string(), + logger_name: "TestLogger".to_string(), + rust_log: true, + module_path: Some("test_module".to_string()), + file_name: Some("test_file.rs".to_string()), + line_number: Some(123), + }; + + // println!("{}", _construct_default_message(record.clone())); + assert!( + _construct_default_message(record).contains("DEBUG @Rust TestLogger:123] Test message") + ); + } + + #[test] + #[should_panic( + expected = "Initialize with `final LOGGER = FRBLogger.getLogger();` or `final LOGGER = FRBLogger.initLogger();`" + )] + fn test_frb_logger_new_panics() { + enable_frb_logging!(); + FRBLogger::new(); + } + + #[test] + fn test_initialize_log_2_dart() { + enable_frb_logging!(); + + // Reset the logger and panic hook for a clean test + // This is crucial because `set_boxed_logger` can only be called once. + // In a real application, you might use a `once_cell` or similar to ensure this. + // For testing, we might need to "reset" the global logger state if possible, + // or ensure tests run in isolation (e.g., with `cargo test -- --test-threads=1`). + // For simplicity here, we'll try to catch a potential panic if already set. + let stream_sink = StreamSink::new(); + let max_log_level = to_u16(log::LevelFilter::Info); + + let result = std::panic::catch_unwind(|| { + initialize_log_2_dart(stream_sink, max_log_level); + }); + + if result.is_err() { + if let Err(err) = result { + if let Some(msg) = err.downcast_ref::<&str>() { + if msg.contains("initialize_log_2_dart is called only once!") { + // This is expected if another test already initialized it. + // To truly test this, you'd need to ensure test isolation + // or use a different testing approach that doesn't rely on global state. + eprintln!("Warning: initialize_log_2_dart already called in another test. This test might not fully cover the `expect` path."); + } else { + panic!("Unexpected panic: {err:?}"); + } + } else { + panic!("Unexpected panic type: {err:?}"); + } + } + } + } + + #[test] + fn test_frb_logger_enabled() { + enable_frb_logging!(); + let stream_sink = StreamSink::new(); + let logger = FRBLogger { stream_sink }; + + // Temporarily set max log level for this test + // NOTE: This modifies global state, which can lead to flaky tests if not carefully managed. + // In a production setup, consider using a logging facade that allows for logger replacement + // or ensure tests run sequentially. + let original_max_level = log::max_level(); + log::set_max_level(log::LevelFilter::Info); + + let metadata_info = Metadata::builder() + .level(Level::Info) + .target("test") + .build(); + let metadata_debug = Metadata::builder() + .level(Level::Debug) + .target("test") + .build(); + let metadata_error = Metadata::builder() + .level(Level::Error) + .target("test") + .build(); + + assert!(logger.enabled(&metadata_info)); + assert!(!logger.enabled(&metadata_debug)); // Debug < Info + assert!(logger.enabled(&metadata_error)); // Error > Info + + log::set_max_level(original_max_level); // Restore original level + } + + #[test] + fn test_frb_logger_log() { + enable_frb_logging!(); + let logger = FRBLogger { + stream_sink: StreamSink::new(), + }; + + // Temporarily set max log level for this test + let original_max_level = log::max_level(); + log::set_max_level(log::LevelFilter::Trace); // Enable all for logging + + let record_info = Record::builder() + .level(Level::Info) + .target("test_target") + .args(format_args!("Test message info")) + .module_path(Some("test_module")) + .file(Some("test_file.rs")) + .line(Some(10)) + .build(); + + let record_debug = Record::builder() + .level(Level::Debug) + .target("test_target_debug") + .args(format_args!("Test message debug")) + .build(); + + logger.log(&record_info); + logger.log(&record_debug); + + let sent_records = logger.stream_sink.sent_records.lock().unwrap(); + assert_eq!(sent_records.len(), 2); + + let record1 = &sent_records[0]; + assert_eq!(record1.level_number, to_u16(log::LevelFilter::Info)); + assert_eq!(record1.message, "Test message info"); + assert_eq!(record1.logger_name, "test_target"); + assert!(record1.rust_log); + assert_eq!(record1.module_path, Some("test_module".to_string())); + assert_eq!(record1.file_name, Some("test_file.rs".to_string())); + assert_eq!(record1.line_number, Some(10)); + + let record2 = &sent_records[1]; + assert_eq!(record2.level_number, to_u16(log::LevelFilter::Debug)); + assert_eq!(record2.message, "Test message debug"); + + log::set_max_level(original_max_level); // Restore original level + } + + #[test] + fn test_frb_logger_flush() { + enable_frb_logging!(); + let stream_sink = StreamSink::new(); + let logger = FRBLogger { stream_sink }; + // This method does nothing, so we just call it to ensure it doesn't panic. + logger.flush(); + } + + #[test] + fn test_from_u16_trace() { + enable_frb_logging!(); + assert_eq!(from_u16(0), log::LevelFilter::Trace); + assert_eq!(from_u16(300), log::LevelFilter::Trace); + assert_eq!(from_u16(500), log::LevelFilter::Trace); + } + + #[test] + fn test_from_u16_debug() { + enable_frb_logging!(); + assert_eq!(from_u16(501), log::LevelFilter::Debug); + assert_eq!(from_u16(700), log::LevelFilter::Debug); + } + + #[test] + fn test_from_u16_info() { + enable_frb_logging!(); + assert_eq!(from_u16(701), log::LevelFilter::Info); + assert_eq!(from_u16(800), log::LevelFilter::Info); + } + + #[test] + fn test_from_u16_warn() { + enable_frb_logging!(); + assert_eq!(from_u16(801), log::LevelFilter::Warn); + assert_eq!(from_u16(900), log::LevelFilter::Warn); + } + + #[test] + fn test_from_u16_error() { + enable_frb_logging!(); + assert_eq!(from_u16(901), log::LevelFilter::Error); + assert_eq!(from_u16(1500), log::LevelFilter::Error); + assert_eq!(from_u16(1999), log::LevelFilter::Error); + } + + #[test] + fn test_from_u16_off() { + enable_frb_logging!(); + assert_eq!(from_u16(2000), log::LevelFilter::Off); + assert_eq!(from_u16(3000), log::LevelFilter::Off); + } + + #[test] + fn test_to_u16_trace() { + enable_frb_logging!(); + assert_eq!(to_u16(log::LevelFilter::Trace), 0); + } + + #[test] + fn test_to_u16_debug() { + enable_frb_logging!(); + assert_eq!(to_u16(log::LevelFilter::Debug), 700); + } + + #[test] + fn test_to_u16_info() { + enable_frb_logging!(); + assert_eq!(to_u16(log::LevelFilter::Info), 800); + } + + #[test] + fn test_to_u16_warn() { + enable_frb_logging!(); + assert_eq!(to_u16(log::LevelFilter::Warn), 900); + } + + #[test] + fn test_to_u16_error() { + enable_frb_logging!(); + assert_eq!(to_u16(log::LevelFilter::Error), 1000); + } + + #[test] + fn test_to_u16_off() { + enable_frb_logging!(); + assert_eq!(to_u16(log::LevelFilter::Off), 2000); + } + + #[test] + fn test_mir_log_record_from_log_record() { + enable_frb_logging!(); + let log_record = Record::builder() + .level(Level::Info) + .target("my_target") + .args(format_args!("Hello, world!")) + .module_path(Some("my_module")) + .file(Some("my_file.rs")) + .line(Some(42)) + .build(); + + let frb_record: MirLogRecord = (&log_record).into(); + + assert_eq!(frb_record.level_number, to_u16(log::LevelFilter::Info)); + assert_eq!(frb_record.message, "Hello, world!"); + assert_eq!(frb_record.logger_name, "my_target"); + assert!(frb_record.rust_log); + assert_eq!(frb_record.module_path, Some("my_module".to_string())); + assert_eq!(frb_record.file_name, Some("my_file.rs".to_string())); + assert_eq!(frb_record.line_number, Some(42)); + } + + #[test] + fn test_mir_log_record_from_log_record_no_optional_fields() { + enable_frb_logging!(); + let log_record = Record::builder() + .level(Level::Warn) + .target("another_target") + .args(format_args!("Simple message")) + .build(); + + let frb_record: MirLogRecord = (&log_record).into(); + + assert_eq!(frb_record.level_number, to_u16(log::LevelFilter::Warn)); + assert_eq!(frb_record.message, "Simple message"); + assert_eq!(frb_record.logger_name, "another_target"); + assert!(frb_record.rust_log); + assert_eq!(frb_record.module_path, None); + assert_eq!(frb_record.file_name, None); + assert_eq!(frb_record.line_number, None); + } +} diff --git a/frb_rust/src/misc/logs.rs b/frb_rust/src/misc/logs.rs index 9e8a99d5d4f..30d54749f6f 100644 --- a/frb_rust/src/misc/logs.rs +++ b/frb_rust/src/misc/logs.rs @@ -6,7 +6,7 @@ pub(crate) fn log_warn_or_println(message: &str) { if log_enabled { #[cfg(feature = "log")] - log::warn!("{}", message); + log::warn!("{message}"); // frb-coverage:ignore-start // this is not reachable, so not coverable #[cfg(not(feature = "log"))] diff --git a/frb_rust/src/misc/mod.rs b/frb_rust/src/misc/mod.rs index f5390d17ec7..e416fa53eb6 100644 --- a/frb_rust/src/misc/mod.rs +++ b/frb_rust/src/misc/mod.rs @@ -1,6 +1,8 @@ pub(crate) mod atomic; pub(crate) mod dart_dynamic; pub(crate) mod into_into_dart; +#[cfg(feature = "log")] +pub(crate) mod logging; pub(crate) mod logs; pub(crate) mod manual_impl; pub(crate) mod panic_backtrace; diff --git a/frb_rust/src/misc/user_utils.rs b/frb_rust/src/misc/user_utils.rs index abf6c57347e..4a0bb630249 100644 --- a/frb_rust/src/misc/user_utils.rs +++ b/frb_rust/src/misc/user_utils.rs @@ -4,8 +4,6 @@ use crate::misc::panic_backtrace::PanicBacktrace; /// Surely, you are free to customize everything. pub fn setup_default_user_utils() { // setup log before others, such that we can see logs in other setup functions - #[cfg(feature = "log")] - setup_log_to_console(log::LevelFilter::Trace); setup_backtrace(); } @@ -22,25 +20,11 @@ pub fn setup_backtrace() { PanicBacktrace::setup(); } -/// Setup platform-specific console logging with the given level filter. -/// -/// # Example -/// -/// ```rust,no_run -/// flutter_rust_bridge::setup_log_to_console( -/// if cfg!(debug_assertions) { log::LevelFilter::Trace } else { log::LevelFilter::Warn } -/// ); -/// ``` -#[cfg(feature = "log")] -pub fn setup_log_to_console(#[allow(unused)] level: log::LevelFilter) { - #[cfg(target_os = "android")] - let _ = android_logger::init_once(android_logger::Config::default().with_max_level(level)); +// TODO: check if web logging requires this setup +// #[cfg(feature = "log")] +// fn setup_log_to_console() { +// #[cfg(target_family = "wasm")] +// let _ = crate::misc::web_utils::WebConsoleLogger::init(); - #[cfg(any(target_os = "ios", target_os = "macos"))] - let _ = oslog::OsLogger::new("frb_user").level_filter(level).init(); - - #[cfg(target_family = "wasm")] - let _ = crate::misc::web_utils::WebConsoleLogger::init(level); - - // TODO add more platforms -} +// // TODO add more platforms +// } diff --git a/frb_rust/src/misc/web_utils.rs b/frb_rust/src/misc/web_utils.rs index 974fa31fe65..a7bf8b094d3 100644 --- a/frb_rust/src/misc/web_utils.rs +++ b/frb_rust/src/misc/web_utils.rs @@ -37,31 +37,32 @@ pub(crate) fn script_path() -> Option { .as_string() } -#[cfg(feature = "log")] -#[derive(Clone, Copy)] -pub(crate) struct WebConsoleLogger; +// TODO check if this is needed for console logging +// #[cfg(feature = "log")] +// #[derive(Clone, Copy)] +// pub(crate) struct WebConsoleLogger; -#[cfg(feature = "log")] -static WEB_CONSOLE_LOGGER: WebConsoleLogger = WebConsoleLogger; +// #[cfg(feature = "log")] +// static WEB_CONSOLE_LOGGER: WebConsoleLogger = WebConsoleLogger; -#[cfg(feature = "log")] -impl WebConsoleLogger { - pub(crate) fn init(level: log::LevelFilter) -> Result<(), log::SetLoggerError> { - log::set_logger(&WEB_CONSOLE_LOGGER).map(|()| log::set_max_level(level)) - } -} +// #[cfg(feature = "log")] +// impl WebConsoleLogger { +// pub(crate) fn init() -> Result<(), log::SetLoggerError> { +// log::set_logger(&WEB_CONSOLE_LOGGER).map(|()| log::set_max_level(log::LevelFilter::Trace)) +// } +// } -#[cfg(feature = "log")] -impl log::Log for WebConsoleLogger { - fn enabled(&self, _metadata: &log::Metadata) -> bool { - true - } +// #[cfg(feature = "log")] +// impl log::Log for WebConsoleLogger { +// fn enabled(&self, _metadata: &log::Metadata) -> bool { +// true +// } - fn log(&self, record: &log::Record) { - if self.enabled(record.metadata()) { - js_console_log(&format!("{} - {}", record.level(), record.args())); - } - } +// fn log(&self, record: &log::Record) { +// if self.enabled(record.metadata()) { +// js_console_log(&format!("{} - {}", record.level(), record.args())); +// } +// } - fn flush(&self) {} -} +// fn flush(&self) {} +// } diff --git a/tools/frb_internal/lib/src/makefile_dart/consts.dart b/tools/frb_internal/lib/src/makefile_dart/consts.dart index 40e15f64694..16e18de24fb 100644 --- a/tools/frb_internal/lib/src/makefile_dart/consts.dart +++ b/tools/frb_internal/lib/src/makefile_dart/consts.dart @@ -5,6 +5,7 @@ import 'package:flutter_rust_bridge_internal/src/utils/makefile_dart_infra.dart' const kRustPackagesAllowWeb = [ 'frb_rust', 'frb_example/dart_minimal/rust', + 'frb_example/dart_logging/rust', 'frb_example/pure_dart/rust', 'frb_example/pure_dart_pde/rust', 'frb_example/dart_build_rs/rust', @@ -30,6 +31,7 @@ const kDartExampleIntegratePackages = [ const kDartExamplePackages = [ 'frb_example/dart_minimal', + 'frb_example/dart_logging', 'frb_example/pure_dart', 'frb_example/pure_dart_pde', 'frb_example/dart_build_rs', @@ -52,6 +54,7 @@ const kDartModeOfPackage = { 'frb_utils': DartMode.dart, 'tools/frb_internal': DartMode.dart, 'frb_example/dart_minimal': DartMode.dart, + 'frb_example/dart_logging': DartMode.dart, 'frb_example/pure_dart': DartMode.dart, 'frb_example/pure_dart_pde': DartMode.dart, 'frb_example/dart_build_rs': DartMode.dart, diff --git a/tools/frb_internal/pubspec.lock b/tools/frb_internal/pubspec.lock index dbe7d3647d3..e0c5b97ebc0 100644 --- a/tools/frb_internal/pubspec.lock +++ b/tools/frb_internal/pubspec.lock @@ -308,10 +308,18 @@ packages: dependency: transitive description: name: logging - sha256: "623a88c9594aa774443aa3eb2d41807a48486b5613e67599fb4c41c0ad47c340" + sha256: c8245ada5f1717ed44271ed1c26b8ce85ca3228fd2ffdb75468ab01979309d61 url: "https://pub.dev" source: hosted - version: "1.2.0" + version: "1.3.0" + macros: + dependency: transitive + description: + name: macros + sha256: "1d9e801cd66f7ea3663c45fc708450db1fa57f988142c64289142c9b7ee80656" + url: "https://pub.dev" + source: hosted + version: "0.1.3-main.0" matcher: dependency: transitive description: diff --git a/website/docs/guides/contributing/overview.md b/website/docs/guides/contributing/overview.md index 87b9597a568..a95c6c39bdc 100644 --- a/website/docs/guides/contributing/overview.md +++ b/website/docs/guides/contributing/overview.md @@ -43,6 +43,7 @@ There is no need to read it word by word, since it serves as a reference to find - `frb_example`: Examples. - `pure_dart`: A pure-Dart example + contains most tests. - `dart_minimal`: Minimalist pure-Dart example. Suitable as a playground. + - `dart_logging`: Minimalist pure-Dart example with logging. - `flutter_via_create` / `flutter_via_integrate`: Examples automatically generated via `flutter_rust_bridge_codegen create/integrate`. - `deliberate_bad`: Deliberately buggy code to check sanitizers catch them. - `frb_dart` (`flutter_rust_bridge` Dart package): Support library for Dart - to be imported by users. @@ -117,7 +118,7 @@ If you want to know more details, here is a table. (Code are adapted to ease understanding, thus it does not reflect actual details.) | Name | Sample Location | Sample code | Source | -|-----------|------------------------------------------------------------------------|-------------------------------------------------------------------|---------------| +| --------- | ---------------------------------------------------------------------- | ----------------------------------------------------------------- | ------------- | | User call | `lib/main.dart` | `print(f('Hello'));` | User provided | | Dart API | `lib/src/rust/api/minimal.dart`,
`lib/src/rust/frb_generated.dart` | `void f(String arg) => wire_f(codec.encode(arg))` | Generated | | Dart Wire | `lib/src/rust/frb_generated.dart` | `void wire_f(char* ptr, int len); /* extern function */` | Generated | diff --git a/website/docs/guides/how-to/logging.md b/website/docs/guides/how-to/logging.md index 87ff3139176..0ebf39e995a 100644 --- a/website/docs/guides/how-to/logging.md +++ b/website/docs/guides/how-to/logging.md @@ -1,89 +1,379 @@ # Logging -Since I have seen some questions asking how logging can be implemented with a Flutter + Rust application, here are some examples. +`flutter_rust_bridge` comes with out-of-the-box logging, but you can override it with your own as well. +More concretely, you can override the log outputting function with the one(s) of your logging framework(s) of choice, which will automatically log statements from Rust as well. -## Approach 1: Use the default one +Under the hood (and in a nutshell) our implementation uses the [Rust 'log' crate](https://crates.io/crates/log) and the [Dart 'logging' package](https://pub.dev/packages/logging), which are maintained by the respective language teams. -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()`. +Log messages are sent via a FRB's Stream implementation from Rust to Dart. -Thus, you do not need to do anything :) +## Setup +### 1. activate logging +Add the macro call `enable_frb_logging!();` in a **Rust** file that is part of your `rust_input` of your `flutter_rust_bridge.yaml` configuration, at any place outside of an item (e.g. function or struct). +You need to make it available via `use flutter_rust_bridge::enable_frb_logging;`. -## Example 2: Print logs to console +It needs to be there so the code generation is picking it up and generates the needed bridge code for connecting Rust and Dart for logging. -```rust -fn setup_the_logger() { - #[cfg(target_os = "android")] - android_logger::init_once(android_logger::Config::default().with_max_level(LevelFilter::Trace)); +If you start a new project and use default values this is all you need to do! +Otherwise read the next steps: - #[cfg(target_os = "ios")] - oslog::OsLogger::new("com.example.test").level_filter(LevelFilter::Trace).init().unwrap(); -} +### 2. add the logging dependency (not needed for new projects) +For a new project (if you prompted `flutter_rust_bridge_codegen create` instead of `flutter_rust_bridge_codegen generate`) the dependency is already added. +Otherwise you need to add a dependency on the logging crate yourself, in your Cargo.toml file with `cargo add log` or by putting `log = "^0.4.20"` in your Cargo.toml file under the `[dependencies]` section. + +### 3. expose the generated code in lib.rs (only if automatic lib.rs configuration is disabled) +Most probably you can skip this step - your generated code might already be available. +Depending on your customization you might need to do this step. + +- I did not set `add_mod_to_lib: false` + - If you did not disabled automatically configuring of your `lib.rs` in your `flutter_rust_bridge.yaml` (with `add_mod_to_lib: false`) you don't have to do anything for this step and can go to the nest one. +- I did set `add_mod_to_lib: false` and + - I did not set `rust_output` to a custom location + - If your lib.rs file contains `mod frb_generated;` you don't need any other changes and can skipp to the next step. + - I set `rust_output` to a custom location + - Additional to setting up the mod sturcture correctly so that `frb_generated` is available to the rust compiler (which you surely did already), you have to import it so the logging code can use it. Thus, add the statement `use crate::rust::output::folder::frb_generated`, where `rust::output::folder` is the path you specified in `rust_output`. + +### (optional) 4. customize the log function +Per default any log output is written to `stdout`, via `println!` in Rust. + +You can provide your own log function, as described further down in `utilize a logging framework`. + +Note that this is needed, if you are developing a _Flutter_ application, as `stdout` is not shown. + +## How to use it + +All logs will be printed to `stdout`. + +You can issue log statements in Rust and Dart by following the usual way done in the respective 3rd party packages: + +In **Rust** simply call `log::info!()` (or any of the [log crate's log levels](https://docs.rs/log/latest/log/enum.Level.html)). + +In **Dart** just follow the usual way of working with a logging framework: Get the logger singleto with a call to `final LOGGER = FRBLogger.getLogger()` or `final LOGGER = FRBDartLogger.getLogger()`. +The latter calls the former, so you can use either. + +To issue a log statement, you then call `LOGGER.info('Hello world');` (or other log levels) on that instance. +Note that in **Rust** code you use the [log crate's log levels](https://docs.rs/log/latest/log/enum.Level.html), while in **Dart** code you use a mixture of those and [Dart's logging package equivalents](https://pub.dev/documentation/logging/latest/logging/Level-class.html). + +All of Dart's logging package log levels are available, but the more exotic ones have been replaced with the more common levels used in Rust: +- FINE -> trace +- CONFIG -> debug +- SEVERE -> error +- SHOUT -> fatal + +While Rust's log crate captures the module, file and line number of the log statement, Dart's logging package does not. +Here it is idiomatic to get a new handle of the logger in each file, and give it a name that tells you where your log statement is originating from. +Usually one calls `final OTHER_LOGGER = Logger("other_logger");` from the library directly, but again, use `final OTHER_LOGGER = FRBLogger.getLogger("other_logger");` instead. + +## Customization + +There are three parameters that can be customized: +1. `name`: Name of the root (=first) logger on the Dart side (default: "FRBLogger"). +2. `maxLoglevel`: Maximum log level to be captured by Rust and Dart (default: "Info"). +3. `customLogFunction` The function to use for logging (default: `println!`). + +You can override the defaults by passing arguments to `enable_frb_logging!();` in your Rust code or `FRBLogger.initLogger()` in your Dart code. +You have the choice in which language you like to do this customization, the result is the same. +The parameter names of these are the same for both languages. +Be aware that while the order doesn't matter in Dart, it matters in the Rust macro call! + +Avoid setting these parameters on both sides (Rust and Dart) at the same time. +The implementation will take the values set in Dart if `FRBLogger.initLogger()` is called before any log statement done via Rust - otherwise, it takes the values set with `enable_frb_logging!();`. +Thus do this preferable in `main.dart`, as a global variable `final LOGGER = FRBLogger.initLogger();`, so no Rust log statement is executed before this setup. + +The call to `FRBLogger.initLogger()` returns the logger singleton, so that a subsequent call to `FRBLogger.getLogger()` is not needed. +Be aware that you need to call `initLogger()` before any call to `getLogger()`, and that you can call `initLogger()` only once - otherwise an exception will be thrown (so we ensure a proper setup). + +In both calls (`.initLogger()` and `.getLogger()`) you can provide a `LoggerName` (which defaults to "FRBLogger"). + +### Change the root logger name + +To change the root logger name, either call `enable_frb_logging!(name = "My Name");` in Rust or `FRBLogger.initLogger(name = "My Name");` in Dart. +If you use the default and instantiate your logger in Dart with a specific name (e.g. `FRBLogger.getLogger("My Logger");`), log statements using this new named logger will display "my logger", but the root logger will retain its default name ("FRBLogger"). +Unless you want to get the root logger (with `FRBLogger.getLogger("FRBLogger")`) you might not notice the difference. + +### Change the log level + +#### via Dart code + +To set the log level filter in the Dart code initialize logging with `FRBLogger.initLogger(maxLoglevel: "WARNING");` (where `newMaxLogLevel` is a mixture of Rust's log levels and [Dart's logging package equivalents](https://pub.dev/documentation/logging/latest/logging/Level-class.html), as described above). +Like anything else, this level will be applied to both, logging statements in Rust and Dart. + +#### via Rust code + +To do the same from your Rust code, you can call `enable_frb_logging!(maxLoglevel: "WARNING");`. +Note that you must use the Dart logging package's log level names as well. + +#### Via an environment variable + +You can set the log level via an environment variable as well. + +Set `LOG_LEVEL=` to a value from the [Dart logging package](https://pub.dev/documentation/logging/latest/logging/Level-class.html). +This will override any programmatically set level. + +### Customize logging output + +Out-of-the-box log messages are sent to _stdout_. If you want to customize the output or replace it with one from a more sophisticated logging framework (e.g. logging to a file), all you need to do is register your custom function for log outputs. + +To do this, set the parameter `customLogFunction`. +This is a `void Function(MirLogRecord)` in Dart and `fn _default_log_fn(record: MirLogRecord)` in Rust. +Instead of a function you can pass a closure as well, in both languages. + +To do so, in your **Dart** code, call +```Dart +FRBLogger.initLogger(customLogFunction: (MirLogRecord record) => {print("This is ${record.level}! ${record.message}")}); +``` +or in your **Rust** code call: +```Rust +enable_frb_logging!( + customLogFunction = (|record: MirLogRecord| { + let lang = if record.rust_log {"Rust"} else {"Dart"}; + let line_number = record.line_number + .map_or("".to_string(), |number| format!(":{}", number)); + format!("[{} {} @{lang} {}{line_number}] {})", record.timestamp, + record.level_name, record.logger_name, record.message) + }) +); ``` +This Rust function is the implemented default. -In other words, use the corresponding platform logger -(https://crates.io/crates/android_logger and https://crates.io/crates/oslog). +Note that your custom log function should be written in the same language where you configure it, i.e. in Dart when using `FRBLogger.initLogger` and in Rust when using `enable_frb_logging!`. -## Example 3: My logger in production +If you specify a custom log function to both calls the Dart function will be used (and the custom function specified in Rust will be ignored).**** -In my own app in production, I use the following strategy for Rust logging: Use normal Rust logging methods, such as `info!` and `debug!` macros. The logs are consumed in two places: They are printed via platform-specific methods (like android Logcat and iOS NSLog), and also use a Stream to send them to the Dart side such that my Dart code and further process are using the same pipeline as normal Dart logs (e.g. save to a file, send to server, etc). +If you are using `FRBLogger.initLogger` (and not `enable_frb_logging!()`) be careful to call this before any `.getLogger()` call! +Otherwise the Rust logger doesn't get initialized correctly. -The *full* code related to logging in my app can be seen here: [#486](https://github.com/fzyzcjy/flutter_rust_bridge/issues/486). +#### utilize a logging framework +The logging support in FRB is intentionally kept low profile, meaning that the logging harness of the language teams (Rust and Dart) are used. +This takes care of dealing with log levels and computing the log message - but not where to write it to. Per default log messages are written to `stdout`. -## Example 4: Send Rust logs to Dart +However, usually this is not enough - you might want to log into a file, a database or another output so you can see log messages from an application inside an emulator or physical device. -@MnlPhlp encapsulates the step-by-step example below into a small Rust package, -such that you can setup Rust-logging-to-Dart in several lines. -Please refer to https://github.com/mnlphlp/flutter_logger for details. +To do so you need to use a logging framework in addition. +Set up the framework as usual and configure its logging function as the custom log function of FRB, as shown above. -## Example 5: A step-by-step guide to send Rust logs to Dart +##### configure the logger package +For example, let's take the Flutter package [logger](https://pub.dev/packages/logger): -Let us implement a simple logging system (adapted from the logging system I use with `flutter_rust_bridge` in my app in production), where Rust code can send logs to Dart code. +1. Add the package to your app, e.g. via `dart pub add logger`. +2. Customize the logging output before any call to `.getLogger`: +```Dart +// import the framework doing the customized output +import 'package:logger/logger.dart'; +// if names are clashing you might have to alias the internally used Logger class. You don't need to add it to your `pubspec.yaml`. +import 'package:logging/logging.dart' as Logging; +// import FRBDartLogger and LogLevel to be used in the customization +import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart'; +``` +(...) +```Dart +late final FRBDartLogger logger; +``` +(...) +```Dart + // setup logging + var frameworkLogger = Logger(); + logger = FRBLogger.initLogger( + name: "StateHandler", + maxLogLevel: LogLevel.debug, + customLogFunction: ({required record}) { + final message = + "[${record.timestamp} ${record.levelName} ${record.rustLog ? "Rust: " : "Dart: "} LoggerName: ${record.loggerName}:${record.lineNumber ?? ""}]\n ${record.message}"; + frameworkLogger.log(_toLoggerLevel(record.levelNumber), message); + }, + ); +``` +The framework requires a log level to be set. Our neutral representation `MirLogRecord` provides a number, which should be mapped to the logging framework's level. +We are implementing this helper function for that: +```Dart +// convert MirLogRecord.levelNumber to logger.level + static Level _toLoggerLevel(int levelNumber) { + switch (levelNumber) { + case <= 1000: + return Level.trace; + case <= 2000: + return Level.debug; + case <= 3000: + return Level.info; + case <= 4000: + return Level.warning; + case <= 5000: + return Level.error; + case <= 6000: + return Level.fatal; + default: + return Level.all; + } + } +``` -The Rust `api.rs`: +#### Anatomie of the log output -```rust -pub struct LogEntry { - pub time_millis: i64, - pub level: i32, - pub tag: String, - pub msg: String, -} +The log function in both languages takes a `MirLogRecord` as parameter: -// Simplified just for demonstration. -// To compile, you need a OnceCell, or Mutex, or RwLock -// Also see https://github.com/fzyzcjy/flutter_rust_bridge/issues/398 -lazy_static! { static ref log_stream_sink: StreamSink; } +`MirLogRecord` combines the information from Dart's [LogRecord](https://pub.dev/documentation/logging/latest/logging/LogRecord-class.html) and Rust's [log::Record](https://docs.rs/log/0.4.22/log/struct.Record.html) as follows -pub fn create_log_stream(s: StreamSink) { - stream_sink = s; +```Rust +pub struct MirLogRecord { + pub level_number: u16, // The log level encoded. Decode with `FRBLogger.logLevelFromNumber(x)` in Dart or `from_u16(x)` in Rust. : `Rust::log::Record::Level`, `Dart::Logger::LogRecord::Level` + pub message: String, // The String given to the log statement: `Rust::log::Record::args`, `Dart::Logger::LogRecord::message` + pub logger_name: String, // The name of the logger given by `FRBLogger.initLogger(name: "MyClass");`, `Rust::log::Record::target`, `Dart::Logger::LogRecord::loggerName` + // pub time: String, // log::Record::?, Dart::Logger::LogRecord::time --> omitted, as there is no time record in the log crate's Record + pub rust_log: bool, // true, if the log statement originates from Rust code + pub module_path: Option, // `Rust::log::Record::module_path`, None for Dart + pub file_name: Option, // `Rust::log::Record::file_name`, None for Dart + pub line_number: Option, // `Rust::log::Record::line_number`, None for Dart } ``` -Now Rust will probably complain at you because `IntoDart` is not implemented for `LogEntry`. This is expected, because `flutter_rust_bridge` will generate this trait implementation for you. -To fix this error you should just rerun `flutter_rust_bridge_codegen`. +### Customize the log target +If you want to use log messages produced by another framework and/or send the log messages to other outputs, like a file, you can do this as well by providing a custom log function as described above. -Generated Dart code: +Here you can use any Dart (or Rust) code, it doesn't need to be a closure, but that might be easier. +Your function only needs to take a single argument of type `LogRecord` as input and return nothing. -```Dart -Stream createLogStream(); +Whatever you provide will be called whenever a log statement is called in Rust or Dart. +If you want to combine multiple targets, like `stdout` and a file, combine them in one function. + +## implementation + +In a nutshell, our implementation uses the Rust [log crate](https://crates.io/crates/log) and the Dart [logging package](https://pub.dev/packages/logging), which are maintained by the respective language teams. + +Log messages are sent via a FRB's Stream implementation from Rust to Dart. + +### Log Levels + +While the Dart logging level names are unusual, they are more fine-granular. +The Rust-side [log levels](https://docs.rs/log/0.4.22/log/enum.LevelFilter.html) are mapped to the Dart-side [log levels](https://pub.dev/documentation/logging/latest/logging/Level-class.html) as follows: + +```Rust + match level { + // Level('ALL', 0); + // Level('OFF', 2000); + // Level('FINEST', 300); + // Level('FINER', 400); + // Level('FINE', 500); + 0..=500 => LevelFilter::Trace, + // Level('CONFIG', 700); + 501..=700 => LevelFilter::Debug, + // Level('INFO', 800); + 701..=800 => LevelFilter::Info, + // Level('WARNING', 900); + 801..=900 => LevelFilter::Warn, + // Level('SEVERE', 1000); + // Level('SHOUT', 1200); + 901..2000 => LevelFilter::Error, + // Level('OFF', 2000); + 2000.. => LevelFilter::Off, + } ``` -Now let us use it in Dart: +However, we replaced the more exotic levels on the Dart side with the more common levels from Rust: +- FINE -> trace +- CONFIG -> debug +- SEVERE -> error +- SHOUT -> fatal + +Thus, when logging from Dart, you can use these levels: +```Dart +enum LogLevel { + /// Maps to `Level.ALL` and integer levels below 300. + all( + level: Level.ALL, + levelNumberThreshold: 300, + ), -```dart -Future setup() async { - createLogStream().listen((event) { - print('log from rust: ${event.level} ${event.tag} ${event.msg} ${event.timeMillis}'); - }); + /// Maps to `Level.FINEST` and integer levels below 400. + finest( + level: Level.FINEST, + levelNumberThreshold: 400, + ), + + /// Maps to `Level.FINER` and integer levels below 500. + finer( + level: Level.FINER, + levelNumberThreshold: 500, + ), + + /// Maps to `Level.FINE` and integer levels below 700. This is typically used for Trace. + trace( + level: Level.FINE, + levelNumberThreshold: 700, + ), + + /// Maps to `Level.CONFIG` and integer levels below 800. This is typically used for Debug. + debug( + level: Level.CONFIG, + levelNumberThreshold: 800, + ), + + /// Maps to `Level.INFO` and integer levels below 900. + info( + level: Level.INFO, + levelNumberThreshold: 900, + ), + + /// Maps to `Level.WARNING` and integer levels below 1000. This is typically used for Warn. + warn( + level: Level.WARNING, + levelNumberThreshold: 1000, + ), + + /// Maps to `Level.SEVERE` and integer levels below 1200. This is typically used for Error. + error( + level: Level.SEVERE, + levelNumberThreshold: 1200, + ), + + /// Maps to `Level.SHOUT` and integer levels below 2000. This is typically used for Fatal/Shout. + fatal( + level: Level.SHOUT, + levelNumberThreshold: 2000, + ), + + /// Maps to `Level.OFF` and integer levels equal to or above 2000. + off( + level: Level.OFF, + levelNumberThreshold: 2000, // Or any value that signifies 'Off' + ); } ``` -And now we can happily log anything in Rust: +As you can see you can define additional levels(`Level(String name, int value)`, stay between 0 and 2000) in Dart. +They will convert to Rust seamlessly. + +### Remarks +#### noop function -```rust -log_stream_sink.add(LogEntry { msg: "hello I am a log from Rust", ... }) +`FRBLogger` exposes a `no-op` function, called `newInstance()`. +This is primarily needed so that the code is picked up for code generation, and not optimized away. +However, if called it panics, reminding that a direct instance of `FRBLogger` is not to be created, instead you need to use `FRBLogger.initLogger()` in your Dart code. + + +## Troubleshooting +### Unrecognized literal: `(/*ERROR*/)` +If you get the error message +``` +Running `(...)/target/debug/flutter_rust_bridge_codegen generate` +thread 'main' panicked at (...)/.cargo/registry/src/index.crates.io-6f17d22bba15001f/syn-2.0.28/src/lit.rs:1095:13: +Unrecognized literal: `(/*ERROR*/)` +``` +the code in the `enable_frb_logging!();` macro has not been expanded correctly - most probably you forgot to add the dependency to `log = "^0.4.20"` in your Cargo.toml file or you passed a syntactically incorrect custom function to the macro. + +### no `StreamSink` in the root +If you get the error message +``` +enable_frb_logging!(); + | ^^^^^^^^^^^^^^^^^^^^^ no `StreamSink` in the root + | + = note: this error originates in the macro `enable_frb_logging` (in Nightly builds, run with -Z macro-backtrace for more info) ``` -Of course, you can implement a logger following the Rust's `log` crate wrapping this raw stream sink, then you can use standard Rust logging mechanisms like `info!`. I did exactly that in my project. +the `StreamSink` is probably not re-exported in your project's `lib.rs`. + +See Step 3 of "setup" how to make the generated code available correctly. + +### no log output in the emulator! +If you are testing a Flutter application in an emulator the output to `stdout` is not visible. +You need to configure a logging plugin to work with, as described above in `utilize a logging framework`. \ No newline at end of file