Skip to content
No description, website, or topics provided.
Swift Rust C Objective-C
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


RustySwift is a unique approach to efficient, asynchronous bilateral communication between Rust and Swift.

The Dream: To implement an asynchronous function in Rust that can be cross-compiled into a static library for iOS and macOS (along with many other targets, but those are not our focus) and invoked using native Swift closures.

The Challenge: Rust is ignorant of the concept of Swift closures. How can it notify Swift when the work is done? What do?

The Solution: Take a look at the comments in rust/ffi/src/ and swift/RustySwift/RustySwift.swift to see how it works.


The Swift project contains a working demonstration of the Rust integration. Open the Xcode project found in swift and run it on an iOS simulator to see it in action. You'll also find helpful documentation describing each piece of the puzzle in excruciating detail.

Building the Rust Library

Requirements: cargo and a macOS host. Optional: cargo-lipo.

The Rust binary is prebuilt and checked into the repo already. But if you want to build it manually, first add the necessary targets via rustup:

rustup target add x86_64-apple-ios aarch64-apple-ios

Then cd into rust and run:

# to build for the iOS simulator
cargo build -p ffi --release --target=x86_64-apple-ios

# to build for an iOS device
cargo build -p ffi --release --target=aarch64-apple-ios

# optionally, build a universal ("fat") binary with `cargo-lipo` instead
cargo lipo -p ffi --release

This will generate a static library in target/${TARGET}/release (or target/universal/release for the cargo-lipo command) that can be imported into the Swift project.

You can’t perform that action at this time.