IMPORTANT MESSAGE USE ONLY UniFFI_bindgen version ~< 0.16.0 Currently, using cargo install uniffi_bindgen, installs non released version 0.17.0 which produces incorrect library
Only use following command :
bash cargo install uniffi_bindgen --version 0.16.0
ATTENTION: Setup your project for Rust UniFFI. This code only works if you have *.UDL file
UDL files are Mozilla UniFFI models to use your rust library in swift or kotlin or python.
To learn more: [Runi Uniffi]
This tool generates a Xcode Framework using your rust code, using UniFFI This solution, runs smoothly on iOS and iOS Simulator and MacOS (Both Intel and M1 Processors/SoCs).
This application will generate Xcode Framework, based on your Rust UniFFI Models and Cargo.toml files
Future versions will support creating Applications as well.
You have to install rust targets for MacOS, iOS, and iOS simulator. Build Targets**
It is important to add following targets to rust compiler. No matter what kind of CPU you use, you have to add both ARM64 libraries and X86_64 libraries to generate libraries for Apple store. (MacOs) The size of following libraries are too small and would not hurt you and will save a lot of problems later. Also, compiler scripts, strictly needs following targets to be available.
platform | Details |
---|---|
x86_64-apple-darwin | MacOS support on Intel platform |
aarch64-apple-darwin | MacOS support on M1 (arm64) platform |
aarch64-apple-ios | iOS arm64 support |
aarch64-apple-ios-sim | iOS simulator on M1 Mac (arm64) |
x86_64-apple-ios | iOS simulator on Intel Mac (arm64) |
rustup target add x86_64-apple-darwin
rustup target add aarch64-apple-darwin
rustup target add x86_64-apple-ios
rustup target add aarch64-apple-ios
rustup target add aarch64-apple-ios-sim
Simply type in terminal:
cargo install xcode_uniffi
Thats it ๐
In order to support iOS/MacOS, static compilation is required. Be sure following line is available in your rust library Cargo.toml file.
[lib]
crate-type = ["staticlib", "cdylib"]
I recommend you to run this code inside the root of your rust project.
Simply type:
xcode_uniffi create
By default, it will create Xcode Framework for iOS + iOS simulator + MacOS in:
It is recommended to run
cargo buildA freshly downloaded or copied Rust project, required to update 'Cargo.lock' files, else you may see this error in your xcode files.
Xcode error log
Showing All Messages the lock file **Cargo.lock needs to be updated but --locked was passed to prevent this
< rust project root directory >/xcode/< Cargo Library name >
You can pass command line arguments to change the default values. Please keep the Xcode project as a subdirectory of your rust project, so, Xcode can compile it everytime for different architectures.
BITCODE support is not available on RUST compiler yet and it is recommended, to disable BITCODE on both framework and Application. Check the following Tutorial, how to disable BITCODE
SUBCOMMANDS:
- create
-
--package-name/-k
Specify cargo package name, only if you have more than one package inside your Cargo.toml file.
-
--lib-name/-l
Specify cargo library name, if you have more than one library in your _Cargo.toml file. By default, Application will try to use a package with crate_type that has "staticlib" feature.
-
--name/-n
Override the Name of the Xcode framework. (Automatically formatted to Pascal format)
By default, the name of the Xcode framework will be the name of the Rust library in Pascal string format.
Example:
Cargo package name : my_fast_algo
Xcode Framework name: MyFastAlgo
-
--path/-p
Path to generate Xcode Framework. By default, Xcode framework will be created inside your rust directory in:
./xcode/< Cargo Lib name >
It is recommended to create Xcode framework as a subfolder of rust project. This way, your xcode will be able to compile and generate code, when ever you update your rust project or ...
-
--cargo/-r
Path to the Rust Project directory or Cargo.toml file.
It is recommended to run this application in command line inside Rust project directory, but you can pass this argument to specify a different path.
Xcode project will be created under this directory, unless you specify a different path
- Update
Still in progress
Both Xcode iOS and MacOS frameworks project targets have same Product Name. The reason is to make it simpler for Xcode cross-platform (ios/macos) projects using this framework without importing different swift framework. The name of the framework will be PasCal format of the Cargo library name, unless you change it using command line arguments.
Author: Jacob Hatami