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] The parameter 'ptr' of the method 'NativeWire.store_dart_post_cobject' has type 'int', which does not match the corresponding type #1339

Closed K-Finlay closed 1 year ago

K-Finlay commented 1 year ago

Describe the bug

I am using the template from https://github.com/Desdaemon/flutter_rust_bridge_template Running flutter_rust_bridge_codegen works just fine. However, there is an issue with the generated code, which causes a compilation error when running flutter run

➜  flutter run                                                                                                                                          
Launching lib/main.dart on Linux in debug mode...
   Compiling native v0.1.0 (/home/redacted/flutter_rust_bridge_template-main/native)
    Finished dev [unoptimized + debuginfo] target(s) in 0.26s
ERROR: lib/bridge_generated.dart:120:9: Error: The parameter 'ptr' of the method 'NativeWire.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: ../../.pub-cache/hosted/pub.dev/flutter_rust_bridge-1.81.0/lib/src/ffi/stub.dart:21:8: Context: This is the overridden method ('store_dart_post_cobject').
ERROR:   void store_dart_post_cobject(DartPostCObject ptr) {
ERROR:        ^
ERROR: Target kernel_snapshot failed: Exception
Building Linux application...                                           
Exception: Build process failed

Integrating flutter_rust_bridge into an existing project yields the same result.

Codegen logs with RUST_LOG=debug environment variable

2023/08/28 21:53:40 [DEBUG] configs=[Opts { rust_input_path: "/home/redacted/Downloads/flutter_rust_bridge_template-main/native/src/api.rs", dart_output_path: "/home/redacted/Downloads/flutter_rust_bridge_template-main/./lib/bridge_generated.dart", dart_decl_output_path: Some("/home/redacted/Downloads/flutter_rust_bridge_template-main/./lib/bridge_definitions.dart"), c_output_path: ["/home/redacted/Downloads/flutter_rust_bridge_template-main/cout.h"], rust_crate_dir: "/home/redacted/Downloads/flutter_rust_bridge_template-main/native", rust_output_path: "/home/redacted/Downloads/flutter_rust_bridge_template-main/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: "/home/redacted/Downloads/flutter_rust_bridge_template-main/native/Cargo.toml", dart_root: Some("/home/redacted/Downloads/flutter_rust_bridge_template-main"), 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/08/28 21:53:40 [INFO] Running cargo expand in '/home/redacted/Downloads/flutter_rust_bridge_template-main/native'
2023/08/28 21:53:40 [DEBUG] execute command: bin=cargo args="expand --theme=none --ugly" current_dir=Some("/home/redacted/Downloads/flutter_rust_bridge_template-main/native") cmd=cd "/home/redacted/Downloads/flutter_rust_bridge_template-main/native" && "cargo" "expand" "--theme=none" "--ugly"
2023/08/28 21:53:40 [DEBUG] command=cd "/home/redacted/Downloads/flutter_rust_bridge_template-main/native" && "cargo" "expand" "--theme=none" "--ugly" stdout=#![feature(prelude_import)]
#[prelude_import]
use std::prelude::rust_2021::*;
#[macro_use]
extern crate std;
mod api {
    pub enum Platform {
        Unknown,
        Android,
        Ios,
        Windows,
        Unix,
        MacIntel,
        MacApple,
        Wasm,
    }
    pub fn platform() -> Platform {
        if false {
                Platform::Windows
            } else if false {
               Platform::Android
           } else if false {
               Platform::Ios
           } else if false {
               Platform::MacApple
           } else if false {
               Platform::MacIntel
           } else if false {
               Platform::Wasm
           } else if true { Platform::Unix } else { Platform::Unknown }
    }
    pub fn rust_release_mode() -> bool { false }
}
mod bridge_generated {
    #![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_platform_impl(port_: MessagePort) {
        FLUTTER_RUST_BRIDGE_HANDLER.wrap::<_, _, _,
            Platform>(WrapInfo {
                debug_name: "platform",
                port: Some(port_),
                mode: FfiCallMode::Normal,
            }, move || move |task_callback| Ok(platform()))
    }
    fn wire_rust_release_mode_impl(port_: MessagePort) {
        FLUTTER_RUST_BRIDGE_HANDLER.wrap::<_, _, _,
            bool>(WrapInfo {
                debug_name: "rust_release_mode",
                port: Some(port_),
                mode: FfiCallMode::Normal,
            }, move || move |task_callback| Ok(rust_release_mode()))
    }
    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())
        }
    }
    impl support::IntoDart for Platform {
        fn into_dart(self) -> support::DartAbi {
            match self {
                    Self::Unknown => 0,
                    Self::Android => 1,
                    Self::Ios => 2,
                    Self::Windows => 3,
                    Self::Unix => 4,
                    Self::MacIntel => 5,
                    Self::MacApple => 6,
                    Self::Wasm => 7,
                }.into_dart()
        }
    }
    impl support::IntoDartExceptPrimitive for Platform {}
    impl rust2dart::IntoIntoDart<Platform> for Platform {
        fn into_into_dart(self) -> Self { self }
    }
    #[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_platform(port_: i64) {
            wire_platform_impl(port_)
        }
        #[no_mangle]
        pub extern "C" fn wire_rust_release_mode(port_: i64) {
            wire_rust_release_mode_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::*;
}
 stderr=    Checking native v0.1.0 (/home/redacted/Downloads/flutter_rust_bridge_template-main/native)
    Finished dev [unoptimized + debuginfo] target(s) in 0.02s

