fzyzcjy / flutter_rust_bridge

Flutter/Dart <-> Rust binding generator, feature-rich, but seamless and simple.
https://fzyzcjy.github.io/flutter_rust_bridge/
MIT License
4.12k stars 283 forks source link

[Bug] API cannot include symbols from external crate - even if mirrored #858

Closed iCodeSometime closed 1 year ago

iCodeSometime commented 1 year ago

Describe the bug

With this api.rs file

use flutter_rust_bridge::frb;
use time::{Date, Month};

#[frb(mirror(Date))]
pub struct _Date {
    value: i32,
}

pub fn getDate() -> Date {
    Date::from_calendar_date(2022, Month::November, 24).expect("constant valid date")
}

After running the generator, cargo build gives errors error[E0412]: cannot find type Date in this scope

Codegen logs with RUST_LOG=debug environment variable

Adding in comment - github is complaining it is too long

To Reproduce

No response

Expected behavior

The generated file should include all necessary imports.

Generated binding code

#![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
)]
// AUTO GENERATED FILE, DO NOT EDIT.
// Generated by `flutter_rust_bridge`@ 1.49.2.

use crate::api::*;
use core::panic::UnwindSafe;
use flutter_rust_bridge::*;

// Section: imports

// Section: wire functions

fn wire_getDate_impl(port_: MessagePort) {
    FLUTTER_RUST_BRIDGE_HANDLER.wrap(
        WrapInfo {
            debug_name: "getDate",
            port: Some(port_),
            mode: FfiCallMode::Normal,
        },
        move || move |task_callback| Ok(mirror_Date(getDate())),
    )
}
// Section: wrapper structs

#[derive(Clone)]
struct mirror_Date(Date);

// Section: static checks

const _: fn() = || {
    let Date = None::<Date>.unwrap();
    let _: i32 = Date.value;
};
// Section: allocate functions

// Section: impl Wire2Api

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())
    }
}
// Section: impl IntoDart

impl support::IntoDart for mirror_Date {
    fn into_dart(self) -> support::DartAbi {
        vec![self.0.value.into_dart()].into_dart()
    }
}
impl support::IntoDartExceptPrimitive for mirror_Date {}

// Section: executor

support::lazy_static! {
    pub static ref FLUTTER_RUST_BRIDGE_HANDLER: support::DefaultHandler = Default::default();
}

/// cbindgen:ignore
#[cfg(target_family = "wasm")]
#[path = "bridge_generated.web.rs"]
mod web;
#[cfg(target_family = "wasm")]
pub use web::*;

#[cfg(not(target_family = "wasm"))]
#[path = "bridge_generated.io.rs"]
mod io;
#[cfg(not(target_family = "wasm"))]
pub use io::*;

OS

MacOS

Version of flutter_rust_bridge_codegen

1.49.2

Flutter info

No response

Version of clang++

No response

Version of ffigen

No response

Additional context

No response

welcome[bot] commented 1 year ago

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

iCodeSometime commented 1 year ago

[removed]

iCodeSometime commented 1 year ago

After re-reading the documentation, this is fixed by using pub use time::Date

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.