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.23k stars 291 forks source link

[Bug] frb codegen api does not match #1408

Closed dryBranch closed 11 months ago

dryBranch commented 11 months ago

Describe the bug

/// generated by flutter_rust_bridge
class NativeWire implements FlutterRustBridgeWireBase {
  // ....
  void store_dart_post_cobject(
    int ptr,
  ) {
    return _store_dart_post_cobject(
      ptr,
    );
  }
}

But the abstract class need DartPostCObject instead of int

void store_dart_post_cobject(DartPostCObject ptr) {
    throw UnimplementedError();
 }

In vscode it throw a error info

'NativeWire.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>)>>)').dart[invalid_override](https://dart.dev/diagnostics/invalid_override)
stub.dart(21, 8): The member being overridden.

Codegen logs with RUST_LOG=debug environment variable

2023/11/03 20:18:00 [DEBUG] configs=[Opts { rust_input_path: "E:\\workspace\\flutter\\frb_test\\native/src/api.rs", dart_output_path: "E:\\workspace\\flutter\\frb_test\\lib/bridge_generated.dart", dart_decl_output_path: Some("E:\\workspace\\flutter\\frb_test\\lib/bridge_definitions.dart"), c_output_path: ["C:\\Users\\24408\\AppData\\Local\\Temp\\.tmp2mLX7p.h"], rust_crate_dir: "E:\\workspace\\flutter\\frb_test\\native", rust_output_path: "E:\\workspace\\flutter\\frb_test\\native/src\\bridge_generated.rs", class_name: "Native", dart_format_line_length: 80, dart_enums_style: false, 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: "E:\\workspace\\flutter\\frb_test\\native\\Cargo.toml", dart_root: Some("E:\\workspace\\flutter\\frb_test"), build_runner: true, block_index: BlockIndex(0), skip_deps_check: false, wasm_enabled: false, inline_rust: false, bridge_in_method: true, extra_headers: "", dart3: true, keep_going: false }]
2023/11/03 20:18:00 [INFO] Running cargo expand in 'E:/workspace/flutter/frb_test/native'
2023/11/03 20:18:00 [DEBUG] execute command: bin=cargo args="expand --theme=none --ugly" current_dir=Some("E:/workspace/flutter/frb_test/native") cmd="cargo" "expand" "--theme=none" "--ugly"
2023/11/03 20:18:00 [DEBUG] command="cargo" "expand" "--theme=none" "--ugly" stdout=#![feature(prelude_import)]
#[prelude_import]
use std::prelude::rust_2021::*;
#[macro_use]
extern crate std;
mod bridge_generated {
    /* AUTO INJECTED BY flutter_rust_bridge. This line may not be accurate, and you can change it according to your needs. */
    #![allow(non_camel_case_types, unused, clippy :: redundant_closure, clippy
    :: useless_conversion, clippy :: unit_arg, clippy :: double_parens,
    non_snake_case, clippy :: too_many_arguments)]
    use crate::api::*;
    use core::panic::UnwindSafe;
    use flutter_rust_bridge::rust2dart::IntoIntoDart;
    use flutter_rust_bridge::*;
    use std::ffi::c_void;
    use std::sync::Arc;
    fn wire_hello_impl(port_: MessagePort) {
        FLUTTER_RUST_BRIDGE_HANDLER.wrap::<_, _, _, String,
            _>(WrapInfo {
                debug_name: "hello",
                port: Some(port_),
                mode: FfiCallMode::Normal,
            }, move || move |task_callback| Result::<_, ()>::Ok(hello()))
    }
    pub trait Wire2Api<T> {
        fn wire2api(self)
        -> T;
    }
    impl<T, S> Wire2Api<Option<T>> for *mut S where *mut S: Wire2Api<T> {
        fn wire2api(self) -> Option<T> {
            (!self.is_null()).then(|| self.wire2api())
        }
    }
    #[allow(missing_copy_implementations)]
    #[allow(non_camel_case_types)]
    #[allow(dead_code)]
    pub struct FLUTTER_RUST_BRIDGE_HANDLER {
        __private_field: (),
    }
    #[doc(hidden)]
    pub static FLUTTER_RUST_BRIDGE_HANDLER: FLUTTER_RUST_BRIDGE_HANDLER =
        FLUTTER_RUST_BRIDGE_HANDLER { __private_field: () };
    impl ::lazy_static::__Deref for FLUTTER_RUST_BRIDGE_HANDLER {
        type Target = support::DefaultHandler;
        fn deref(&self) -> &support::DefaultHandler {
            #[inline(always)]
            fn __static_ref_initialize() -> support::DefaultHandler {
                Default::default()
            }
            #[inline(always)]
            fn __stability() -> &'static support::DefaultHandler {
                static LAZY:
                    ::lazy_static::lazy::Lazy<support::DefaultHandler> =
                    ::lazy_static::lazy::Lazy::INIT;
                LAZY.get(__static_ref_initialize)
            }
            __stability()
        }
    }
    impl ::lazy_static::LazyStatic for FLUTTER_RUST_BRIDGE_HANDLER {
        fn initialize(lazy: &Self) { let _ = &**lazy; }
    }
    #[cfg(not(target_family = "wasm"))]
    #[path = "bridge_generated.io.rs"]
    mod io {
        use super::*;
        #[no_mangle]
        pub extern "C" fn wire_hello(port_: i64) { wire_hello_impl(port_) }
        pub trait NewWithNullPtr {
            fn new_with_null_ptr()
            -> Self;
        }
        impl<T> NewWithNullPtr for *mut T {
            fn new_with_null_ptr() -> Self { std::ptr::null_mut() }
        }
        #[no_mangle]
        pub extern "C" fn free_WireSyncReturn(ptr: support::WireSyncReturn) {
            unsafe { let _ = support::box_from_leak_ptr(ptr); };
        }
    }
    #[cfg(not(target_family = "wasm"))]
    pub use io::*;
}
pub mod api {
    pub fn hello() -> String { "hello from rust".to_string() }
}
 stderr=    Checking native v0.1.0 (E:\workspace\flutter\frb_test\native)
    Finished dev [unoptimized + debuginfo] target(s) in 0.18s

