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.26k stars 300 forks source link

Enums, structs and `pub use *` won't be compiled to dart #1409

Closed lomirus closed 10 months ago

lomirus commented 1 year ago

Describe the bug

Here's the native/src/api.rs:

use as_any::AsAny;

mod ithkuil_svg;
mod primary;
mod quarternary;
mod secondary;
mod tertiary;
mod utils;

pub trait Character: AsAny {
    fn get_svg(&self, base_x: f64, base_y: f64, fill_color: &str) -> (String, f64);
}

pub use ithkuil_svg::ithkuil_svg;
pub use primary::Primary;
pub use quarternary::Quarternary;
pub use secondary::Secondary;
pub use tertiary::Tertiary;

pub fn a() {}

pub enum B {
    A,
    B,
}

pub struct C {
    a: String,
    b: String
}

Then I ran:

flutter_rust_bridge_codegen --rust-input native\src\api.rs --dart-output .\lib\bridge_generated.dart --dart-decl-output .\lib\bridge_definitions.dart --w
asm

The output file lib/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 'bridge_generated.io.dart'
    if (dart.library.html) 'bridge_generated.web.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';

abstract class Native {
  Future<void> a({dynamic hint});

  FlutterRustBridgeTaskConstMeta get kAConstMeta;
}

Only fn a() was compiled, enum B, struct C, fn ithkuil_svg(), struct Primary etc. was not compiled to dart.

Codegen logs with RUST_LOG=debug environment variable

When I attemped to post this issue, the github said:

Comment is too long (maximum is 65536 characters)

So I will omit some unnecessary logs below.