2023/08/28 21:53:40 [DEBUG] Trying to parse "/home/redacted/Downloads/flutter_rust_bridge_template-main/native/src/api.rs"
2023/08/28 21:53:40 [DEBUG] Trying to parse "/home/redacted/Downloads/flutter_rust_bridge_template-main/native/src/bridge_generated.rs"
2023/08/28 21:53:40 [DEBUG] parse_function function name: Ident(platform)
2023/08/28 21:53:40 [DEBUG] parse_function function name: Ident(rust_release_mode)
2023/08/28 21:53:40 [INFO] Phase: Validate config(s)
2023/08/28 21:53:40 [INFO] Picked config: Opts { rust_input_path: "/home/redacted/Downloads/flutter_rust_bridge_template-main/native/src/api.rs", dart_output_path: "/home/redacted/Downloads/flutter_rust_bridge_template-main/./lib/bridge_generated.dart", dart_decl_output_path: Some("/home/redacted/Downloads/flutter_rust_bridge_template-main/./lib/bridge_definitions.dart"), c_output_path: ["/home/redacted/Downloads/flutter_rust_bridge_template-main/cout.h"], rust_crate_dir: "/home/redacted/Downloads/flutter_rust_bridge_template-main/native", rust_output_path: "/home/redacted/Downloads/flutter_rust_bridge_template-main/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: "/home/redacted/Downloads/flutter_rust_bridge_template-main/native/Cargo.toml", dart_root: Some("/home/redacted/Downloads/flutter_rust_bridge_template-main"), 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/08/28 21:53:40 [INFO] Phase: Parse source code to AST, then to IR
2023/08/28 21:53:40 [DEBUG] Trying to parse "/home/redacted/Downloads/flutter_rust_bridge_template-main/native/src/api.rs"
2023/08/28 21:53:40 [DEBUG] Trying to parse "/home/redacted/Downloads/flutter_rust_bridge_template-main/native/src/bridge_generated.rs"
2023/08/28 21:53:40 [DEBUG] parse_function function name: Ident(platform)
2023/08/28 21:53:40 [DEBUG] parse_function function name: Ident(rust_release_mode)
2023/08/28 21:53:40 [INFO] Phase: Transform IR
2023/08/28 21:53:40 [INFO] Phase: Generate Rust code
2023/08/28 21:53:40 [DEBUG] execute format_rust path=["/home/redacted/Downloads/flutter_rust_bridge_template-main/native/src/bridge_generated.rs"]
2023/08/28 21:53:40 [DEBUG] execute command: bin=rustfmt args="/home/redacted/Downloads/flutter_rust_bridge_template-main/native/src/bridge_generated.rs" current_dir=None cmd="rustfmt" "/home/redacted/Downloads/flutter_rust_bridge_template-main/native/src/bridge_generated.rs"
2023/08/28 21:53:40 [DEBUG] command="rustfmt" "/home/redacted/Downloads/flutter_rust_bridge_template-main/native/src/bridge_generated.rs" stdout= stderr=
2023/08/28 21:53:40 [INFO] Phase: Generate Dart code
2023/08/28 21:53:40 [DEBUG] Guessing toolchain the runner is run into
2023/08/28 21:53:40 [DEBUG] execute command: bin=sh args="-c \"flutter\" \"--version\"" current_dir=None cmd="sh" "-c" "\"flutter\" \"--version\""
2023/08/28 21:53:40 [DEBUG] command="sh" "-c" "\"flutter\" \"--version\"" stdout=Flutter 3.13.1 • channel stable • https://github.com/flutter/flutter.git
Framework • revision e1e47221e8 (5 days ago) • 2023-08-22 21:43:18 -0700
Engine • revision b20183e040
Tools • Dart 3.1.0 • DevTools 2.25.0
 stderr=
2023/08/28 21:53:40 [DEBUG] Checking presence of ffi in dependencies at /home/redacted/Downloads/flutter_rust_bridge_template-main
2023/08/28 21:53:40 [DEBUG] Checking presence of ffi in dependencies at /home/redacted/Downloads/flutter_rust_bridge_template-main
2023/08/28 21:53:40 [DEBUG] Checking presence of ffigen in dev_dependencies at /home/redacted/Downloads/flutter_rust_bridge_template-main
2023/08/28 21:53:40 [DEBUG] Checking presence of ffigen in dev_dependencies at /home/redacted/Downloads/flutter_rust_bridge_template-main
2023/08/28 21:53:40 [INFO] Phase: Generating Dart bindings for Rust
2023/08/28 21:53:40 [DEBUG] execute cbindgen rust_crate_dir=/home/redacted/Downloads/flutter_rust_bridge_template-main/native c_output_path=/tmp/.tmpNnvIha.h
2023/08/28 21:53:40 [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/08/28 21:53:40 [DEBUG] Parsing crate native
2023/08/28 21:53:40 [INFO] Take native::Platform - opaque (Enum is not marked with a valid #[repr(prim)] or #[repr(C)].).
2023/08/28 21:53:40 [INFO] Take native::DartPort.
2023/08/28 21:53:40 [INFO] Take native::DartPostCObjectFnType.
2023/08/28 21:53:40 [INFO] Take native::store_dart_post_cobject.
2023/08/28 21:53:40 [INFO] Take native::get_dart_object.
2023/08/28 21:53:40 [INFO] Take native::drop_dart_object.
2023/08/28 21:53:40 [INFO] Take native::new_dart_opaque.
2023/08/28 21:53:40 [INFO] Take native::init_frb_dart_api_dl.
2023/08/28 21:53:40 [INFO] Take native::DartCObject - opaque (Struct is not marked #[repr(C)] or #[repr(transparent)].).
2023/08/28 21:53:40 [INFO] Take native::WireSyncReturn.
2023/08/28 21:53:40 [INFO] Take native::wire_platform.
2023/08/28 21:53:40 [INFO] Take native::wire_rust_release_mode.
2023/08/28 21:53:40 [INFO] Take native::free_WireSyncReturn.
2023/08/28 21:53:40 [WARN] Can't find Dart_Handle. This usually means that this type was incompatible or not found.
2023/08/28 21:53:40 [WARN] Can't find Dart_Handle. This usually means that this type was incompatible or not found.
2023/08/28 21:53:40 [WARN] Missing `[defines]` entry for `target_family = "wasm"` in cbindgen config.
2023/08/28 21:53:40 [WARN] Missing `[defines]` entry for `target_family = "wasm"` in cbindgen config.
2023/08/28 21:53:40 [WARN] Missing `[defines]` entry for `target_family = "wasm"` in cbindgen config.
2023/08/28 21:53:40 [DEBUG] execute ffigen c_path=/tmp/.tmpNnvIha.h dart_path=/tmp/.tmppQf1bm 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/08/28 21:53:40 [DEBUG] ffigen config: 
        output: '/tmp/.tmppQf1bm'
        name: 'NativeWire'
        description: 'generated by flutter_rust_bridge'
        headers:
          entry-points:
            - '/tmp/.tmpNnvIha.h'
          include-directives:
            - '/tmp/.tmpNnvIha.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/08/28 21:53:40 [DEBUG] ffigen config_file: NamedTempFile("/tmp/.tmp3S4ndZ")
2023/08/28 21:53:40 [DEBUG] Guessing toolchain the runner is run into
2023/08/28 21:53:40 [DEBUG] execute command: bin=sh args="-c \"flutter\" \"pub\" \"run\" \"ffigen\" \"--config\" \"/tmp/.tmp3S4ndZ\"" current_dir=Some("/home/redacted/Downloads/flutter_rust_bridge_template-main") cmd=cd "/home/redacted/Downloads/flutter_rust_bridge_template-main" && "sh" "-c" "\"flutter\" \"pub\" \"run\" \"ffigen\" \"--config\" \"/tmp/.tmp3S4ndZ\""
2023/08/28 21:53:40 [DEBUG] command=cd "/home/redacted/Downloads/flutter_rust_bridge_template-main" && "sh" "-c" "\"flutter\" \"pub\" \"run\" \"ffigen\" \"--config\" \"/tmp/.tmp3S4ndZ\"" stdout=Running in Directory: '/home/redacted/Downloads/flutter_rust_bridge_template-main'
Input Headers: [/tmp/.tmpNnvIha.h]
[SEVERE] : Header /tmp/.tmpNnvIha.h: Total errors/warnings: 1.
[SEVERE] :     /tmp/.tmpNnvIha.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 /tmp/.tmppQf1bm
 stderr=
2023/08/28 21:53:40 [WARN] See keywords such as `error` in command output. Maybe there is a problem? command=cd "/home/redacted/Downloads/flutter_rust_bridge_template-main" && "sh" "-c" "\"flutter\" \"pub\" \"run\" \"ffigen\" \"--config\" \"/tmp/.tmp3S4ndZ\"" output=Output { status: ExitStatus(unix_wait_status(0)), stdout: "Running in Directory: '/home/redacted/Downloads/flutter_rust_bridge_template-main'\nInput Headers: [/tmp/.tmpNnvIha.h]\n[SEVERE] : Header /tmp/.tmpNnvIha.h: Total errors/warnings: 1.\n[SEVERE] :     /tmp/.tmpNnvIha.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 /tmp/.tmppQf1bm\n", stderr: "" }
the path is "/home/redacted/Downloads/flutter_rust_bridge_template-main/cout.h"
2023/08/28 21:53:40 [DEBUG] distinct_input_types=[]
2023/08/28 21:53:40 [DEBUG] distinct_output_types=[Primitive(Bool), Primitive(I32), Delegate(PrimitiveEnum { ir: IrTypeEnumRef { name: "Platform" }, repr: I32 })]
2023/08/28 21:53:40 [INFO] Phase: Running build_runner
2023/08/28 21:53:40 [INFO] Phase: Formatting Dart code
2023/08/28 21:53:40 [DEBUG] execute format_dart path=["/home/redacted/Downloads/flutter_rust_bridge_template-main/./lib/bridge_generated.dart", "/home/redacted/Downloads/flutter_rust_bridge_template-main/./lib/bridge_definitions.dart"] line_length=80
2023/08/28 21:53:40 [DEBUG] execute command: bin=sh args="-c \"dart\" \"format\" \"--line-length\" \"80\" \"/home/redacted/Downloads/flutter_rust_bridge_template-main/./lib/bridge_generated.dart\" \"/home/redacted/Downloads/flutter_rust_bridge_template-main/./lib/bridge_definitions.dart\"" current_dir=None cmd="sh" "-c" "\"dart\" \"format\" \"--line-length\" \"80\" \"/home/redacted/Downloads/flutter_rust_bridge_template-main/./lib/bridge_generated.dart\" \"/home/redacted/Downloads/flutter_rust_bridge_template-main/./lib/bridge_definitions.dart\""
2023/08/28 21:53:41 [DEBUG] command="sh" "-c" "\"dart\" \"format\" \"--line-length\" \"80\" \"/home/redacted/Downloads/flutter_rust_bridge_template-main/./lib/bridge_generated.dart\" \"/home/redacted/Downloads/flutter_rust_bridge_template-main/./lib/bridge_definitions.dart\"" stdout=Formatted /home/redacted/Downloads/flutter_rust_bridge_template-main/./lib/bridge_generated.dart
Formatted /home/redacted/Downloads/flutter_rust_bridge_template-main/./lib/bridge_definitions.dart
Formatted 2 files (2 changed) in 0.12 seconds.
 stderr=
2023/08/28 21:53:41 [INFO] Success!
2023/08/28 21:53:41 [INFO] Now go and use it :)

To Reproduce

Download the template and cd into it. Run flutter_rust_bridge_codegen --rust-input native/src/api.rs --dart-output ./lib/bridge_generated.dart --dart-decl-output ./lib/bridge_definitions.dart Followed by flutter run.

Expected behavior

The Flutter application compiles and runs.

Generated binding code

#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
typedef struct _Dart_Handle* Dart_Handle;

typedef struct DartCObject DartCObject;

typedef int64_t DartPort;

typedef bool (*DartPostCObjectFnType)(DartPort port_id, void *message);

typedef struct DartCObject *WireSyncReturn;

void store_dart_post_cobject(DartPostCObjectFnType ptr);

Dart_Handle get_dart_object(uintptr_t ptr);

void drop_dart_object(uintptr_t ptr);

uintptr_t new_dart_opaque(Dart_Handle handle);

intptr_t init_frb_dart_api_dl(void *obj);

void wire_platform(int64_t port_);

void wire_rust_release_mode(int64_t port_);

void free_WireSyncReturn(WireSyncReturn ptr);

static int64_t dummy_method_to_enforce_bundling(void) {
    int64_t dummy_var = 0;
    dummy_var ^= ((int64_t) (void*) wire_platform);
    dummy_var ^= ((int64_t) (void*) wire_rust_release_mode);
    dummy_var ^= ((int64_t) (void*) free_WireSyncReturn);
    dummy_var ^= ((int64_t) (void*) store_dart_post_cobject);
    dummy_var ^= ((int64_t) (void*) get_dart_object);
    dummy_var ^= ((int64_t) (void*) drop_dart_object);
    dummy_var ^= ((int64_t) (void*) new_dart_opaque);
    return dummy_var;
}

---

// AUTO GENERATED FILE, DO NOT EDIT.
// Generated by `flutter_rust_bridge`@ 1.81.0.
// 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<Platform> platform({dynamic hint}) {
    return _platform.executeNormal(FlutterRustBridgeTask(
      callFfi: (port_) => _platform.inner.wire_platform(port_),
      parseSuccessData: _wire2api_platform,
      constMeta: kPlatformConstMeta,
      argValues: [],
      hint: hint,
    ));
  }

  FlutterRustBridgeTaskConstMeta get kPlatformConstMeta =>
      const FlutterRustBridgeTaskConstMeta(
        debugName: "platform",
        argNames: [],
      );

  Future<bool> rustReleaseMode({dynamic hint}) {
    return _platform.executeNormal(FlutterRustBridgeTask(
      callFfi: (port_) => _platform.inner.wire_rust_release_mode(port_),
      parseSuccessData: _wire2api_bool,
      constMeta: kRustReleaseModeConstMeta,
      argValues: [],
      hint: hint,
    ));
  }

  FlutterRustBridgeTaskConstMeta get kRustReleaseModeConstMeta =>
      const FlutterRustBridgeTaskConstMeta(
        debugName: "rust_release_mode",
        argNames: [],
      );

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

  bool _wire2api_bool(dynamic raw) {
    return raw as bool;
  }

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

  Platform _wire2api_platform(dynamic raw) {
    return Platform.values[raw as int];
  }
}

// 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.UintPtr)>>(
          '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.UintPtr)>>(
          '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.UintPtr 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.IntPtr 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_platform(
    int port_,
  ) {
    return _wire_platform(
      port_,
    );
  }

  late final _wire_platformPtr =
      _lookup<ffi.NativeFunction<ffi.Void Function(ffi.Int64)>>(
          'wire_platform');
  late final _wire_platform =
      _wire_platformPtr.asFunction<void Function(int)>();

  void wire_rust_release_mode(
    int port_,
  ) {
    return _wire_rust_release_mode(
      port_,
    );
  }

  late final _wire_rust_release_modePtr =
      _lookup<ffi.NativeFunction<ffi.Void Function(ffi.Int64)>>(
          'wire_rust_release_mode');
  late final _wire_rust_release_mode =
      _wire_rust_release_modePtr.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 {}

