Skip to content

Commit

Permalink
chore: more
Browse files Browse the repository at this point in the history
  • Loading branch information
fzyzcjy committed Jun 18, 2024
1 parent f18c96a commit e235b8b
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::codegen::parser::mir::internal_config::RustInputNamespacePack;
use crate::utils::crate_name::CrateName;
use crate::utils::namespace::Namespace;
use crate::utils::path_utils::canonicalize_with_error_message;
use anyhow::{ensure, Context};
use anyhow::{Context};
use itertools::Itertools;
use std::path::{Path, PathBuf};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ impl<'a, 'b> FunctionParser<'a, 'b> {
Ok(create_output_skip(func, IgnoreBecauseSelfTypeNotAllowed))
} else {
Err(e)
}
};
}
};
info = info.merge(arg_info)?;
Expand Down
51 changes: 47 additions & 4 deletions website/docs/manual/integrate/04-cargokit.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,51 @@
# Cargokit
# Flutter package via Cargokit

Please refer to its documentation for how to use it.
Its GitHub repository is https://github.com/irondash/cargokit.
In addition, it has a companion blog about how to integrate it at https://matejknopp.com/post/flutter_plugin_in_rust_with_no_prebuilt_binaries/.
In this page, we show how to use [Cargokit](https://github.com/irondash/cargokit)
to create a Flutter package that can be published and used by other Flutter apps/packages.

## Step 1: Follow Cargokit tutorial

For simplicity, we directly clone it to get a Flutter package that can compile Rust code:

```shell
git clone https://github.com/irondash/hello_rust_ffi_plugin && cd hello_rust_ffi_plugin
flutter pub get
```

<details>
<summary>The following links may also be useful for customizations (click to expand).</summary>

* Tutorial (step-by-step generating that sample repo): https://matejknopp.com/post/flutter_plugin_in_rust_with_no_prebuilt_binaries/
* Configuration: https://github.com/irondash/cargokit/blob/main/docs/architecture.md#configuring-cargokit
* Use precompiled binaries (instead of default compile-on-the-fly): https://github.com/irondash/cargokit/blob/main/docs/precompiled_binaries.md

</details>

## Step 2: Add `flutter_rust_bridge`

Create `flutter_rust_bridge.yaml` with the following content:

```yaml
rust_root: rust/
rust_input: crate::api
dart_output: lib/src/rust
```
Let's put a few boilerplate files there as well (feel free to put whatever you like instead):
```shell
mkdir -p lib/src/rust rust/src/api
echo "pub mod simple;" > rust/src/api/mod.rs
wget -O rust/src/api/simple.rs https://raw.githubusercontent.com/fzyzcjy/flutter_rust_bridge/master/frb_example/flutter_via_create/rust/src/api/simple.rs
```

Then we can run code generator:

```shell
flutter_rust_bridge_codegen generate
```

## Remarks

[It seems that](https://github.com/irondash/cargokit/issues/39#issuecomment-1831584430),
after Dart [native assets](native-assets) is stablized,
Expand Down
2 changes: 1 addition & 1 deletion website/docs/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ Please refer to [this page](guides/miscellaneous/pure-dart).
<TabItem value="Flutter Package">

To create a publishable Flutter package instead of a Flutter app,
please refer to TODO.
please refer to [this page](manual/integrate/cargokit).

</TabItem>

Expand Down

0 comments on commit e235b8b

Please sign in to comment.