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.12k stars 283 forks source link

can't get code generator to work on my machine #744

Closed thomas725 closed 1 year ago

thomas725 commented 1 year ago

I've got a clone of this repository (https://github.com/fzyzcjy/flutter_rust_bridge) checked out & up to date @129cafa261c1377ed36685e41ccb7e9330e7614a.

When I run flutter run -d linux in the frb_example/with_flutter/ subfolder, it works fine.

But after I run the code generator (in the repositories root folder) it stops working.

Output of code generator:

$ just
cd frb_codegen && cargo build
    Finished dev [unoptimized + debuginfo] target(s) in 0.03s
(cd frb_example/with_flutter && flutter pub get)
Running "flutter pub get" in with_flutter...                       10.9s
cargo run --manifest-path frb_codegen/Cargo.toml -- -r frb_example/with_flutter/rust/src/api.rs -d frb_example/with_flutter/lib/bridge_generated.dart --dart-decl-output frb_example/with_flutter/lib/bridge_definitions.dart -c frb_example/with_flutter/ios/Runner/bridge_generated.h -c frb_example/with_flutter/macos/Runner/bridge_generated.h --dart-format-line-length 120 --wasm
    Finished dev [unoptimized + debuginfo] target(s) in 0.04s
     Running `frb_codegen/target/debug/flutter_rust_bridge_codegen -r frb_example/with_flutter/rust/src/api.rs -d frb_example/with_flutter/lib/bridge_generated.dart --dart-decl-output frb_example/with_flutter/lib/bridge_definitions.dart -c frb_example/with_flutter/ios/Runner/bridge_generated.h -c frb_example/with_flutter/macos/Runner/bridge_generated.h --dart-format-line-length 120 --wasm`
