Skip to content

wojteklu/rust-to-ios

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rust-to-ios

Swift 5.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.

About

Example project for building a library for iOS in Rust.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published