Using UniFFI binding iOS App#
Cedarling UniFFI binding exposes its init
, authz
and log
interfaces to different languages and on all the different platforms, including Swift for iOS. This section covers how to build and use Cedarling UniFFI binding in an iOS app.
Prerequisites#
- Rust: Install it from the official Rust website.
- Xcode: Available on the Mac App Store.
Building#
-
Clone the jans monorepo and change directory to
/path/of/jans/jans-cedarling
.git clone https://github.com/JanssenProject/jans.git cd /path/of/jans/jans-cedarling
-
Build the library:
In target/debug, you should find the libmobile.dylib file.cargo build
-
Generate the bindings:
cargo run --bin uniffi-bindgen generate --library ./target/debug/libmobile.dylib --language swift --out-dir ./bindings/cedarling_uniffi/output
-
Building the iOS binaries and adding these targets to Rust.
rustup target add aarch64-apple-ios-sim aarch64-apple-ios
-
Build the library for Swift.
You should have two binariescargo build --release --target=aarch64-apple-ios-sim cargo build --release --target=aarch64-apple-ios
target/aarch64-apple-ios-sim/release/libmobile.a
andtarget/aarch64-apple-ios/release/libmobile.a
. -
The XCFramework will allow us to import the library with zero effort in Xcode. First, we need to rename the file ./bindings/cedarling_uniffi/output/mobileFFI.modulemap to ./bindings/cedarling_uniffi/output/module.modulemap. Then, we can create the XCFramework:
xcodebuild -create-xcframework \ -library ./target/aarch64-apple-ios-sim/release/libmobile.a -headers ./bindings/cedarling_uniffi/output \ -library ./target/aarch64-apple-ios/release/libmobile.a -headers ./bindings/cedarling_uniffi/output \ -output "ios/Mobile.xcframework"
-
Open
./jans-cedarling/bindings/cedarling_uniffi/iOSApp
in Xcode. Import both the XCFramework Mobile.xcframework and the Swift file bindingsbindings/output/mobile.swift
files into your project (drag and drop should work). -
Run iOS project on simulator.
We have included a sample iOS app using Cedarling UniFFI binding for making authorisation decisions. Here is a demonstration video of its working.
Created: 2025-02-18