OS

Nobara Linux

Version of flutter_rust_bridge_codegen

1.81.0

Flutter info

[✓] Flutter (Channel stable, 3.13.1, on Nobara Linux 38 (Thirty Eight) 6.4.10-202.fsync.fc38.x86_64, locale en_AU.UTF-8)
    • Flutter version 3.13.1 on channel stable at /home/redacted/Development/Sdk/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision e1e47221e8 (5 days ago), 2023-08-22 21:43:18 -0700
    • Engine revision b20183e040
    • Dart version 3.1.0
    • DevTools version 2.25.0

[✗] Android toolchain - develop for Android devices
    ✗ Unable to locate Android SDK.
      Install Android Studio from: https://developer.android.com/studio/index.html
      On first launch it will assist you in installing the Android SDK components.
      (or visit https://flutter.dev/docs/get-started/install/linux#android-setup for detailed instructions).
      If the Android SDK has been installed to a custom location, please use
      `flutter config --android-sdk` to update to that location.

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

[✓] Linux toolchain - develop for Linux desktop
    • clang version 15.0.7 (Fedora 15.0.7-2.fc38)
    • cmake version 3.27.3
    • ninja version 1.11.1
    • pkg-config version 1.8.0

[!] Android Studio (not installed)
    • Android Studio not found; download from https://developer.android.com/studio/index.html
      (or visit https://flutter.dev/docs/get-started/install/linux#android-setup for detailed instructions).

[✓] IntelliJ IDEA Community Edition (version 2023.2)
    • IntelliJ at /home/redacted/.local/share/JetBrains/Toolbox/apps/intellij-idea-community-edition
    • Flutter plugin version 75.1.4
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart

[✓] Connected device (1 available)
    • Linux (desktop) • linux • linux-x64 • Nobara Linux 38 (Thirty Eight) 6.4.10-202.fsync.fc38.x86_64

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

! Doctor found issues in 3 categories.

Version of clang++

15.0.7

Version of ffigen

8.0.2

Additional context

No response

welcome[bot] commented 1 year ago

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

fzyzcjy commented 1 year ago

[SEVERE] : /tmp/.tmpNnvIha.h:1:10: fatal error: 'stdbool.h' file not found [Lexical or Preprocessor Issue]

thus

https://github.com/fzyzcjy/flutter_rust_bridge/issues?q=%27stdbool.h%27+file+not+found

K-Finlay commented 1 year ago

It looks like this is an issue with ffigen. For anyone else who has the same problem, the following command linked here resolved it for me: https://github.com/dart-lang/native/issues/338

Closing this issue.

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.