Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support more attributes ; Add examples ; Fix generated use statement pointing to self ; Fix linter warning avoid_return_types_on_setters ; Reduce number of generated files #2140

Merged
merged 99 commits into from
Jun 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
99 commits
Select commit Hold shift + click to select a range
4f17f9c
chore: attr
fzyzcjy Jun 22, 2024
12ec8d3
chore: more
fzyzcjy Jun 22, 2024
cdc4bd3
refactor: split
fzyzcjy Jun 22, 2024
7adc2e4
more
fzyzcjy Jun 22, 2024
2bbf2c4
more
fzyzcjy Jun 22, 2024
272b46f
more
fzyzcjy Jun 22, 2024
1bc0364
more
fzyzcjy Jun 22, 2024
1248041
feat: macro
fzyzcjy Jun 22, 2024
ee4d43a
more
fzyzcjy Jun 22, 2024
c36e694
more
fzyzcjy Jun 22, 2024
81ed68c
fix: err
fzyzcjy Jun 22, 2024
331c9ed
feat: more
fzyzcjy Jun 22, 2024
1eedd05
chore: empty
fzyzcjy Jun 22, 2024
31ab60f
feat: should
fzyzcjy Jun 22, 2024
1a3a64b
feat: inject
fzyzcjy Jun 22, 2024
540a833
feat: await
fzyzcjy Jun 22, 2024
a52d374
feat: more
fzyzcjy Jun 22, 2024
a2c85d8
chore: more
fzyzcjy Jun 22, 2024
9918700
feat: more
fzyzcjy Jun 22, 2024
bbce3c6
feat: namespace
fzyzcjy Jun 22, 2024
f4f5790
feat: filter
fzyzcjy Jun 22, 2024
110c128
feat: more
fzyzcjy Jun 22, 2024
93894d1
fix: err
fzyzcjy Jun 22, 2024
b17eecc
feat: more
fzyzcjy Jun 22, 2024
1780a4a
fix: err
fzyzcjy Jun 22, 2024
7f63212
feat: empty
fzyzcjy Jun 22, 2024
ac83c29
feat: more
fzyzcjy Jun 22, 2024
f2f428e
feat: more
fzyzcjy Jun 22, 2024
49840c9
feat: more
fzyzcjy Jun 22, 2024
5d5795d
fix: err
fzyzcjy Jun 22, 2024
986d99f
chore: lint
fzyzcjy Jun 22, 2024
d383e0d
feat: more
fzyzcjy Jun 22, 2024
c8e1051
feat: more
fzyzcjy Jun 22, 2024
86f8e85
fix: err
fzyzcjy Jun 22, 2024
1254fa1
feat: more
fzyzcjy Jun 22, 2024
7b5d761
feat: more
fzyzcjy Jun 22, 2024
c9458ac
feat: ir
fzyzcjy Jun 22, 2024
89e8989
feat: more
fzyzcjy Jun 22, 2024
80e59e9
feat: pass
fzyzcjy Jun 22, 2024
552879a
feat: more
fzyzcjy Jun 22, 2024
1da4e0b
Merge branch 'feat/12385' into feat/12392
fzyzcjy Jun 22, 2024
78f16e3
chore: more
fzyzcjy Jun 22, 2024
9ad1083
Merge branch 'master' into feat/12392
fzyzcjy Jun 22, 2024
d964866
chore: empty
fzyzcjy Jun 22, 2024
29455cb
chore: mv, cfg
fzyzcjy Jun 22, 2024
7cffbcc
chore: dir
fzyzcjy Jun 22, 2024
992dd9b
Merge remote-tracking branch 'origin/feat/12392' into feat/12392
fzyzcjy Jun 22, 2024
e9d97c0
chore: yaml
fzyzcjy Jun 22, 2024
224ce1c
fix: err
fzyzcjy Jun 22, 2024
d9f11f1
chore: run macos
fzyzcjy Jun 22, 2024
0b49e26
chore: readme
fzyzcjy Jun 22, 2024
fc6321e
chore: more
fzyzcjy Jun 22, 2024
bdd7ba0
chore: mv
fzyzcjy Jun 22, 2024
953edcd
chore: rust
fzyzcjy Jun 22, 2024
b7d8ad5
chore: codegen
fzyzcjy Jun 22, 2024
6721829
chore: more
fzyzcjy Jun 22, 2024
e4584c1
chore: more
fzyzcjy Jun 22, 2024
66df33e
chore: more
fzyzcjy Jun 22, 2024
db5648d
fix: err
fzyzcjy Jun 22, 2024
a1b275c
chore: codegen
fzyzcjy Jun 22, 2024
62221d7
chore: more
fzyzcjy Jun 22, 2024
d7424ab
feat: setter
fzyzcjy Jun 22, 2024
0339b5c
chore: codegen
fzyzcjy Jun 22, 2024
fdeebb0
chore: codegen
fzyzcjy Jun 22, 2024
4ad8602
fix: err
fzyzcjy Jun 22, 2024
41280e0
chore: cp
fzyzcjy Jun 22, 2024
1f21417
chore: replace
fzyzcjy Jun 22, 2024
339febf
chore: rename
fzyzcjy Jun 22, 2024
afc631f
chore: codegen
fzyzcjy Jun 22, 2024
350c94e
feat: logic
fzyzcjy Jun 22, 2024
7b49dca
feat: more
fzyzcjy Jun 22, 2024
b7c2f53
chore: fmt
fzyzcjy Jun 22, 2024
31b5686
chore: more
fzyzcjy Jun 22, 2024
9867a4c
chore: codegen
fzyzcjy Jun 22, 2024
58b7168
chore: replace
fzyzcjy Jun 22, 2024
7d68a0b
feat: more
fzyzcjy Jun 22, 2024
e693ed2
feat: ci
fzyzcjy Jun 22, 2024
19ad622
fix: err
fzyzcjy Jun 22, 2024
24d46f0
chore: more rename
fzyzcjy Jun 22, 2024
7fa9de7
chore: lint
fzyzcjy Jun 22, 2024
4f03115
feat: simp
fzyzcjy Jun 22, 2024
492c7be
feat: ir and config
fzyzcjy Jun 22, 2024
d4256df
feat: usage
fzyzcjy Jun 22, 2024
53f4420
feat: more
fzyzcjy Jun 22, 2024
35ef519
feat: more
fzyzcjy Jun 22, 2024
d3e6c62
feat: more
fzyzcjy Jun 22, 2024
e7ef862
feat: more
fzyzcjy Jun 22, 2024
20550a3
chore: codegen
fzyzcjy Jun 22, 2024
2ca06c2
chore: rm
fzyzcjy Jun 22, 2024
30e5dad
chore: manual rm
fzyzcjy Jun 22, 2024
d8d8866
Revert "chore: manual rm"
fzyzcjy Jun 22, 2024
759e004
chore: codegen
fzyzcjy Jun 22, 2024
f3c169b
Revert "Revert "chore: manual rm""
fzyzcjy Jun 22, 2024
e034f2b
chore: cp
fzyzcjy Jun 22, 2024
c98f77f
chore: more
fzyzcjy Jun 22, 2024
4952899
feat: more
fzyzcjy Jun 22, 2024
5afc998
chore: more
fzyzcjy Jun 22, 2024
3c5dc5c
chore: more
fzyzcjy Jun 22, 2024
1537b49
chore: lint
fzyzcjy Jun 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
26 changes: 26 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ jobs:
- frb_example--flutter_via_create
- frb_example--flutter_via_integrate
- frb_example--flutter_package
- frb_example--rust_ui_counter--ui
- frb_example--rust_ui_todo_list--ui
exclude:
- { image: windows-2019, package: frb_example--deliberate_bad }
- { image: macos-11, package: frb_example--deliberate_bad }
Expand Down Expand Up @@ -756,6 +758,8 @@ jobs:
package:
- frb_example--flutter_via_create
- frb_example--flutter_package--example
- frb_example--rust_ui_counter--ui
- frb_example--rust_ui_todo_list--ui
# no `frb_example--flutter_via_integrate` since it is similar to `flutter_via_create`
device:
- "pixel"
Expand Down Expand Up @@ -822,6 +826,8 @@ jobs:
package:
- frb_example--flutter_via_create
- frb_example--flutter_package--example
- frb_example--rust_ui_counter--ui
- frb_example--rust_ui_todo_list--ui
# no `frb_example--flutter_via_integrate` since it is similar to `flutter_via_create`
device:
- "iPad (10th generation) Simulator (17.2)"
Expand Down Expand Up @@ -880,6 +886,26 @@ jobs:
platform: linux
package: frb_example--flutter_package--example

