This is a simple example showing how to build a static library in Rust and use it in a Swift-based iOS application — works for both real devices and simulators.
✅ Supports both Apple Silicon and Intel-based Macs
✅ No CocoaPods, Carthage, or SwiftPM needed
✅ Just Rust + Xcode + one clean.a
This is a simple example of how to create a static library in Rust and use it in an iOS application.
You can place your Rust project anywhere — this just assumes a
rust_addproject insidestatic_libs/.
rustup target add aarch64-apple-ios aarch64-apple-ios-sim x86_64-apple-ioscargo build --release --target aarch64-apple-ios
cargo build --release --target aarch64-apple-ios-sim
cargo build --release --target x86_64-apple-iosmkdir -p ../builtlibtool -static -o "../built/librust_add-iphoneos.a" \
"target/aarch64-apple-ios/release/librust_add.a"
libtool -static -o "../built/librust_add-iphonesimulator.a" \
"target/aarch64-apple-ios-sim/release/librust_add.a" \
"target/x86_64-apple-ios/release/librust_add.a"rm -rf targettouch rust_add.h#ifndef RUST_ADD_H
#define RUST_ADD_H
#ifdef __cplusplus
extern "C" {
#endif
int add_numbers(int a, int b);
#ifdef __cplusplus
}
#endif
#endif // RUST_ADD_Htouch Rust_iOS-Bridging-Header.h#import "rust_add.h"Objective-C Bridging Header - /Rust_iOS/Rust_iOS-Bridging-Header.h
$(inherited) $(PROJECT_DIR)/Rust_iOS/static_libs/built/librust_add$(EFFECTIVE_PLATFORM_NAME).a
import SwiftUI
struct ContentView: View {
var body: some View {
let result = add_numbers(10, 10)
VStack {
Image(systemName: "globe")
.imageScale(.large)
.foregroundStyle(.tint)
Text("Hello, world!")
Text("\(result)")
}
.padding()
}
}
#Preview {
ContentView()
}