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

[Bug] Codegen wasm option creates files that flutter cannot run against #938

Closed
davidpbrown opened this issue Dec 27, 2022 · 4 comments
Closed
Labels
bug Something isn't working wontfix This will not be worked on

Comments

@davidpbrown
Copy link

Describe the bug

Codegen is really useful; so, surprised to see an option that's not just working well.

Using the basic flutter_rust_bridge_template.

This with wasm option included, completes ok but creates generated files that it seems flutter cannot run against:

flutter_rust_bridge_codegen --rust-input ./native/src/api.rs --dart-output ./lib/bridge_generated.dart --wasm --dart-decl-output ./lib/bridge_generated.web.dart

This works well for flutter to run but without that wasm option:

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

flutter run error seems to centre on

Error: 'NativePlatform' is imported from both 'package:flutter_rust_bridge_template/bridge_generated.web.dart' and 'package:flutter_rust_bridge_template/bridge_generated.io.dart'.
import 'bridge_generated.io.dart'

Full error from flutter against wasm generated Codegen outputs:

$ flutter run
Using hardware rendering with device sdk gphone64 x86 64. If you notice graphics artifacts, consider enabling software rendering with
"--enable-software-rendering".
Launching lib/main.dart on sdk gphone64 x86 64 in debug mode...
lib/main.dart:54:15: Error: Type 'Platform' not found.
  late Future<Platform> platform;
              ^^^^^^^^
lib/main.dart:54:15: Error: 'Platform' isn't a type.
  late Future<Platform> platform;
              ^^^^^^^^
lib/main.dart:132:23: Error: 'Platform' isn't a type.
                final Platform platform = data[0];
                      ^^^^^^^^
lib/main.dart:135:23: Error: Undefined name 'Platform'.
                      Platform.Android: 'Android',
                      ^^^^^^^^
lib/main.dart:136:23: Error: Undefined name 'Platform'.
                      Platform.Ios: 'iOS',
                      ^^^^^^^^
lib/main.dart:137:23: Error: Undefined name 'Platform'.
                      Platform.MacApple: 'MacOS with Apple Silicon',
                      ^^^^^^^^
lib/main.dart:138:23: Error: Undefined name 'Platform'.
                      Platform.MacIntel: 'MacOS',
                      ^^^^^^^^
lib/main.dart:139:23: Error: Undefined name 'Platform'.
                      Platform.Windows: 'Windows',
                      ^^^^^^^^
lib/main.dart:140:23: Error: Undefined name 'Platform'.
                      Platform.Unix: 'Unix',
                      ^^^^^^^^
lib/main.dart:141:23: Error: Undefined name 'Platform'.
                      Platform.Wasm: 'the Web',
                      ^^^^^^^^
