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:
Incargo build --release
target/release
, you should find thelibmobile.dylib
,libmobile.so
, orlibmobile.dll
file, depending on the operating system you are using. -
.so (Shared Object) – This is the shared library format used in Linux and other Unix-based operating systems.
- .dylib (Dynamic Library) – This is the shared library format for macOS.
-
.dll (Dynamic Link Library) - The shared library format used in Windows.
-
Generate the bindings for Swift by running the command below. Replace
{build_file}
withlibmobile.dylib
,libmobile.so
, orlibmobile.dll
, depending on which file is generated intarget/release
.cargo run --bin uniffi-bindgen generate --library ./target/release/{build_file} --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