[2022-09-25T16:40:13Z WARN  lib_flutter_rust_bridge_codegen::source_graph] Skipping unresolvable module web (tried /home/thomas/Development/git/flutter_rust_bridge/frb_example/with_flutter/rust/src/web.rs, /home/thomas/Development/git/flutter_rust_bridge/frb_example/with_flutter/rust/src/web/mod.rs, /home/thomas/Development/git/flutter_rust_bridge/frb_example/with_flutter/rust/src/bridge_generated/web.rs, /home/thomas/Development/git/flutter_rust_bridge/frb_example/with_flutter/rust/src/bridge_generated/web/mod.rs, )
[2022-09-25T16:40:13Z WARN  lib_flutter_rust_bridge_codegen::source_graph] Skipping unresolvable module io (tried /home/thomas/Development/git/flutter_rust_bridge/frb_example/with_flutter/rust/src/io.rs, /home/thomas/Development/git/flutter_rust_bridge/frb_example/with_flutter/rust/src/io/mod.rs, /home/thomas/Development/git/flutter_rust_bridge/frb_example/with_flutter/rust/src/bridge_generated/io.rs, /home/thomas/Development/git/flutter_rust_bridge/frb_example/with_flutter/rust/src/bridge_generated/io/mod.rs, )
Flutter 3.3.2 • channel stable • https://github.com/flutter/flutter.git
Framework • revision e3c29ec00c (11 days ago) • 2022-09-14 08:46:55 -0500
Engine • revision a4ff2c53d8
Tools • Dart 2.18.1 • DevTools 2.15.0
[2022-09-25T16:40:14Z INFO  lib_flutter_rust_bridge_codegen] Picked config: Opts { rust_input_path: "/home/thomas/Development/git/flutter_rust_bridge/frb_example/with_flutter/rust/src/api.rs", dart_output_path: "/home/thomas/Development/git/flutter_rust_bridge/frb_example/with_flutter/lib/bridge_generated.dart", dart_decl_output_path: Some("/home/thomas/Development/git/flutter_rust_bridge/frb_example/with_flutter/lib/bridge_definitions.dart"), c_output_path: ["/home/thomas/Development/git/flutter_rust_bridge/frb_example/with_flutter/ios/Runner/bridge_generated.h", "/home/thomas/Development/git/flutter_rust_bridge/frb_example/with_flutter/macos/Runner/bridge_generated.h"], rust_crate_dir: "/home/thomas/Development/git/flutter_rust_bridge/frb_example/with_flutter/rust", rust_output_path: "/home/thomas/Development/git/flutter_rust_bridge/frb_example/with_flutter/rust/src/bridge_generated.rs", class_name: "FlutterRustBridgeExample", dart_format_line_length: 120, skip_add_mod_to_lib: false, llvm_path: ["/opt/homebrew/opt/llvm", "/usr/local/opt/llvm", "/usr/lib/llvm-9", "/usr/lib/llvm-10", "/usr/lib/llvm-11", "/usr/lib/llvm-12", "/usr/lib/llvm-13", "/usr/lib/llvm-14", "/usr/lib/", "/usr/lib64/", "C:/Program Files/llvm", "C:/msys64/mingw64"], llvm_compiler_opts: "", manifest_path: "/home/thomas/Development/git/flutter_rust_bridge/frb_example/with_flutter/rust/Cargo.toml", dart_root: Some("/home/thomas/Development/git/flutter_rust_bridge/frb_example/with_flutter"), build_runner: true, block_index: BlockIndex(0), skip_deps_check: false, wasm_enabled: true, inline_rust: false }
[2022-09-25T16:40:14Z INFO  lib_flutter_rust_bridge_codegen] Phase: Parse source code to AST, then to IR
[2022-09-25T16:40:15Z WARN  lib_flutter_rust_bridge_codegen::source_graph] Skipping unresolvable module web (tried /home/thomas/Development/git/flutter_rust_bridge/frb_example/with_flutter/rust/src/web.rs, /home/thomas/Development/git/flutter_rust_bridge/frb_example/with_flutter/rust/src/web/mod.rs, /home/thomas/Development/git/flutter_rust_bridge/frb_example/with_flutter/rust/src/bridge_generated/web.rs, /home/thomas/Development/git/flutter_rust_bridge/frb_example/with_flutter/rust/src/bridge_generated/web/mod.rs, )
[2022-09-25T16:40:15Z WARN  lib_flutter_rust_bridge_codegen::source_graph] Skipping unresolvable module io (tried /home/thomas/Development/git/flutter_rust_bridge/frb_example/with_flutter/rust/src/io.rs, /home/thomas/Development/git/flutter_rust_bridge/frb_example/with_flutter/rust/src/io/mod.rs, /home/thomas/Development/git/flutter_rust_bridge/frb_example/with_flutter/rust/src/bridge_generated/io.rs, /home/thomas/Development/git/flutter_rust_bridge/frb_example/with_flutter/rust/src/bridge_generated/io/mod.rs, )
[2022-09-25T16:40:15Z INFO  lib_flutter_rust_bridge_codegen] Phase: Transform IR
[2022-09-25T16:40:15Z INFO  lib_flutter_rust_bridge_codegen] Phase: Generate Rust code
[2022-09-25T16:40:15Z INFO  lib_flutter_rust_bridge_codegen] Phase: Generate Dart code
[2022-09-25T16:40:15Z INFO  lib_flutter_rust_bridge_codegen] Phase: Generating Dart bindings for Rust
Running in Directory: '/home/thomas/Development/git/flutter_rust_bridge/frb_example/with_flutter'
Input Headers: [/tmp/.tmp4tJwA3.h]
[SEVERE] : Header /tmp/.tmp4tJwA3.h: Total errors/warnings: 1.
[SEVERE] :     /tmp/.tmp4tJwA3.h:1:10: fatal error: 'stdbool.h' file not found [Lexical or Preprocessor Issue]
Finished, Bindings generated in /tmp/.tmpfF2Ya2
[2022-09-25T16:40:19Z INFO  lib_flutter_rust_bridge_codegen] Phase: Running build_runner
[2022-09-25T16:40:19Z INFO  lib_flutter_rust_bridge_codegen] Phase: Formatting Dart code
Formatted /home/thomas/Development/git/flutter_rust_bridge/frb_example/with_flutter/lib/bridge_generated.dart
Formatted /home/thomas/Development/git/flutter_rust_bridge/frb_example/with_flutter/lib/bridge_definitions.dart
Formatted /home/thomas/Development/git/flutter_rust_bridge/frb_example/with_flutter/lib/bridge_generated.web.dart
Formatted /home/thomas/Development/git/flutter_rust_bridge/frb_example/with_flutter/lib/bridge_generated.io.dart
Formatted 4 files (4 changed) in 0.43 seconds.
[2022-09-25T16:40:20Z INFO  lib_flutter_rust_bridge_codegen] Success!
[2022-09-25T16:40:20Z INFO  flutter_rust_bridge_codegen] Now go and use it :)
cd frb_example/pure_dart/rust && cargo clean -p flutter_rust_bridge_example_single_block_test && cargo build
   Compiling flutter_rust_bridge_example_single_block_test v1.0.0 (/home/thomas/Development/git/flutter_rust_bridge/frb_example/pure_dart/rust)
    Finished dev [unoptimized + debuginfo] target(s) in 14.91s
