Example project for building a library for iOS in Rust.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
iOS/Example
rust/message
.gitignore
LICENSE
README.md

README.md

rust-to-ios

Swift 4.0 @wojteklu

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

Setup

  1. Download rustup needed to setup Rust for cross-compiling.

    curl https://sh.rustup.rs -sSf | sh
  2. Download targets for iOS.

    rustup target add aarch64-apple-ios armv7-apple-ios armv7s-apple-ios x86_64-apple-ios i386-apple-ios
  3. Install cargo-lipo to generate the iOS universal library.

    cargo install cargo-lipo

Building the library

  1. Create a new cargo project.

    cargo new message
  2. Update Cargo.toml by adding the [lib] section.

    [lib]
    name = "message"
    crate-type = ["staticlib"]
  3. Write the library and expose its public interface in a C header.

  4. Build the library.

    cd message
    
    cargo lipo --release

Using the library

  1. Create the iOS project.

  2. Add the C header to allow using the Rust functions from C.

  3. Copy target/universal/release/libmessage.a to project.

  4. Add libresolv.tbd to Linked frameworks and libraries.

  5. Note that cargo-lipo does not support bitcode yet. You must set ENABLE_BITCODE to NO.

Author

Wojtek Lukaszuk @wojteklu

License

Available under the MIT license. See the LICENSE file for more info.