2023/11/03 20:18:01 [DEBUG] Trying to parse "\\\\?\\E:\\workspace\\flutter\\frb_test\\native\\src\\bridge_generated.rs"
2023/11/03 20:18:01 [DEBUG] Trying to parse "\\\\?\\E:\\workspace\\flutter\\frb_test\\native\\src\\api.rs"
2023/11/03 20:18:01 [DEBUG] parse_function function name: Ident(hello)
2023/11/03 20:18:01 [INFO] Phase: Validate config(s)
2023/11/03 20:18:01 [INFO] Picked config: Opts { rust_input_path: "E:\\workspace\\flutter\\frb_test\\native/src/api.rs", dart_output_path: "E:\\workspace\\flutter\\frb_test\\lib/bridge_generated.dart", dart_decl_output_path: Some("E:\\workspace\\flutter\\frb_test\\lib/bridge_definitions.dart"), c_output_path: ["C:\\Users\\24408\\AppData\\Local\\Temp\\.tmp2mLX7p.h"], rust_crate_dir: "E:\\workspace\\flutter\\frb_test\\native", rust_output_path: "E:\\workspace\\flutter\\frb_test\\native/src\\bridge_generated.rs", class_name: "Native", dart_format_line_length: 80, dart_enums_style: false, 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: "E:\\workspace\\flutter\\frb_test\\native\\Cargo.toml", dart_root: Some("E:\\workspace\\flutter\\frb_test"), build_runner: true, block_index: BlockIndex(0), skip_deps_check: false, wasm_enabled: false, inline_rust: false, bridge_in_method: true, extra_headers: "", dart3: true, keep_going: false }
2023/11/03 20:18:01 [INFO] Phase: Parse source code to AST, then to IR
2023/11/03 20:18:01 [DEBUG] Trying to parse "\\\\?\\E:\\workspace\\flutter\\frb_test\\native\\src\\bridge_generated.rs"
2023/11/03 20:18:01 [DEBUG] Trying to parse "\\\\?\\E:\\workspace\\flutter\\frb_test\\native\\src\\api.rs"
2023/11/03 20:18:01 [DEBUG] parse_function function name: Ident(hello)
2023/11/03 20:18:01 [INFO] Phase: Transform IR
2023/11/03 20:18:01 [INFO] Phase: Generate Rust code
2023/11/03 20:18:01 [DEBUG] execute format_rust path=["E:\\workspace\\flutter\\frb_test\\native/src\\bridge_generated.rs"]
2023/11/03 20:18:01 [DEBUG] execute command: bin=rustfmt args="E:\\workspace\\flutter\\frb_test\\native/src\\bridge_generated.rs" current_dir=None cmd="rustfmt" "E:\\workspace\\flutter\\frb_test\\native/src\\bridge_generated.rs"
2023/11/03 20:18:01 [DEBUG] command="rustfmt" "E:\\workspace\\flutter\\frb_test\\native/src\\bridge_generated.rs" stdout= stderr=
2023/11/03 20:18:01 [INFO] Phase: Generate Dart code
2023/11/03 20:18:01 [DEBUG] Guessing toolchain the runner is run into
2023/11/03 20:18:01 [DEBUG] execute command: bin=powershell args="-noprofile -command & \"flutter\" \"--version\"" current_dir=None cmd="powershell" "-noprofile" "-command" "& \"flutter\" \"--version\""
2023/11/03 20:18:02 [DEBUG] command="powershell" "-noprofile" "-command" "& \"flutter\" \"--version\"" stdout=Flutter 3.13.9 • channel stable • https://github.com/flutter/flutter.git
Framework • revision d211f42860 (9 days ago) • 2023-10-25 13:42:25 -0700
Engine • revision 0545f8705d
Tools • Dart 3.1.5 • DevTools 2.25.0
 stderr=
