I'm using UniFFI to generate Swift bindings for a Rust library.
Following the documentation, I have:
1. Compiled the Rust library:
- Once as a static library
libuniffi_example.afor iOS devices (aarch64-apple-ios). - Once as a fat static library
libuniffi_example.afor the simulator (x86_64-apple-iosandaarch64-apple-ios-sim).
2. Generated the Swift bindings by running uniffi-bindgen generate src/example.udl --language swift. This outputs two things:
- A C header file
exampleFFI.hdeclaring the low-level structs and functions for calling into Rust, along with a correspondingexampleFFI.modulemapto expose them to Swift. - A Swift source file example.swift that imports the exampleFFI module and wraps it to provide the higher-level Swift API.
I've managed to build an XCFramework exposing the low-level C FFI layer defined in exampleFFI.h using:
xcodebuild -create-xcframework
-library (...)/libuniffi_example.a -headers (...)/exampleFFI.h
(...)
But when I use that XCFramework, I still need to include the generated example.swift source file in my project to access the higher-level Swift bindings.
Ideally, I'd like to create a single XCFramework that bundles everything necessary to access the Rust library via the generated higher-level Swift bindings directly.
I specifically don't want the consumers of the library to have to manually include anything else than the XCFramework and be able to access the higher-level Swift bindings as generated in the example.swift source file.