fzyzcjy / flutter_rust_bridge

Flutter/Dart <-> Rust binding generator, feature-rich, but seamless and simple.

Home Page:https://fzyzcjy.github.io/flutter_rust_bridge/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Formatting of Generated Code is Ugly

MatthewLM opened this issue · comments

Describe the bug

When generating code using 2.0.0-dev.28, the output of rust_ffi.g.dart is ugly with weird indentation. A example snippet:

@freezed
                 class CustomError with _$CustomError implements FrbException {
                     const factory CustomError.error0(  String field0,) = CustomError_Error0;
 const factory CustomError.error1(  int field0,) = CustomError_Error1;
                }

Steps to reproduce

Use flutter_rust_bridge_codegen = "=2.0.0-dev.28" as a build dependency and generate for the following code:

pub enum CustomError {
    Error0(String),
    Error1(u32),
}

pub fn return_err_custom_error() -> Result<u32, CustomError> {
    Err(CustomError::Error1(3))
}

I generated using build.rs:

use lib_flutter_rust_bridge_codegen::codegen;
use lib_flutter_rust_bridge_codegen::codegen::Config;
use anyhow;

fn main() -> anyhow::Result<()> {
  // Tell Cargo that if the input Rust code changes, rerun this build script
  println!("cargo:rerun-if-changed=src/api");

  codegen::generate(
    Config::from_config_file("./flutter_rust_bridge.yaml")?.unwrap(),
    Default::default(),
  )

}

Configuration is uncomplicated:

rust_input: src/api/**/*.rs
dart_output: ../libtest/lib/src/rust_bindings/
local: true

Logs

Cannot do right now sorry. Probably doesn't matter.

Expected behavior

No response

Generated binding code

No response

OS

Linux Debian 12

Version of flutter_rust_bridge_codegen

2.0.0-dev.28

Flutter info

No response

Version of clang++

No response

Additional context

No response

Hi, could you please paste the full codegen logs? (I suspect there may be some warnings) In addition, if you use command line instead of build.rs, does this problem still occurs?

I ran with cargo build and when I generated into an empty directory, there are no warnings and curiously no rust_ffi.g.dart generated. The generated files are OK:

        ▾ api/
            main.dart
            main.freezed.dart
          frb_generated.dart
          frb_generated.io.dart
          frb_generated.web.dart

I tried generating into the previous v1 directory again and rust_ffi.g.dart wasn't changed this time, so I don't know how that got corrupted previously. I suppose it's prudent to ask people to remove all v1 generated files before running v2.

No issue using flutter_rust_bridge_codegen generate either, so not sure what happened before.

I suppose it's prudent to ask people to remove all v1 generated files before running v2.

Looks reasonable! Feel free to PR to modify https://cjycode.com/flutter_rust_bridge/guides/miscellaneous/upgrade/v2