cd frb_example/pure_dart_multi/rust && cargo clean -p flutter_rust_bridge_example_multi_blocks_test && cargo build
   Compiling flutter_rust_bridge_example_multi_blocks_test v1.0.0 (/home/thomas/Development/git/flutter_rust_bridge/frb_example/pure_dart_multi/rust)
    Finished dev [unoptimized + debuginfo] target(s) in 9.72s

Error I get with the locally generated code:

'FlutterRustBridgeExampleWire.store_dart_post_cobject' ('void Function(int)') isn't a valid override of 'FlutterRustBridgeWireBase.store_dart_post_cobject' ('void Function(Pointer<NativeFunction<Bool Function(Int64, Pointer<Void>)>>)')

More verbose error printed when trying to run with CLI:

ERROR: lib/bridge_generated.io.dart:117:9: Error: The parameter 'ptr' of the method 'FlutterRustBridgeExampleWire.store_dart_post_cobject' has type 'int', which does not match the corresponding type, 'Pointer<NativeFunction<Bool Function(Int64, Pointer<Void>)>>', in the overridden method, 'FlutterRustBridgeWireBase.store_dart_post_cobject'.
ERROR:  - 'Pointer' is from 'dart:ffi'.
ERROR:  - 'NativeFunction' is from 'dart:ffi'.
ERROR:  - 'Bool' is from 'dart:ffi'.
ERROR:  - 'Int64' is from 'dart:ffi'.
ERROR:  - 'Void' is from 'dart:ffi'.
ERROR: Change to a supertype of 'Pointer<NativeFunction<Bool Function(Int64, Pointer<Void>)>>', or, for a covariant parameter, a subtype.
ERROR:     int ptr,
ERROR:         ^
ERROR: ../../frb_dart/lib/src/ffi/stub.dart:14:8: Context: This is the overridden method ('store_dart_post_cobject').
ERROR:   void store_dart_post_cobject(DartPostCObject ptr) {}
ERROR:        ^
Building Linux application...                                           
Exception: Build process failed

Can you help me? Are those warnings about missing modules web & io at fault? I've got very similar problems with https://github.com/Desdaemon/flutter_rust_bridge_template

thomas725 commented 1 year ago

Ah sorry I've been missing the export CPATH="$(clang -v 2>&1 | grep "Selected GCC installation: " | cut -d' ' -f4-)/include" in the terminal session I've used, with that the example included here works fine again. My problem with the template seems to have a different cause: https://github.com/Desdaemon/flutter_rust_bridge_template/issues/16

github-actions[bot] commented 1 year 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.