From 6dfb1e5dc21170b6a85878363e7d9781a2aa5282 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Fri, 3 Jan 2025 10:54:15 +0800 Subject: [PATCH 1/9] temp demo --- frb_example/dart_minimal/rust/src/api/minimal.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/frb_example/dart_minimal/rust/src/api/minimal.rs b/frb_example/dart_minimal/rust/src/api/minimal.rs index 517e29973f..402fbdc090 100644 --- a/frb_example/dart_minimal/rust/src/api/minimal.rs +++ b/frb_example/dart_minimal/rust/src/api/minimal.rs @@ -8,3 +8,6 @@ pub fn init_app() { pub fn minimal_adder(a: i32, b: i32) -> i32 { a + b } + +#[frb(opaque)] +pub struct MyOpaqueStruct; From 228faced89d07c3f896db502ca8aa00865ffd3eb Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Fri, 3 Jan 2025 10:59:35 +0800 Subject: [PATCH 2/9] Revert "temp demo" This reverts commit 6dfb1e5dc21170b6a85878363e7d9781a2aa5282. --- frb_example/dart_minimal/rust/src/api/minimal.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/frb_example/dart_minimal/rust/src/api/minimal.rs b/frb_example/dart_minimal/rust/src/api/minimal.rs index 402fbdc090..517e29973f 100644 --- a/frb_example/dart_minimal/rust/src/api/minimal.rs +++ b/frb_example/dart_minimal/rust/src/api/minimal.rs @@ -8,6 +8,3 @@ pub fn init_app() { pub fn minimal_adder(a: i32, b: i32) -> i32 { a + b } - -#[frb(opaque)] -pub struct MyOpaqueStruct; From d00fd7978f6b00439616d1bdcf728429743ffcad Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Fri, 3 Jan 2025 11:00:14 +0800 Subject: [PATCH 3/9] more --- website/docs/manual/troubleshooting.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/website/docs/manual/troubleshooting.md b/website/docs/manual/troubleshooting.md index 591df67589..b8f0fb9e96 100644 --- a/website/docs/manual/troubleshooting.md +++ b/website/docs/manual/troubleshooting.md @@ -141,6 +141,10 @@ Try to uninstall the rust toolchain and install it again from the scratch: Check [the related issue on GitHub](https://github.com/fzyzcjy/flutter_rust_bridge/issues/2348) for the context. +## Warning: unexpected `cfg` condition name: `frb_expand` + +Please refer to [#2425](https://github.com/fzyzcjy/flutter_rust_bridge/issues/2425) for more details. + ## Other problems? Don't hesitate to [open an issue](https://github.com/fzyzcjy/flutter_rust_bridge/issues/new/choose)! I usually reply From 0b0a5bfb24805a91787f8c9ad8eb25525497eb9d Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Fri, 3 Jan 2025 11:04:28 +0800 Subject: [PATCH 4/9] more --- .../src/library/commands/command_runner.rs | 19 ++++++++++++------- frb_codegen/src/library/commands/fvm.rs | 2 +- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/frb_codegen/src/library/commands/command_runner.rs b/frb_codegen/src/library/commands/command_runner.rs index 09955b84f4..c6f8fb93a5 100644 --- a/frb_codegen/src/library/commands/command_runner.rs +++ b/frb_codegen/src/library/commands/command_runner.rs @@ -25,12 +25,12 @@ macro_rules! command_run { let args = $crate::command_args!($($rest)*); $crate::library::commands::command_runner::execute_command($binary, args.iter(), None, None) }}; - ($binary:ident in $pwd:expr, envs = $envs:expr, $($rest:tt)*) => {{ + ($binary:ident in $pwd:expr, options = $options:expr, $($rest:tt)*) => {{ let args = $crate::command_args!($($rest)*); - $crate::library::commands::command_runner::execute_command($binary, args.iter(), $pwd, $envs) + $crate::library::commands::command_runner::execute_command($binary, args.iter(), $pwd, $options) }}; ($binary:ident in $pwd:expr, $($rest:tt)*) => {{ - $crate::command_run!($binary in $pwd, envs = None, $($rest)*) + $crate::command_run!($binary in $pwd, options = None, $($rest)*) }}; ($command:path $([ $($args:expr),* ])?, $($rest:tt)*) => {{ let args = $crate::command_args!($($rest)*); @@ -76,11 +76,11 @@ macro_rules! command_args { pub(crate) fn call_shell( cmd: &[PathBuf], pwd: Option<&Path>, - envs: Option>, + options: Option, ) -> anyhow::Result { let CommandInfo { program, args } = call_shell_info(cmd); let program = &program; - command_run!(program in pwd, envs = envs, *args) + command_run!(program in pwd, options = options, *args) } pub(crate) struct CommandInfo { @@ -108,11 +108,16 @@ pub(crate) fn call_shell_info(cmd: &[PathBuf]) -> CommandInfo { }; } +#[derive(Default)] +pub(crate) struct ExecuteCommandOptions { + pub envs: Option>, +} + pub(crate) fn execute_command<'a>( bin: &str, args: impl IntoIterator, current_dir: Option<&Path>, - envs: Option>, + options: Option, ) -> anyhow::Result { let args = args.into_iter().collect_vec(); let args_display = args.iter().map(|path| path.to_string_lossy()).join(" "); @@ -122,7 +127,7 @@ pub(crate) fn execute_command<'a>( if let Some(current_dir) = current_dir { cmd.current_dir(normalize_windows_unc_path(&path_to_string(current_dir)?)); } - if let Some(envs) = envs { + if let Some(envs) = options.unwrap_or_default().envs { cmd.envs(envs); } diff --git a/frb_codegen/src/library/commands/fvm.rs b/frb_codegen/src/library/commands/fvm.rs index 0151c2df20..2d2e5a6f9c 100644 --- a/frb_codegen/src/library/commands/fvm.rs +++ b/frb_codegen/src/library/commands/fvm.rs @@ -1,5 +1,5 @@ use crate::command_run; -use crate::library::commands::command_runner::call_shell; +use crate::library::commands::command_runner::{call_shell, execute_command}; use std::path::Path; pub(crate) fn command_arg_maybe_fvm(pwd: Option<&Path>) -> Option { From f4e28d04bbe895e2cf9a8772955a7392a388b5f6 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Fri, 3 Jan 2025 11:05:43 +0800 Subject: [PATCH 5/9] more --- .../src/library/commands/cargo_expand/real.rs | 13 ++++++++++--- .../src/library/commands/dart_build_runner.rs | 3 ++- frb_codegen/src/library/commands/ffigen.rs | 3 ++- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/frb_codegen/src/library/commands/cargo_expand/real.rs b/frb_codegen/src/library/commands/cargo_expand/real.rs index 6472d036bb..1fbf6e1304 100644 --- a/frb_codegen/src/library/commands/cargo_expand/real.rs +++ b/frb_codegen/src/library/commands/cargo_expand/real.rs @@ -1,7 +1,7 @@ use crate::codegen::dumper::Dumper; use crate::codegen::ConfigDumpContent; use crate::command_args; -use crate::library::commands::command_runner::execute_command; +use crate::library::commands::command_runner::{execute_command, ExecuteCommandOptions}; use crate::utils::crate_name::CrateName; use anyhow::{bail, Context, Result}; use itertools::Itertools; @@ -92,8 +92,15 @@ fn run_raw( )] .into(); - let output = execute_command("cargo", &args, Some(rust_crate_dir), Some(extra_env)) - .with_context(|| format!("Could not expand rust code at path {rust_crate_dir:?}"))?; + let output = execute_command( + "cargo", + &args, + Some(rust_crate_dir), + Some(ExecuteCommandOptions { + envs: Some(extra_env), + }), + ) + .with_context(|| format!("Could not expand rust code at path {rust_crate_dir:?}"))?; let stdout = String::from_utf8(output.stdout)?; let stderr = String::from_utf8(output.stderr)?; diff --git a/frb_codegen/src/library/commands/dart_build_runner.rs b/frb_codegen/src/library/commands/dart_build_runner.rs index e419f5e5b0..158fe32c32 100644 --- a/frb_codegen/src/library/commands/dart_build_runner.rs +++ b/frb_codegen/src/library/commands/dart_build_runner.rs @@ -1,5 +1,6 @@ use crate::command_run; use crate::commands::command_runner::call_shell; +use crate::library::commands::command_runner::ExecuteCommandOptions; use crate::library::commands::fvm::command_arg_maybe_fvm; use crate::utils::dart_repository::dart_repo::DartRepository; use anyhow::bail; @@ -12,7 +13,7 @@ pub fn dart_build_runner(dart_root: &Path) -> anyhow::Result<()> { let repo = DartRepository::from_path(dart_root)?; let out = command_run!( - call_shell[Some(dart_root), Some(dart_run_extra_env())], + call_shell[Some(dart_root), Some(ExecuteCommandOptions{envs:Some(dart_run_extra_env())})], ?command_arg_maybe_fvm(Some(dart_root)), *repo.toolchain.as_run_command(), *repo.command_extra_args(), diff --git a/frb_codegen/src/library/commands/ffigen.rs b/frb_codegen/src/library/commands/ffigen.rs index b165b7faee..4e4a0917cc 100644 --- a/frb_codegen/src/library/commands/ffigen.rs +++ b/frb_codegen/src/library/commands/ffigen.rs @@ -1,6 +1,7 @@ use super::dart_build_runner::dart_run_extra_env; use crate::command_run; use crate::commands::command_runner::call_shell; +use crate::library::commands::command_runner::ExecuteCommandOptions; use crate::utils::dart_repository::dart_repo::DartRepository; use anyhow::bail; use itertools::Itertools; @@ -78,7 +79,7 @@ pub(crate) fn ffigen_raw(config: &FfigenCommandConfig, dart_root: &Path) -> anyh let repo = DartRepository::from_path(dart_root).unwrap(); let res = command_run!( - call_shell[Some(dart_root), Some(dart_run_extra_env())], + call_shell[Some(dart_root), Some(ExecuteCommandOptions{envs:Some(dart_run_extra_env())})], *repo.toolchain.as_run_command(), *repo.command_extra_args(), "run", From 5d9d21ab219f029d30ec191c4cece661298907fd Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Fri, 3 Jan 2025 11:07:04 +0800 Subject: [PATCH 6/9] more --- .../src/library/commands/command_runner.rs | 19 ++++++++++++------- frb_codegen/src/library/commands/fvm.rs | 6 ++++-- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/frb_codegen/src/library/commands/command_runner.rs b/frb_codegen/src/library/commands/command_runner.rs index c6f8fb93a5..c6260e0d1c 100644 --- a/frb_codegen/src/library/commands/command_runner.rs +++ b/frb_codegen/src/library/commands/command_runner.rs @@ -111,6 +111,7 @@ pub(crate) fn call_shell_info(cmd: &[PathBuf]) -> CommandInfo { #[derive(Default)] pub(crate) struct ExecuteCommandOptions { pub envs: Option>, + pub log_when_error: Option, } pub(crate) fn execute_command<'a>( @@ -119,6 +120,8 @@ pub(crate) fn execute_command<'a>( current_dir: Option<&Path>, options: Option, ) -> anyhow::Result { + let options = options.unwrap_or_default(); + let args = args.into_iter().collect_vec(); let args_display = args.iter().map(|path| path.to_string_lossy()).join(" "); let mut cmd = Command::new(bin); @@ -127,7 +130,7 @@ pub(crate) fn execute_command<'a>( if let Some(current_dir) = current_dir { cmd.current_dir(normalize_windows_unc_path(&path_to_string(current_dir)?)); } - if let Some(envs) = options.unwrap_or_default().envs { + if let Some(envs) = options.envs { cmd.envs(envs); } @@ -155,12 +158,14 @@ pub(crate) fn execute_command<'a>( // frb-coverage:ignore-end } } else { - warn!( - "command={:?} stdout={} stderr={}", - cmd, - stdout, - String::from_utf8_lossy(&result.stderr) - ); + if options.log_when_error.unwrap_or(true) { + warn!( + "command={:?} stdout={} stderr={}", + cmd, + stdout, + String::from_utf8_lossy(&result.stderr) + ); + } } Ok(result) } diff --git a/frb_codegen/src/library/commands/fvm.rs b/frb_codegen/src/library/commands/fvm.rs index 2d2e5a6f9c..622c02d6c8 100644 --- a/frb_codegen/src/library/commands/fvm.rs +++ b/frb_codegen/src/library/commands/fvm.rs @@ -1,5 +1,7 @@ use crate::command_run; -use crate::library::commands::command_runner::{call_shell, execute_command}; +use crate::library::commands::command_runner::{ + call_shell, execute_command, ExecuteCommandOptions, +}; use std::path::Path; pub(crate) fn command_arg_maybe_fvm(pwd: Option<&Path>) -> Option { @@ -34,6 +36,6 @@ fn has_fvmrc(pwd: &Path) -> bool { #[allow(clippy::vec_init_then_push)] fn has_fvm_installation() -> bool { - command_run!(call_shell[None, None], "fvm", "--version") + command_run!(call_shell[None, Some(ExecuteCommandOptions { log_when_error: Some(false), ..Default::default() })], "fvm", "--version") .map_or(false, |res| res.status.success()) } From d83bd5bf878f6c08399a88db9c22a8e6dde03e9b Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Fri, 3 Jan 2025 11:07:12 +0800 Subject: [PATCH 7/9] more --- frb_codegen/src/library/commands/fvm.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/frb_codegen/src/library/commands/fvm.rs b/frb_codegen/src/library/commands/fvm.rs index 622c02d6c8..cf9b976fe0 100644 --- a/frb_codegen/src/library/commands/fvm.rs +++ b/frb_codegen/src/library/commands/fvm.rs @@ -1,7 +1,5 @@ use crate::command_run; -use crate::library::commands::command_runner::{ - call_shell, execute_command, ExecuteCommandOptions, -}; +use crate::library::commands::command_runner::{call_shell, ExecuteCommandOptions}; use std::path::Path; pub(crate) fn command_arg_maybe_fvm(pwd: Option<&Path>) -> Option { From 8ded8c2bc08acc280a385f5dd79c489fcab4b2f3 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Fri, 3 Jan 2025 11:12:35 +0800 Subject: [PATCH 8/9] more --- frb_codegen/src/library/commands/cargo_expand/real.rs | 1 + frb_codegen/src/library/commands/dart_build_runner.rs | 5 ++++- frb_codegen/src/library/commands/ffigen.rs | 5 ++++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/frb_codegen/src/library/commands/cargo_expand/real.rs b/frb_codegen/src/library/commands/cargo_expand/real.rs index 1fbf6e1304..ab31421842 100644 --- a/frb_codegen/src/library/commands/cargo_expand/real.rs +++ b/frb_codegen/src/library/commands/cargo_expand/real.rs @@ -98,6 +98,7 @@ fn run_raw( Some(rust_crate_dir), Some(ExecuteCommandOptions { envs: Some(extra_env), + ..Default::default() }), ) .with_context(|| format!("Could not expand rust code at path {rust_crate_dir:?}"))?; diff --git a/frb_codegen/src/library/commands/dart_build_runner.rs b/frb_codegen/src/library/commands/dart_build_runner.rs index 158fe32c32..017d2e9955 100644 --- a/frb_codegen/src/library/commands/dart_build_runner.rs +++ b/frb_codegen/src/library/commands/dart_build_runner.rs @@ -13,7 +13,10 @@ pub fn dart_build_runner(dart_root: &Path) -> anyhow::Result<()> { let repo = DartRepository::from_path(dart_root)?; let out = command_run!( - call_shell[Some(dart_root), Some(ExecuteCommandOptions{envs:Some(dart_run_extra_env())})], + call_shell[Some(dart_root), Some(ExecuteCommandOptions { + envs: Some(dart_run_extra_env()), + ..Default::default() + })], ?command_arg_maybe_fvm(Some(dart_root)), *repo.toolchain.as_run_command(), *repo.command_extra_args(), diff --git a/frb_codegen/src/library/commands/ffigen.rs b/frb_codegen/src/library/commands/ffigen.rs index 4e4a0917cc..8ac5be6811 100644 --- a/frb_codegen/src/library/commands/ffigen.rs +++ b/frb_codegen/src/library/commands/ffigen.rs @@ -79,7 +79,10 @@ pub(crate) fn ffigen_raw(config: &FfigenCommandConfig, dart_root: &Path) -> anyh let repo = DartRepository::from_path(dart_root).unwrap(); let res = command_run!( - call_shell[Some(dart_root), Some(ExecuteCommandOptions{envs:Some(dart_run_extra_env())})], + call_shell[Some(dart_root), Some(ExecuteCommandOptions { + envs: Some(dart_run_extra_env()), + ..Default::default() + })], *repo.toolchain.as_run_command(), *repo.command_extra_args(), "run", From 6f9f6384d6ffd7c102ff5c4881b4cdd3246de2a6 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Fri, 3 Jan 2025 11:35:17 +0800 Subject: [PATCH 9/9] lint --- .../src/library/commands/command_runner.rs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/frb_codegen/src/library/commands/command_runner.rs b/frb_codegen/src/library/commands/command_runner.rs index c6260e0d1c..425dfa5bf2 100644 --- a/frb_codegen/src/library/commands/command_runner.rs +++ b/frb_codegen/src/library/commands/command_runner.rs @@ -157,15 +157,13 @@ pub(crate) fn execute_command<'a>( warn!("See keywords such as `error` in command output. Maybe there is a problem? command={:?} stdout={:?}", cmd, stdout); // frb-coverage:ignore-end } - } else { - if options.log_when_error.unwrap_or(true) { - warn!( - "command={:?} stdout={} stderr={}", - cmd, - stdout, - String::from_utf8_lossy(&result.stderr) - ); - } + } else if options.log_when_error.unwrap_or(true) { + warn!( + "command={:?} stdout={} stderr={}", + cmd, + stdout, + String::from_utf8_lossy(&result.stderr) + ); } Ok(result) }