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

Do we support this syntax for code generation `Lazy<Arc<RwLock<Option<T>>>>` ? #831

Closed thaodt closed 1 year ago

thaodt commented 1 year ago

Is your feature request related to a problem? Please describe. I'm not sure if it related to this #775 In api.rs, I declare a static var like below:

pub static GLOB_DATA: Lazy<Arc<RwLock<Option<MyDataWrapper>>>> =
    Lazy::new(|| Arc::new(RwLock::new(None)));

and the struct:

pub struct MyDataWrapper {}
impl MyDataWrapper {
// ....
}

Because I got the following messages:

[2022-11-09T08:56:02Z WARN  cbindgen::bindgen::parser] Skip native::GLOB_DATA - (not `no_mangle`).
[2022-11-09T08:56:02Z INFO  cbindgen::bindgen::parser] Take native::MyDataWrapper - opaque (Struct is not marked #[repr(C)] or #[repr(transparent)].).

Describe the solution you'd like If this is relating to the issue I linked above, when I can use this feature?

Describe alternatives you've considered Otherwise is there any alternative solutions to work around it?

p/s: I'm checking examples here, but I'm confused which one served for which purposes and also the example link here is not found now, please point me out the update link if possible. I just want to check more types that this code generator can generate.

Thank you.

fzyzcjy commented 1 year ago

GLOB_DATA itself is ok

what error do you have indeed? "skip" is not an error

thaodt commented 1 year ago

GLOB_DATA itself is ok

what error do you have indeed? "skip" is not an error

Hmmm, lemme check again. Because I didn't see any updates in bridge_generated.rs after running build runner for generation. Therefore I thought the message about opaque type for my struct MyDataWrapper is a problem also

fzyzcjy commented 1 year ago

please provide full output log. maybe somewhere else is wrong

thaodt commented 1 year ago

@fzyzcjy Okay, I found the problem. Im not sure why flutter_rust_bridge_codegen --version still kept the old one (1.30.0) even though in Cargo.toml I put the version 1.49.1. After updating, I got this error:

[2022-11-09T12:23:44Z DEBUG lib_flutter_rust_bridge_codegen::parser] parse_function function name: Ident(get_latest_block_hash__static_method__MyDataWrapper)
thread 'main' panicked at 'Failed to parse function output type `Result<Sha256Hash,String>`', /home/thaodt/.cargo/registry/src/github.com-1ecc6299db9ec823/flutter_rust_bridge_codegen-1.49.1/src/parser/mod.rs:161:25
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
error: Recipe `gen` failed on line 16 with exit code 101

And actually Sha256Hash is [u8; 32]. Could you please advise me on this ?

fzyzcjy commented 1 year ago

could you please provide full information? maybe open a new issue

thaodt commented 1 year ago

@fzyzcjy also, please provide me the update link for this one? I want to check more types that this code generator can generate.

thaodt commented 1 year ago

could you please provide full information? maybe open a new issue

Sure this is full log:

RUST_LOG=debug flutter_rust_bridge_codegen  --rust-input native/src/api.rs --dart-output lib/bridge_generated.dart --c-output ios/Runner/bridge_generated.h --rust-output native/src/bridge_generated.rs
[2022-11-09T12:23:43Z DEBUG flutter_rust_bridge_codegen] configs=[Opts { rust_input_path: "/home/thaodt/projects/MyWallet/native/src/api.rs", dart_output_path: "/home/thaodt/projects/MyWallet/lib/bridge_generated.dart", dart_decl_output_path: None, c_output_path: ["/home/thaodt/projects/MyWallet/ios/Runner/bridge_generated.h"], rust_crate_dir: "/home/thaodt/projects/MyWallet/native", rust_output_path: "/home/thaodt/projects/MyWallet/native/src/bridge_generated.rs", class_name: "Native", dart_format_line_length: 80, 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/thaodt/projects/MyWallet/native/Cargo.toml", dart_root: Some("/home/thaodt/projects/MyWallet"), build_runner: true, block_index: BlockIndex(0), skip_deps_check: false, wasm_enabled: false, inline_rust: false }]
[2022-11-09T12:23:44Z DEBUG lib_flutter_rust_bridge_codegen::source_graph] Trying to parse "/home/thaodt/projects/MyWallet/native/src/api.rs"
[2022-11-09T12:23:44Z DEBUG lib_flutter_rust_bridge_codegen::source_graph] Trying to parse "/home/thaodt/projects/MyWallet/native/src/bridge_generated.rs"
[2022-11-09T12:23:44Z DEBUG lib_flutter_rust_bridge_codegen::parser] parse_function function name: Ident(get_balance__static_method__MyDataWrapper)
[2022-11-09T12:23:44Z DEBUG lib_flutter_rust_bridge_codegen::parser] parse_function function name: Ident(get_latest_block_id__static_method__MyDataWrapper)
[2022-11-09T12:23:44Z DEBUG lib_flutter_rust_bridge_codegen::parser] parse_function function name: Ident(get_latest_block_hash__static_method__MyDataWrapper)
thread 'main' panicked at 'Failed to parse function output type `Result<Sha256Hash,String>`', /home/thaodt/.cargo/registry/src/github.com-1ecc6299db9ec823/flutter_rust_bridge_codegen-1.49.1/src/parser/mod.rs:161:25
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
error: Recipe `gen` failed on line 16 with exit code 101
fzyzcjy commented 1 year ago

e.g. what is Sha256Hash etc please see issue template -> https://github.com/fzyzcjy/flutter_rust_bridge/issues/new?assignees=&labels=bug&template=bug_report.yaml&title=%5BBug%5D+

thaodt commented 1 year ago

e.g. what is Sha256Hash etc please see issue template -> https://github.com/fzyzcjy/flutter_rust_bridge/issues/new?assignees=&labels=bug&template=bug_report.yaml&title=%5BBug%5D+

actually I mentioned Sha256Hash type here, but its okay. Lemme close this issue and open new bug issue.

fzyzcjy commented 1 year ago

and actually Sha256Hash is [u8; 32].

Indeed this is insufficient. need to at least know: where is it defined? is it pub? etc

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.