Skip to content
Example Project to show how to build a Catalyst static library with Rust
Rust Shell C
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src Initial Commit Sep 28, 2019
.gitignore
Cargo.toml
Readme.md Updated docs, fixed bug Sep 28, 2019
Xargo.toml Initial Commit Sep 28, 2019
build.rs Initial Commit Sep 28, 2019
cbindgen.toml Initial Commit Sep 28, 2019
make_fat.sh
test1_rust.h
x86_64-apple-ios-macabi.json

Readme.md

Rust Catalyst Example

This is an example that shows how to build a static library supporting Catalyst from Rust.

Requirements

  1. Xargo
  2. Rust Nightly
  3. Rust Source (after switching to nightly)
  4. Xcode 11+

Not Required

  • the XARGO_RUST_SRC env variable

Full Local Installation

cargo install xargo
rustup toolchain install nightly
rustup toolchain default nightly

# Or use a directory override
rustup override set nightly

Using It

Just do a release build with the correct target

xargo build --target x86_64-apple-ios-macabi --release

Caveats

  • Building for other archs (such as the host arch) also requires setting the target.
  • Non-Release builds fail on some targets
  • Lipo can be used to make a fat binary (see below)

Fat Binary

This requires that the correct targets are installed for non-macabi:

rustup target add aarch64-apple-ios

Then the following will generate a fat binary. You can also just call the make_fat.sh included in the example project.

# lipo together the different architectures into a universal 'fat' file
xargo build --target x86_64-apple-ios-macabi --release
xargo build --target aarch64-apple-ios --release
lipo -create -output target/libtest1.a target/{x86_64-apple-darwin,aarch64-apple-ios,x86_64-apple-darwin}/release/libtest1.a

Note that we're not including x86_64-apple-darwin because a fat binary cannot contain darwing x86_64 and iOS x86_64 together.

How it works

Tx86_64-he x86_64-apple-ios-macabi.json file contains the information that Xargo needs to build a custom sysroot to compile your project with. A sysroot is the libstd, libcore and so on.

Cargo.toml

The panic line:

[profile.release]
panic = "abort"

Seems to be required as panic_unwind leads to a failing build.

Xargo.toml

Just copy the contents verbatim. Otherwise it fails to build libstd.

std = {features = ["jemalloc"]}

[dependencies]
std = {}
You can’t perform that action at this time.