atagen

matrix-rust-sdk

public
Star0
Watch0
ssh://brewery@pls.lobotomise.me:33/atagen/matrix-rust-sdk.git

Blame: bindings/matrix-sdk-crypto-ffi/README.md

7ff8adafe9e4atagen2026-10-22 12:30 UTC1
# Uniffi based bindings for the Rust SDK crypto crate
7ff8adafe9e4atagen2026-10-22 12:30 UTC2
7ff8adafe9e4atagen2026-10-22 12:30 UTC3
This crate contains Uniffi based bindings for the `matrix-sdk-crypto` crate. The
7ff8adafe9e4atagen2026-10-22 12:30 UTC4
README mainly describes how to build and integrate the bindings into a Kotlin
7ff8adafe9e4atagen2026-10-22 12:30 UTC5
based Android project, but the Android specific bits can be skipped if you are
7ff8adafe9e4atagen2026-10-22 12:30 UTC6
targeting an x86 Linux project.
7ff8adafe9e4atagen2026-10-22 12:30 UTC7
7ff8adafe9e4atagen2026-10-22 12:30 UTC8
To build and distribute bindings for iOS projects, see a
7ff8adafe9e4atagen2026-10-22 12:30 UTC9
[dedicated page](../apple/README.md)
7ff8adafe9e4atagen2026-10-22 12:30 UTC10
7ff8adafe9e4atagen2026-10-22 12:30 UTC11
## Prerequisites
7ff8adafe9e4atagen2026-10-22 12:30 UTC12
7ff8adafe9e4atagen2026-10-22 12:30 UTC13
### Rust
7ff8adafe9e4atagen2026-10-22 12:30 UTC14
7ff8adafe9e4atagen2026-10-22 12:30 UTC15
To build the bindings [Rust] will be needed it can be either installed using an
7ff8adafe9e4atagen2026-10-22 12:30 UTC16
OS specific package manager or directly with the provided
7ff8adafe9e4atagen2026-10-22 12:30 UTC17
[installer](https://rustup.rs/).
7ff8adafe9e4atagen2026-10-22 12:30 UTC18
7ff8adafe9e4atagen2026-10-22 12:30 UTC19
### Android NDK
7ff8adafe9e4atagen2026-10-22 12:30 UTC20
7ff8adafe9e4atagen2026-10-22 12:30 UTC21
The Android NDK will be required as well, it can be installed either through
7ff8adafe9e4atagen2026-10-22 12:30 UTC22
Android Studio or directly using an
7ff8adafe9e4atagen2026-10-22 12:30 UTC23
[installer](https://developer.android.com/ndk/downloads).
7ff8adafe9e4atagen2026-10-22 12:30 UTC24
7ff8adafe9e4atagen2026-10-22 12:30 UTC25
### Configuring Rust for cross compilation
7ff8adafe9e4atagen2026-10-22 12:30 UTC26
7ff8adafe9e4atagen2026-10-22 12:30 UTC27
First we'll need to install the Rust target for our desired Android
7ff8adafe9e4atagen2026-10-22 12:30 UTC28
architecture, for example:
7ff8adafe9e4atagen2026-10-22 12:30 UTC29
7ff8adafe9e4atagen2026-10-22 12:30 UTC30
```text
7ff8adafe9e4atagen2026-10-22 12:30 UTC31
# rustup target add aarch64-linux-android
7ff8adafe9e4atagen2026-10-22 12:30 UTC32
```
7ff8adafe9e4atagen2026-10-22 12:30 UTC33
7ff8adafe9e4atagen2026-10-22 12:30 UTC34
This will add support to cross-compile for the aarch64-linux-android target,
7ff8adafe9e4atagen2026-10-22 12:30 UTC35
Rust supports many different [targets], you'll have to make sure to pick the
7ff8adafe9e4atagen2026-10-22 12:30 UTC36
right one for your device or emulator.
7ff8adafe9e4atagen2026-10-22 12:30 UTC37
7ff8adafe9e4atagen2026-10-22 12:30 UTC38
After this is done, we'll have to configure [Cargo] to use the correct linker
7ff8adafe9e4atagen2026-10-22 12:30 UTC39
for our target, by providing the Cargo setting of
7ff8adafe9e4atagen2026-10-22 12:30 UTC40
[target.<triple>.linker](https://doc.rust-lang.org/cargo/reference/config.html#targettriplelinker)
7ff8adafe9e4atagen2026-10-22 12:30 UTC41
with a value of the path to an appropriate linker in your NDK installation.
7ff8adafe9e4atagen2026-10-22 12:30 UTC42
7ff8adafe9e4atagen2026-10-22 12:30 UTC43
This may be set through an environment variable:
7ff8adafe9e4atagen2026-10-22 12:30 UTC44
7ff8adafe9e4atagen2026-10-22 12:30 UTC45
```text
7ff8adafe9e4atagen2026-10-22 12:30 UTC46
$ export CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER="<path-to-ndk-installation>/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android30-clang"
7ff8adafe9e4atagen2026-10-22 12:30 UTC47
```
7ff8adafe9e4atagen2026-10-22 12:30 UTC48
7ff8adafe9e4atagen2026-10-22 12:30 UTC49
Alternatively, it may be set in the `.cargo/config.toml` file in the current
7ff8adafe9e4atagen2026-10-22 12:30 UTC50
directory, any parent directory, or your home directory:
7ff8adafe9e4atagen2026-10-22 12:30 UTC51
7ff8adafe9e4atagen2026-10-22 12:30 UTC52
```text
7ff8adafe9e4atagen2026-10-22 12:30 UTC53
[target.aarch64-linux-android]
7ff8adafe9e4atagen2026-10-22 12:30 UTC54
linker = "<path-to-ndk-installation>/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android30-clang"
7ff8adafe9e4atagen2026-10-22 12:30 UTC55
```
7ff8adafe9e4atagen2026-10-22 12:30 UTC56
7ff8adafe9e4atagen2026-10-22 12:30 UTC57
## Building
7ff8adafe9e4atagen2026-10-22 12:30 UTC58
7ff8adafe9e4atagen2026-10-22 12:30 UTC59
To enable cross compilation for `olm-sys` which builds our `libolm` C library
7ff8adafe9e4atagen2026-10-22 12:30 UTC60
we'll need to set the `ANDROID_NDK` environment variable to the location of our
7ff8adafe9e4atagen2026-10-22 12:30 UTC61
Android NDK installation.
7ff8adafe9e4atagen2026-10-22 12:30 UTC62
7ff8adafe9e4atagen2026-10-22 12:30 UTC63
```text
7ff8adafe9e4atagen2026-10-22 12:30 UTC64
$ export ANDROID_NDK=$HOME/Android/Sdk/ndk/<some-installed-version>
7ff8adafe9e4atagen2026-10-22 12:30 UTC65
```
7ff8adafe9e4atagen2026-10-22 12:30 UTC66
7ff8adafe9e4atagen2026-10-22 12:30 UTC67
Also, include the NDK tools directory in your `PATH`:
7ff8adafe9e4atagen2026-10-22 12:30 UTC68
7ff8adafe9e4atagen2026-10-22 12:30 UTC69
```text
7ff8adafe9e4atagen2026-10-22 12:30 UTC70
$ export PATH="$ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64/bin:$PATH"
7ff8adafe9e4atagen2026-10-22 12:30 UTC71
```
7ff8adafe9e4atagen2026-10-22 12:30 UTC72
7ff8adafe9e4atagen2026-10-22 12:30 UTC73
### Building for a target
7ff8adafe9e4atagen2026-10-22 12:30 UTC74
7ff8adafe9e4atagen2026-10-22 12:30 UTC75
The bindings can built for the `aarch64` target with:
7ff8adafe9e4atagen2026-10-22 12:30 UTC76
7ff8adafe9e4atagen2026-10-22 12:30 UTC77
```text
7ff8adafe9e4atagen2026-10-22 12:30 UTC78
$ cargo build --target aarch64-linux-android
7ff8adafe9e4atagen2026-10-22 12:30 UTC79
```
7ff8adafe9e4atagen2026-10-22 12:30 UTC80
7ff8adafe9e4atagen2026-10-22 12:30 UTC81
After that, a dynamic library can be found in the
7ff8adafe9e4atagen2026-10-22 12:30 UTC82
`target/aarch64-linux-android/debug` directory, under the repository root
7ff8adafe9e4atagen2026-10-22 12:30 UTC83
directory. The library will be called `libmatrix_sdk_crypto_ffi.so` and needs to
7ff8adafe9e4atagen2026-10-22 12:30 UTC84
be renamed and copied into the `jniLibs` directory of your Android project, for
7ff8adafe9e4atagen2026-10-22 12:30 UTC85
Element Android:
7ff8adafe9e4atagen2026-10-22 12:30 UTC86
7ff8adafe9e4atagen2026-10-22 12:30 UTC87
```text
7ff8adafe9e4atagen2026-10-22 12:30 UTC88
$ cp ../../target/aarch64-linux-android/debug/libmatrix_sdk_crypto_ffi.so \
7ff8adafe9e4atagen2026-10-22 12:30 UTC89
     /home/example/matrix-sdk-android/src/main/jniLibs/aarch64/libuniffi_olm.so
7ff8adafe9e4atagen2026-10-22 12:30 UTC90
```
7ff8adafe9e4atagen2026-10-22 12:30 UTC91
7ff8adafe9e4atagen2026-10-22 12:30 UTC92
## License
7ff8adafe9e4atagen2026-10-22 12:30 UTC93
7ff8adafe9e4atagen2026-10-22 12:30 UTC94
[Apache-2.0](https://www.apache.org/licenses/LICENSE-2.0)
7ff8adafe9e4atagen2026-10-22 12:30 UTC95
7ff8adafe9e4atagen2026-10-22 12:30 UTC96
[Rust]: https://www.rust-lang.org/
7ff8adafe9e4atagen2026-10-22 12:30 UTC97
[installer]: https://rustup.rs/
7ff8adafe9e4atagen2026-10-22 12:30 UTC98
[targets]: https://doc.rust-lang.org/nightly/rustc/platform-support.html
7ff8adafe9e4atagen2026-10-22 12:30 UTC99
[Cargo]: https://doc.rust-lang.org/cargo/