2023/11/03 20:18:02 [DEBUG] Checking presence of ffi in dependencies at E:\workspace\flutter\frb_test
2023/11/03 20:18:02 [DEBUG] Checking presence of ffi in dependencies at E:\workspace\flutter\frb_test
2023/11/03 20:18:02 [DEBUG] Checking presence of ffigen in dev_dependencies at E:\workspace\flutter\frb_test
2023/11/03 20:18:02 [DEBUG] Checking presence of ffigen in dev_dependencies at E:\workspace\flutter\frb_test
2023/11/03 20:18:02 [INFO] Phase: Generating Dart bindings for Rust
2023/11/03 20:18:02 [DEBUG] execute cbindgen rust_crate_dir=E:\workspace\flutter\frb_test\native c_output_path=C:\Users\24408\AppData\Local\Temp\.tmpwg3Aep.h
2023/11/03 20:18:02 [DEBUG] cbindgen config: Config {
    header: None,
    includes: [],
    sys_includes: [
        "stdbool.h",
        "stdint.h",
        "stdlib.h",
    ],
    after_includes: Some(
        "typedef struct _Dart_Handle* Dart_Handle;",
    ),
    trailer: None,
    include_guard: None,
    pragma_once: false,
    no_includes: true,
    autogen_warning: None,
    include_version: false,
    namespace: None,
    namespaces: None,
    using_namespaces: None,
    braces: SameLine,
    line_length: 100,
    tab_width: 2,
    line_endings: LF,
    language: C,
    cpp_compat: false,
    style: Both,
    sort_by: None,
    usize_is_size_t: false,
    parse: ParseConfig {
        parse_deps: false,
        include: None,
        exclude: [],
        expand: ParseExpandConfig {
            crates: [],
            all_features: false,
            default_features: true,
            features: None,
            profile: Debug,
        },
        clean: false,
        extra_bindings: [],
    },
    export: ExportConfig {
        include: [],
        exclude: [],
        rename: {},
        pre_body: {},
        body: {},
        prefix: None,
        item_types: [],
        renaming_overrides_prefixing: false,
        mangle: MangleConfig {
            rename_types: None,
            remove_underscores: false,
        },
    },
    macro_expansion: MacroExpansionConfig {
        bitflags: false,
    },
    layout: LayoutConfig {
        packed: None,
        aligned_n: None,
    },
    function: FunctionConfig {
        prefix: None,
        postfix: None,
        must_use: None,
        args: Auto,
        rename_args: None,
        swift_name_macro: None,
        sort_by: None,
        no_return: None,
    },
    structure: StructConfig {
        rename_fields: None,
        derive_constructor: false,
        derive_eq: false,
        derive_neq: false,
        derive_lt: false,
        derive_lte: false,
        derive_gt: false,
        derive_gte: false,
        derive_ostream: false,
        associated_constants_in_body: false,
        must_use: None,
    },
    enumeration: EnumConfig {
        rename_variants: None,
        rename_variant_name_fields: SnakeCase,
        add_sentinel: false,
        prefix_with_name: false,
        derive_helper_methods: false,
        derive_const_casts: false,
        derive_mut_casts: false,
        cast_assert_name: None,
        must_use: None,
        derive_tagged_enum_destructor: false,
        derive_tagged_enum_copy_constructor: false,
        derive_tagged_enum_copy_assignment: false,
        derive_ostream: false,
        enum_class: true,
        private_default_tagged_enum_constructor: false,
    },
    constant: ConstantConfig {
        allow_static_const: true,
        allow_constexpr: true,
        sort_by: None,
    },
    defines: {},
    documentation: true,
    documentation_style: Auto,
    documentation_length: Full,
    pointer: PtrConfig {
        non_null_attribute: None,
    },
    only_target_dependencies: false,
    cython: CythonConfig {
        header: None,
        cimports: {},
    },
}
2023/11/03 20:18:02 [DEBUG] Parsing crate native
2023/11/03 20:18:02 [INFO] Take native::DartPort.
2023/11/03 20:18:02 [INFO] Take native::DartPostCObjectFnType.
2023/11/03 20:18:02 [INFO] Take native::store_dart_post_cobject.
2023/11/03 20:18:02 [INFO] Take native::get_dart_object.
2023/11/03 20:18:02 [INFO] Take native::drop_dart_object.
2023/11/03 20:18:02 [INFO] Take native::new_dart_opaque.
2023/11/03 20:18:02 [INFO] Take native::init_frb_dart_api_dl.
2023/11/03 20:18:02 [INFO] Take native::DartCObject - opaque (Struct is not marked #[repr(C)] or #[repr(transparent)].).
2023/11/03 20:18:02 [INFO] Take native::WireSyncReturn.
2023/11/03 20:18:02 [INFO] Take native::wire_hello.
2023/11/03 20:18:02 [INFO] Take native::free_WireSyncReturn.
2023/11/03 20:18:02 [WARN] Can't find Dart_Handle. This usually means that this type was incompatible or not found.
2023/11/03 20:18:02 [WARN] Can't find Dart_Handle. This usually means that this type was incompatible or not found.
2023/11/03 20:18:02 [WARN] Missing `[defines]` entry for `target_family = "wasm"` in cbindgen config.
2023/11/03 20:18:02 [WARN] Missing `[defines]` entry for `target_family = "wasm"` in cbindgen config.
2023/11/03 20:18:02 [DEBUG] execute ffigen c_path=C:\Users\24408\AppData\Local\Temp\.tmpwg3Aep.h dart_path=C:\Users\24408\AppData\Local\Temp\.tmpP1y4Sx 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"]
2023/11/03 20:18:02 [DEBUG] ffigen config: 
        output: 'C:\Users\24408\AppData\Local\Temp\.tmpP1y4Sx'
        name: 'NativeWire'
        description: 'generated by flutter_rust_bridge'
        headers:
          entry-points:
            - 'C:\Users\24408\AppData\Local\Temp\.tmpwg3Aep.h'
          include-directives:
            - 'C:\Users\24408\AppData\Local\Temp\.tmpwg3Aep.h'
        comments: false
        preamble: |
          // ignore_for_file: camel_case_types, non_constant_identifier_names, avoid_positional_boolean_parameters, annotate_overrides, constant_identifier_names

        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'

2023/11/03 20:18:02 [DEBUG] ffigen config_file: NamedTempFile("C:\\Users\\24408\\AppData\\Local\\Temp\\.tmpWR7Qdl")
2023/11/03 20:18:02 [DEBUG] Guessing toolchain the runner is run into
2023/11/03 20:18:02 [DEBUG] execute command: bin=powershell args="-noprofile -command & \"flutter\" \"pub\" \"run\" \"ffigen\" \"--config\" \"C:\\\\Users\\\\24408\\\\AppData\\\\Local\\\\Temp\\\\.tmpWR7Qdl\"" current_dir=Some("E:\\workspace\\flutter\\frb_test") cmd="powershell" "-noprofile" "-command" "& \"flutter\" \"pub\" \"run\" \"ffigen\" \"--config\" \"C:\\\\Users\\\\24408\\\\AppData\\\\Local\\\\Temp\\\\.tmpWR7Qdl\""
2023/11/03 20:18:04 [DEBUG] command="powershell" "-noprofile" "-command" "& \"flutter\" \"pub\" \"run\" \"ffigen\" \"--config\" \"C:\\\\Users\\\\24408\\\\AppData\\\\Local\\\\Temp\\\\.tmpWR7Qdl\"" stdout=Running in Directory: 'E:\workspace\flutter\frb_test'
Input Headers: [C:\Users\24408\AppData\Local\Temp\.tmpwg3Aep.h]
[SEVERE] : Header C:\Users\24408\AppData\Local\Temp\.tmpwg3Aep.h: Total errors/warnings: 1.
[SEVERE] :     C:\Users\24408\AppData\Local\Temp\.tmpwg3Aep.h:1:10: fatal error: 'stdbool.h' file not found [Lexical or Preprocessor Issue]
[WARNING]: No definition found for declaration - (Cursor) spelling: _Dart_Handle, kind: 2, kindSpelling: StructDecl, type: 105, typeSpelling: struct _Dart_Handle, usr: c:@S@_Dart_Handle
[WARNING]: No definition found for declaration - (Cursor) spelling: _Dart_Handle, kind: 2, kindSpelling: StructDecl, type: 105, typeSpelling: struct _Dart_Handle, usr: c:@S@_Dart_Handle
[WARNING]: No definition found for declaration - (Cursor) spelling: DartCObject, kind: 2, kindSpelling: StructDecl, type: 105, typeSpelling: struct DartCObject, usr: c:@S@DartCObject
[WARNING]: No definition found for declaration - (Cursor) spelling: DartCObject, kind: 2, kindSpelling: StructDecl, type: 105, typeSpelling: struct DartCObject, usr: c:@S@DartCObject
[WARNING]: No definition found for declaration - (Cursor) spelling: _Dart_Handle, kind: 2, kindSpelling: StructDecl, type: 105, typeSpelling: struct _Dart_Handle, usr: c:@S@_Dart_Handle
[WARNING]: No definition found for declaration - (Cursor) spelling: _Dart_Handle, kind: 2, kindSpelling: StructDecl, type: 105, typeSpelling: struct _Dart_Handle, usr: c:@S@_Dart_Handle
[WARNING]: No definition found for declaration - (Cursor) spelling: _Dart_Handle, kind: 2, kindSpelling: StructDecl, type: 105, typeSpelling: struct _Dart_Handle, usr: c:@S@_Dart_Handle
[WARNING]: No definition found for declaration - (Cursor) spelling: _Dart_Handle, kind: 2, kindSpelling: StructDecl, type: 105, typeSpelling: struct _Dart_Handle, usr: c:@S@_Dart_Handle
[WARNING]: No definition found for declaration - (Cursor) spelling: DartCObject, kind: 2, kindSpelling: StructDecl, type: 105, typeSpelling: struct DartCObject, usr: c:@S@DartCObject
[WARNING]: Generated declaration '_Dart_Handle' start's with '_' and therefore will be private.
Finished, Bindings generated in C:\Users\24408\AppData\Local\Temp\.tmpP1y4Sx
 stderr=
2023/11/03 20:18:04 [WARN] See keywords such as `error` in command output. Maybe there is a problem? command="powershell" "-noprofile" "-command" "& \"flutter\" \"pub\" \"run\" \"ffigen\" \"--config\" \"C:\\\\Users\\\\24408\\\\AppData\\\\Local\\\\Temp\\\\.tmpWR7Qdl\"" output=Output { status: ExitStatus(ExitStatus(0)), stdout: "Running in Directory: 'E:\\workspace\\flutter\\frb_test'\r\nInput Headers: [C:\\Users\\24408\\AppData\\Local\\Temp\\.tmpwg3Aep.h]\r\n[SEVERE] : Header C:\\Users\\24408\\AppData\\Local\\Temp\\.tmpwg3Aep.h: Total errors/warnings: 1.\n[SEVERE] :     C:\\Users\\24408\\AppData\\Local\\Temp\\.tmpwg3Aep.h:1:10: fatal error: 'stdbool.h' file not found [Lexical or Preprocessor Issue]\n[WARNING]: No definition found for declaration - (Cursor) spelling: _Dart_Handle, kind: 2, kindSpelling: StructDecl, type: 105, typeSpelling: struct _Dart_Handle, usr: c:@S@_Dart_Handle\n[WARNING]: No definition found for declaration - (Cursor) spelling: _Dart_Handle, kind: 2, kindSpelling: StructDecl, type: 105, typeSpelling: struct _Dart_Handle, usr: c:@S@_Dart_Handle\n[WARNING]: No definition found for declaration - (Cursor) spelling: DartCObject, kind: 2, kindSpelling: StructDecl, type: 105, typeSpelling: struct DartCObject, usr: c:@S@DartCObject\n[WARNING]: No definition found for declaration - (Cursor) spelling: DartCObject, kind: 2, kindSpelling: StructDecl, type: 105, typeSpelling: struct DartCObject, usr: c:@S@DartCObject\n[WARNING]: No definition found for declaration - (Cursor) spelling: _Dart_Handle, kind: 2, kindSpelling: StructDecl, type: 105, typeSpelling: struct _Dart_Handle, usr: c:@S@_Dart_Handle\n[WARNING]: No definition found for declaration - (Cursor) spelling: _Dart_Handle, kind: 2, kindSpelling: StructDecl, type: 105, typeSpelling: struct _Dart_Handle, usr: c:@S@_Dart_Handle\n[WARNING]: No definition found for declaration - (Cursor) spelling: _Dart_Handle, kind: 2, kindSpelling: StructDecl, type: 105, typeSpelling: struct _Dart_Handle, usr: c:@S@_Dart_Handle\n[WARNING]: No definition found for declaration - (Cursor) spelling: _Dart_Handle, kind: 2, kindSpelling: StructDecl, type: 105, typeSpelling: struct _Dart_Handle, usr: c:@S@_Dart_Handle\n[WARNING]: No definition found for declaration - (Cursor) spelling: DartCObject, kind: 2, kindSpelling: StructDecl, type: 105, typeSpelling: struct DartCObject, usr: c:@S@DartCObject\n[WARNING]: Generated declaration '_Dart_Handle' start's with '_' and therefore will be private.\nFinished, Bindings generated in C:\\Users\\24408\\AppData\\Local\\Temp\\.tmpP1y4Sx\n", stderr: "" }
the path is "C:\\Users\\24408\\AppData\\Local\\Temp\\.tmp2mLX7p.h"
2023/11/03 20:18:04 [DEBUG] distinct_input_types=[]
2023/11/03 20:18:04 [DEBUG] distinct_output_types=[Delegate(String), Primitive(U8), PrimitiveList(IrTypePrimitiveList { primitive: U8 })]
2023/11/03 20:18:04 [INFO] Phase: Running build_runner
2023/11/03 20:18:04 [INFO] Phase: Formatting Dart code
2023/11/03 20:18:04 [DEBUG] execute format_dart path=["E:\\workspace\\flutter\\frb_test\\lib/bridge_generated.dart", "E:\\workspace\\flutter\\frb_test\\lib/bridge_definitions.dart"] line_length=80
2023/11/03 20:18:04 [DEBUG] execute command: bin=powershell args="-noprofile -command & \"dart\" \"format\" \"--line-length\" \"80\" \"E:\\\\workspace\\\\flutter\\\\frb_test\\\\lib/bridge_generated.dart\" \"E:\\\\workspace\\\\flutter\\\\frb_test\\\\lib/bridge_definitions.dart\"" current_dir=None cmd="powershell" "-noprofile" "-command" "& \"dart\" \"format\" \"--line-length\" \"80\" \"E:\\\\workspace\\\\flutter\\\\frb_test\\\\lib/bridge_generated.dart\" \"E:\\\\workspace\\\\flutter\\\\frb_test\\\\lib/bridge_definitions.dart\""
2023/11/03 20:18:05 [DEBUG] command="powershell" "-noprofile" "-command" "& \"dart\" \"format\" \"--line-length\" \"80\" \"E:\\\\workspace\\\\flutter\\\\frb_test\\\\lib/bridge_generated.dart\" \"E:\\\\workspace\\\\flutter\\\\frb_test\\\\lib/bridge_definitions.dart\"" stdout=Formatted E:\\workspace\\flutter\\frb_test\\lib/bridge_generated.dart
Formatted E:\\workspace\\flutter\\frb_test\\lib/bridge_definitions.dart
Formatted 2 files (2 changed) in 0.34 seconds.
 stderr=
2023/11/03 20:18:05 [INFO] Success!
2023/11/03 20:18:05 [INFO] Now go and use it :)

