fzyzcjy / flutter_rust_bridge

Flutter/Dart <-> Rust binding generator, feature-rich, but seamless and simple.
https://fzyzcjy.github.io/flutter_rust_bridge/
MIT License
4.29k stars 301 forks source link

Upgrade Guide from pre-2.0 #2360

Closed dragazo closed 2 weeks ago

dragazo commented 1 month ago

Hi, I've had a flutter app I've been maintaining since pre 2.0 of this package. I'm trying to upgrade to the latest version, but I'm having some issues.

I was previously using this command to generate bindings:

flutter_rust_bridge_codegen \
    --rust-input native/src/api.rs \
    --dart-output lib/bridge_generated.dart \
    --c-output ios/Runner/bridge_generated.h \
    --extra-c-output-path macos/Runner/ \
    --dart-decl-output lib/bridge_definitions.dart \
    --wasm

In the latest version, I noticed it's switched to a sub-command flutter_rust_bridge_codegen generate, which I did. However, there have apparently been a few arg changes. I saw that --extra-c-output-path was renamed to --duplicated-c-output, which I also applied. It looks like --rust-input has also changed, but it conveniently gives directions for updating that part.

However, I cannot seem to find equivalents for --dart-decl-output or --wasm. Do you have an info about this?

I've tried just removing --dart-decl-output and --wasm, which will get past the arg parser, but I then get a File exists (os error 17) error from building:

flutter_rust_bridge_codegen generate --rust-root native/ --rust-input crate::api --dart-output lib/bridge_generated.dart --c-output ios/Runner/bridge_generated.h --duplicated-c-output macos/Runner/ 
[2024-10-21T15:56:14.040Z INFO /home/devin/.cargo/registry/src/index.crates.io-6f17d22bba15001f/flutter_rust_bridge_codegen-2.2.0/src/library/codegen/parser/mir/parser/ty/enum_or_struct.rs:73] Skip parsing enum_or_struct `NamespacedName { namespace: Namespace { joined_path: "crate::api" }, name: "C" }` because of error (e=struct with unit fields are not supported yet, what about using `struct C {}` or `#[frb(opaque)] struct C;` instead)
[2024-10-21T15:56:14.040Z INFO /home/devin/.cargo/registry/src/index.crates.io-6f17d22bba15001f/flutter_rust_bridge_codegen-2.2.0/src/library/codegen/parser/mir/parser/ty/enum_or_struct.rs:73] Skip parsing enum_or_struct `NamespacedName { namespace: Namespace { joined_path: "crate::api" }, name: "EntityState" }` because of error (e=struct with unit fields are not supported yet, what about using `struct EntityState {}` or `#[frb(opaque)] struct EntityState;` instead)
[2024-10-21T15:56:14.040Z INFO /home/devin/.cargo/registry/src/index.crates.io-6f17d22bba15001f/flutter_rust_bridge_codegen-2.2.0/src/library/codegen/parser/mir/parser/ty/enum_or_struct.rs:73] Skip parsing enum_or_struct `NamespacedName { namespace: Namespace { joined_path: "crate::api" }, name: "ProcessState" }` because of error (e=struct with unit fields are not supported yet, what about using `struct ProcessState {}` or `#[frb(opaque)] struct ProcessState;` instead)
[2024-10-21T15:56:14.046Z INFO /home/devin/.cargo/registry/src/index.crates.io-6f17d22bba15001f/flutter_rust_bridge_codegen-2.2.0/src/library/codegen/parser/mir/parser/ty/lifetimeable.rs:52] To handle some types, `enable_lifetime: true` may need to be set. Please visit https://fzyzcjy.github.io/flutter_rust_bridge/guides/lifetimes for more details
[2024-10-21T15:56:14.046Z INFO /home/devin/.cargo/registry/src/index.crates.io-6f17d22bba15001f/flutter_rust_bridge_codegen-2.2.0/src/library/codegen/parser/mir/parser/ty/enum_or_struct.rs:73] Skip parsing enum_or_struct `NamespacedName { namespace: Namespace { joined_path: "crate::api" }, name: "C" }` because of error (e=struct with unit fields are not supported yet, what about using `struct C {}` or `#[frb(opaque)] struct C;` instead)
[2024-10-21T15:56:14.046Z INFO /home/devin/.cargo/registry/src/index.crates.io-6f17d22bba15001f/flutter_rust_bridge_codegen-2.2.0/src/library/codegen/parser/mir/parser/ty/enum_or_struct.rs:73] Skip parsing enum_or_struct `NamespacedName { namespace: Namespace { joined_path: "crate::api" }, name: "EntityState" }` because of error (e=struct with unit fields are not supported yet, what about using `struct EntityState {}` or `#[frb(opaque)] struct EntityState;` instead)
[2024-10-21T15:56:14.046Z INFO /home/devin/.cargo/registry/src/index.crates.io-6f17d22bba15001f/flutter_rust_bridge_codegen-2.2.0/src/library/codegen/parser/mir/parser/ty/enum_or_struct.rs:73] Skip parsing enum_or_struct `NamespacedName { namespace: Namespace { joined_path: "crate::api" }, name: "ProcessState" }` because of error (e=struct with unit fields are not supported yet, what about using `struct ProcessState {}` or `#[frb(opaque)] struct ProcessState;` instead)
[0.4s] Parse  
  └── [0.3s] Cargo expand & syn parse  
  └── [0.0s] Parse HIR  
  └── [0.0s] Parse MIR  
[0.0s] Generate
Error: File exists (os error 17)

I don't have a minimal example, but here's my code (just master branch) if needed: https://github.com/dragazo/phone-iot-2

dragazo commented 1 month ago

I've updated the command to:

flutter_rust_bridge_codegen generate \
    --rust-root native/ \
    --rust-input crate::api \
    --dart-output lib/bridge_generated.dart \
    --c-output ios/Runner/bridge_generated.h \
    --duplicated-c-output macos/Runner/ \
    --enable-lifetime

(I guess lifetimes are not supported by default anymore?)

This fixes the warnings, but I still get a mysterious file exists error:

flutter_rust_bridge_codegen generate --rust-root native/ --rust-input crate::api --dart-output lib/bridge_generated.dart --c-output ios/Runner/bridge_generated.h --duplicated-c-output macos/Runner/ --enable-lifetime 
[0.4s] Parse  
  └── [0.4s] Cargo expand & syn parse  
  └── [0.0s] Parse HIR  
  └── [0.0s] Parse MIR  
[0.0s] Generate
Error: File exists (os error 17)
fzyzcjy commented 1 month ago

Hi, upgrade guide: https://cjycode.com/flutter_rust_bridge/guides/miscellaneous/upgrade/v2

Feel free to ping me if you have any questions after reading it!

fzyzcjy commented 2 weeks ago

Close since this seems to be solved, but feel free to reopen if you have any questions!

github-actions[bot] commented 3 days ago

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new issue.