How matrix-org/matrix-rust-components-swift works
Project type and purpose
• This is not a full‐stack application but an open‐source “packaging” library / wrapper. Its goal is to expose the Matrix Rust SDK to Swift projects via the Swift Package Manager (SPM). It does so by bundling a pre-built Rust binary and providing Swift/FFI glue code.
File structure
• Top‐level:
• .github: issue/pr templates, CI and contribution guidelines
• Package.swift, README.md, CONTRIBUTING.md, LICENSE, SECURITY.md: SPM manifest and repo docs
• Sources/MatrixRustSDK: Swift source modules (matrix_sdk.swift, base, common, crypto, ffi, ui)
• Tools/Release: a Swift tool and script (Release.swift) to automate tagging and packaging of new Rust binaries
• docs: “Getting Started” guide
• .swiftpm/xcode: Xcode workspace metadata
• Patterns: modular Swift wrapper (split by functionality), FFI bridge module, release-automation tooling
README for additional insights
• Describes usage (import via SwiftPM), release process (run Tools/Release script when upstream Rust SDK releases), local testing (development happens in the Rust SDK repo, not here).
a. Main components:
• Swift Package Manager (SPM) resolver (consumer of this package)
• MatrixRustSDK Swift modules:
– matrix_sdk_common, matrix_sdk_base, matrix_sdk_crypto, matrix_sdk_ui
– matrix_sdk_ffi (FFI layer)
• Embedded pre-compiled Rust SDK binary
• Tools/Release script (automates tagging, fetching new Rust binaries, updating Package.swift)
• GitHub repository (host, CI, issue templates)
b. Relationships and interactions:
• SPM pulls the package (Package.swift) from GitHub
• Package defines targets for Swift modules, declares a binary target pointing to the Rust SDK archive
• matrix_sdk_ffi uses Swift’s C interop to load and call into the Rust binary
• Other Swift modules wrap, extend, or expose higher-level APIs to Swift apps
• Tools/Release interacts with Git tags, downloads new Rust binary, updates package metadata, commits changes
c. Architectural patterns and design principles:
• Modular layering:
– FFI layer isolated from higher-level Swift logic
– Each functional area (crypto, UI, common) separated into distinct targets
• Binary packaging pattern: SPM binaryTarget to embed platform-specific pre-built library
• Release automation: single-responsibility tool that updates and publishes new versions
d. Key technologies and frameworks:
• Swift Package Manager (Package.swift, binaryTarget)
• Swift language modules
• Rust compiled into a C‐compatible binary (Cargo, rustc)
• Swift FFI / C interop
• Xcode workspace for local IDE support
• GitHub Actions or other CI (implied by .github)