To Reproduce

All I do

  1. flutter create frb_test && cd frb_test
  2. cargo new --lib native
  3. flutter pub add --dev ffigen && flutter pub add ffi
  4. flutter pub add flutter_rust_bridge
  5. add flutter_rust_bridge = "1" in cargo.toml
  6. add a hello() function in src/api.rs
  7. flutter_rust_bridge_codegen.exe -r native/src/api.rs -d lib/bridge_generated.dart --dart-decl-output lib/bridge_defini tions.dart

Expected behavior

No response

Generated binding code

/// bridge_generated.dart
// AUTO GENERATED FILE, DO NOT EDIT.
// Generated by `flutter_rust_bridge`@ 1.82.3.
// ignore_for_file: non_constant_identifier_names, unused_element, duplicate_ignore, directives_ordering, curly_braces_in_flow_control_structures, unnecessary_lambdas, slash_for_doc_comments, prefer_const_literals_to_create_immutables, implicit_dynamic_list_literal, duplicate_import, unused_import, unnecessary_import, prefer_single_quotes, prefer_const_constructors, use_super_parameters, always_use_package_imports, annotate_overrides, invalid_use_of_protected_member, constant_identifier_names, invalid_use_of_internal_member, prefer_is_empty, unnecessary_const

import "bridge_definitions.dart";
import 'dart:convert';
import 'dart:async';
import 'package:meta/meta.dart';
import 'package:flutter_rust_bridge/flutter_rust_bridge.dart';
import 'package:uuid/uuid.dart';

