atagen

matrix-rust-sdk

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

Blame: bindings/apple/README.md

7ff8adafe9e4atagen2026-10-22 12:30 UTC1
# Apple platforms support
7ff8adafe9e4atagen2026-10-22 12:30 UTC2
7ff8adafe9e4atagen2026-10-22 12:30 UTC3
This project and build script demonstrate how to create an XCFramework that can
7ff8adafe9e4atagen2026-10-22 12:30 UTC4
be imported into an Xcode project and run on Apple platforms. It can compile and
7ff8adafe9e4atagen2026-10-22 12:30 UTC5
bundle an [entire SDK](#Building-the-SDK), or only a smaller
7ff8adafe9e4atagen2026-10-22 12:30 UTC6
[Crypto module](#Building-only-the-Crypto-SDK) that provides end-to-end
7ff8adafe9e4atagen2026-10-22 12:30 UTC7
encryption for clients that already depend on an SDK (e.g.
7ff8adafe9e4atagen2026-10-22 12:30 UTC8
[Matrix iOS SDK](https://github.com/matrix-org/matrix-ios-sdk))
7ff8adafe9e4atagen2026-10-22 12:30 UTC9
7ff8adafe9e4atagen2026-10-22 12:30 UTC10
## Building
7ff8adafe9e4atagen2026-10-22 12:30 UTC11
7ff8adafe9e4atagen2026-10-22 12:30 UTC12
### Prerequisites for building universal frameworks
7ff8adafe9e4atagen2026-10-22 12:30 UTC13
7ff8adafe9e4atagen2026-10-22 12:30 UTC14
- the Rust toolchain
7ff8adafe9e4atagen2026-10-22 12:30 UTC15
- Apple targets (e.g.
7ff8adafe9e4atagen2026-10-22 12:30 UTC16
  `rustup target add aarch64-apple-ios aarch64-apple-ios-sim x86_64-apple-ios aarch64-apple-darwin x86_64-apple-darwin`) <!-- rumdl-disable-line MD013 -->
7ff8adafe9e4atagen2026-10-22 12:30 UTC17
- `xcodebuild` command line tool from
7ff8adafe9e4atagen2026-10-22 12:30 UTC18
  [Apple](https://developer.apple.com/library/archive/technotes/tn2339/_index.html)
7ff8adafe9e4atagen2026-10-22 12:30 UTC19
- `lipo` for creating the fat static libs
7ff8adafe9e4atagen2026-10-22 12:30 UTC20
7ff8adafe9e4atagen2026-10-22 12:30 UTC21
### Building the SDK
7ff8adafe9e4atagen2026-10-22 12:30 UTC22
7ff8adafe9e4atagen2026-10-22 12:30 UTC23
```text
7ff8adafe9e4atagen2026-10-22 12:30 UTC24
cargo xtask swift build-framework
7ff8adafe9e4atagen2026-10-22 12:30 UTC25
```
7ff8adafe9e4atagen2026-10-22 12:30 UTC26
7ff8adafe9e4atagen2026-10-22 12:30 UTC27
The `build-framework` task will go through all the steps required to generate a
7ff8adafe9e4atagen2026-10-22 12:30 UTC28
fully usable `.xcframework`:
7ff8adafe9e4atagen2026-10-22 12:30 UTC29
7ff8adafe9e4atagen2026-10-22 12:30 UTC30
1. compile `matrix-sdk-ffi` libraries for iOS, the iOS simulator and macOS under
7ff8adafe9e4atagen2026-10-22 12:30 UTC31
   `/target`. Some targets are not part of the standard library and they will be
7ff8adafe9e4atagen2026-10-22 12:30 UTC32
   built using the nightly toolchain.
7ff8adafe9e4atagen2026-10-22 12:30 UTC33
2. `lipo` together the libraries for the same platform under `/generated`
7ff8adafe9e4atagen2026-10-22 12:30 UTC34
3. run `uniffi` and generate the C header, module map and swift files
7ff8adafe9e4atagen2026-10-22 12:30 UTC35
4. `xcodebuild` an `xcframework` from the fat static libs and the original iOS
7ff8adafe9e4atagen2026-10-22 12:30 UTC36
   one, and add the header and module map to it under
7ff8adafe9e4atagen2026-10-22 12:30 UTC37
   `generated/MatrixSDKFFI.xcframework`
7ff8adafe9e4atagen2026-10-22 12:30 UTC38
5. cleanup and delete the generated files except the .xcframework and the swift
7ff8adafe9e4atagen2026-10-22 12:30 UTC39
   sources (that aren't part of the framework)
7ff8adafe9e4atagen2026-10-22 12:30 UTC40
7ff8adafe9e4atagen2026-10-22 12:30 UTC41
For development purposes, it will additionally generate a `Package.swift` file
7ff8adafe9e4atagen2026-10-22 12:30 UTC42
in the root of the repo that can be used to add the framework to your project
7ff8adafe9e4atagen2026-10-22 12:30 UTC43
and enable debugging through the use of
7ff8adafe9e4atagen2026-10-22 12:30 UTC44
[rust-xcode-plugin](https://github.com/BrainiumLLC/rust-xcode-plugin) (make sure
7ff8adafe9e4atagen2026-10-22 12:30 UTC45
to run the task with the argument `--profile=reldbg`).
7ff8adafe9e4atagen2026-10-22 12:30 UTC46
7ff8adafe9e4atagen2026-10-22 12:30 UTC47
When building the SDK for release you should pass the `--release` argument to
7ff8adafe9e4atagen2026-10-22 12:30 UTC48
the task, which will strip away any symbols and optimise the created binary.
7ff8adafe9e4atagen2026-10-22 12:30 UTC49
7ff8adafe9e4atagen2026-10-22 12:30 UTC50
### Building only the crypto SDK
7ff8adafe9e4atagen2026-10-22 12:30 UTC51
7ff8adafe9e4atagen2026-10-22 12:30 UTC52
```text
7ff8adafe9e4atagen2026-10-22 12:30 UTC53
build_crypto_xcframework.sh
7ff8adafe9e4atagen2026-10-22 12:30 UTC54
```
7ff8adafe9e4atagen2026-10-22 12:30 UTC55
7ff8adafe9e4atagen2026-10-22 12:30 UTC56
The `build_crypto_xcframework.sh` script will go through all the steps required
7ff8adafe9e4atagen2026-10-22 12:30 UTC57
to generate a fully usable `.xcframework`:
7ff8adafe9e4atagen2026-10-22 12:30 UTC58
7ff8adafe9e4atagen2026-10-22 12:30 UTC59
1. compile `matrix-sdk-crypto-ffi` libraries for iOS and the iOS simulator under
7ff8adafe9e4atagen2026-10-22 12:30 UTC60
   `/target`
7ff8adafe9e4atagen2026-10-22 12:30 UTC61
2. `lipo` together the libraries for the same platform under `/generated`
7ff8adafe9e4atagen2026-10-22 12:30 UTC62
3. run `uniffi` and generate the C header, module map and swift files
7ff8adafe9e4atagen2026-10-22 12:30 UTC63
4. `xcodebuild` an `xcframework` from the fat static libs and the original iOS
7ff8adafe9e4atagen2026-10-22 12:30 UTC64
   one, and add the header and module map to it under
7ff8adafe9e4atagen2026-10-22 12:30 UTC65
   `generated/MatrixSDKCryptoFFI.xcframework`
7ff8adafe9e4atagen2026-10-22 12:30 UTC66
5. cleanup and delete the generated files except the .xcframework and the swift
7ff8adafe9e4atagen2026-10-22 12:30 UTC67
   sources (that aren't part of the framework)
7ff8adafe9e4atagen2026-10-22 12:30 UTC68
7ff8adafe9e4atagen2026-10-22 12:30 UTC69
### Building & testing the Swift package
7ff8adafe9e4atagen2026-10-22 12:30 UTC70
7ff8adafe9e4atagen2026-10-22 12:30 UTC71
The `Package.swift` file in this directory provides a simple example on how to
7ff8adafe9e4atagen2026-10-22 12:30 UTC72
integrate everything together but also a place to run unit and integration tests
7ff8adafe9e4atagen2026-10-22 12:30 UTC73
from.
7ff8adafe9e4atagen2026-10-22 12:30 UTC74
7ff8adafe9e4atagen2026-10-22 12:30 UTC75
It's pre-configured to link to the generated static lib and .swift files so
7ff8adafe9e4atagen2026-10-22 12:30 UTC76
successfully running `cargo xtask swift build-library` first is necessary for it
7ff8adafe9e4atagen2026-10-22 12:30 UTC77
to compile. Afterwards you can execute the tests with `swift test`. Note that
7ff8adafe9e4atagen2026-10-22 12:30 UTC78
for the moment this only works on macOS but we're planning to add Linux support
7ff8adafe9e4atagen2026-10-22 12:30 UTC79
in the future.
7ff8adafe9e4atagen2026-10-22 12:30 UTC80
7ff8adafe9e4atagen2026-10-22 12:30 UTC81
## Distribution
7ff8adafe9e4atagen2026-10-22 12:30 UTC82
7ff8adafe9e4atagen2026-10-22 12:30 UTC83
The generated framework and Swift code can be distributed and integrated
7ff8adafe9e4atagen2026-10-22 12:30 UTC84
directly but in order to make things simpler we bundle them together as a
7ff8adafe9e4atagen2026-10-22 12:30 UTC85
[Swift package](https://github.com/matrix-org/matrix-rust-components-swift/) in
7ff8adafe9e4atagen2026-10-22 12:30 UTC86
the case of SDK, and as a CocoaPods podspec in the case of Crypto SDK.
7ff8adafe9e4atagen2026-10-22 12:30 UTC87
7ff8adafe9e4atagen2026-10-22 12:30 UTC88
### Publishing `MatrixSDKCrypto`
7ff8adafe9e4atagen2026-10-22 12:30 UTC89
7ff8adafe9e4atagen2026-10-22 12:30 UTC90
1. Navigate into `bindings/apple` and run
7ff8adafe9e4atagen2026-10-22 12:30 UTC91
   [`build_crypto_xcframework.sh`](#building-only-the-crypto-sdk) script which
7ff8adafe9e4atagen2026-10-22 12:30 UTC92
   generates a .zip file with the framework in `./generated` folder
7ff8adafe9e4atagen2026-10-22 12:30 UTC93
7ff8adafe9e4atagen2026-10-22 12:30 UTC94
   Note that whilst you can run this command from any git branch, if you want to
7ff8adafe9e4atagen2026-10-22 12:30 UTC95
   make a public release, ensure you are building from latest `main`
7ff8adafe9e4atagen2026-10-22 12:30 UTC96
7ff8adafe9e4atagen2026-10-22 12:30 UTC97
2. Tag the commit you just used to build the release and push the tag to GitHub
7ff8adafe9e4atagen2026-10-22 12:30 UTC98
7ff8adafe9e4atagen2026-10-22 12:30 UTC99
   Use `matrix-sdk-crypto-ffi-<major>.<minor>.<patch>` tag name
7ff8adafe9e4atagen2026-10-22 12:30 UTC100
7ff8adafe9e4atagen2026-10-22 12:30 UTC101
3. Create a new
7ff8adafe9e4atagen2026-10-22 12:30 UTC102
   [GitHub release](https://github.com/matrix-org/matrix-rust-sdk/releases)
7ff8adafe9e4atagen2026-10-22 12:30 UTC103
   using this tag (see
7ff8adafe9e4atagen2026-10-22 12:30 UTC104
   [example](https://github.com/matrix-org/matrix-rust-sdk/releases/tag/matrix-sdk-crypto-ffi-0.3.4))
7ff8adafe9e4atagen2026-10-22 12:30 UTC105
4. Upload the previously generated .zip file to this release
7ff8adafe9e4atagen2026-10-22 12:30 UTC106
5. Increment the version in
7ff8adafe9e4atagen2026-10-22 12:30 UTC107
   [`MatrixSDKCrypto.podspec`](./MatrixSDKCrypto.podspec)
7ff8adafe9e4atagen2026-10-22 12:30 UTC108
7ff8adafe9e4atagen2026-10-22 12:30 UTC109
   Note that this is not automated and is a local-only change. To determine the
7ff8adafe9e4atagen2026-10-22 12:30 UTC110
   most recent published version, run
7ff8adafe9e4atagen2026-10-22 12:30 UTC111
   `pod repo update && pod search MatrixSDKCrypto` or check git tags via
7ff8adafe9e4atagen2026-10-22 12:30 UTC112
   `git tag | grep matrix-sdk-crypto-ffi`
7ff8adafe9e4atagen2026-10-22 12:30 UTC113
7ff8adafe9e4atagen2026-10-22 12:30 UTC114
6. Push new Podspec version to Cocoapods via
7ff8adafe9e4atagen2026-10-22 12:30 UTC115
   `pod trunk push MatrixSDKCrypto.podspec --allow-warnings`