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

Issue with flutter_rust_bridge_codegen after updating Rust code #2462

Closed
joe-ton opened this issue Dec 20, 2024 · 6 comments
Closed

Issue with flutter_rust_bridge_codegen after updating Rust code #2462

joe-ton opened this issue Dec 20, 2024 · 6 comments
Labels
awaiting Waiting for responses, PR, further discussions, upstream release, etc bug Something isn't working

Comments

@joe-ton
Copy link

joe-ton commented Dec 20, 2024

Describe the bug

First, I would like to express my appreciation for all the work you and the team have put into flutter_rust_bridge. I’m excited about the direction this project is heading and the possibilities it opens up for seamless integration between Rust and Flutter.

Issue Description:
I am encountering an error when running flutter_rust_bridge_codegen generate after making changes to my Rust code. Despite following the recommended crate-based syntax (e.g., using --rust-input crate:: and --rust-root), the code generator fails to produce the expected output. I have also attempted to remove any stale generated files (e.g., frb_generated.rs) and re-run the code generation with various configurations, but the issue persists.

Steps to reproduce

  1. I have a Flutter project in /app/ and a Rust crate under /app/rust/.
  2. My Rust functions are defined in rust/src/lib.rs and rust/src/api/simple.rs.
  3. I run the following command:

flutter_rust_bridge_codegen generate
--rust-root rust
--rust-input crate::
--dart-output lib/src/rust/frb_generated.dart
--rust-output rust/src/frb_generated.rs
--watch

After making changes to the Rust functions, the code generator either fails with a “prefix not found” error or does not properly generate the updated bindings. The output would look like this:

Error: When compute_mod_from_rust_path(code_path="C:\Users\joett\code\projects\SyncUp\app\rust/src/frb_generated.rs", base_dir=
"\\?\C:\Users\joett\code\projects\SyncUp\app\rust\src")

Caused by:
prefix not found

Logs

$ RUST_LOG=debug flutter_rust_bridge_codegen generate \
>   --rust-root rust \
>   --rust-input crate:: \
>   --dart-output lib/src/rust/frb_generated.dart \
>   --rust-output rust/src/frb_generated.rs \
>   --watch
[2024-12-20T07:57:32.150Z DEBUG C:\Users\joett\.cargo\registry\src\index.crates.io-6f17d22bba15001f\flutter_rust_bridge_codegen-2.7.0\
src/main.rs:25] cli=Cli { verbose: false, command: Generate(GenerateCommandArgs { watch: true, primary: GenerateCommandArgsPrimary { c
onfig_file: None, rust_input: Some("crate::"), dart_output: Some("lib/src/rust/frb_generated.dart"), c_output: None, duplicated_c_outp
ut: None, rust_root: Some("rust"), rust_output: Some("rust/src/frb_generated.rs"), dart_entrypoint_class_name: None, dart_format_line_
length: None, dart_preamble: None, rust_preamble: None, no_dart_enums_style: false, no_add_mod_to_lib: false, llvm_path: None, llvm_co
mpiler_opts: None, dart_root: None, no_build_runner: false, extra_headers: None, no_web: false, no_deps_check: false, default_external
_library_loader_web_prefix: None, no_dart3: false, full_dep: false, local: false, enable_lifetime: false, type_64bit_int: false, no_de
fault_dart_async: false, stop_on_error: false, dump: None, dump_all: false, rust_features: None } }) }
[2024-12-20T07:57:32.151Z DEBUG C:\Users\joett\.cargo\registry\src\index.crates.io-6f17d22bba15001f\flutter_rust_bridge_codegen-2.7.0\
src\library\codegen\config\config_parser.rs:51] Found config file flutter_rust_bridge.yaml
[2024-12-20T07:57:32.151Z DEBUG C:\Users\joett\.cargo\registry\src\index.crates.io-6f17d22bba15001f\flutter_rust_bridge_codegen-2.7.0\
src\library\codegen\mod.rs:23] config=Config { base_dir: Some(""), rust_input: Some("crate::"), dart_output: Some("lib/src/rust/frb_ge
nerated.dart"), c_output: None, duplicated_c_output: None, rust_root: Some("rust"), rust_output: Some("rust/src/frb_generated.rs"), da
rt_entrypoint_class_name: None, dart_format_line_length: None, dart_preamble: None, rust_preamble: None, dart_enums_style: None, add_m
od_to_lib: None, llvm_path: None, llvm_compiler_opts: None, dart_root: None, build_runner: None, extra_headers: None, web: None, deps_
check: None, dart3: None, full_dep: None, local: None, default_external_library_loader_web_prefix: None, dart_type_rename: None, enabl
e_lifetime: None, type_64bit_int: None, default_dart_async: None, stop_on_error: None, dump: None, dump_all: None, rust_features: None
 } meta_config=MetaConfig { watch: true }
[2024-12-20T07:57:32.152Z DEBUG C:\Users\joett\.cargo\registry\src\index.crates.io-6f17d22bba15001f\flutter_rust_bridge_codegen-2.7.0\
src\library\codegen\config\internal_config_parser\mod.rs:33] InternalConfig.parse base_dir="C:\\Users\\joett\\code\\projects\\SyncUp\\
app"
Error: When compute_mod_from_rust_path(code_path="C:\\Users\\joett\\code\\projects\\SyncUp\\app\\rust/src/frb_generated.rs", base_dir=
"\\\\?\\C:\\Users\\joett\\code\\projects\\SyncUp\\app\\rust\\src")

Caused by:
    prefix not found

Expected behavior

Updated Dart and Rust bindings should be regenerated after modifying and saving changes to Rust files, enabling me to run flutter run and see the updated functionality in the Flutter app.

Generated binding code

I deleted the bindings for --dart-output lib/src/rust/frb_generated.dart hoping that would fix the issue.

If you have instructions for me to help you get this, I would be happy to go look for it.

OS

Windows

Version of flutter_rust_bridge_codegen

2.7.0

Flutter info

$ flutter doctor -v
[√] Flutter (Channel stable, 3.27.0, on Microsoft Windows [Version 10.0.19045.5247], locale en-US)
    • Flutter version 3.27.0 on channel stable at C:\Users\joett\flutter\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 8495dee1fd (9 days ago), 2024-12-10 14:23:39 -0800
    • Engine revision 83bacfc525
    • Dart version 3.6.0
    • DevTools version 2.40.2

[√] Windows Version (Installed version of Windows is version 10 or higher)

[√] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
    • Android SDK at C:\Users\joett\AppData\Local\Android\sdk
    • Platform android-35, build-tools 35.0.0
    • Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java
    • Java version OpenJDK Runtime Environment (build 21.0.3+-12282718-b509.11)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.9.5)
    • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
    • Visual Studio Community 2022 version 17.9.34723.18
    • Windows 10 SDK version 10.0.19041.0

