Generating bindings
Now that we've got most of the plumbing out of the way, let's compile our Rust
application. If you just created your crate a few moments ago, go ahead and
add a new file at $crate/src/api.rs
and replace its contents with this snippet or
whatever suits your fancy:
pub fn greet() -> String {
"Hello from Rust! 🦀".into()
}
then in $crate/src/lib.rs
:
+mod api;
Running the codegen
Before we can compile the library, we need to generate the bindings first. From the root of the app, run these commands:
flutter_rust_bridge_codegen \
-r $crate/src/api.rs \
-d lib/bridge_generated.dart \
-c ios/Runner/bridge_generated.h \
-e macos/Runner/ # if building for MacOS, extra path is essential
Note: These will be the same commands to use whenever you modify your Rust library code.
Running this command yields the C header of the functions and types exported by the Rust library, which we will need to keep the symbols from being stripped.