A Swift Package that exposes Rust logic via UniFFI, distributed as an XCFramework.
- Rust
- Xcode Command Line Tools (
xcode-select --install) - A valid Apple Developer certificate installed in your Keychain (required only for signing)
git clone https://github.com/OpenSwiftXO/RustSwiftFFI.git
cd RustSwiftFFI./build_xcframework.shThis will:
- Install the required Rust targets (
aarch64-apple-ios,aarch64-apple-ios-sim,aarch64-apple-darwin) - Compile the Rust library for each target in release mode
- Generate Swift bindings, C headers, and a modulemap via UniFFI
- Bundle everything into
build/rust_swiftFFI.xcframework - Copy the Swift wrapper to
build/RustSwift.swift
| File | Description |
|---|---|
build/rust_swiftFFI.xcframework |
XCFramework containing static libraries for iOS, iOS Simulator, and macOS |
build/RustSwift.swift |
Generated Swift wrapper to include in your app target |
By default, signing is skipped. To sign the XCFramework (required for App Store distribution):
Step 1 — Find your signing identity:
security find-identity -v -p codesigningYou will see output like:
1) XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX "Apple Development: Nguyen Van A (TEAMID)"
Step 2 — Run the build with your identity:
SIGNING_IDENTITY="Apple Development: Nguyen Van A (TEAMID)" ./build_xcframework.shOr export it for the current shell session:
export SIGNING_IDENTITY="Apple Development: Nguyen Van A (TEAMID)"
./build_xcframework.shStep 3 — Verify the signature:
codesign -dvvv build/rust_swiftFFI.xcframeworkSPM recommends distributing XCFrameworks as a remote binary target — a zipped .xcframework hosted at a public URL with a SHA-256 checksum for verification. Do not commit the .xcframework directly into the repository.
cd build
zip -r rust_swiftFFI.xcframework.zip rust_swiftFFI.xcframeworkswift package compute-checksum build/rust_swiftFFI.xcframework.zipCopy the printed hash (e.g. a1b2c3d4e5f6...).
Upload rust_swiftFFI.xcframework.zip to a publicly accessible URL, such as a GitHub Release asset:
- Create a new GitHub Release for your repository
- Attach
rust_swiftFFI.xcframework.zipas a release asset - Copy the download URL (e.g.
https://github.com/OpenSwiftXO/RustSwiftFFI/releases/download/1.0.0/rust_swiftFFI.xcframework.zip)
.binaryTarget(
name: "rust_swiftFFI",
url: "https://github.com/OpenSwiftXO/RustSwiftFFI/releases/download/1.0.0/rust_swiftFFI.xcframework.zip",
checksum: "a1b2c3d4e5f6..." // paste the hash from Step 2
)Commit build/RustSwift.swift into your package repository and add it to your library's source target in Package.swift.
Simply call the exposed functions directly from your own Swift code:
let result = addCoreLogic(left: 1, right: 2)
let greeting = sayHiFromRust()See the RustSwiftFFI-SPM repository for a complete example of how to integrate this XCFramework into a Swift Package Manager project.
UniFFI-rs – Official Mozilla UniFFI documentation and source code