[√] Android Studio (version 2024.2)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 21.0.3+-12282718-b509.11)

[√] IntelliJ IDEA Ultimate Edition (version 2020.3)
    • IntelliJ at C:\Program Files\JetBrains\IntelliJ IDEA 2020.3.1
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart

[√] VS Code (version 1.95.3)
    • VS Code at C:\Users\joett\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.102.0

[√] Connected device (4 available)
    • Pixel 7 (mobile)  • 29121FDH200CP4 • android-arm64  • Android 15 (API 35)
    • Windows (desktop) • windows        • windows-x64    • Microsoft Windows [Version 10.0.19045.5247]
    • Chrome (web)      • chrome         • web-javascript • Google Chrome 131.0.6778.204
    • Edge (web)        • edge           • web-javascript • Microsoft Edge 131.0.2903.70

[√] Network resources
    • All expected network resources are available.

• No issues found!

Version of clang++

No response

Additional context

  • I have mod api; in lib.rs, and mod simple; in api/mod.rs.
  • I’ve tried removing mod frb_generated; from lib.rs when not using --rust-output.
  • I’ve also tested different combinations of --rust-input paths and cleaned up old generated files.

If there is any additional information I can provide, such as a minimal reproducible example, logs, or directory listings, please let me know. I’m grateful for your hard work on this project and look forward to any guidance you can offer to resolve this issue.

Thank you for your time and support!

@joe-ton joe-ton added the bug Something isn't working label Dec 20, 2024
Copy link

welcome bot commented Dec 20, 2024

Hi! Thanks for opening your first issue here! 😄

@fzyzcjy
Copy link
Owner

fzyzcjy commented Dec 20, 2024

You are welcome and thanks for the praise!

I run the following command

Hmm, maybe try to use flutter_rust_bridge.yaml to configure everything (instead of using command line), and see whether it works

@fzyzcjy fzyzcjy added the awaiting Waiting for responses, PR, further discussions, upstream release, etc label Dec 20, 2024
@fzyzcjy
Copy link
Owner

fzyzcjy commented Jan 3, 2025

Close since inactivity, and suggestions are made above, but feel free to ping me if there are any questions!

@fzyzcjy fzyzcjy closed this as completed Jan 3, 2025
@joe-ton
Copy link
Author

joe-ton commented Jan 4, 2025

Ah, sorry about that! I forgot to respond. Yeah, it seems to be working now. Thanks!

@fzyzcjy
Copy link
Owner

fzyzcjy commented Jan 4, 2025

You are welcome!

Copy link
Contributor

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 19, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
awaiting Waiting for responses, PR, further discussions, upstream release, etc bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants