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

Not able to build with_flutter after codegen #771

Closed jwinarske closed 1 year ago

jwinarske commented 1 year ago

Describe the bug

With frb_example/with_flutter example and flutter_rust_bridge_codegen 1.48.1 I am not able to reproduce a working project.

I'm using this command:

flutter_rust_bridge_codegen --rust-input rust/src/bridge_generated.rs --dart-output lib/bridge_generated.dart

It shows the following files changed:

modified:   lib/bridge_generated.dart
modified:   rust/src/bridge_generated.io.rs
modified:   rust/src/bridge_generated.rs

How do I reproduce the with_flutter example codegen for tip of tree master?

Running the example without codegen works fine.

Codegen logs with RUST_LOG=debug environment variable

too big to list here...

To Reproduce

No response

Expected behavior

No response

Generated binding code

No response

OS

MacOS

Version of flutter_rust_bridge_codegen

1.48.1

Flutter info

% flutter doctor -v
[✓] Flutter (Channel stable, 3.3.4, on macOS 12.6 21G115 darwin-arm (Rosetta), locale en-US)
    • Flutter version 3.3.4 on channel stable at /Users/joel/development/meta-flutter/tools/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision eb6d86ee27 (5 days ago), 2022-10-04 22:31:45 -0700
    • Engine revision c08d7d5efc
    • Dart version 2.18.2
    • DevTools version 2.15.0

[✓] Xcode - develop for iOS and macOS (Xcode 14.0.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14A400
    • CocoaPods version 1.11.3

[✓] VS Code (version 1.72.0-insider)
    • VS Code at /Applications/Visual Studio Code - Insiders.app/Contents
    • Flutter extension version 3.48.0

[✓] Connected device (1 available)
    • macOS (desktop) • macos • darwin-arm64 • macOS 12.6 21G115 darwin-arm (Rosetta)

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!


### Version of `clang++`

_No response_

### Version of `ffigen`

_No response_

### Additional context

_No response_
welcome[bot] commented 1 year ago

Hi! Thanks for opening your first issue here! :smile:

jwinarske commented 1 year ago

frb_codegen_log.txt

fzyzcjy commented 1 year ago

could you please provide the diff?

jwinarske commented 1 year ago

I'm just checking out master and running

cd frb_example/with_flutter
flutter_rust_bridge_codegen --rust-input rust/src/bridge_generated.rs --dart-output lib/bridge_generated.dart

I want to run codegen and then compile to see the master check-in is the same as codegen output.

What do you run prior to checking in the generated files?

I'm also having a problem on Fedora with pure_dart. Not able to codegen and build for some reason.

fzyzcjy commented 1 year ago

I mean, could you please copy-paste the diff from "It shows the following files changed"

using git diff probably

jwinarske commented 1 year ago

Sequence with Linux (Fedora 34)

git clone https://github.com/fzyzcjy/flutter_rust_bridge.git
cd flutter_rust_bridge/frb_example/with_flutter
flutter pub get
pushd rust && cargo build --release --verbose && popd
flutter_rust_bridge_codegen --rust-input rust/src/api.rs --dart-output lib/bridge_generated.dart
flutter build bundle

diff.txt

Build error

$ flutter build bundle
Running "flutter pub get" in with_flutter...                     1,006ms

💪 Building with sound null safety 💪

lib/bridge_generated.io.dart:9:1: Error: 'Point' is imported from both
'package:flutter_rust_bridge_example/bridge_definitions.dart' and
'package:flutter_rust_bridge_example/bridge_generated.dart'.
import 'bridge_generated.dart';
^^^^^
lib/bridge_generated.io.dart:9:1: Error: 'Size' is imported from both
'package:flutter_rust_bridge_example/bridge_definitions.dart' and
'package:flutter_rust_bridge_example/bridge_generated.dart'.
import 'bridge_generated.dart';
^^^^
lib/bridge_generated.io.dart:9:1: Error: 'TreeNode' is imported from both
'package:flutter_rust_bridge_example/bridge_definitions.dart' and
'package:flutter_rust_bridge_example/bridge_generated.dart'.
import 'bridge_generated.dart';
^^^^^^^^
lib/bridge_generated.dart:556: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'.
 - 'Pointer' is from 'dart:ffi'.
 - 'NativeFunction' is from 'dart:ffi'.
 - 'Bool' is from 'dart:ffi'.
 - 'Int64' is from 'dart:ffi'.
 - 'Void' is from 'dart:ffi'.
Change to a supertype of 'Pointer<NativeFunction<Bool Function(Int64, Pointer<Void>)>>', or, for a covariant
parameter, a subtype.
    int ptr,
        ^
../../frb_dart/lib/src/ffi/stub.dart:14:8: Context: This is the overridden method ('store_dart_post_cobject').
  void store_dart_post_cobject(DartPostCObject ptr) {}
       ^
lib/main.dart:42:20: Error: The argument type 'Size/*1*/' can't be assigned to the parameter type 'Size/*2*/'.
 - 'Size/*1*/' is from 'package:flutter_rust_bridge_example/bridge_definitions.dart'
 ('lib/bridge_definitions.dart').
 - 'Size/*2*/' is from 'package:flutter_rust_bridge_example/bridge_generated.dart' ('lib/bridge_generated.dart').
        imageSize: Size(width: 50, height: 50), zoomPoint: examplePoint, scale: generateScale(), numThreads: 4);
                   ^
lib/main.dart:42:60: Error: The argument type 'Point/*1*/' can't be assigned to the parameter type 'Point/*2*/'.
 - 'Point/*1*/' is from 'package:flutter_rust_bridge_example/bridge_definitions.dart'
 ('lib/bridge_definitions.dart').
 - 'Point/*2*/' is from 'package:flutter_rust_bridge_example/bridge_generated.dart' ('lib/bridge_generated.dart').
        imageSize: Size(width: 50, height: 50), zoomPoint: examplePoint, scale: generateScale(), numThreads: 4);
                                                           ^