import 'dart:convert';
import 'dart:async';
import 'package:meta/meta.dart';
import 'package:flutter_rust_bridge/flutter_rust_bridge.dart';
import 'package:uuid/uuid.dart';

import 'dart:ffi' as ffi;

class NativeImpl implements Native {
  final NativePlatform _platform;
  factory NativeImpl(ExternalLibrary dylib) =>
      NativeImpl.raw(NativePlatform(dylib));

  /// Only valid on web/WASM platforms.
  factory NativeImpl.wasm(FutureOr<WasmModule> module) =>
      NativeImpl(module as ExternalLibrary);
  NativeImpl.raw(this._platform);
  Future<String> hello({dynamic hint}) {
    return _platform.executeNormal(FlutterRustBridgeTask(
      callFfi: (port_) => _platform.inner.wire_hello(port_),
      parseSuccessData: _wire2api_String,
      parseErrorData: null,
      constMeta: kHelloConstMeta,
      argValues: [],
      hint: hint,
    ));
  }

  FlutterRustBridgeTaskConstMeta get kHelloConstMeta =>
      const FlutterRustBridgeTaskConstMeta(
        debugName: "hello",
        argNames: [],
      );

  void dispose() {
    _platform.dispose();
  }
// Section: wire2api

  String _wire2api_String(dynamic raw) {
    return raw as String;
  }

