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

[Bug] Unable to parse pubspec.yaml #826

Closed banool closed 1 year ago

banool commented 1 year ago

Describe the bug

Problem

The problem is code generation fails due to some issue with the spec, though as far as I can tell, it's valid yaml (according to yq).

Repro

Get the repo:

git clone git@github.com:banool/aclip.git
git switch banool/update_deps

Try to generate the code:

cd frontend
just

I recently pulled the latest justfile from the template repo.

Some other information:

$ cargo --version
cargo 1.64.0 (387270bc7 2022-09-16)

$ rustc --version
rustc 1.64.0 (a55dd71d5 2022-09-19)

$ flutter_rust_bridge_codegen --version
flutter_rust_bridge_codegen 1.49.1

Codegen logs with RUST_LOG=debug environment variable

$ RUST_LOG=debug just
flutter pub get
Running "flutter pub get" in frontend...                           847ms
flutter_rust_bridge_codegen --rust-input native/src/api.rs --dart-output lib/bridge_generated.dart --c-output ios/Runner/bridge_generated.h --c-output macos/Runner/bridge_generated.h --dart-decl-output lib/bridge_definitions.dart --wasm
[2022-11-06T16:36:29Z DEBUG flutter_rust_bridge_codegen] configs=[Opts { rust_input_path: "/Users/dport/github/aclip/frontend/native/src/api.rs", dart_output_path: "/Users/dport/github/aclip/frontend/lib/bridge_generated.dart", dart_decl_output_path: Some("/Users/dport/github/aclip/frontend/lib/bridge_definitions.dart"), c_output_path: ["/Users/dport/github/aclip/frontend/ios/Runner/bridge_generated.h", "/Users/dport/github/aclip/frontend/macos/Runner/bridge_generated.h"], rust_crate_dir: "/Users/dport/github/aclip/frontend/native", rust_output_path: "/Users/dport/github/aclip/frontend/native/src/bridge_generated.rs", class_name: "Native", dart_format_line_length: 80, 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: "/Users/dport/github/aclip/frontend/native/Cargo.toml", dart_root: Some("/Users/dport/github/aclip/frontend"), build_runner: true, block_index: BlockIndex(0), skip_deps_check: false, wasm_enabled: true, inline_rust: false }]
[2022-11-06T16:36:29Z DEBUG lib_flutter_rust_bridge_codegen::source_graph] Trying to parse "/Users/dport/github/aclip/frontend/native/src/api.rs"
[2022-11-06T16:36:29Z DEBUG lib_flutter_rust_bridge_codegen::source_graph] Trying to parse "/Users/dport/github/aclip/frontend/native/src/bridge_generated.rs"
[2022-11-06T16:36:29Z DEBUG lib_flutter_rust_bridge_codegen::parser] parse_function function name: Ident(download_page)
[2022-11-06T16:36:29Z DEBUG lib_flutter_rust_bridge_codegen::parser] parse_function function name: Ident(platform)
[2022-11-06T16:36:29Z DEBUG lib_flutter_rust_bridge_codegen::parser] parse_function function name: Ident(rust_release_mode)
[2022-11-06T16:36:29Z DEBUG lib_flutter_rust_bridge_codegen::tools] Guessing toolchain the runner is run into
[2022-11-06T16:36:29Z DEBUG lib_flutter_rust_bridge_codegen::commands] execute command: bin=sh args="-c \"flutter\" \"--version\"" current_dir=None cmd="sh" "-c" "\"flutter\" \"--version\""
Flutter 3.3.5 • channel stable • https://github.com/flutter/flutter.git
Framework • revision d9111f6402 (3 weeks ago) • 2022-10-19 12:27:13 -0700
Engine • revision 3ad69d7be3
Tools • Dart 2.18.2 • DevTools 2.15.0
[2022-11-06T16:36:30Z DEBUG lib_flutter_rust_bridge_codegen::commands] command="sh" "-c" "\"flutter\" \"--version\"" stdout= stderr=
[2022-11-06T16:36:30Z DEBUG lib_flutter_rust_bridge_codegen::tools] Checking presence of ffi in dependencies at /Users/dport/github/aclip/frontend
[2022-11-06T16:36:30Z ERROR flutter_rust_bridge_codegen] fatal: unable to parse pubspec.yaml in /Users/dport/github/aclip/frontend
error: Recipe `gen` failed on line 11 with exit code 1

### To Reproduce

_No response_

### Expected behavior

_No response_

### Generated binding code

_No response_

### OS

MacOS

### Version of `flutter_rust_bridge_codegen`

1.49.1

### Flutter info

```shell
$ flutter doctor -v
[✓] Flutter (Channel stable, 3.3.5, on macOS 13.0 22A380 darwin-arm, locale
    en-US)
    • Flutter version 3.3.5 on channel stable at /Users/dport/.flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision d9111f6402 (3 weeks ago), 2022-10-19 12:27:13 -0700
    • Engine revision 3ad69d7be3
    • Dart version 2.18.2
    • DevTools version 2.15.0

[✓] Android toolchain - develop for Android devices (Android SDK version
    33.0.0-rc2)
    • Android SDK at /Users/dport/Library/Android/sdk
    • Platform android-33, build-tools 33.0.0-rc2
    • Java binary at: /Applications/Android
      Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7772763)
    • All Android licenses accepted.

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

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • 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 11.0.11+0-b60-7772763)

[✓] VS Code (version 1.72.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.52.0

[✓] Connected device (2 available)
    • macOS (desktop) • macos  • darwin-arm64   • macOS 13.0 22A380 darwin-arm
    • Chrome (web)    • chrome • web-javascript • Google Chrome 107.0.5304.87

[✓] 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_
fzyzcjy commented 1 year ago

unable to parse pubspec.yaml in /Users/dport/github/aclip/frontend

What about debugging like this: Add some more outputs around this yaml parsing functions, so we can clearly see what exactly is failing

banool commented 1 year ago

Alright will do, though probably not for a week or so.

fzyzcjy commented 1 year ago

Take your time!

flutterfromscratch commented 1 year ago

In my case, pubspec.yaml validation always failed if there were no version constraints specified for packages in pubspec.yaml

In prototyping, you can specify your dependencies like this:

dependencies:
  flutter:
    sdk: flutter
  potato__package:

...and you'll just get the latest available package of potato_package. But, specifying packages with no version constraints causes flutter_rust_bridge YAML validation to choke.

To resolve, make sure all your packages have versions specified in the pubspec.yaml

fzyzcjy commented 1 year ago

@flutterfromscratch That looks like a bug in the validation logic and should be quite easy to fix. Feel free to PR!

banool commented 1 year ago

I'm attempting a fix now. I'll use this message to update my progress.

So changing to show the error, I see this:

[2022-11-15T13:16:16Z ERROR flutter_rust_bridge_codegen] fatal: unable to parse pubspec.yaml in /Users/dport/github/aclip/frontend: dependencies: data did not match any variant of untagged enum PackageVersion at line 11 column 17

Investigating now what the problem is specifically. It does indeed seem to be that you need to specify versions explicitly.

banool commented 1 year ago

Okay got it, check out https://github.com/fzyzcjy/flutter_rust_bridge/pull/846.

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.