-
Notifications
You must be signed in to change notification settings - Fork 5
Building library for iOS
- Install rustup
- Add targets: device:
rustup target add aarch64-apple-ios
, simulator:rustup target add x86_64-apple-ios
,
The next 2 sections are here only for context. Skip to "Universal (that works)" if you just want to build quickly.
This generates a library with all supported architectures.
- Run in the root directory of this repo:
cargo lipo --release
- You will find the generated library in
./target/universal/release/
If you try to run it on a device, you will likely get an error:
“libtcn_client.a does not contain bitcode”
Which leads to the next section.
Building for a real device is a bit more complicated, because 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/
But now we've 2 separate libraries for the simulator and the device. We need only one.
From the previous sections, it follows that we need to generate the libraries for the simulator and the device separately and merge them in one single library.
So:
- Generate lib for device, as described in "Device"
- Generate lib only for the simulator, with:
cargo build --target=x86_64-apple-ios
Now, from the root directory of this repo, we will call libtool
to assemble these 2 libraries into one:
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.
To use library in the iOS app:
- Copy
libtcn_client.a
file intarget > x86_64-apple-ios > release
- Paste in iOS app's root dir. Ensure to have checked out the Rust integration branch.
To change the interface:
- Aside from updating the library (
.a
file), update the headers inmobileapp-ios.h
(which is in the iOS app).