GithubHelp home page GithubHelp logo

mjhatamy / xcode_uniffi Goto Github PK

View Code? Open in Web Editor NEW
4.0 2.0 1.0 76 KB

Xcode Framework (iOS/Simulator/MacOS) generator for Rust UniFFI ready Projects

License: Mozilla Public License 2.0

Rust 97.61% Shell 2.39%
rust xcode rust-lang ios macos uniffi xcode-framework

xcode_uniffi's Introduction

Xcode Framework Generator/Updater for Rust UniFFI

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]

UniFFI Github

Rust UniFFI Learning Center


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.

Prepare to use the

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

Installation

Simply type in terminal:

cargo install xcode_uniffi

Thats it ๐Ÿ˜‚


Update Library Cargo.toml

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"]

How to use

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 build

A 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

Command line arguments

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

Xcode framework details

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

xcode_uniffi's People

Contributors

mjhatamy avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

aniket-sarowar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.