2025-01-21 17:07:27 +02:00
|
|
|
### Rust to Flutter Build Script
|
|
|
|
|
|
2025-01-11 12:30:08 +02:00
|
|
|
This script compiles a Rust library for both Android and iOS and copies the generated libraries to the appropriate Flutter project directories.
|
|
|
|
|
|
|
|
|
|
#### Features:
|
2025-01-21 17:07:27 +02:00
|
|
|
- Installs missing cross-compilation targets.
|
2025-01-11 12:41:32 +02:00
|
|
|
- Compiles Rust for Android.
|
2025-01-11 12:30:08 +02:00
|
|
|
- Conditionally compiles Rust for iOS if running on macOS.
|
2025-01-21 17:07:27 +02:00
|
|
|
- Optionally includes `x86` and `x86_64` Android targets using the `-x` flag.
|
2025-01-11 12:30:08 +02:00
|
|
|
- Automatically cleans the build directory before compiling.
|
2025-01-21 17:07:27 +02:00
|
|
|
- Copies `.so` (Android) and `.dylib` (iOS) files to the Flutter project.
|
2025-01-11 12:30:08 +02:00
|
|
|
|
|
|
|
|
#### Usage:
|
|
|
|
|
1. Ensure the following are installed:
|
2025-01-21 17:07:27 +02:00
|
|
|
- `cargo-ndk`: Install via `cargo install cargo-ndk`.
|
|
|
|
|
- Android NDK (set `ANDROID_NDK_HOME` or `ANDROID_SDK_ROOT`).
|
|
|
|
|
- Rust toolchains for iOS targets if compiling on macOS.
|
2025-01-11 12:30:08 +02:00
|
|
|
|
|
|
|
|
2. Run the script:
|
|
|
|
|
```bash
|
2025-01-21 17:07:27 +02:00
|
|
|
./rust_to_flutter.sh [-x] <path_to_rust_project> <path_to_flutter_project>
|
2025-01-11 12:30:08 +02:00
|
|
|
```
|
|
|
|
|
|
2025-01-21 17:07:27 +02:00
|
|
|
- The optional `-x` flag includes `x86` and `x86_64` targets for Android.
|
|
|
|
|
|
|
|
|
|
#### Examples:
|
|
|
|
|
- Standard build for Android and (on macOS) iOS:
|
|
|
|
|
```bash
|
|
|
|
|
./rust_to_flutter.sh ./rust_project ./flutter_project
|
|
|
|
|
```
|
|
|
|
|
- Include `x86` and `x86_64` targets for Android:
|
|
|
|
|
```bash
|
|
|
|
|
./rust_to_flutter.sh -x ./rust_project ./flutter_project
|
|
|
|
|
```
|
2025-01-11 12:30:08 +02:00
|
|
|
|
|
|
|
|
#### Notes:
|
|
|
|
|
- Android libraries are copied to `android/app/src/main/jniLibs/<arch>`.
|
|
|
|
|
- iOS libraries are copied to the `ios` directory.
|
2025-01-21 17:07:27 +02:00
|
|
|
|
|
|
|
|
#### Additional Information:
|
|
|
|
|
- iOS compilation is skipped automatically if the script is not running on macOS.
|
|
|
|
|
- The script checks for missing Rust cross-compilation targets and installs them as needed.
|