  int _wire2api_u8(dynamic raw) {
    return raw as int;
  }

  Uint8List _wire2api_uint_8_list(dynamic raw) {
    return raw as Uint8List;
  }
}

// Section: api2wire

// Section: finalizer

class NativePlatform extends FlutterRustBridgeBase<NativeWire> {
  NativePlatform(ffi.DynamicLibrary dylib) : super(NativeWire(dylib));

// Section: api2wire

// Section: finalizer

// Section: api_fill_to_wire
}

// ignore_for_file: camel_case_types, non_constant_identifier_names, avoid_positional_boolean_parameters, annotate_overrides, constant_identifier_names

// AUTO GENERATED FILE, DO NOT EDIT.
//
// Generated by `package:ffigen`.
// ignore_for_file: type=lint

/// generated by flutter_rust_bridge
class NativeWire implements FlutterRustBridgeWireBase {
  @internal
  late final dartApi = DartApiDl(init_frb_dart_api_dl);

  /// Holds the symbol lookup function.
  final ffi.Pointer<T> Function<T extends ffi.NativeType>(String symbolName)
      _lookup;

  /// The symbols are looked up in [dynamicLibrary].
  NativeWire(ffi.DynamicLibrary dynamicLibrary)
      : _lookup = dynamicLibrary.lookup;

