Skip to main content

Generating bindings

info

This guide was written for flutter_rust_bridge v1, thus some content may be outdated. The quickest approach to integrate is to follow the one-click approach in flutter_rust_bridge's quickstart page.

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:

{{#include command.sh.txt}}

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.