matrix-rust-sdk/bindings/matrix-sdk-crypto-ffi
Kévin Commaille da2abccc0d chore: Disable clippy::assigning_clones lint
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-04-02 15:05:41 +02:00
..
src doc(crypto-ffi): `Device::first_time_seen_ts` has an incorrect unit. 2024-03-21 09:05:30 +01:00
Cargo.toml chore: Disable clippy::assigning_clones lint 2024-04-02 15:05:41 +02:00
README.md Update iOS Crypto SDK docs 2023-04-19 18:09:21 +02:00
build.rs Move matrix-sdk-crypto enum definitions out of UDL 2024-01-27 00:31:42 +01:00
uniffi.toml Fix naming of generated crypto .so files 2022-11-28 11:47:59 +01:00

README.md

Uniffi based bindings for the Rust SDK crypto crate.

This crate contains Uniffi based bindings for the matrix-sdk-crypto crate. The README mainly describes how to build and integrate the bindings into a Kotlin based Android project, but the Android specific bits can be skipped if you are targeting an x86 Linux project.

To build and distribute bindings for iOS projects, see a dedicated page

Prerequisites

Rust

To build the bindings Rust will be needed it can be either installed using an OS specific package manager or directly with the provided installer.

Android NDK

The Android NDK will be required as well, it can be installed either through Android Studio or directly using an installer.

Configuring Rust for cross compilation

First we'll need to install the Rust target for our desired Android architecture, for example:

# rustup target add aarch64-linux-android

This will add support to cross-compile for the aarch64-linux-android target, Rust supports many different targets, you'll have to make sure to pick the right one for your device or emulator.

After this is done, we'll have to configure Cargo to use the correct linker for our target. Cargo is configured using a TOML file that will be found in %USERPROFILE%\.cargo\config.toml on Windows or $HOME/.cargo/config on Unix platforms. More details and configuration options for Cargo can be found in the official docs over here.

[target.aarch64-linux-android]
ar = "NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/ar"
linker = "NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android30-clang"

Building

To enable cross compilation for olm-sys which builds our libolm C library we'll need to set the ANDROID_NDK environment variable to the location of our Android NDK installation.

$ export ANDROID_NDK=$HOME/Android/Sdk/ndk/22.0.7026061/

Building for a target

The bindings can built for the aarch64 target with:

$ cargo build --target aarch64-linux-android

After that, a dynamic library can be found in the target/aarch64-linux-android/debug directory. The library will be called libmatrix_crypto.so and needs to be renamed and copied into the jniLibs directory of your Android project, for Element Android:

$ cp ../../target/aarch64-linux-android/debug/libmatrix_crypto.so \
     /home/example/matrix-sdk-android/src/main/jniLibs/aarch64/libuniffi_olm.so

Minimum Supported Rust Version (MSRV)

These crates are built with the Rust language version 2021 and require a minimum compiler version of 1.62.

License

Apache-2.0