Installing dependencies
Next, we need to install a few build-time and runtime dependencies.
Build-time dependencies
These depdencies are required only in build-time:
flutter_rust_bridge_codegen
, the core codegen for Rust-Dart glue codeffigen
, to generate Dart code from C headerscargo-xcode
, to generate Xcode projects for iOS and MacOS- A working installation of LLVM, see Installing LLVM
An easy way to install most of these dependencies is to run:
cargo install flutter_rust_bridge_codegen
dart pub global activate ffigen
# if building for iOS or MacOS
cargo install cargo-xcode
Dart dependencies
On the Dart side, flutter_rust_bridge
is the required runtime component of
flutter_rust_bridge_codegen
. If you plan to use enum structs in Rust, the
following dependencies are also needed:
build_runner
(dev)freezed
(dev)freezed_annotation
Their usage is explained in Using build_runner
.
flutter pub add flutter_rust_bridge
# if using Dart codegen
flutter pub add -d build_runner
flutter pub add -d freezed
flutter pub add freezed_annotation
Rust dependencies
Similar to Dart, Rust requires the flutter_rust_bridge
runtime component for support.
Add these lines to Cargo.toml
:
+[dependencies]
+flutter_rust_bridge = "1"
Note
If you wish to return aResult
, keep in mind that this library can only run codegen foranyhow::Result
.