Skip to content

Building library for iOS

Ivan Schütz edited this page May 14, 2020 · 21 revisions

Generate library (.a file):

  • Install rustup
  • Add targets: device: rustup target add aarch64-apple-ios, simulator: rustup target add x86_64-apple-ios,

Update: Now you can execute the create_ios_universal.sh script in ./scripts/ios/ to generate a universal library with Bitcode support.

Without Bitcode (not recommended)

  • Turn off bitcode support in Xcode
  • Run in the root directory of this repo: cargo lipo --release. This generates a universal library for all supported architectures.
  • You will find the library in ./target/universal/release/

With Bitcode

Device

Xcode uses often a different LLVM version than Rust. The rust-bitcode library helps us with this.

After you've installed this library, in this repo's root folder, execute:

RUSTFLAGS="-Z embed-bitcode" cargo +ios-arm64 build --target aarch64-apple-ios --release --lib

To generate the library for the device. It will be in ./target/aarch64-apple-ios/release/

Simulator

The simulator doesn't require bitcode, independently of the project's settings. So you can create the library with only cargo build --target=x86_64-apple-ios

Universal library with bitcode

We've now 2 separate libraries for the simulator and the device. We have to merge them into one, which can be used by Xcode. From the root directory of this repo, execute:

libtool -static -o libtcn_client.a ./target/aarch64-apple-ios/release/libtcn_client.a ./target/x86_64-apple-ios/release/libtcn_client.a

The generated libtcn_client.a will be where you indicate, in this case, in the same directory where libtool was executed.

Using library in the iOS app

  • Copy libtcn_client.a file into the iOS app's root dir.

Updating the interface

  • Aside from updating the library (.a file), update the headers in mobileapp-ios.h (which is in the iOS app).
Clone this wiki locally