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.31k stars 301 forks source link

[Bug] `Err` value: Error("expected square brackets") #1152

Closed kthecoder closed 1 year ago

kthecoder commented 1 year ago

Describe the bug

I've tried running the generator on:

  1. https://github.com/iotaledger/iota.rs
  2. https://github.com/iotaledger/wallet.rs
  3. https://github.com/signalapp/libsignal

All give the same error of

[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

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 variable

//=============== Iota.rs

flutter_rust_bridge_codegen --rust-input rust\iota.rs-develop\client\src\lib.rs --dart-output lib\iota_bridge_generated.dart --verbose
2023/04/02 15:12:02 [DEBUG] configs=[Opts { rust_input_path: "C:\\Users\\Documents\\Files\\Repos\\iota_bridge\\rust\\iota.rs-develop\\client\\src\\lib.rs", dart_output_path: "C:\\Users\Documents\\Files\\Repos\\iota_bridge\\lib\\iota_bridge_generated.dart", dart_decl_output_path: None, c_output_path: ["C:\\Users\\AppData\\Local\\Temp\\.tmpBrJIh7.h"], rust_crate_dir: "C:\\Users\\Documents\\Files\\Repos\\iota_bridge\\rust\\iota.rs-develop\\client", rust_output_path: "C:\\Users\\Documents\\Files\\Repos\\iota_bridge\\rust\\iota.rs-develop\\client\\src\\bridge_generated.rs", class_name: "IotaClient", 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\\iota_bridge\\rust\\iota.rs-develop\\client\\Cargo.toml", dart_root: Some("C:\\Users\\Documents\\Files\\Repos\\iota_bridge"), build_runner: true, block_index: BlockIndex(0), skip_deps_check: false, wasm_enabled: false, inline_rust: false }]
2023/04/02 15:12:02 [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

//=============== Wallet.rs

flutter_rust_bridge_codegen --rust-input rust\wallet.rs-develop\wallet\src\lib.rs --dart-output lib\wallet_bridge_generated.dart --verbose
2023/04/02 15:27:33 [DEBUG] configs=[Opts { rust_input_path: "C:\\Users\\Documents\\Files\\Repos\\iota_bridge\\rust\\wallet.rs-develop\\wallet\\src\\lib.rs", dart_output_path: "C:\\Users\\Documents\\Files\\Repos\\iota_bridge\\lib\\wallet_bridge_generated.dart", dart_decl_output_path: None, c_output_path: ["C:\\Users\\AppData\\Local\\Temp\\.tmpSRG3YK.h"], rust_crate_dir: "C:\\Users\\Documents\\Files\\Repos\\iota_bridge\\rust\\wallet.rs-develop\\wallet", rust_output_path: "C:\\Users\\Documents\\Files\\Repos\\iota_bridge\\rust\\wallet.rs-develop\\wallet\\src\\bridge_generated.rs", class_name: "IotaWallet", 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\\iota_bridge\\rust\\wallet.rs-develop\\wallet\\Cargo.toml", dart_root: Some("C:\\Users\\Documents\\Files\\Repos\\iota_bridge"), build_runner: true, block_index: BlockIndex(0), skip_deps_check: false, wasm_enabled: false, inline_rust: false }]
2023/04/02 15:27:33 [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

//=============== Libsignal

flutter_rust_bridge_codegen --rust-input rust\libsignal-main\rust\protocol\src\lib.rs --dart-output lib\libsignal_bridge_generated.dart --verbose
2023/04/02 15:16:04 [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\\.tmpt92637.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 }]
2023/04/02 15:16:48 [DEBUG] Trying to parse "\\\\?\\C:\\Users\\\Documents\\Files\\Repos\\libsignal_bridge\\rust\\libsignal-main\\rust\\protocol\\src\\address.rs"
2023/04/02 15:16:48 [DEBUG] Trying to parse "\\\\?\\C:\\Users\\Documents\\Files\\Repos\\libsignal_bridge\\rust\\libsignal-main\\rust\\protocol\\src\\consts.rs"
2023/04/02 15:16:48 [DEBUG] Trying to parse "\\\\?\\C:\\Users\\Documents\\Files\\Repos\\libsignal_bridge\\rust\\libsignal-main\\rust\\protocol\\src\\crypto.rs"
2023/04/02 15:16:48 [DEBUG] Trying to parse "\\\\?\\C:\\Users\\Documents\\Files\\Repos\\libsignal_bridge\\rust\\libsignal-main\\rust\\protocol\\src\\curve.rs"
2023/04/02 15:16:48 [DEBUG] Trying to parse "\\\\?\\C:\\Users\\Documents\\Files\\Repos\\libsignal_bridge\\rust\\libsignal-main\\rust\\protocol\\src\\curve\\curve25519.rs"
2023/04/02 15:16:48 [DEBUG] Trying to parse "\\\\?\\C:\\Users\\Documents\\Files\\Repos\\libsignal_bridge\\rust\\libsignal-main\\rust\\protocol\\src\\error.rs"
2023/04/02 15:16:48 [DEBUG] Trying to parse "\\\\?\\C:\\Users\\Documents\\Files\\Repos\\libsignal_bridge\\rust\\libsignal-main\\rust\\protocol\\src\\fingerprint.rs"
2023/04/02 15:16:48 [DEBUG] Trying to parse "\\\\?\\C:\\Users\\Documents\\Files\\Repos\\libsignal_bridge\\rust\\libsignal-main\\rust\\protocol\\src\\group_cipher.rs"
2023/04/02 15:16:48 [DEBUG] Trying to parse "\\\\?\\C:\\Users\\Documents\\Files\\Repos\\libsignal_bridge\\rust\\libsignal-main\\rust\\protocol\\src\\identity_key.rs"
2023/04/02 15:16:48 [DEBUG] Trying to parse "\\\\?\\C:\\Users\\Documents\\Files\\Repos\\libsignal_bridge\\rust\\libsignal-main\\rust\\protocol\\src\\proto.rs"
2023/04/02 15:16:48 [DEBUG] Trying to parse "\\\\?\\C:\\Users\\Documents\\Files\\Repos\\libsignal_bridge\\rust\\libsignal-main\\rust\\protocol\\src\\fingerprint.rs"
2023/04/02 15:16:48 [DEBUG] Trying to parse "\\\\?\\C:\\Users\\Documents\\Files\\Repos\\libsignal_bridge\\rust\\libsignal-main\\rust\\protocol\\src\\sealed_sender.rs"
2023/04/02 15:16:48 [DEBUG] Trying to parse "\\\\?\\C:\\Users\\Documents\\Files\\Repos\\libsignal_bridge\\rust\\libsignal-main\\rust\\protocol\\src\\proto\\service.rs"
2023/04/02 15:16:48 [DEBUG] Trying to parse "\\\\?\\C:\\Users\\Documents\\Files\\Repos\\libsignal_bridge\\rust\\libsignal-main\\rust\\protocol\\src\\storage.rs"
2023/04/02 15:16:48 [DEBUG] Trying to parse "\\\\?\\C:\\Users\\Documents\\Files\\Repos\\libsignal_bridge\\rust\\libsignal-main\\rust\\protocol\\src\\storage\\inmem.rs"
2023/04/02 15:16:48 [DEBUG] Trying to parse "\\\\?\\C:\\Users\\Documents\\Files\\Repos\\libsignal_bridge\\rust\\libsignal-main\\rust\\protocol\\src\\storage\\traits.rs"
2023/04/02 15:16:48 [DEBUG] Trying to parse "\\\\?\\C:\\Users\\Documents\\Files\\Repos\\libsignal_bridge\\rust\\libsignal-main\\rust\\protocol\\src\\proto\\wire.rs"
2023/04/02 15:16:48 [DEBUG] Trying to parse "\\\\?\\C:\\Users\\Documents\\Files\\Repos\\libsignal_bridge\\rust\\libsignal-main\\rust\\protocol\\src\\protocol.rs"
2023/04/02 15:16:48 [DEBUG] Trying to parse "\\\\?\\C:\\Users\\Documents\\Files\\Repos\\libsignal_bridge\\rust\\libsignal-main\\rust\\protocol\\src\\ratchet.rs"
2023/04/02 15:16:48 [DEBUG] Trying to parse "\\\\?\\C:\\Users\\Documents\\Files\\Repos\\libsignal_bridge\\rust\\libsignal-main\\rust\\protocol\\src\\ratchet\\keys.rs"
2023/04/02 15:16:48 [DEBUG] Trying to parse "\\\\?\\C:\\Users\\Documents\\Files\\Repos\\libsignal_bridge\\rust\\libsignal-main\\rust\\protocol\\src\\ratchet\\params.rs"
2023/04/02 15:16:48 [DEBUG] Trying to parse "\\\\?\\C:\\Users\\Documents\\Files\\Repos\\libsignal_bridge\\rust\\libsignal-main\\rust\\protocol\\src\\sealed_sender.rs"
2023/04/02 15:16:48 [DEBUG] Trying to parse "\\\\?\\C:\\Users\\Documents\\Files\\Repos\\libsignal_bridge\\rust\\libsignal-main\\rust\\protocol\\src\\sender_keys.rs"
2023/04/02 15:16:48 [DEBUG] Trying to parse "\\\\?\\C:\\Users\\Documents\\Files\\Repos\\libsignal_bridge\\rust\\libsignal-main\\rust\\protocol\\src\\session.rs"
2023/04/02 15:16:48 [DEBUG] Trying to parse "\\\\?\\C:\\Users\\Documents\\Files\\Repos\\libsignal_bridge\\rust\\libsignal-main\\rust\\protocol\\src\\session_cipher.rs"
2023/04/02 15:16:48 [DEBUG] Trying to parse "\\\\?\\C:\\Users\\Documents\\Files\\Repos\\libsignal_bridge\\rust\\libsignal-main\\rust\\protocol\\src\\state.rs"
2023/04/02 15:16:48 [DEBUG] Trying to parse "\\\\?\\C:\\Users\\Documents\\Files\\Repos\\libsignal_bridge\\rust\\libsignal-main\\rust\\protocol\\src\\state\\bundle.rs"
2023/04/02 15:16:48 [DEBUG] Trying to parse "\\\\?\\C:\\Users\\Documents\\Files\\Repos\\libsignal_bridge\\rust\\libsignal-main\\rust\\protocol\\src\\state\\prekey.rs"
2023/04/02 15:16:48 [DEBUG] Trying to parse "\\\\?\\C:\\Users\\Documents\\Files\\Repos\\libsignal_bridge\\rust\\libsignal-main\\rust\\protocol\\src\\session.rs"
2023/04/02 15:16:48 [DEBUG] Trying to parse "\\\\?\\C:\\Users\\Documents\\Files\\Repos\\libsignal_bridge\\rust\\libsignal-main\\rust\\protocol\\src\\state\\signed_prekey.rs"
2023/04/02 15:16:48 [DEBUG] Trying to parse "\\\\?\\C:\\Users\\Documents\\Files\\Repos\\libsignal_bridge\\rust\\libsignal-main\\rust\\protocol\\src\\storage.rs"
2023/04/02 15:16:48 [DEBUG] Trying to parse "\\\\?\\C:\\Users\Documents\\Files\\Repos\\libsignal_bridge\\rust\\libsignal-main\\rust\\protocol\\src\\storage\\inmem.rs"
2023/04/02 15:16:48 [DEBUG] Trying to parse "\\\\?\\C:\\Users\\Documents\\Files\\Repos\\libsignal_bridge\\rust\\libsignal-main\\rust\\protocol\\src\\storage\\traits.rs"
2023/04/02 15:16:48 [DEBUG] Trying to parse "\\\\?\\C:\\Users\\Documents\\Files\\Repos\\libsignal_bridge\\rust\\libsignal-main\\rust\\protocol\\src\\utils.rs"
2023/04/02 15:16:48 [INFO] Phase: Validate config(s)
2023/04/02 15:16:48 [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\\.tmpt92637.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 }
2023/04/02 15:16:48 [INFO] Phase: Parse source code to AST, then to IR
2023/04/02 15:16:49 [DEBUG] Trying to parse "\\\\?\\C:\\Users\\Documents\\Files\\Repos\\libsignal_bridge\\rust\\libsignal-main\\rust\\protocol\\src\\address.rs"
2023/04/02 15:16:49 [DEBUG] Trying to parse "\\\\?\\C:\\Users\\Documents\\Files\\Repos\\libsignal_bridge\\rust\\libsignal-main\\rust\\protocol\\src\\consts.rs"
2023/04/02 15:16:49 [DEBUG] Trying to parse "\\\\?\\C:\\Users\\Documents\\Files\\Repos\\libsignal_bridge\\rust\\libsignal-main\\rust\\protocol\\src\\crypto.rs"
2023/04/02 15:16:49 [DEBUG] Trying to parse "\\\\?\\C:\\Users\\Documents\\Files\\Repos\\libsignal_bridge\\rust\\libsignal-main\\rust\\protocol\\src\\curve.rs"
2023/04/02 15:16:49 [DEBUG] Trying to parse "\\\\?\\C:\\Users\\Documents\\Files\\Repos\\libsignal_bridge\\rust\\libsignal-main\\rust\\protocol\\src\\curve\\curve25519.rs"
2023/04/02 15:16:49 [DEBUG] Trying to parse "\\\\?\\C:\\Users\\Documents\\Files\\Repos\\libsignal_bridge\\rust\\libsignal-main\\rust\\protocol\\src\\error.rs"
2023/04/02 15:16:49 [DEBUG] Trying to parse "\\\\?\\C:\\Users\\Documents\\Files\\Repos\\libsignal_bridge\\rust\\libsignal-main\\rust\\protocol\\src\\fingerprint.rs"
2023/04/02 15:16:49 [DEBUG] Trying to parse "\\\\?\\C:\\Users\\Documents\\Files\\Repos\\libsignal_bridge\\rust\\libsignal-main\\rust\\protocol\\src\\group_cipher.rs"
2023/04/02 15:16:49 [DEBUG] Trying to parse "\\\\?\\C:\\Users\\Documents\\Files\\Repos\\libsignal_bridge\\rust\\libsignal-main\\rust\\protocol\\src\\identity_key.rs"
2023/04/02 15:16:49 [DEBUG] Trying to parse "\\\\?\\C:\\Users\\Documents\\Files\\Repos\\libsignal_bridge\\rust\\libsignal-main\\rust\\protocol\\src\\proto.rs"
2023/04/02 15:16:49 [DEBUG] Trying to parse "\\\\?\\C:\\Users\\Documents\\Files\\Repos\\libsignal_bridge\\rust\\libsignal-main\\rust\\protocol\\src\\fingerprint.rs"
2023/04/02 15:16:49 [DEBUG] Trying to parse "\\\\?\\C:\\Users\\Documents\\Files\\Repos\\libsignal_bridge\\rust\\libsignal-main\\rust\\protocol\\src\\sealed_sender.rs"
2023/04/02 15:16:49 [DEBUG] Trying to parse "\\\\?\\C:\\Users\\Documents\\Files\\Repos\\libsignal_bridge\\rust\\libsignal-main\\rust\\protocol\\src\\proto\\service.rs"
2023/04/02 15:16:49 [DEBUG] Trying to parse "\\\\?\\C:\\Users\\Documents\\Files\\Repos\\libsignal_bridge\\rust\\libsignal-main\\rust\\protocol\\src\\storage.rs"
2023/04/02 15:16:49 [DEBUG] Trying to parse "\\\\?\\C:\\Users\\Documents\\Files\\Repos\\libsignal_bridge\\rust\\libsignal-main\\rust\\protocol\\src\\storage\\inmem.rs"
2023/04/02 15:16:49 [DEBUG] Trying to parse "\\\\?\\C:\\Users\\Documents\\Files\\Repos\\libsignal_bridge\\rust\\libsignal-main\\rust\\protocol\\src\\storage\\traits.rs"
2023/04/02 15:16:49 [DEBUG] Trying to parse "\\\\?\\C:\\Users\\Documents\\Files\\Repos\\libsignal_bridge\\rust\\libsignal-main\\rust\\protocol\\src\\proto\\wire.rs"
2023/04/02 15:16:49 [DEBUG] Trying to parse "\\\\?\\C:\\Users\\Documents\\Files\\Repos\\libsignal_bridge\\rust\\libsignal-main\\rust\\protocol\\src\\protocol.rs"
2023/04/02 15:16:49 [DEBUG] Trying to parse "\\\\?\\C:\\Users\\Documents\\Files\\Repos\\libsignal_bridge\\rust\\libsignal-main\\rust\\protocol\\src\\ratchet.rs"
2023/04/02 15:16:49 [DEBUG] Trying to parse "\\\\?\\C:\\Users\\Documents\\Files\\Repos\\libsignal_bridge\\rust\\libsignal-main\\rust\\protocol\\src\\ratchet\\keys.rs"
2023/04/02 15:16:49 [DEBUG] Trying to parse "\\\\?\\C:\\Users\\Documents\\Files\\Repos\\libsignal_bridge\\rust\\libsignal-main\\rust\\protocol\\src\\ratchet\\params.rs"
2023/04/02 15:16:49 [DEBUG] Trying to parse "\\\\?\\C:\\Users\\Documents\\Files\\Repos\\libsignal_bridge\\rust\\libsignal-main\\rust\\protocol\\src\\sealed_sender.rs"
2023/04/02 15:16:49 [DEBUG] Trying to parse "\\\\?\\C:\\Users\\Documents\\Files\\Repos\\libsignal_bridge\\rust\\libsignal-main\\rust\\protocol\\src\\sender_keys.rs"
2023/04/02 15:16:49 [DEBUG] Trying to parse "\\\\?\\C:\\Users\\Documents\\Files\\Repos\\libsignal_bridge\\rust\\libsignal-main\\rust\\protocol\\src\\session.rs"
2023/04/02 15:16:49 [DEBUG] Trying to parse "\\\\?\\C:\\Users\\Documents\\Files\\Repos\\libsignal_bridge\\rust\\libsignal-main\\rust\\protocol\\src\\session_cipher.rs"
2023/04/02 15:16:49 [DEBUG] Trying to parse "\\\\?\\C:\\Users\\Documents\\Files\\Repos\\libsignal_bridge\\rust\\libsignal-main\\rust\\protocol\\src\\state.rs"
2023/04/02 15:16:49 [DEBUG] Trying to parse "\\\\?\\C:\\Users\\Documents\\Files\\Repos\\libsignal_bridge\\rust\\libsignal-main\\rust\\protocol\\src\\state\\bundle.rs"
2023/04/02 15:16:49 [DEBUG] Trying to parse "\\\\?\\C:\\Users\\Documents\\Files\\Repos\\libsignal_bridge\\rust\\libsignal-main\\rust\\protocol\\src\\state\\prekey.rs"
2023/04/02 15:16:49 [DEBUG] Trying to parse "\\\\?\\C:\\Users\\Documents\\Files\\Repos\\libsignal_bridge\\rust\\libsignal-main\\rust\\protocol\\src\\session.rs"
2023/04/02 15:16:49 [DEBUG] Trying to parse "\\\\?\\C:\\Users\\Documents\\Files\\Repos\\libsignal_bridge\\rust\\libsignal-main\\rust\\protocol\\src\\state\\signed_prekey.rs"
2023/04/02 15:16:49 [DEBUG] Trying to parse "\\\\?\\C:\\Users\\Documents\\Files\\Repos\\libsignal_bridge\\rust\\libsignal-main\\rust\\protocol\\src\\storage.rs"
2023/04/02 15:16:49 [DEBUG] Trying to parse "\\\\?\\C:\\Users\\Documents\\Files\\Repos\\libsignal_bridge\\rust\\libsignal-main\\rust\\protocol\\src\\storage\\inmem.rs"
2023/04/02 15:16:49 [DEBUG] Trying to parse "\\\\?\\C:\\Users\\Documents\\Files\\Repos\\libsignal_bridge\\rust\\libsignal-main\\rust\\protocol\\src\\storage\\traits.rs"
2023/04/02 15:16:49 [DEBUG] Trying to parse "\\\\?\\C:\\Users\\Documents\\Files\\Repos\\libsignal_bridge\\rust\\libsignal-main\\rust\\protocol\\src\\utils.rs"
2023/04/02 15:16:49 [INFO] Phase: Transform IR
2023/04/02 15:16:49 [INFO] Phase: Generate Rust code
2023/04/02 15:16:49 [INFO] Inject `mod bridge_generated;` into "C:\\Users\\Documents\\Files\\Repos\\libsignal_bridge\\rust\\libsignal-main\\rust\\protocol\\src\\lib.rs"
2023/04/02 15:16:49 [DEBUG] execute format_rust path=["C:\\Users\\Documents\\Files\\Repos\\libsignal_bridge\\rust\\libsignal-main\\rust\\protocol\\src\\bridge_generated.rs"]
2023/04/02 15:16:49 [DEBUG] execute command: bin=rustfmt args="C:\\Users\\Documents\\Files\\Repos\\libsignal_bridge\\rust\\libsignal-main\\rust\\protocol\\src\\bridge_generated.rs" current_dir=None cmd="rustfmt" "C:\\Users\\Documents\\Files\\Repos\\libsignal_bridge\\rust\\libsignal-main\\rust\\protocol\\src\\bridge_generated.rs"
Warning: can't set `imports_granularity = Module`, unstable features are only available in nightly channel.
2023/04/02 15:16:49 [DEBUG] command="rustfmt" "C:\\Users\\Documents\\Files\\Repos\\libsignal_bridge\\rust\\libsignal-main\\rust\\protocol\\src\\bridge_generated.rs" stdout= stderr=   
2023/04/02 15:16:49 [INFO] Phase: Generate Dart code
2023/04/02 15:16:49 [DEBUG] Guessing toolchain the runner is run into
2023/04/02 15:16:49 [DEBUG] execute command: bin=powershell args="-noprofile -command & \"flutter\" \"--version\"" current_dir=None cmd="powershell" "-noprofile" "-command" "& \"flutter\" \"--version\""
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
2023/04/02 15:16:50 [DEBUG] command="powershell" "-noprofile" "-command" "& \"flutter\" \"--version\"" stdout= stderr=
2023/04/02 15:16:50 [DEBUG] Checking presence of ffi in dependencies at C:\Users\Documents\Files\Repos\libsignal_bridge
2023/04/02 15:16:50 [DEBUG] Checking presence of ffi in dependencies at C:\Users\Documents\Files\Repos\libsignal_bridge
2023/04/02 15:16:50 [DEBUG] Checking presence of ffigen in dev_dependencies at C:\Users\Documents\Files\Repos\libsignal_bridge
2023/04/02 15:16:50 [DEBUG] Checking presence of ffigen in dev_dependencies at C:\Users\Documents\Files\Repos\libsignal_bridge
2023/04/02 15:16:50 [INFO] Phase: Generating Dart bindings for Rust
2023/04/02 15:16:50 [DEBUG] execute cbindgen rust_crate_dir=C:\Users\Documents\Files\Repos\libsignal_bridge\rust\libsignal-main\rust\protocol c_output_path=C:\Users\AppData\Local\Temp\.tmpcO1JSk.h
2023/04/02 15:16:50 [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/04/02 15:16:50 [DEBUG] Parsing crate libsignal-protocol
2023/04/02 15:16:50 [ERROR] fatal: Parsing crate `libsignal-protocol`:`C:\Users\Documents\Files\Repos\libsignal_bridge\rust\libsignal-main\rust\protocol\src\lib.rs`:
Error("expected square brackets")
Try running `rustc -Z parse-only C:\Users\Documents\Files\Repos\libsignal_bridge\rust\libsignal-main\rust\protocol\src\lib.rs` to see a nicer error message

To Reproduce

  1. Create a Flutter Library Template
  2. Add in either libsignal, wallet.rs or iota.rs to a rust folder
  3. Add in the tutorial dependencies and installations to run the generator
  4. Run the generator on the rust code to create the bindings

Expected behavior

Expect a generated output to complete

Generated binding code

Never got any generated code.

OS

Windows

Version of flutter_rust_bridge_codegen

1.72.1

Flutter info

flutter doctor -v
[√] Flutter (Channel stable, 3.7.9, on Microsoft Windows [Version 10.0.22621.1485], locale en-US)
    • Flutter version 3.7.9 on channel stable at C:\src\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 62bd79521d (3 days ago), 2023-03-30 10:59:36 -0700
    • Engine revision ec975089ac
    • Dart version 2.19.6
    • DevTools version 2.20.1

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

[√] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
    • Android SDK at C:\Users\AppData\Local\Android\sdk
    • Platform android-33, build-tools 33.0.0
    • Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java
    • Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-9505619)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[√] Visual Studio - develop for Windows (Visual Studio Community 2022 17.5.3)
    • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
    • Visual Studio Community 2022 version 17.5.33516.290
    • Windows 10 SDK version 10.0.22000.0

[√] Android Studio (version 2022.1)
    • 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 11.0.15+0-b2043.56-9505619)

[√] VS Code (version 1.77.0)
    • VS Code at C:\Users\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.60.0

[√] Connected device (3 available)
    • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.22621.1485]
    • Chrome (web)      • chrome  • web-javascript • Google Chrome 111.0.5563.147
    • Edge (web)        • edge    • web-javascript • Microsoft Edge 111.0.1661.54

[√] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!

Version of clang++

16.0.0

Version of ffigen

7.2.9

Additional context

No response

welcome[bot] commented 1 year ago

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

fzyzcjy commented 1 year ago

Hi, it would be great to show more logs, e.g. RUST_BACKTRACE=1

kthecoder commented 1 year ago

Do I just put env::set_var("RUST_BACKTRACE", "1"); inside of the lib file? Cause that isn't working.

fzyzcjy commented 1 year ago

IMHO just do sth similar to RUST_LOG=debug

kthecoder commented 1 year ago

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 - 1: 0x7ff6cceb771b - 2: 0x7ff6cce8f1da - 3: 0x7ff6cce93c9b - 4: 0x7ff6cce96dc9 - 5: 0x7ff6cce96a4b - 6: 0x7ff6cc90cf0b - 7: 0x7ff6cce9768f - 8: 0x7ff6cce973ee - 9: 0x7ff6cce94c4f - 10: 0x7ff6cce970a0 - 11: 0x7ff6cced9615 - 12: 0x7ff6cced9b36 - 13: 0x7ff6cc8b7759 - 14: 0x7ff6cc933d35 - 15: 0x7ff6cc8a1c90 - 16: 0x7ff6cc8a23f6 - 17: 0x7ff6cc8a241a - 18: 0x7ff6cce87d1e - 19: 0x7ff6cc8a23dc - 20: 0x7ff6ccec091c - 21: 0x7ffdf8ec269d - BaseThreadInitThunk 22: 0x7ffdfa96a9f8 - RtlUserThreadStart

//==========================================================================//

fzyzcjy commented 1 year ago

[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?

kthecoder commented 1 year ago

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?

fzyzcjy commented 1 year ago

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

kthecoder commented 1 year ago

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?

fzyzcjy commented 1 year ago

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!

stale[bot] commented 1 year ago

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.

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.