Example project for building a library for iOS.
- ✓ sending primitives between Rust and iOS
- ✓ sending strings between Rust and iOS
- ✓ giving ownership of a Rust instance to Swift
-
Download rustup needed to setup Rust for cross-compiling.
curl https://sh.rustup.rs -sSf | sh
-
Download targets for iOS.
rustup target add aarch64-apple-ios armv7-apple-ios armv7s-apple-ios x86_64-apple-ios i386-apple-ios
-
Install cargo-lipo to generate the iOS universal library.
cargo install cargo-lipo
-
Create a new cargo project.
cargo new message
-
Update Cargo.toml by adding the [lib] section.
[lib] name = "message" crate-type = ["staticlib"]
-
Write the library and expose its public interface in a C header.
-
Build the library.
cd message cargo lipo --release
-
Create the iOS project.
-
Add the C header to allow using the Rust functions from C.
-
Copy
target/universal/release/libmessage.a
to project. -
Add
libresolv.tbd
toLinked frameworks and libraries
. -
Note that
cargo-lipo
does not support bitcode yet. You must setENABLE_BITCODE
toNO
.
Wojtek Lukaszuk @wojteklu
Available under the MIT license. See the LICENSE file for more info.