atagen

matrix-rust-sdk

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

Blame: bindings/CONTRIBUTING.md

7ff8adafe9e4atagen2026-10-22 12:30 UTC1
## Introduction
7ff8adafe9e4atagen2026-10-22 12:30 UTC2
7ff8adafe9e4atagen2026-10-22 12:30 UTC3
**matrix-rust-sdk** leverages [UniFFI](https://mozilla.github.io/uniffi-rs/) to
7ff8adafe9e4atagen2026-10-22 12:30 UTC4
generate bindings for host languages (eg. Swift and Kotlin).
7ff8adafe9e4atagen2026-10-22 12:30 UTC5
7ff8adafe9e4atagen2026-10-22 12:30 UTC6
Rust code related with bindings live in the
7ff8adafe9e4atagen2026-10-22 12:30 UTC7
[matrix-rust-sdk/bindings](https://github.com/matrix-org/matrix-rust-sdk/tree/main/bindings)
7ff8adafe9e4atagen2026-10-22 12:30 UTC8
folder.
7ff8adafe9e4atagen2026-10-22 12:30 UTC9
7ff8adafe9e4atagen2026-10-22 12:30 UTC10
Developers can expose Rust code to UniFFI using two different approaches:
7ff8adafe9e4atagen2026-10-22 12:30 UTC11
7ff8adafe9e4atagen2026-10-22 12:30 UTC12
- Using an `.udl` file. When a crate has one, you find it under the `src` folder
7ff8adafe9e4atagen2026-10-22 12:30 UTC13
  ([an example is here](https://github.com/matrix-org/matrix-rust-sdk/blob/main/bindings/matrix-sdk-ffi/src/api.udl)).
7ff8adafe9e4atagen2026-10-22 12:30 UTC14
- Add UniFFI directivies as Rust attributes. In this case Rust source files
7ff8adafe9e4atagen2026-10-22 12:30 UTC15
  (`.rs`) contain attributes related to UniFFI (e.g. `#[uniffi::export]`).
7ff8adafe9e4atagen2026-10-22 12:30 UTC16
  Attributes are preferred, where applicable.
7ff8adafe9e4atagen2026-10-22 12:30 UTC17
7ff8adafe9e4atagen2026-10-22 12:30 UTC18
## Expose Rust definitions to UniFFI
7ff8adafe9e4atagen2026-10-22 12:30 UTC19
7ff8adafe9e4atagen2026-10-22 12:30 UTC20
### Check if the API is already on UniFFI
7ff8adafe9e4atagen2026-10-22 12:30 UTC21
7ff8adafe9e4atagen2026-10-22 12:30 UTC22
First of all check if the Rust definition you are looking for exists on UniFFI
7ff8adafe9e4atagen2026-10-22 12:30 UTC23
already. Most of exposed matrix definitions are collected in the crate
7ff8adafe9e4atagen2026-10-22 12:30 UTC24
[matrix-sdk-ffi](https://github.com/matrix-org/matrix-rust-sdk/tree/main/bindings/matrix-sdk-ffi).
7ff8adafe9e4atagen2026-10-22 12:30 UTC25
This crate contains mainly small Rust wrappers around the actual Rust SDK (e.g.
7ff8adafe9e4atagen2026-10-22 12:30 UTC26
the crate
7ff8adafe9e4atagen2026-10-22 12:30 UTC27
[matrix-sdk](https://github.com/matrix-org/matrix-rust-sdk/tree/main/crates/matrix-sdk))
7ff8adafe9e4atagen2026-10-22 12:30 UTC28
7ff8adafe9e4atagen2026-10-22 12:30 UTC29
If the Rust definition is on UniFFI already, you either:
7ff8adafe9e4atagen2026-10-22 12:30 UTC30
7ff8adafe9e4atagen2026-10-22 12:30 UTC31
- find it in a `.udl` file like
7ff8adafe9e4atagen2026-10-22 12:30 UTC32
  [matrix-sdk-ffi/src/api.udl](https://github.com/matrix-org/matrix-rust-sdk/blob/main/bindings/matrix-sdk-ffi/src/api.udl)
7ff8adafe9e4atagen2026-10-22 12:30 UTC33
- see it marked with a proper UniFFI Rust attribute like this
7ff8adafe9e4atagen2026-10-22 12:30 UTC34
  `#[uniffi::export]`
7ff8adafe9e4atagen2026-10-22 12:30 UTC35
7ff8adafe9e4atagen2026-10-22 12:30 UTC36
### Adding a missing matrix API
7ff8adafe9e4atagen2026-10-22 12:30 UTC37
7ff8adafe9e4atagen2026-10-22 12:30 UTC38
1. Unless you want to contribute on the crypto side, you probably need to add
7ff8adafe9e4atagen2026-10-22 12:30 UTC39
   some code in the
7ff8adafe9e4atagen2026-10-22 12:30 UTC40
   [matrix-sdk-ffi](https://github.com/matrix-org/matrix-rust-sdk/tree/main/bindings/matrix-sdk-ffi)
7ff8adafe9e4atagen2026-10-22 12:30 UTC41
   crate. After you find the crate you need to understand which file is best to
7ff8adafe9e4atagen2026-10-22 12:30 UTC42
   contain the new Rust definition. When exposing new matrix API often (but not
7ff8adafe9e4atagen2026-10-22 12:30 UTC43
   always) you need to touch the file
7ff8adafe9e4atagen2026-10-22 12:30 UTC44
   [client.rs](https://github.com/matrix-org/matrix-rust-sdk/blob/main/bindings/matrix-sdk-ffi/src/client.rs)
7ff8adafe9e4atagen2026-10-22 12:30 UTC45
7ff8adafe9e4atagen2026-10-22 12:30 UTC46
2. Identify the API to expose in the target Rust crate (typically in
7ff8adafe9e4atagen2026-10-22 12:30 UTC47
   [matrix-sdk](https://github.com/matrix-org/matrix-rust-sdk/tree/main/crates/matrix-sdk).
7ff8adafe9e4atagen2026-10-22 12:30 UTC48
   If you can’t find it, you probably need to touch the actual Rust SDK as well.
7ff8adafe9e4atagen2026-10-22 12:30 UTC49
   In this case you typically just need to write some code around
7ff8adafe9e4atagen2026-10-22 12:30 UTC50
   [ruma](https://github.com/ruma/ruma) (a Rust SDK’s dependency) which already
7ff8adafe9e4atagen2026-10-22 12:30 UTC51
   implements most of the matrix protocol
7ff8adafe9e4atagen2026-10-22 12:30 UTC52
7ff8adafe9e4atagen2026-10-22 12:30 UTC53
3. After you got (by finding or writing) the required Rust code, you need to
7ff8adafe9e4atagen2026-10-22 12:30 UTC54
   expose to UniFFI. To do that just write a small Rust wrapper in the related
7ff8adafe9e4atagen2026-10-22 12:30 UTC55
   UniFFI crate (most of the time is **matrix-sdk-ffi**) you found on step 1.
7ff8adafe9e4atagen2026-10-22 12:30 UTC56
7ff8adafe9e4atagen2026-10-22 12:30 UTC57
4. When your new (wrapping) Rust definition is ready, remember to expose it to
7ff8adafe9e4atagen2026-10-22 12:30 UTC58
   UniFFI.
7ff8adafe9e4atagen2026-10-22 12:30 UTC59
It’s best to do it using UniFFI Rust attributes (e.g. `#[uniffi::export]`).
7ff8adafe9e4atagen2026-10-22 12:30 UTC60
Otherwise add the new definition in the crate’s `.udl` file. For the
7ff8adafe9e4atagen2026-10-22 12:30 UTC61
**matrix-sdk-ffi** crate the definition file is
7ff8adafe9e4atagen2026-10-22 12:30 UTC62
[api.udl](https://github.com/matrix-org/matrix-rust-sdk/blob/main/bindings/matrix-sdk-ffi/src/api.udl).
7ff8adafe9e4atagen2026-10-22 12:30 UTC63
**Remember**: the language inside a `.udl` file isn’t Rust. To
7ff8adafe9e4atagen2026-10-22 12:30 UTC64
[learn more about how map Rust into UDL read here](https://mozilla.github.io/uniffi-rs/udl_file_spec.html)
7ff8adafe9e4atagen2026-10-22 12:30 UTC65
7ff8adafe9e4atagen2026-10-22 12:30 UTC66
## FAQ
7ff8adafe9e4atagen2026-10-22 12:30 UTC67
7ff8adafe9e4atagen2026-10-22 12:30 UTC68
**Q**: I wrote my Rust code and exposed it to UniFFI. How can I check if the
7ff8adafe9e4atagen2026-10-22 12:30 UTC69
compiler is happy?\
7ff8adafe9e4atagen2026-10-22 12:30 UTC70
**A**: Run `cargo build` in the crate you touched (e.g. matrix-sdk-ffi). The
7ff8adafe9e4atagen2026-10-22 12:30 UTC71
compiler will complain if the Rust code and/or the `.udl` is wrong.
7ff8adafe9e4atagen2026-10-22 12:30 UTC72
7ff8adafe9e4atagen2026-10-22 12:30 UTC73
**Q**: The compiler is happy with my code but the CI is failing on GitHub. How
7ff8adafe9e4atagen2026-10-22 12:30 UTC74
can I fix it?\
7ff8adafe9e4atagen2026-10-22 12:30 UTC75
**A**: The CI may fail for different reasons, you need to have a look on the
7ff8adafe9e4atagen2026-10-22 12:30 UTC76
failing GitHub workflow. One common reason though is that the linter
7ff8adafe9e4atagen2026-10-22 12:30 UTC77
([Clippy](https://github.com/rust-lang/rust-clippy)) isn’t happy with your code.
7ff8adafe9e4atagen2026-10-22 12:30 UTC78
If this is the case, you can run `cargo clippy` in the crate you touched to see
7ff8adafe9e4atagen2026-10-22 12:30 UTC79
what’s wrong and fix it accordingly.