fzyzcjy / flutter_rust_bridge

Flutter/Dart <-> Rust binding generator, feature-rich, but seamless and simple.

Home Page:https://fzyzcjy.github.io/flutter_rust_bridge/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Documentation request: How Rust code compiles and loads into Flutter/Rust runtime.

NightBlaze opened this issue · comments

I would like to read more about how FRB works.
As I understood one of the main part is flutter_rust_bridge_codegen generate which generates *_generated.rs, *_generated.dart and api/*.dart files. It's just glue code between Flutter/Dart runtime and Rust library which are communicates using FFI.

But I didn't find information how Rust code actually compiles into binary code/lib, where the lib stored, how and when it loaded, etc. Also I didn't find how flags (e.g. --release) are passed to cargo(?). Or, for example, what will happend when I change scheme configuration to release in Xcode project (this question is related to Flutter itself probably?), how my Rust code will understand that it will be need to compile with --release flag?

Additional context
I would like to "sell" the FRB to my company because I would like to write on Rust but there are some senior devs who will ask a lot of "why" and "how" questions (and it's right) when I will present FRB to them. So I need to be prepared :)

But I didn't find information how Rust code actually compiles into binary code/lib, where the lib stored, how and when it loaded, etc.
Also I didn't find how flags (e.g. --release) are passed to cargo(?).
Or, for example, what will happend when I change scheme configuration to release in Xcode project (this question is related to Flutter itself probably?), how my Rust code will understand that it will be need to compile with --release flag?

There are many different possible ways that you can choose freely: https://cjycode.com/flutter_rust_bridge/manual/integrate/overview.

For example, suppose you are using the default template, then it is cargokit which does the compilation logic.

However, in the future, when Dart/Flutter's "native asset" feature is stablized (I guess it should be there within one or two Dart versions?), we can have easier integration logic.

I would like to "sell" the FRB to my company because I would like to write on Rust but there are some senior devs who will ask a lot of "why" and "how" questions (and it's right) when I will present FRB to them. So I need to be prepared :)

Feel free to ask questions! As can be seen, I usually reply quickly (except when sleeping) :)

There are many different possible ways that you can choose freely: https://cjycode.com/flutter_rust_bridge/manual/integrate/overview.

I saw it. Will read more carefully.

For example, suppose you are using the default template, then it is cargokit which does the compilation logic.

The most interesting question for me right now is how flutter run command knows that it needs to build some Rust code. Probably will find the answer in the link above.

The most interesting question for me right now is how flutter run command knows that it needs to build some Rust code. Probably will find the answer in the link above.

Yes more details can be found in cargokit's blog. In short, for example: In android, you have freedom to add whatever custom scripts in build.gradle - so the general approach is to add a script which compiles rust.