  /// The symbols are looked up with [lookup].
  NativeWire.fromLookup(
      ffi.Pointer<T> Function<T extends ffi.NativeType>(String symbolName)
          lookup)
      : _lookup = lookup;

  void store_dart_post_cobject(
    int ptr,
  ) {
    return _store_dart_post_cobject(
      ptr,
    );
  }

  late final _store_dart_post_cobjectPtr =
      _lookup<ffi.NativeFunction<ffi.Void Function(ffi.Int)>>(
          'store_dart_post_cobject');
  late final _store_dart_post_cobject =
      _store_dart_post_cobjectPtr.asFunction<void Function(int)>();

  Object get_dart_object(
    int ptr,
  ) {
    return _get_dart_object(
      ptr,
    );
  }

  late final _get_dart_objectPtr =
      _lookup<ffi.NativeFunction<ffi.Handle Function(ffi.Int)>>(
          'get_dart_object');
  late final _get_dart_object =
      _get_dart_objectPtr.asFunction<Object Function(int)>();

  void drop_dart_object(
    int ptr,
  ) {
    return _drop_dart_object(
      ptr,
    );
  }

  late final _drop_dart_objectPtr =
      _lookup<ffi.NativeFunction<ffi.Void Function(ffi.Int)>>(
          'drop_dart_object');
  late final _drop_dart_object =
      _drop_dart_objectPtr.asFunction<void Function(int)>();

  int new_dart_opaque(
    Object handle,
  ) {
    return _new_dart_opaque(
      handle,
    );
  }

  late final _new_dart_opaquePtr =
      _lookup<ffi.NativeFunction<ffi.Int Function(ffi.Handle)>>(
          'new_dart_opaque');
  late final _new_dart_opaque =
      _new_dart_opaquePtr.asFunction<int Function(Object)>();

  int init_frb_dart_api_dl(
    ffi.Pointer<ffi.Void> obj,
  ) {
    return _init_frb_dart_api_dl(
      obj,
    );
  }

  late final _init_frb_dart_api_dlPtr =
      _lookup<ffi.NativeFunction<ffi.Int Function(ffi.Pointer<ffi.Void>)>>(
          'init_frb_dart_api_dl');
  late final _init_frb_dart_api_dl = _init_frb_dart_api_dlPtr
      .asFunction<int Function(ffi.Pointer<ffi.Void>)>();

  void wire_hello(
    int port_,
  ) {
    return _wire_hello(
      port_,
    );
  }

  late final _wire_helloPtr =
      _lookup<ffi.NativeFunction<ffi.Void Function(ffi.Int)>>('wire_hello');
  late final _wire_hello = _wire_helloPtr.asFunction<void Function(int)>();

  void free_WireSyncReturn(
    WireSyncReturn ptr,
  ) {
    return _free_WireSyncReturn(
      ptr,
    );
  }

  late final _free_WireSyncReturnPtr =
      _lookup<ffi.NativeFunction<ffi.Void Function(WireSyncReturn)>>(
          'free_WireSyncReturn');
  late final _free_WireSyncReturn =
      _free_WireSyncReturnPtr.asFunction<void Function(WireSyncReturn)>();
}