lib/main.dart:47:64: Error: The argument type 'TreeNode/*1*/' can't be assigned to the parameter type
'TreeNode/*2*/'.
 - 'TreeNode/*1*/' is from 'package:flutter_rust_bridge_example/bridge_definitions.dart'
 ('lib/bridge_definitions.dart').
 - 'TreeNode/*2*/' is from 'package:flutter_rust_bridge_example/bridge_generated.dart'
 ('lib/bridge_generated.dart').
    final receivedText = await api.passingComplexStructs(root: createExampleTree());
                                                               ^
Target kernel_snapshot failed: Exception
Failed to build bundle.
jwinarske commented 1 year ago

On M1 Mac (same sequence as above)

diff.txt

Build error

% flutter build bundle

💪 Building with sound null safety 💪

lib/bridge_generated.io.dart:9:1: Error: 'Point' is imported from both 'package:flutter_rust_bridge_example/bridge_definitions.dart' and
'package:flutter_rust_bridge_example/bridge_generated.dart'.
import 'bridge_generated.dart';
^^^^^
lib/bridge_generated.io.dart:9:1: Error: 'Size' is imported from both 'package:flutter_rust_bridge_example/bridge_definitions.dart' and
'package:flutter_rust_bridge_example/bridge_generated.dart'.
import 'bridge_generated.dart';
^^^^
lib/bridge_generated.io.dart:9:1: Error: 'TreeNode' is imported from both 'package:flutter_rust_bridge_example/bridge_definitions.dart' and
'package:flutter_rust_bridge_example/bridge_generated.dart'.
import 'bridge_generated.dart';
^^^^^^^^
lib/main.dart:42:20: Error: The argument type 'Size/*1*/' can't be assigned to the parameter type 'Size/*2*/'.
 - 'Size/*1*/' is from 'package:flutter_rust_bridge_example/bridge_definitions.dart' ('lib/bridge_definitions.dart').
 - 'Size/*2*/' is from 'package:flutter_rust_bridge_example/bridge_generated.dart' ('lib/bridge_generated.dart').
        imageSize: Size(width: 50, height: 50), zoomPoint: examplePoint, scale: generateScale(), numThreads: 4);
                   ^
lib/main.dart:42:60: Error: The argument type 'Point/*1*/' can't be assigned to the parameter type 'Point/*2*/'.
 - 'Point/*1*/' is from 'package:flutter_rust_bridge_example/bridge_definitions.dart' ('lib/bridge_definitions.dart').
 - 'Point/*2*/' is from 'package:flutter_rust_bridge_example/bridge_generated.dart' ('lib/bridge_generated.dart').
        imageSize: Size(width: 50, height: 50), zoomPoint: examplePoint, scale: generateScale(), numThreads: 4);
                                                           ^
lib/main.dart:47:64: Error: The argument type 'TreeNode/*1*/' can't be assigned to the parameter type 'TreeNode/*2*/'.
 - 'TreeNode/*1*/' is from 'package:flutter_rust_bridge_example/bridge_definitions.dart' ('lib/bridge_definitions.dart').
 - 'TreeNode/*2*/' is from 'package:flutter_rust_bridge_example/bridge_generated.dart' ('lib/bridge_generated.dart').
    final receivedText = await api.passingComplexStructs(root: createExampleTree());
                                                               ^
Target kernel_snapshot failed: Exception
Failed to build bundle.
jwinarske commented 1 year ago

flutter build bundle passes without error if I skip the flutter_rust_bridge_codegen step

fzyzcjy commented 1 year ago

Suspect the codegen command is wrong. /cc @Desdaemon IIRC you have pointed out somewhere before that the codegen command needs some modifications? Maybe we need to do that in our book as well.

fzyzcjy commented 1 year ago

Btw, please refer to .github/workflow/...yaml to see a working sample configuration

jwinarske commented 1 year ago

This works

flutter_rust_bridge_codegen --rust-input rust/src/api.rs --dart-output lib/bridge_generated.dart --dart-decl-output lib/bridge_definitions.dart
fzyzcjy commented 1 year ago

Great! Where did you see the wrong command? Feel free to PR to modify the book to fix it

jwinarske commented 1 year ago

In the case of pure_dart flutter_rust_bridge_codegen requires being built with

cargo run --package flutter_rust_bridge_codegen --bin flutter_rust_bridge_codegen --features "chrono,uuid"

pure_dart won't generate correctly with cargo install flutter_rust_bridge_codegen package. Thinking it's missing uuid feature.

So on M1 I can now repro other post codegen, so that's progress:

pushd frm_codegen
cargo run --package flutter_rust_bridge_codegen --bin flutter_rust_bridge_codegen --features "chrono,uuid" -- \
          --rust-input ../frb_example/pure_dart/rust/src/api.rs \
          --dart-output ../frb_example/pure_dart/dart/lib/bridge_generated.dart \
          --dart-decl-output ../frb_example/pure_dart/dart/lib/bridge_definitions.dart \
          --dart-format-line-length 120 --wasm
popd
pushd frb_example/pure_dart
pushd rust && cargo build --verbose && popd
pushd dart && dart compile exe lib/main.dart -o main && popd
dart/main ../../../target/debug/libflutter_rust_bridge_example.dylib
popd
fzyzcjy commented 1 year ago

pure_dart won't generate correctly with cargo install flutter_rust_bridge_codegen package. Thinking it's missing uuid feature.

/cc @Roms1383 maybe we should make the uuid feature default?

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.