7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1 | # Apple platforms support |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3 | This project and build script demonstrate how to create an XCFramework that can |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 4 | be imported into an Xcode project and run on Apple platforms. It can compile and |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 5 | bundle an [entire SDK](#Building-the-SDK), or only a smaller |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 6 | [Crypto module](#Building-only-the-Crypto-SDK) that provides end-to-end |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 7 | encryption for clients that already depend on an SDK (e.g. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 8 | [Matrix iOS SDK](https://github.com/matrix-org/matrix-ios-sdk)) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 9 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 10 | ## Building |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 11 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 12 | ### Prerequisites for building universal frameworks |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 13 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 14 | - the Rust toolchain |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 15 | - Apple targets (e.g. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 16 | `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 --> |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 17 | - `xcodebuild` command line tool from |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 18 | [Apple](https://developer.apple.com/library/archive/technotes/tn2339/_index.html) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 19 | - `lipo` for creating the fat static libs |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 20 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 21 | ### Building the SDK |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 22 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 23 | ```text |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 24 | cargo xtask swift build-framework |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 25 | ``` |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 26 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 27 | The `build-framework` task will go through all the steps required to generate a |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 28 | fully usable `.xcframework`: |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 29 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 30 | 1. compile `matrix-sdk-ffi` libraries for iOS, the iOS simulator and macOS under |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 31 | `/target`. Some targets are not part of the standard library and they will be |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 32 | built using the nightly toolchain. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 33 | 2. `lipo` together the libraries for the same platform under `/generated` |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 34 | 3. run `uniffi` and generate the C header, module map and swift files |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 35 | 4. `xcodebuild` an `xcframework` from the fat static libs and the original iOS |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 36 | one, and add the header and module map to it under |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 37 | `generated/MatrixSDKFFI.xcframework` |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 38 | 5. cleanup and delete the generated files except the .xcframework and the swift |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 39 | sources (that aren't part of the framework) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 40 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 41 | For development purposes, it will additionally generate a `Package.swift` file |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 42 | in the root of the repo that can be used to add the framework to your project |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 43 | and enable debugging through the use of |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 44 | [rust-xcode-plugin](https://github.com/BrainiumLLC/rust-xcode-plugin) (make sure |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 45 | to run the task with the argument `--profile=reldbg`). |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 46 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 47 | When building the SDK for release you should pass the `--release` argument to |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 48 | the task, which will strip away any symbols and optimise the created binary. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 49 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 50 | ### Building only the crypto SDK |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 51 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 52 | ```text |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 53 | build_crypto_xcframework.sh |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 54 | ``` |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 55 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 56 | The `build_crypto_xcframework.sh` script will go through all the steps required |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 57 | to generate a fully usable `.xcframework`: |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 58 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 59 | 1. compile `matrix-sdk-crypto-ffi` libraries for iOS and the iOS simulator under |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 60 | `/target` |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 61 | 2. `lipo` together the libraries for the same platform under `/generated` |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 62 | 3. run `uniffi` and generate the C header, module map and swift files |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 63 | 4. `xcodebuild` an `xcframework` from the fat static libs and the original iOS |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 64 | one, and add the header and module map to it under |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 65 | `generated/MatrixSDKCryptoFFI.xcframework` |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 66 | 5. cleanup and delete the generated files except the .xcframework and the swift |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 67 | sources (that aren't part of the framework) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 68 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 69 | ### Building & testing the Swift package |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 70 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 71 | The `Package.swift` file in this directory provides a simple example on how to |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 72 | integrate everything together but also a place to run unit and integration tests |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 73 | from. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 74 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 75 | It's pre-configured to link to the generated static lib and .swift files so |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 76 | successfully running `cargo xtask swift build-library` first is necessary for it |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 77 | to compile. Afterwards you can execute the tests with `swift test`. Note that |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 78 | for the moment this only works on macOS but we're planning to add Linux support |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 79 | in the future. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 80 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 81 | ## Distribution |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 82 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 83 | The generated framework and Swift code can be distributed and integrated |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 84 | directly but in order to make things simpler we bundle them together as a |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 85 | [Swift package](https://github.com/matrix-org/matrix-rust-components-swift/) in |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 86 | the case of SDK, and as a CocoaPods podspec in the case of Crypto SDK. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 87 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 88 | ### Publishing `MatrixSDKCrypto` |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 89 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 90 | 1. Navigate into `bindings/apple` and run |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 91 | [`build_crypto_xcframework.sh`](#building-only-the-crypto-sdk) script which |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 92 | generates a .zip file with the framework in `./generated` folder |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 93 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 94 | Note that whilst you can run this command from any git branch, if you want to |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 95 | make a public release, ensure you are building from latest `main` |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 96 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 97 | 2. Tag the commit you just used to build the release and push the tag to GitHub |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 98 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 99 | Use `matrix-sdk-crypto-ffi-<major>.<minor>.<patch>` tag name |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 100 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 101 | 3. Create a new |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 102 | [GitHub release](https://github.com/matrix-org/matrix-rust-sdk/releases) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 103 | using this tag (see |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 104 | [example](https://github.com/matrix-org/matrix-rust-sdk/releases/tag/matrix-sdk-crypto-ffi-0.3.4)) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 105 | 4. Upload the previously generated .zip file to this release |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 106 | 5. Increment the version in |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 107 | [`MatrixSDKCrypto.podspec`](./MatrixSDKCrypto.podspec) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 108 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 109 | Note that this is not automated and is a local-only change. To determine the |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 110 | most recent published version, run |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 111 | `pod repo update && pod search MatrixSDKCrypto` or check git tags via |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 112 | `git tag | grep matrix-sdk-crypto-ffi` |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 113 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 114 | 6. Push new Podspec version to Cocoapods via |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 115 | `pod trunk push MatrixSDKCrypto.podspec --allow-warnings` |