2023/11/04 21:58:17 [DEBUG] configs=[Opts { rust_input_path: "D:\\Projects\\ithkuil_helper\\native\\src\\api.rs", dart_output_path: "D:\\Projects\\ithkuil_helper\\.\\lib\\bridge_generated.dart", dart_decl_output_path: Some("D:\\Projects\\ithkuil_helper\\.\\lib\\bridge_definitions.dart"), c_output_path: ["C:\\Users\\28154\\AppData\\Local\\Temp\\.tmpXBtDuQ.h"], rust_crate_dir: "D:\\Projects\\ithkuil_helper\\native", rust_output_path: "D:\\Projects\\ithkuil_helper\\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: "D:\\Projects\\ithkuil_helper\\native\\Cargo.toml", dart_root: Some("D:\\Projects\\ithkuil_helper"), build_runner: true, block_index: BlockIndex(0), skip_deps_check: false, wasm_enabled: true, inline_rust: false, bridge_in_method: true, extra_headers: "", dart3: true, keep_going: false }]
2023/11/04 21:58:17 [INFO] Running cargo expand in 'D:/Projects/ithkuil_helper/native'
2023/11/04 21:58:17 [DEBUG] execute command: bin=cargo args="expand --theme=none --ugly" current_dir=Some("D:/Projects/ithkuil_helper/native") cmd="cargo" "expand" "--theme=none" "--ugly"
2023/11/04 21:58:17 [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_a_impl(port_: MessagePort) {
        FLUTTER_RUST_BRIDGE_HANDLER.wrap::<_, _, _, (),
            _>(WrapInfo {
                debug_name: "a",
                port: Some(port_),
                mode: FfiCallMode::Normal,
            }, move || move |task_callback| Result::<_, ()>::Ok(a()))
    }
    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_a(port_: i64) { wire_a_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 {
    use as_any::AsAny;

    /***********************************/
    /* Omit more than 3000 lines here. */
    /***********************************/

    pub trait Character: AsAny {
        fn get_svg(&self, base_x: f64, base_y: f64, fill_color: &str)
        -> (String, f64);
    }
    pub use ithkuil_svg::ithkuil_svg;
    pub use primary::Primary;
    pub use quarternary::Quarternary;
    pub use secondary::Secondary;
    pub use tertiary::Tertiary;
    pub fn a() {}
    pub enum B { A, B, }
    pub struct C {
        a: String,
        b: String,
    }
}
 stderr=    Checking native v0.1.0 (D:\Projects\ithkuil_helper\native)
    Finished dev [unoptimized + debuginfo] target(s) in 0.11s

2023/11/04 21:58:18 [DEBUG] Trying to parse "\\\\?\\D:\\Projects\\ithkuil_helper\\native\\src\\bridge_generated.rs"
2023/11/04 21:58:18 [DEBUG] Trying to parse "\\\\?\\D:\\Projects\\ithkuil_helper\\native\\src\\api.rs"
2023/11/04 21:58:18 [DEBUG] parse_function function name: Ident(a)
2023/11/04 21:58:18 [INFO] Phase: Validate config(s)
2023/11/04 21:58:18 [INFO] Picked config: Opts { rust_input_path: "D:\\Projects\\ithkuil_helper\\native\\src\\api.rs", dart_output_path: "D:\\Projects\\ithkuil_helper\\.\\lib\\bridge_generated.dart", dart_decl_output_path: Some("D:\\Projects\\ithkuil_helper\\.\\lib\\bridge_definitions.dart"), c_output_path: ["C:\\Users\\28154\\AppData\\Local\\Temp\\.tmpXBtDuQ.h"], rust_crate_dir: "D:\\Projects\\ithkuil_helper\\native", rust_output_path: "D:\\Projects\\ithkuil_helper\\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: "D:\\Projects\\ithkuil_helper\\native\\Cargo.toml", dart_root: Some("D:\\Projects\\ithkuil_helper"), build_runner: true, block_index: BlockIndex(0), skip_deps_check: false, wasm_enabled: true, inline_rust: false, bridge_in_method: true, extra_headers: "", dart3: true, keep_going: false }
2023/11/04 21:58:18 [INFO] Phase: Parse source code to AST, then to IR
2023/11/04 21:58:18 [DEBUG] Trying to parse "\\\\?\\D:\\Projects\\ithkuil_helper\\native\\src\\bridge_generated.rs"
2023/11/04 21:58:18 [DEBUG] Trying to parse "\\\\?\\D:\\Projects\\ithkuil_helper\\native\\src\\api.rs"
2023/11/04 21:58:18 [DEBUG] parse_function function name: Ident(a)
2023/11/04 21:58:18 [INFO] Phase: Transform IR
2023/11/04 21:58:18 [INFO] Phase: Generate Rust code
2023/11/04 21:58:18 [DEBUG] execute format_rust path=["D:\\Projects\\ithkuil_helper\\native\\src\\bridge_generated.rs", "D:\\Projects\\ithkuil_helper\\native\\src\\bridge_generated.io.rs", "D:\\Projects\\ithkuil_helper\\native\\src\\bridge_generated.web.rs"]
2023/11/04 21:58:18 [DEBUG] execute command: bin=rustfmt args="D:\\Projects\\ithkuil_helper\\native\\src\\bridge_generated.rs D:\\Projects\\ithkuil_helper\\native\\src\\bridge_generated.io.rs D:\\Projects\\ithkuil_helper\\native\\src\\bridge_generated.web.rs" current_dir=None cmd="rustfmt" "D:\\Projects\\ithkuil_helper\\native\\src\\bridge_generated.rs" "D:\\Projects\\ithkuil_helper\\native\\src\\bridge_generated.io.rs" "D:\\Projects\\ithkuil_helper\\native\\src\\bridge_generated.web.rs"
2023/11/04 21:58:18 [DEBUG] command="rustfmt" "D:\\Projects\\ithkuil_helper\\native\\src\\bridge_generated.rs" "D:\\Projects\\ithkuil_helper\\native\\src\\bridge_generated.io.rs" "D:\\Projects\\ithkuil_helper\\native\\src\\bridge_generated.web.rs" stdout= stderr=
2023/11/04 21:58:18 [INFO] Phase: Generate Dart code
2023/11/04 21:58:18 [DEBUG] Guessing toolchain the runner is run into
2023/11/04 21:58:18 [DEBUG] execute command: bin=powershell args="-noprofile -command & \"flutter\" \"--version\"" current_dir=None cmd="powershell" "-noprofile" "-command" "& \"flutter\" \"--version\""
2023/11/04 21:58:19 [DEBUG] command="powershell" "-noprofile" "-command" "& \"flutter\" \"--version\"" stdout=Flutter 3.12.0-1.1.pre • channel beta • https://github.com/flutter/flutter.git
Framework • revision e2e0aa7037 (5 months ago) • 2023-06-20 19:48:59 -0700
Engine • revision 45712dd2f1
Tools • Dart 3.1.0 (build 3.1.0-163.1.beta) • DevTools 2.24.0
 stderr=
2023/11/04 21:58:19 [DEBUG] Checking presence of ffi in dependencies at D:\Projects\ithkuil_helper
2023/11/04 21:58:19 [DEBUG] Checking presence of ffi in dependencies at D:\Projects\ithkuil_helper
2023/11/04 21:58:19 [DEBUG] Checking presence of ffigen in dev_dependencies at D:\Projects\ithkuil_helper
2023/11/04 21:58:19 [DEBUG] Checking presence of ffigen in dev_dependencies at D:\Projects\ithkuil_helper
2023/11/04 21:58:19 [INFO] Phase: Generating Dart bindings for Rust
2023/11/04 21:58:19 [DEBUG] execute cbindgen rust_crate_dir=D:\Projects\ithkuil_helper\native c_output_path=C:\Users\28154\AppData\Local\Temp\.tmprxxuhp.h
2023/11/04 21:58:19 [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/04 21:58:19 [DEBUG] Parsing crate native
2023/11/04 21:58:19 [INFO] Take native::DartPort.
2023/11/04 21:58:19 [INFO] Take native::DartPostCObjectFnType.
2023/11/04 21:58:19 [INFO] Take native::store_dart_post_cobject.
2023/11/04 21:58:19 [INFO] Take native::get_dart_object.
2023/11/04 21:58:19 [INFO] Take native::drop_dart_object.
2023/11/04 21:58:19 [INFO] Take native::new_dart_opaque.
2023/11/04 21:58:19 [INFO] Take native::init_frb_dart_api_dl.
2023/11/04 21:58:19 [INFO] Take native::DartCObject - opaque (Struct is not marked #[repr(C)] or #[repr(transparent)].).
2023/11/04 21:58:19 [INFO] Take native::WireSyncReturn.
2023/11/04 21:58:19 [INFO] Take native::wire_a.
2023/11/04 21:58:19 [INFO] Take native::free_WireSyncReturn.
2023/11/04 21:58:19 [INFO] Take native::B - opaque (Enum is not marked with a valid #[repr(prim)] or #[repr(C)].).
2023/11/04 21:58:19 [INFO] Take native::C - opaque (Struct is not marked #[repr(C)] or #[repr(transparent)].).
2023/11/04 21:58:19 [WARN] Skip native::UNIT_HEIGHT - (not `pub`).
2023/11/04 21:58:19 [WARN] Skip native::VERTICAL_PADDING - (not `pub`).
2023/11/04 21:58:19 [WARN] Skip native::HORIZONTAL_PADDING - (not `pub`).
2023/11/04 21:58:19 [WARN] Skip native::HORIZONTAL_GAP - (not `pub`).
2023/11/04 21:58:19 [INFO] Take native::Primary - opaque (Struct is not marked #[repr(C)] or #[repr(transparent)].).
2023/11/04 21:58:19 [INFO] Take native::ComponentA - opaque (Struct is not marked #[repr(C)] or #[repr(transparent)].).
2023/11/04 21:58:19 [INFO] Take native::ComponentB - opaque (Struct is not marked #[repr(C)] or #[repr(transparent)].).
2023/11/04 21:58:19 [INFO] Take native::ComponentC - opaque (Struct is not marked #[repr(C)] or #[repr(transparent)].).
2023/11/04 21:58:19 [INFO] Take native::ComponentD - opaque (Struct is not marked #[repr(C)] or #[repr(transparent)].).
2023/11/04 21:58:19 [INFO] Take native::Affiliation - opaque (Enum is not marked with a valid #[repr(prim)] or #[repr(C)].).
2023/11/04 21:58:19 [INFO] Take native::Context - opaque (Enum is not marked with a valid #[repr(prim)] or #[repr(C)].).
2023/11/04 21:58:19 [INFO] Take native::Essence - opaque (Enum is not marked with a valid #[repr(prim)] or #[repr(C)].).
2023/11/04 21:58:19 [INFO] Take native::Extension - opaque (Enum is not marked with a valid #[repr(prim)] or #[repr(C)].).
2023/11/04 21:58:19 [INFO] Take native::Function - opaque (Enum is not marked with a valid #[repr(prim)] or #[repr(C)].).
2023/11/04 21:58:19 [INFO] Take native::Perspective - opaque (Enum is not marked with a valid #[repr(prim)] or #[repr(C)].).
2023/11/04 21:58:19 [INFO] Take native::Plexity - opaque (Enum is not marked with a valid #[repr(prim)] or #[repr(C)].).
2023/11/04 21:58:19 [INFO] Take native::Separability - opaque (Enum is not marked with a valid #[repr(prim)] or #[repr(C)].).
2023/11/04 21:58:19 [INFO] Take native::Similarity - opaque (Enum is not marked with a valid #[repr(prim)] or #[repr(C)].).
2023/11/04 21:58:19 [INFO] Take native::Specification - opaque (Enum is not marked with a valid #[repr(prim)] or #[repr(C)].).
2023/11/04 21:58:19 [INFO] Take native::Stem - opaque (Enum is not marked with a valid #[repr(prim)] or #[repr(C)].).
2023/11/04 21:58:19 [INFO] Take native::Version - opaque (Enum is not marked with a valid #[repr(prim)] or #[repr(C)].).
2023/11/04 21:58:19 [WARN] Skip native::CORE_PATH - (not `pub`).
2023/11/04 21:58:19 [WARN] Skip native::CORE_TOP_ANCHOR - (not `pub`).
2023/11/04 21:58:19 [WARN] Skip native::CORE_BOTTOM_ANCHOR - (not `pub`).
2023/11/04 21:58:19 [INFO] Take native::Quarternary - opaque (Struct is not marked #[repr(C)] or #[repr(transparent)].).
2023/11/04 21:58:19 [INFO] Take native::CaseQuarternary - opaque (Struct is not marked #[repr(C)] or #[repr(transparent)].).
2023/11/04 21:58:19 [INFO] Take native::VerbalQuarternary - opaque (Struct is not marked #[repr(C)] or #[repr(transparent)].).
2023/11/04 21:58:19 [INFO] Take native::QuarternaryBottom - opaque (Enum is not marked with a valid #[repr(prim)] or #[repr(C)].).
2023/11/04 21:58:19 [INFO] Take native::QuarternaryTop - opaque (Enum is not marked with a valid #[repr(prim)] or #[repr(C)].).
2023/11/04 21:58:19 [INFO] Take native::Secondary - opaque (Struct is not marked #[repr(C)] or #[repr(transparent)].).
2023/11/04 21:58:19 [INFO] Take native::Orientation - opaque (Enum is not marked with a valid #[repr(prim)] or #[repr(C)].).
2023/11/04 21:58:19 [INFO] Take native::Anchor - opaque (Struct is not marked #[repr(C)] or #[repr(transparent)].).
2023/11/04 21:58:19 [INFO] Take native::Phoneme - opaque (Enum is not marked with a valid #[repr(prim)] or #[repr(C)].).
2023/11/04 21:58:19 [INFO] Take native::PhonemeCore - opaque (Enum is not marked with a valid #[repr(prim)] or #[repr(C)].).
2023/11/04 21:58:19 [INFO] Take native::Tertiary - opaque (Struct is not marked #[repr(C)] or #[repr(transparent)].).
2023/11/04 21:58:19 [INFO] Take native::TertiaryExtension - opaque (Enum is not marked with a valid #[repr(prim)] or #[repr(C)].).
2023/11/04 21:58:19 [INFO] Take native::Valence - opaque (Enum is not marked with a valid #[repr(prim)] or #[repr(C)].).
2023/11/04 21:58:19 [INFO] Take native::Coord - opaque (Struct is not marked #[repr(C)] or #[repr(transparent)].).
2023/11/04 21:58:19 [WARN] Can't find Dart_Handle. This usually means that this type was incompatible or not found.
2023/11/04 21:58:19 [WARN] Can't find Dart_Handle. This usually means that this type was incompatible or not found.
2023/11/04 21:58:19 [WARN] Missing `[defines]` entry for `target_family = "wasm"` in cbindgen config.
2023/11/04 21:58:19 [WARN] Missing `[defines]` entry for `target_family = "wasm"` in cbindgen config.
2023/11/04 21:58:19 [DEBUG] execute ffigen c_path=C:\Users\28154\AppData\Local\Temp\.tmprxxuhp.h dart_path=C:\Users\28154\AppData\Local\Temp\.tmppeuQwo 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/04 21:58:19 [DEBUG] ffigen config: 
        output: 'C:\Users\28154\AppData\Local\Temp\.tmppeuQwo'
        name: 'NativeWire'
        description: 'generated by flutter_rust_bridge'
        headers:
          entry-points:
            - 'C:\Users\28154\AppData\Local\Temp\.tmprxxuhp.h'
          include-directives:
            - 'C:\Users\28154\AppData\Local\Temp\.tmprxxuhp.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/04 21:58:19 [DEBUG] ffigen config_file: NamedTempFile("C:\\Users\\28154\\AppData\\Local\\Temp\\.tmpmx47OK")
2023/11/04 21:58:19 [DEBUG] Guessing toolchain the runner is run into
2023/11/04 21:58:19 [DEBUG] execute command: bin=powershell args="-noprofile -command & \"flutter\" \"pub\" \"run\" \"ffigen\" \"--config\" \"C:\\\\Users\\\\28154\\\\AppData\\\\Local\\\\Temp\\\\.tmpmx47OK\"" current_dir=Some("D:\\Projects\\ithkuil_helper") cmd="powershell" "-noprofile" "-command" "& \"flutter\" \"pub\" \"run\" \"ffigen\" \"--config\" \"C:\\\\Users\\\\28154\\\\AppData\\\\Local\\\\Temp\\\\.tmpmx47OK\""
2023/11/04 21:58:21 [DEBUG] command="powershell" "-noprofile" "-command" "& \"flutter\" \"pub\" \"run\" \"ffigen\" \"--config\" \"C:\\\\Users\\\\28154\\\\AppData\\\\Local\\\\Temp\\\\.tmpmx47OK\"" stdout=Running in Directory: 'D:\Projects\ithkuil_helper'
Input Headers: [C:\Users\28154\AppData\Local\Temp\.tmprxxuhp.h]
[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\28154\AppData\Local\Temp\.tmppeuQwo
 stderr=
the path is "C:\\Users\\28154\\AppData\\Local\\Temp\\.tmpXBtDuQ.h"
2023/11/04 21:58:21 [DEBUG] distinct_input_types=[]
2023/11/04 21:58:21 [DEBUG] distinct_output_types=[Primitive(Unit)]
2023/11/04 21:58:21 [INFO] Phase: Running build_runner
2023/11/04 21:58:21 [INFO] Phase: Formatting Dart code
2023/11/04 21:58:21 [DEBUG] execute format_dart path=["D:\\Projects\\ithkuil_helper\\.\\lib\\bridge_generated.dart", "D:\\Projects\\ithkuil_helper\\.\\lib\\bridge_definitions.dart", "D:\\Projects\\ithkuil_helper\\.\\lib\\bridge_generated.web.dart", "D:\\Projects\\ithkuil_helper\\.\\lib\\bridge_generated.io.dart"] line_length=80
2023/11/04 21:58:21 [DEBUG] execute command: bin=powershell args="-noprofile -command & \"dart\" \"format\" \"--line-length\" \"80\" \"D:\\\\Projects\\\\ithkuil_helper\\\\.\\\\lib\\\\bridge_generated.dart\" \"D:\\\\Projects\\\\ithkuil_helper\\\\.\\\\lib\\\\bridge_definitions.dart\" \"D:\\\\Projects\\\\ithkuil_helper\\\\.\\\\lib\\\\bridge_generated.web.dart\" \"D:\\\\Projects\\\\ithkuil_helper\\\\.\\\\lib\\\\bridge_generated.io.dart\"" current_dir=None cmd="powershell" "-noprofile" "-command" "& \"dart\" \"format\" \"--line-length\" \"80\" \"D:\\\\Projects\\\\ithkuil_helper\\\\.\\\\lib\\\\bridge_generated.dart\" \"D:\\\\Projects\\\\ithkuil_helper\\\\.\\\\lib\\\\bridge_definitions.dart\" \"D:\\\\Projects\\\\ithkuil_helper\\\\.\\\\lib\\\\bridge_generated.web.dart\" \"D:\\\\Projects\\\\ithkuil_helper\\\\.\\\\lib\\\\bridge_generated.io.dart\""
2023/11/04 21:58:22 [DEBUG] command="powershell" "-noprofile" "-command" "& \"dart\" \"format\" \"--line-length\" \"80\" \"D:\\\\Projects\\\\ithkuil_helper\\\\.\\\\lib\\\\bridge_generated.dart\" \"D:\\\\Projects\\\\ithkuil_helper\\\\.\\\\lib\\\\bridge_definitions.dart\" \"D:\\\\Projects\\\\ithkuil_helper\\\\.\\\\lib\\\\bridge_generated.web.dart\" \"D:\\\\Projects\\\\ithkuil_helper\\\\.\\\\lib\\\\bridge_generated.io.dart\"" stdout=Formatted D:\\Projects\\ithkuil_helper\\.\\lib\\bridge_generated.dart
Formatted D:\\Projects\\ithkuil_helper\\.\\lib\\bridge_definitions.dart
Formatted D:\\Projects\\ithkuil_helper\\.\\lib\\bridge_generated.web.dart
Formatted D:\\Projects\\ithkuil_helper\\.\\lib\\bridge_generated.io.dart
Formatted 4 files (4 changed) in 0.28 seconds.
 stderr=
2023/11/04 21:58:22 [INFO] Success!
2023/11/04 21:58:22 [INFO] Now go and use it :)

To Reproduce

See Describe the bug

Expected behavior

enum B, struct C, fn ithkuil_svg(), struct Primary etc. would be compiled to dart as the fn a()

Generated binding code

// 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 'bridge_generated.io.dart'
    if (dart.library.html) 'bridge_generated.web.dart';

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<void> a({dynamic hint}) {
    return _platform.executeNormal(FlutterRustBridgeTask(
      callFfi: (port_) => _platform.inner.wire_a(port_),
      parseSuccessData: _wire2api_unit,
      parseErrorData: null,
      constMeta: kAConstMeta,
      argValues: [],
      hint: hint,
    ));
  }

  FlutterRustBridgeTaskConstMeta get kAConstMeta =>
      const FlutterRustBridgeTaskConstMeta(
        debugName: "a",
        argNames: [],
      );

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

  void _wire2api_unit(dynamic raw) {
    return;
  }
}

// Section: api2wire

// Section: finalizer

OS

Windows

Version of flutter_rust_bridge_codegen

1.82.3

Flutter info

[√] Flutter (Channel beta, 3.12.0-1.1.pre, on Microsoft Windows [版本 10.0.22621.2428], locale zh-CN)
    • Flutter version 3.12.0-1.1.pre on channel beta at C:\Packages\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision e2e0aa7037 (5 months ago), 2023-06-20 19:48:59 -0700
    • Engine revision 45712dd2f1
    • Dart version 3.1.0 (build 3.1.0-163.1.beta)
    • DevTools version 2.24.0

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

[√] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
    • Android SDK at C:\Users\28154\AppData\Local\Android\sdk
    • Platform android-33, build-tools 33.0.2
    • 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
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.6.4)
    • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
    • Visual Studio Community 2022 version 17.6.33815.320
    • 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\28154\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.76.0

[!] Proxy Configuration
    • HTTP_PROXY is set
    ! NO_PROXY is not set

[√] Connected device (3 available)
    • Windows (desktop) • windows • windows-x64    • Microsoft Windows [版本 10.0.22621.2428]
    • Chrome (web)      • chrome  • web-javascript • Google Chrome 118.0.5993.120
    • Edge (web)        • edge    • web-javascript • Microsoft Edge 119.0.2151.44

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

! Doctor found issues in 1 category.

Version of clang++

17.0.1

Version of ffigen

^9.0.1

Additional context

No response

welcome[bot] commented 1 year ago

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

fzyzcjy commented 1 year ago

That looks like a bug. One way may be to reproduce this / compare this with the https://github.com/fzyzcjy/flutter_rust_bridge/tree/master/frb_example/pure_dart example (since that one works well)

lomirus commented 1 year ago

I cloned fzyzcjy/flutter_rust_bridge and cd into the pure_dart, removed generated files and regenerated by:

flutter_rust_bridge_codegen --rust-input rust\src\api.rs --dart-output dart\lib\bridge_generated.dart --dart-decl-output dart\lib\bridge_definitions.dart --wasm

It built successfully and there seems only formatting changes.

QQ截图20231105144728

Then I added struct Test at the end of the api.rs:

QQ截图20231105144957

Then ran codegen again:

flutter_rust_bridge_codegen --rust-input rust\src\api.rs --dart-output dart\lib\bridge_generated.dart --dart-decl-output dart\lib\bridge_definitions.dart --wasm

Nothing changed. The bridge_definitions.dart stayed the same.

fzyzcjy commented 1 year ago

Oh I see: So it seems that you never use the struct in any function? Maybe try to use them in a function (just create a function that does exactly nothing and that should be enough)

lomirus commented 1 year ago

Thanks, it works now for the struct. But how about the function imported to api.rs? For example, I created fn get_svg() in rust/src/svg/mod.rs, and then in rust/src/api.rs I added:

pub use crate::svg::get_svg;

But it wasn't compiled to dart.

lomirus commented 1 year ago

It seems that there's a bug in Github Issue, your last comment is earlier than mine but what it displays in fact is that my previous comment is earlier. 🤔

fzyzcjy commented 1 year ago

Thanks, it works now for the struct. But how about the function imported to api.rs? For example, I created fn get_svg() in rust/src/svg/mod.rs, and then in rust/src/api.rs I added:

pub use crate::svg::get_svg;

But it wasn't compiled to dart.

IIRC that one is not implemented yet. Feel free to PR to fix it!

fzyzcjy commented 10 months ago

In v2, flutter_rust_bridge supports a whole folder (indeed a whole crate) as input, so this is no longer an issue. Feel free to reopen if needed!

lomirus commented 10 months ago

Thanks ! 👍

fzyzcjy commented 10 months ago

You are welcome!

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