final class _Dart_Handle extends ffi.Opaque {}

/// bridge_definitions.dart
// AUTO GENERATED FILE, DO NOT EDIT.
// Generated by `flutter_rust_bridge`@ 1.82.3.
// ignore_for_file: non_constant_identifier_names, unused_element, duplicate_ignore, directives_ordering, curly_braces_in_flow_control_structures, unnecessary_lambdas, slash_for_doc_comments, prefer_const_literals_to_create_immutables, implicit_dynamic_list_literal, duplicate_import, unused_import, unnecessary_import, prefer_single_quotes, prefer_const_constructors, use_super_parameters, always_use_package_imports, annotate_overrides, invalid_use_of_protected_member, constant_identifier_names, invalid_use_of_internal_member, prefer_is_empty, unnecessary_const

import 'dart:convert';
import 'dart:async';
import 'package:meta/meta.dart';
import 'package:flutter_rust_bridge/flutter_rust_bridge.dart';
import 'package:uuid/uuid.dart';

abstract class Native {
  Future<String> hello({dynamic hint});

  FlutterRustBridgeTaskConstMeta get kHelloConstMeta;
}

OS

Windows10 22H2 19045.2846

Version of flutter_rust_bridge_codegen

flutter_rust_bridge_codegen 1.82.3

Flutter info

[✓] Flutter (Channel stable, 3.13.9, on Microsoft Windows [版本 10.0.19045.2846], locale zh-CN)
    • Flutter version 3.13.9 on channel stable at E:\dev\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision d211f42860 (9 days ago), 2023-10-25 13:42:25 -0700
    • Engine revision 0545f8705d
    • Dart version 3.1.5
    • DevTools version 2.25.0

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

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at C:\Users\24408\AppData\Local\Android\Sdk
    • Platform android-34, build-tools 34.0.0
    • Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-b2043.56-9586694)
    • All Android licenses accepted.

[✗] Chrome - develop for the web (Cannot find Chrome executable at .\Google\Chrome\Application\chrome.exe)
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.

[✓] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.5.5)
    • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
    • Visual Studio Community 2022 version 17.5.33627.172
    • Windows 10 SDK version 10.0.22000.0

[✓] Android Studio (version 2022.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 17.0.6+0-b2043.56-9586694)

[✓] VS Code (version 1.84.0)
    • VS Code at C:\Users\24408\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.76.0

[✓] Proxy Configuration
    • HTTP_PROXY is set
    • NO_PROXY is 127.0.0.1,::1,localhost
    • NO_PROXY contains localhost
    • NO_PROXY contains ::1
    • NO_PROXY contains 127.0.0.1

[✓] Connected device (2 available)
    • Windows (desktop) • windows • windows-x64    • Microsoft Windows [版本 10.0.19045.2846]
    • Edge (web)        • edge    • web-javascript • Microsoft Edge 118.0.2088.76

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

! Doctor found issues in 1 category.

Version of clang++

No response

Version of ffigen

^9.0.1

Additional context

src/api.rs

pub fn hello() -> String {
    "hello from rust".to_string()
}

src/lib.rs

mod bridge_generated; /* AUTO INJECTED BY flutter_rust_bridge. This line may not be accurate, and you can change it according to your needs. */
mod api;

Cargo.toml

[package]
name = "native"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
crate-type = ["staticlib", "cdylib"]

[dependencies]
flutter_rust_bridge = "1"

pubspec.yaml

name: frb_test
description: A new Flutter project.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev

version: 1.0.0+1

environment:
  sdk: '>=3.1.5 <4.0.0'

dependencies:
  flutter:
    sdk: flutter

  cupertino_icons: ^1.0.2
  ffi: ^2.1.0
  flutter_rust_bridge: ^1.82.3

dev_dependencies:
  flutter_test:
    sdk: flutter

  flutter_lints: ^2.0.0
  ffigen: ^9.0.1

flutter:
  uses-material-design: true
welcome[bot] commented 11 months ago

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

fzyzcjy commented 11 months ago

[SEVERE] : C:\Users\24408\AppData\Local\Temp.tmpwg3Aep.h:1:10: fatal error: 'stdbool.h' file not found [Lexical or Preprocessor Issue]

This is what I expected :) search this in the issue section and you will find solution IMHO

dryBranch commented 11 months ago

Absolutely Right! It seems the error of upstream tool ffigen. I set the CPATH and it works.

Maybe it need to show explicitly as a error log when using frb codegen? @fzyzcjy

fzyzcjy commented 11 months ago

Good idea - maybe e.g. we can detect this "fatal error: stdbool.h" thing, and print out a message to users saying one possible reason is blah blah. Looking forward to your PR!

github-actions[bot] commented 11 months 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.