Closed kthecoder closed 1 year ago
Hi! Thanks for opening your first issue here! :smile:
Hi, it would be great to show more logs, e.g. RUST_BACKTRACE=1
Do I just put env::set_var("RUST_BACKTRACE", "1");
inside of the lib file? Cause that isn't working.
IMHO just do sth similar to RUST_LOG=debug
I must be tired I just realized these are environment variables.
//==========================================================================//
Running: $env:RUST_LOG="debug"
Running: flutter_rust_bridge_codegen --rust-input rust\libsignal-main\rust\protocol\src\lib.rs --dart-output lib\libsignal_bridge_generated.dart
[ERROR] panicked at 'fail to guess class_name, please specify it manually in command line arguments', C:\Users.cargo\registry\src\github.com-1ecc6299db9ec823\flutter_rust_bridge_codegen-1.72.1\src\config\opts_parser.rs:177:37 thread 'main' panicked at 'fail to guess class_name, please specify it manually in command line arguments', C:\Users.cargo\registry\src\github.com-1ecc6299db9ec823\flutter_rust_bridge_codegen-1.72.1\src\config\o2023/04/02 21:15:10
[DEBUG] configs=[Opts { rust_input_path: "C:\Users\Documents\Files\Repos\libsignal_bridge\rust\libsignal-main\rust\protocol\src\lib.rs", dart_output_path: "C:\Users\Documents\Files\Repos\libsignal_bridge\lib\libsignal_bridge_generated.dart", dart_decl_output_path: None, c_output_path: ["C:\Users\AppData\Local\Temp\.tmpwtVrrj.h"], rust_crate_dir: "C:\Users\Documents\Files\Repos\libsignal_bridge\rust\libsignal-main\rust\protocol", rust_output_path: "C:\Users\Documents\Files\Repos\libsignal_bridge\rust\libsignal-main\rust\protocol\src\bridge_generated.rs", class_name: "LibsignalProtocol", 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: "C:\Users\Documents\Files\Repos\libsignal_bridge\rust\libsignal-main\rust\protocol\Cargo.toml", dart_root: Some("C:\Users\Documents\Files\Repos\libsignal_bridge"), build_runner: true, block_index: BlockIndex(0), skip_deps_check: false, wasm_enabled: false, inline_rust: false }]
[ERROR] panicked at 'called Result::unwrap()
on an Err
value: Error("expected square brackets")',
C:\Users.cargo\registry\src\github.com-1ecc6299db9ec823\flutter_rust_bridge_codegen-1.72.1\src\config\opts.rs:41:62
thread 'main' panicked at 'called Result::unwrap()
on an Err
value: Error("expected square brackets")',
C:\Users.cargo\registry\src\github.com-1ecc6299db9ec823\flutter_rust_bridge_codegen-1.72.1\src\config\opts.rs:41:62
note: run with RUST_BACKTRACE=1
environment variable to display a backtrace
//======================================================================//
Running : $env:RUST_BACKTRACE=1
Running: flutter_rust_bridge_codegen --rust-input rust\libsignal-main\rust\protocol\src\lib.rs --dart-output lib\libsignal_bridge_generated.dart
2023/04/02 20:55:37 [ERROR] panicked at 'called Result::unwrap()
on an Err
value: Error("expected square brackets")',
C:\Users.cargo\registry\src\github.com-1ecc6299db9ec823\flutter_rust_bridge_codegen-1.72.1\src\config\opts.rs:41:62
thread 'main' panicked at 'called Result::unwrap()
on an Err
value: Error("expected square brackets")',
C:\Users.cargo\registry\src\github.com-1ecc6299db9ec823\flutter_rust_bridge_codegen-1.72.1\src\config\opts.rs:41:62
stack backtrace:
note: Some details are omitted, run with RUST_BACKTRACE=full
for a verbose backtrace.
//=====================================================================//
Running: $env:RUST_BACKTRACE="full"
Running: flutter_rust_bridge_codegen --rust-input rust\libsignal-main\rust\protocol\src\lib.rs --dart-output lib\libsignal_bridge_generated.dart
[INFO] Phase: Validate config(s)
[INFO] Picked config: Opts { rust_input_path: "C:\Users\Documents\Files\Repos\libsignal_bridge\rust\libsignal-main\rust\protocol\src\lib.rs", dart_output_path: "C:\Users\Documents\Files\Repos\libsignal_bridge\lib\libsignal_bridge_generated.dart", dart_decl_output_path: None, c_output_path: ["C:\Users\AppData\Local\Temp\.tmpNtVdIY.h"], rust_crate_dir: "C:\Users\Documents\Files\Repos\libsignal_bridge\rust\libsignal-main\rust\protocol", rust_output_path: "C:\Users\Documents\Files\Repos\libsignal_bridge\rust\libsignal-main\rust\protocol\src\bridge_generated.rs", class_name: "LibsignalProtocol", 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: "C:\Users\Documents\Files\Repos\libsignal_bridge\rust\libsignal-main\rust\protocol\Cargo.toml", dart_root: Some("C:\Users\Documents\Files\Repos\libsignal_bridge"), build_runner: true, block_index: BlockIndex(0), skip_deps_check: false, wasm_enabled: false, inline_rust: false }
[INFO] Phase: Parse source code to AST, then to IR
[INFO] Phase: Transform IR
[INFO] Phase: Generate Rust code
[INFO] Inject mod bridge_generated;
into "C:\Users\Documents\Files\Repos\libsignal_bridge\rust\libsignal-main\rust\protocol\src\lib.rs"
Warning: can't set imports_granularity = Module
, unstable features are only available in nightly channel.
[INFO] Phase: Generate Dart code Flutter 3.7.9 • channel stable • https://github.com/flutter/flutter.git Framework • revision 62bd79521d (3 days ago) • 2023-03-30 10:59:36 -0700 Engine • revision ec975089ac Tools • Dart 2.19.6 • DevTools 2.20.1
[INFO] Phase: Generating Dart bindings for Rust
[ERROR] fatal: Parsing crate libsignal-protocol
:C:\Users\Documents\libsignal_bridge\rust\libsignal-main\rust\protocol\src\lib.rs
:
Error("expected square brackets")
Try running rustc -Z parse-only C:\Users\Documents\libsignal_bridge\rust\libsignal-main\rust\protocol\src\lib.rs
to see a nicer error message
PS C:\Users\Documents\libsignal_bridge> flutter_rust_bridge_codegen --rust-input rust\libsignal-main\rust\protocol\src\lib.rs --dart-output lib\libsignal_bridge_generated.dart
[ERROR] panicked at 'called Result::unwrap()
on an Err
value: Error("expected square brackets")', C:\Users.cargo\registry\src\github.com-1ecc6299db9ec823\flutter_rust_bridge_codegen-1.72.1\src\config\opts.rs:41:62
thread 'main' panicked at 'called Result::unwrap()
on an Err
value: Error("expected square brackets")', C:\Users.cargo\registry\src\github.com-1ecc6299db9ec823\flutter_rust_bridge_codegen-1.72.1\src\config\opts.rs:41:62
stack backtrace:
0: 0x7ff6cce93f52 -
//==========================================================================//
[ERROR] fatal: Parsing crate libsignal-protocol:C:\Users\Documents\libsignal_bridge\rust\libsignal-main\rust\protocol\src\lib.rs: Error("expected square brackets") Try running rustc -Z parse-only C:\Users\Documents\libsignal_bridge\rust\libsignal-main\rust\protocol\src\lib.rs to see a nicer error message
Ok so the problem seems that, syn
crate fails to parse the rust code. I am not sure, maybe this is a bug of syn, or your code has syntax error?
Looking at Signals Bindings Builder for Swift they build the entire library using cbindgen which produces Swift Bindings for C.
Flutter_Rust_Bridge also uses cbindgen. The rust project I am trying to create bindings for consists of a set of multiple libraries using a Workspace. There is no main lib.rs file. Furthermore, each lib.rs in each crate contains pub's pointing to actual implementations.
What is the difference in steps to generate the bindings?
The difference is that, frb firstly uses syn
to parse rust files. cbindgen is a later step.
The folder seems a bit complex, so I am not sure current frb implementation understands it correctly. Feel free to PR! I guess you only need to modify some parser https://github.com/fzyzcjy/flutter_rust_bridge/tree/master/frb_codegen/src/parser
If its not too much of a bother, I have a few questions.
So the goal is, someone comes along and just wants to use some random unknown Rust project. The solution being just generate all possible bindings for whatever is found.
To do so, the only change that needs to be made is the ability to iterate over all possible connected files.
FRB runs on just a single file. So is the only necessary change to find all possible files connected by pub mod
, use crate
or mod
?
And if file exists, run the current FRB on each of the files? And where for instance create::path::to::{foo1, foo2 as foo3}
only parse those defined functions/classes?
Would this be the function to change? Parser -> mod.rs:
pub fn parse(source_rust_content: &str, file: File, manifest_path: &str) -> IrFile {
let crate_map = Crate::new(manifest_path);
let mut src_fns = extract_fns_from_file(&file);
src_fns.extend(extract_methods_from_file(&file));
let src_structs = crate_map.root_module.collect_structs_to_vec();
let src_enums = crate_map.root_module.collect_enums_to_vec();
let src_types = crate_map.root_module.collect_types_to_pool();
let src_types = topo_resolve(src_types);
let parser = Parser::new(TypeParser::new(src_structs, src_enums, src_types));
parser.parse(source_rust_content, src_fns)
}
Or best to create a second function and a cmd flag?
IIRC, currently we only have a limited feature: https://cjycode.com/flutter_rust_bridge/feature/lang_external.html#types-in-other-crates. By searching the related PRs you may know more design choices why it was implemented like that (IIRC simplicity?).
However, feel free to enhance the library to support automated generation of arbitrary crates - that looks like a quite useful feature!
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
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.
Describe the bug
I've tried running the generator on:
All give the same error of
I don't know if its something I am doing wrong or what. I followed the guides on adding in all necessary dependencies and installed LLVM, Visual Studio C++ development. I added build runner, ffigen, ffi, and flutter_rust_bridge_codegen; to the pubspec
Codegen logs with
RUST_LOG=debug
environment variableTo Reproduce
Expected behavior
Expect a generated output to complete
Generated binding code
OS
Windows
Version of
flutter_rust_bridge_codegen
1.72.1
Flutter info
Version of
clang++
16.0.0
Version of
ffigen
7.2.9
Additional context
No response