Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use leaf FFI calls to reduce memory copy #421

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/issue_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ _Please provide the output from the command below, using markdown codeblock synt
```bash
rustc --version
flutter doctor
dart pub global run native_doctor
```
1 change: 0 additions & 1 deletion .github/workflows/quality_control.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ jobs:
- name: Fetch Flutter dependencies
run: |
flutter pub get --directory flutter_ffi_plugin/
flutter pub get --directory flutter_ffi_plugin/cargokit/build_tool

- name: Generate message files
working-directory: flutter_ffi_plugin/example/
Expand Down
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,15 @@ All platforms available with Flutter are [tested](https://github.com/cunarist/ri

## 📞 Communication

Below is Dart code with widgets, and following that is Rust code with business logic.
Below is Rust code with business logic, and following that is Dart code with widgets.

```rust
MyMessage {
current_number: 7,
other_bool: true,
}
.send_signal_to_dart();
```

```dart
StreamBuilder(
Expand All @@ -45,14 +53,6 @@ StreamBuilder(
),
```

```rust
MyMessage {
current_number: 7,
other_bool: true,
}
.send_signal_to_dart();
```

Of course, the opposite way from Dart to Rust is also possible in a similar manner.

All message classes and structs are generated by Rinf. You can define the message schema simply with Protobuf, making message passing between Dart and Rust very convenient.
Expand Down
8 changes: 0 additions & 8 deletions automate/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,6 @@ def replace_text_in_file(filepath: str, change_from: str, change_to: str):
print("Automation option is not provided.")
print("Use `python automate --help` to see all available operations.")

elif sys.argv[1] == "cargokit-update":
print("Updating CargoKit...")
command = "git subtree pull"
command += " --prefix flutter_ffi_plugin/cargokit"
command += " https://github.com/irondash/cargokit.git"
command += " main"
os.system(command)

elif sys.argv[1] == "prepare-test-app":
filepath = ".gitignore"
with open(filepath, mode="r", encoding="utf8") as file:
Expand Down
16 changes: 0 additions & 16 deletions documentation/docs/frequently-asked-questions.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,6 @@ No, the updated Rust code cannot be loaded upon Dart's hot restart. To incorpora

On native platforms, Dart's hot restart makes the Rust logic restart, in other words, the `async fn main()` function. On the web, Dart's hot restart has no effect on the Rust logic, because it's not possible to cancel all the async tasks that are already queued inside the JavaScript event loop.

### How do I use nightly Rust?

In order to use nightly Rust, you need to add a cargokit configuration file. Cargokit is the build connector between Dart and Rust used by this framework.

```yaml title="native/hub/cargokit.yaml"
cargo:
debug:
toolchain: nightly
release:
toolchain: nightly
```

More information about `cargokit.yaml` can be found at the link below. Cargokit is the linker for Rust crates that are used in various Flutter projects, including Rinf.

- https://github.com/irondash/cargokit/blob/main/docs/architecture.md

### Is it safe enough to pass secret parameters between Dart and Rust?

It is safe to pass secret parameters between Dart and Rust. Some other Rust GUI frameworks use HTTP or websockets to communicate between GUI and Rust, which is quite insecure. However, that's not the case for Rinf because messages are passed within the Flutter app's process. Please note that while it is hard to reverse-engineer compiled native binaries to search for secret keys or params, it is generally not recommended to hardcode sensitive information in the application itself. This caution applies to this framework as well as any other distributed binaries.
Expand Down
13 changes: 12 additions & 1 deletion documentation/docs/installing-components.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,20 @@ To get started, you need to have [Flutter SDK](https://docs.flutter.dev/get-star

[^1]: If you're working on Linux, do not install Flutter from `snap`. Flutter from `snap` comes with its own binary linker called `ld`, which is fundamentally incompatible with Rust. Instead, follow the manual installation method as written in the Flutter docs.

Once you're done with the installations, verify your system's readiness with the following commands. Make sure you have installed all the subcomponents that Flutter suggests. If there are no issues in the output, you are good to go onto the next step!
Then, activate some necessary features:

```bash title="CLI"
flutter channel master
flutter config --enable-native-assets
dart pub global activate native_doctor
```

Once the installations are complete, verify your system's readiness with the following commands:

```bash title="CLI"
rustc --version
flutter doctor
dart pub global run native_doctor
```

Ensure all suggested subcomponents are installed. If no issues appear in the output, you’re ready to move on to the next step!
2 changes: 1 addition & 1 deletion documentation/docs/running-and-building.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

The following commands are just enough to run and build apps for native platforms. It's that simple.[^1]

[^1]: Rinf builds the native Rust library and links it to the Flutter app using [Cargokit](https://github.com/irondash/cargokit).
[^1]: Rinf builds the native Rust library and links it to the Flutter app using [`native_toolchain_rust`](https://pub.dev/packages/native_toolchain_rust).

To run the app:

Expand Down
4 changes: 2 additions & 2 deletions documentation/docs/state-management.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This section provides a general guide on effectively managing application state

Rinf performs best when the application logic is written entirely in Rust, with Flutter used solely for the GUI. In such cases, you might want to store the application state in Rust.

## 💥 Actor model
## 💥 Actor Model

The actor model is highly recommended for managing asynchronous state in Rust. By encapsulating state and behavior within actor structs, which maintain ownership and handle their own async tasks, the actor model provides a scalable and reliable way to manage complex state interactions.

Expand Down Expand Up @@ -53,7 +53,7 @@ async fn main() {
}
```

## 🧱 Static variables
## 🧱 Static Variables

Generally, it's advisable to avoid static variables due to their characteristics, which can lead to issues such as difficulties in testing and managing lifetimes. If you must use static variables, you can declare them as shown below, ensuring they span the entire duration of the app.

Expand Down
2 changes: 1 addition & 1 deletion documentation/docs/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ rinf message
Define an async Rust function that runs forever, sending numbers to Dart every second.

```toml title="native/hub/Cargo.toml"
tokio = { version = "1", features = ["sync", "rt", "time"] }
tokio = { version = "1", features = ["sync", "time"] }
```

```rust title="native/hub/src/tutorial_functions.rs"
Expand Down
18 changes: 9 additions & 9 deletions flutter_ffi_plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,15 @@ All platforms available with Flutter are [tested](https://github.com/cunarist/ri

## 📞 Communication

Below is Dart code with widgets, and following that is Rust code with business logic.
Below is Rust code with business logic, and following that is Dart code with widgets.

```rust
MyMessage {
current_number: 7,
other_bool: true,
}
.send_signal_to_dart();
```

```dart
StreamBuilder(
Expand All @@ -45,14 +53,6 @@ StreamBuilder(
),
```

```rust
MyMessage {
current_number: 7,
other_bool: true,
}
.send_signal_to_dart();
```

Of course, the opposite way from Dart to Rust is also possible in a similar manner.

All message classes and structs are generated by Rinf. You can define the message schema simply with Protobuf, making message passing between Dart and Rust very convenient.
Expand Down
7 changes: 0 additions & 7 deletions flutter_ffi_plugin/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,3 @@ android {
}
}
}

// Include Rust crates in the build process
apply from: "../cargokit/gradle/plugin.gradle"
cargokit {
manifestDir = "${rootProject.projectDir}/../native/hub"
libname = "hub"
}
11 changes: 10 additions & 1 deletion flutter_ffi_plugin/bin/src/helpers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,25 @@ This project leverages Flutter for GUI and Rust for the backend logic,
utilizing the capabilities of the
[Rinf](https://pub.dev/packages/rinf) framework.

Please activate the necessary features first.

```
flutter channel master
flutter config --enable-native-assets
dart pub global activate native_doctor
```

To run and build this app, you need to have
[Flutter SDK](https://docs.flutter.dev/get-started/install)
and [Rust toolchain](https://www.rust-lang.org/tools/install)
installed on your system.
You can check that your system is ready with the commands below.
Note that all the Flutter subcomponents should be installed.
Note that all the subcomponents should be installed.

```bash
rustc --version
flutter doctor
dart pub global run native_doctor
```

You also need to have the CLI tool for Rinf ready.
Expand Down
26 changes: 0 additions & 26 deletions flutter_ffi_plugin/cargokit/.github/workflows/check_and_lint.yml

This file was deleted.

This file was deleted.

39 changes: 0 additions & 39 deletions flutter_ffi_plugin/cargokit/LICENSE

This file was deleted.

8 changes: 0 additions & 8 deletions flutter_ffi_plugin/cargokit/README

This file was deleted.

Loading
Loading