- image: windows-2019
platform: windows
package: frb_example--rust_ui_counter--ui
- image: macos-13
platform: macos
package: frb_example--rust_ui_counter--ui
- image: ubuntu-latest
platform: linux
package: frb_example--rust_ui_counter--ui

- image: windows-2019
platform: windows
package: frb_example--rust_ui_todo_list--ui
- image: macos-13
platform: macos
package: frb_example--rust_ui_todo_list--ui
- image: ubuntu-latest
platform: linux
package: frb_example--rust_ui_todo_list--ui

# only slightly test `flutter_via_integrate` since quite similar to `flutter_via_create`
- image: ubuntu-latest
platform: linux
Expand Down
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ exclude = [
"frb_example/pure_dart/rust",
"frb_example/pure_dart_pde/rust",
"frb_example/integrate_third_party/rust",
"frb_example/rust_ui_counter",
"frb_example/rust_ui_todo_list",
]
resolver = "2"

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -231,14 +231,46 @@ impl SseEncode for bool {
}

#[cfg(not(target_family = "wasm"))]
#[path = "frb_generated.io.rs"]
mod io;
mod io {
// This file is automatically generated, so please do not edit it.
// Generated by `flutter_rust_bridge`@ 2.0.0.

// 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")]
#[path = "frb_generated.web.rs"]
mod web;
mod web {
// This file is automatically generated, so please do not edit it.
// Generated by `flutter_rust_bridge`@ 2.0.0.

// 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::*;

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
use crate::codegen::config::internal_config::ControllerInternalConfig;
use crate::codegen::generator::misc::target::TargetOrCommonMap;
use crate::codegen::MetaConfig;
use std::path::{Path, PathBuf};
use std::path::Path;

pub(super) fn parse(
meta_config: &MetaConfig,
rust_crate_dir: &Path,
rust_output_path: &TargetOrCommonMap<PathBuf>,
rust_output_path: &Path,
) -> anyhow::Result<ControllerInternalConfig> {
let watching_paths = vec![
// The whole crate needs to be watched, because e.g. when a struct definition changes
// in a non-input file, it may still cause the generated code to change.
rust_crate_dir.join("src"),
];
let exclude_paths = rust_output_path.clone().into_vec();
let exclude_paths = vec![rust_output_path.to_owned()];

Ok(ControllerInternalConfig {
watch: meta_config.watch,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use crate::codegen::config::internal_config::{
use crate::codegen::config::internal_config_parser::dart_path_parser::DartOutputPathPack;
use crate::codegen::generator::api_dart::internal_config::GeneratorApiDartInternalConfig;
use crate::codegen::generator::codec::structs::CodecMode;
use crate::codegen::generator::misc::target::TargetOrCommonMap;
use crate::codegen::generator::wire::c::internal_config::GeneratorWireCInternalConfig;
use crate::codegen::generator::wire::dart::internal_config::{
DartOutputClassNamePack, GeneratorWireDartDefaultExternalLibraryLoaderInternalConfig,
Expand All @@ -29,7 +28,7 @@ pub(super) struct Args<'a> {
pub rust_crate_dir: &'a Path,
pub dart_output_path_pack: &'a DartOutputPathPack,
pub dart_output_class_name_pack: &'a DartOutputClassNamePack,
pub rust_output_path: &'a TargetOrCommonMap<PathBuf>,
pub rust_output_path: &'a Path,
pub default_stream_sink_codec: CodecMode,
pub default_rust_opaque_codec: RustOpaqueCodecMode,
pub c_output_path: &'a Option<PathBuf>,
Expand Down Expand Up @@ -90,7 +89,7 @@ pub(super) fn parse(args: Args) -> anyhow::Result<GeneratorInternalConfig> {
rust: GeneratorWireRustInternalConfig {
rust_crate_dir: rust_crate_dir.to_owned(),
web_enabled,
rust_output_path: rust_output_path.clone(),
rust_output_path: rust_output_path.to_owned(),
c_symbol_prefix: c_symbol_prefix.clone(),
has_ffigen: full_dep,
default_stream_sink_codec,
Expand All @@ -100,7 +99,7 @@ pub(super) fn parse(args: Args) -> anyhow::Result<GeneratorInternalConfig> {
c: GeneratorWireCInternalConfig {
enable: full_dep,
rust_crate_dir: rust_crate_dir.to_owned(),
rust_output_path: rust_output_path.clone(),
rust_output_path: rust_output_path.to_owned(),
c_output_path: c_output_path.clone(),
c_symbol_prefix,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,9 @@ mod tests {

assert!(result.is_err());
let error = result.err().unwrap();
assert!(error.to_string().contains("rust_output: is wrong:"));
assert!(error
.source()
.unwrap()
.to_string()
.contains("A path for input/output needs to include the file name"));
.contains("Rust output path needs to include the file name."));
Ok(())
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
use crate::codegen::config::internal_config_parser::dart_path_parser::compute_path_map;
use crate::codegen::config::internal_config_parser::rust_path_migrator::ConfigRustRootAndRustInput;
use crate::codegen::generator::misc::target::TargetOrCommonMap;
use crate::codegen::parser::mir::internal_config::RustInputNamespacePack;
use crate::utils::crate_name::CrateName;
use crate::utils::namespace::Namespace;
use crate::utils::path_utils::canonicalize_with_error_message;
use anyhow::Context;
use anyhow::ensure;
use itertools::Itertools;
use std::path::{Path, PathBuf};

pub(super) struct RustInputInfo {
pub rust_crate_dir: PathBuf,
pub third_party_crate_names: Vec<CrateName>,
pub rust_input_namespace_pack: RustInputNamespacePack,
pub rust_output_path: TargetOrCommonMap<PathBuf>,
pub rust_output_path: PathBuf,
}

pub(super) fn compute_rust_path_info(
Expand All @@ -28,7 +26,7 @@ pub(super) fn compute_rust_path_info(
let rust_output_path = compute_rust_output_path(config_rust_output, base_dir, &rust_crate_dir)?;

let rust_output_path_namespace =
Namespace::new_from_rust_crate_path(&rust_output_path.common, &rust_crate_dir)?;
Namespace::new_from_rust_crate_path(&rust_output_path, &rust_crate_dir)?;

Ok(RustInputInfo {
rust_crate_dir,
Expand Down Expand Up @@ -79,12 +77,21 @@ fn compute_rust_output_path(
config_rust_output: &Option<String>,
base_dir: &Path,
rust_crate_dir: &Path,
) -> anyhow::Result<TargetOrCommonMap<PathBuf>> {
let path_common = base_dir.join(
) -> anyhow::Result<PathBuf> {
let ans = base_dir.join(
(config_rust_output.clone().map(PathBuf::from))
.unwrap_or_else(|| fallback_rust_output_path(rust_crate_dir)),
);
compute_path_map(&path_common).context("rust_output: is wrong: ")

// We do not care about codecov for this, since it is just a sanity check warning
// frb-coverage:ignore-start
ensure!(
ans.extension().is_some(),
"Rust output path needs to include the file name."
);
// frb-coverage:ignore-end

Ok(ans)
}

fn fallback_rust_output_path(rust_crate_dir: &Path) -> PathBuf {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,14 @@ fn generate_signature(
) -> String {
let is_static_method = method_info.mode == MirFuncOwnerInfoMethodMode::Static;
let maybe_static = if is_static_method { "static" } else { "" };
let return_type = &api_dart_func.func_return_type;
let (func_params, maybe_accessor) = match func.accessor {
Some(MirFuncAccessorMode::Getter) => ("".to_owned(), "get"),
let (return_type, func_params, maybe_accessor) = match func.accessor {
Some(MirFuncAccessorMode::Getter) => (
api_dart_func.func_return_type.as_ref(),
"".to_owned(),
"get",
),
Some(MirFuncAccessorMode::Setter) => (
"",
// TODO: merge with below
format!(
"({})",
Expand All @@ -245,6 +249,7 @@ fn generate_signature(
"set",
),
None => (
api_dart_func.func_return_type.as_ref(),
format!("({})", compute_params_str(func_params, func.arg_mode)),
"",
),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use crate::codegen::generator::misc::target::TargetOrCommonMap;
use serde::{Deserialize, Serialize};
use std::path::PathBuf;

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub(crate) struct GeneratorWireCInternalConfig {
pub(crate) enable: bool,
pub(crate) rust_crate_dir: PathBuf,
pub(crate) rust_output_path: TargetOrCommonMap<PathBuf>,
pub(crate) rust_output_path: PathBuf,
pub(crate) c_output_path: Option<PathBuf>,
pub(crate) c_symbol_prefix: String,
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
};
use crate::codegen::generator::wire::dart::spec_generator::output_code::WireDartOutputCode;
use crate::codegen::generator::wire::rust::spec_generator::extern_func::ExternFunc;
use crate::codegen::ir::mir::func::MirFuncMode;
use crate::codegen::ir::mir::pack::MirPackComputedCache;
use crate::codegen::misc::GeneratorProgressBarPack;
use crate::library::codegen::generator::wire::dart::spec_generator::misc::ty::WireDartGeneratorMiscTrait;
Expand All @@ -29,6 +30,7 @@
pub(crate) boilerplate: Acc<Vec<WireDartOutputCode>>,
pub(crate) api_impl_normal_functions: Vec<WireDartOutputCode>,
pub(crate) extra_functions: Acc<Vec<WireDartOutputCode>>,
pub(crate) extra_from_parser: Acc<Vec<WireDartOutputCode>>,
}

#[allow(clippy::too_many_arguments)]
Expand Down Expand Up @@ -63,6 +65,11 @@
extra_functions: (cache.distinct_types.iter())
.flat_map(|ty| WireDartGenerator::new(ty.clone(), context).generate_extra_functions())
.collect(),
extra_from_parser: Acc::new_common(vec![WireDartOutputCode {
header: context.mir_pack.extra_dart_output_code.header.clone(),
body: context.mir_pack.extra_dart_output_code.body.clone(),
..Default::default()
}]),
})
}

Expand Down Expand Up @@ -102,7 +109,17 @@

let execute_rust_initializers = (context.mir_pack.funcs_with_impl().iter())
.filter(|f| f.initializer)
.map(|f| format!("await api.{}();\n", f.name_dart_wire()))
.map(|f| {
format!(
"{maybe_await}api.{name}();\n",
maybe_await = if f.mode == MirFuncMode::Normal {
"await "
} else {
""

Check warning on line 118 in frb_codegen/src/library/codegen/generator/wire/dart/spec_generator/misc/mod.rs

View check run for this annotation

Codecov / codecov/patch

frb_codegen/src/library/codegen/generator/wire/dart/spec_generator/misc/mod.rs#L118

Added line #L118 was not covered by tests
},
name = f.name_dart_wire()
)
})
.join("");

let codegen_version = env!("CARGO_PKG_VERSION");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ fn generate_merged_code(spec: &WireDartOutputSpec) -> Acc<WireDartOutputCode> {
);
// add("wire_delegate_functions", &spec.misc.wire_delegate_functions);
add("extra_functions", &spec.misc.extra_functions);
add("extra_from_parser", &spec.misc.extra_from_parser);
add("wire_class", &spec.misc.wire_class);
add("rust2dart", &spec.rust2dart.inner);
add("dart2rust", &spec.dart2rust.inner);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::codegen::generator::codec::structs::CodecMode;
use crate::codegen::generator::misc::target::TargetOrCommonMap;
use crate::codegen::ir::mir::ty::rust_opaque::RustOpaqueCodecMode;
use serde::{Deserialize, Serialize};
use std::path::PathBuf;
Expand All @@ -8,7 +7,7 @@ use std::path::PathBuf;
pub(crate) struct GeneratorWireRustInternalConfig {
pub rust_crate_dir: PathBuf,
pub web_enabled: bool,
pub rust_output_path: TargetOrCommonMap<PathBuf>,
pub rust_output_path: PathBuf,
pub c_symbol_prefix: String,
pub has_ffigen: bool,
pub default_stream_sink_codec: CodecMode,
Expand Down
Loading
Loading