Rust Code


In the following subchapters we'll prepare the Rust Code for each example. We will only discuss the changes in the Cargo.toml and api.rs files.


Initial Situation

This is the situation upon which we are basing our starting point.

Rust - Initial Situation

Rust - Initial Situation

Preparation

  1. As usual, create an empty file called api.rs, at the same level as lib.rs.

  2. Include it as module in lib.rs:

    mod api;

New: Checks using cargo build

In the next subchapters, we will test individually for each example whether our library can be cross-compiled to the target platforms Android, macOS, and iOS.

This way, we can independently test the correctness of the dependencies in Cargo.toml, and the paths and the syntax of our Rust Code in api.rs, regardless of the Flutter build process.

πŸ‘‰ Β  How to manually cross-compile to a target of your choice

To examine the various targets, you should navigate from playground_app root directory to the rust directory:

cd rust

Then, within the rust directory, excute the following commands.

Android

If you haven't already, install the cargo-ndk command using:

cargo install cargo-ndk

I only check the ABI arm64-v8a.

cargo ndk -t arm64-v8a build

macOS

cargo build --target aarch64-apple-darwin

iOS Simulator or iOS Device

cargo build --target aarch64-apple-ios-sim
cargo build --target aarch64-apple-ios