lib/ffi.dart:20:7: Error: Type 'Native' not found.
final Native api = NativeImpl(io.Platform.isIOS || io.Platform.isMacOS
      ^^^^^^
lib/ffi.dart:20:7: Error: 'Native' isn't a type.
final Native api = NativeImpl(io.Platform.isIOS || io.Platform.isMacOS
      ^^^^^^
lib/bridge_generated.dart:14:29: Error: Type 'Native' not found.
class NativeImpl implements Native {
                            ^^^^^^
lib/bridge_generated.dart:88:10: Error: Type 'Platform' not found.
  Future<Platform> platform({dynamic hint}) {
         ^^^^^^^^
lib/bridge_generated.dart:137:3: Error: Type 'Platform' not found.
  Platform _wire2api_platform(dynamic raw) {
  ^^^^^^^^
lib/bridge_generated.dart:9:1: Error: 'NativePlatform' is imported from both 'package:flutter_rust_bridge_template/bridge_generated.web.dart' and 'package:flutter_rust_bridge_template/bridge_generated.io.dart'.
import 'bridge_generated.io.dart'
^^^^^^^^^^^^^^
lib/bridge_generated.dart:17:22: Error: 'NativePlatform' is imported from both 'package:flutter_rust_bridge_template/bridge_generated.web.dart' and 'package:flutter_rust_bridge_template/bridge_generated.io.dart'.
      NativeImpl.raw(NativePlatform(dylib));
                     ^^^^^^^^^^^^^^
lib/bridge_generated.dart:138:12: Error: The getter 'Platform' isn't defined for the class 'NativeImpl'.
 - 'NativeImpl' is from 'package:flutter_rust_bridge_template/bridge_generated.dart' ('lib/bridge_generated.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'Platform'.
    return Platform.values[raw];
           ^^^^^^^^
lib/bridge_generated.web.dart:52:26: Error: Type 'FlutterRustBridgeWasmWireBase' not found.
class NativeWire extends FlutterRustBridgeWasmWireBase<NativeWasmModule> {
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/bridge_generated.web.dart:28:2: Error: Couldn't find constructor 'JS'.
@JS('wasm_bindgen')
 ^^
lib/bridge_generated.web.dart:13:30: Error: Type argument 'NativeWire' doesn't conform to the bound 'FlutterRustBridgeWireBase' of the type variable 'T' on 'FlutterRustBridgeBase'.
 - 'NativeWire' is from 'package:flutter_rust_bridge_template/bridge_generated.web.dart' ('lib/bridge_generated.web.dart').
 - 'FlutterRustBridgeWireBase' is from 'package:flutter_rust_bridge/src/ffi/stub.dart' ('../../dev-tools/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_rust_bridge-1.57.0/lib/src/ffi/stub.dart').
Try changing type arguments so that they conform to the bounds.
class NativePlatform extends FlutterRustBridgeBase<NativeWire>
                             ^
lib/bridge_generated.web.dart:14:10: Error: Inferred type argument 'NativeWire' doesn't conform to the bound 'FlutterRustBridgeWireBase' of the type variable 'T' on 'FlutterRustBridgeSetupMixin'.
 - 'NativeWire' is from 'package:flutter_rust_bridge_template/bridge_generated.web.dart' ('lib/bridge_generated.web.dart').
 - 'FlutterRustBridgeWireBase' is from 'package:flutter_rust_bridge/src/ffi/stub.dart' ('../../dev-tools/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_rust_bridge-1.57.0/lib/src/ffi/stub.dart').
Try specifying type arguments explicitly so that they conform to the bounds.
    with FlutterRustBridgeSetupMixin {
         ^
lib/bridge_generated.web.dart:31:2: Error: Couldn't find constructor 'JS'.
@JS()
 ^^
lib/bridge_generated.web.dart:32:2: Error: Undefined name 'anonymous'.
@anonymous
 ^^^^^^^^^
lib/bridge_generated.web.dart:32:2: Error: This can't be used as an annotation; an annotation should be a reference to a compile-time constant variable, or a call to a constant constructor.
@anonymous
 ^
lib/bridge_generated.web.dart:18:33: Error: The getter 'init' isn't defined for the class 'NativeWire'.
 - 'NativeWire' is from 'package:flutter_rust_bridge_template/bridge_generated.web.dart' ('lib/bridge_generated.web.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'init'.
  Future<void> setup() => inner.init;
                                ^^^^
lib/bridge_generated.web.dart:54:14: Error: Too many positional arguments: 0 allowed, but 1 found.
Try removing the extra positional arguments.
      : super(WasmModule.cast<NativeWasmModule>(module));
             ^


FAILURE: Build failed with an exception.

* Where:
Script '/mnt/vault/dev-tools/flutter/packages/flutter_tools/gradle/flutter.gradle' line: 1159

* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command '/mnt/vault/dev-tools/flutter/bin/flutter'' finished with non-zero exit value 1

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 35s
Running Gradle task 'assembleDebug'...                             37.7s
Exception: Gradle task assembleDebug failed with exit code 1

Codegen logs with RUST_LOG=debug environment variable

Codegen completes with no errors.. but the output is evidently muddled for what flutter can make sense of.

To Reproduce

include the option --wasm --dart-decl-output ./lib/bridge_generated.web.dart
flutter run in Android Studio
generates error where without that option it works.

Expected behavior

wasm generated file bridge_generated.web should work well and flutter should not complain about 'NativePlatform' imported from both 'package:flutter_rust_bridge_template/bridge_generated.web.dart' and 'package:flutter_rust_bridge_template/bridge_generated.io.dart'.

Generated binding code

No response

OS

Linux

Version of flutter_rust_bridge_codegen

Generated by flutter_rust_bridge@ 1.58.2

Flutter info

$ flutter doctor -v
[✓] Flutter (Channel stable, 3.3.10, on Linux Mint 21 5.15.0-56-generic, locale
    en_GB.UTF-8)
    • Flutter version 3.3.10 on channel stable at /mnt/vault/dev-tools/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 135454af32 (12 days ago), 2022-12-15 07:36:55 -0800
    • Engine revision 3316dd8728
    • Dart version 2.18.6
    • DevTools version 2.15.0

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
    • Android SDK at /mnt/vault/dev-tools/Android/Sdk
    • Platform android-33, build-tools 33.0.1
    • ANDROID_SDK_ROOT = /mnt/vault/dev-tools/Android/Sdk
    • Java binary at: /mnt/vault/dev-tools/Android/android-studio/jre/bin/java
    • Java version OpenJDK Runtime Environment (build
      11.0.13+0-b1751.21-8125866)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • CHROME_EXECUTABLE = /usr/bin/chromium

[✓] Linux toolchain - develop for Linux desktop
    • Ubuntu clang version 14.0.0-1ubuntu1
    • cmake version 3.22.1
    • ninja version 1.10.1
    • pkg-config version 0.29.2

[✓] Android Studio (version 2021.3)
    • Android Studio at /mnt/vault/dev-tools/Android/android-studio
    • Flutter plugin version 71.2.3
    • Dart plugin version 213.7433
    • Java version OpenJDK Runtime Environment (build
      11.0.13+0-b1751.21-8125866)

[✓] VS Code (version 1.74.2)
    • VS Code at /usr/share/code
    • Flutter extension version 3.56.0

[✓] Connected device (3 available)
    • sdk gphone64 x86 64 (mobile) • emulator-5554 • android-x64    • Android 12
      (API 31) (emulator)
    • Linux (desktop)              • linux         • linux-x64      • Linux Mint
      21 5.15.0-56-generic
    • Chrome (web)                 • chrome        • web-javascript • Chromium
      108.0.5359.124 for Linux Mint

[✓] 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

@davidpbrown davidpbrown added the bug Something isn't working label Dec 27, 2022
@welcome
Copy link

welcome bot commented Dec 27, 2022

Hi! Thanks for opening your first issue here! 😄

@fzyzcjy
Copy link
Owner

fzyzcjy commented Dec 27, 2022

/cc @Desdaemon who implemented the great web feature

@stale
Copy link

stale bot commented Feb 26, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix This will not be worked on label Feb 26, 2023
@stale stale bot closed this as completed Mar 5, 2023
@github-actions
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 Mar 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants