Gordon-F / cargo-xcodebuild

Helps cargo build and run apps for iOS
Apache License 2.0
28 stars 2 forks source link

cargo-xcodebuild

Helps cargo build and run apps for iOS. 📦 ⚙️ 🍏

Setup

You need to install Xcode (NOT just Command Line Tools!), xcodegen, cargo-xcodebuild, and required rust targets.

1. Xcode

Install via App Store.

2. xcodegen

brew install xcodegen

Check xcodegen installation guide for other options.

2. cargo-xcodebuild:

Release version:

cargo install cargo-xcodebuild

Git version:

cargo install --git https://github.com/Gordon-F/cargo-xcodebuild cargo-xcodebuild

4. Install required rust targets:

rustup target add aarch64-apple-ios x86_64-apple-ios aarch64-apple-ios-sim

Commands

For example:

# Boot a simulator
cargo xcodebuild boot 4F57337E-1AF2-4D30-9726-87040063C016
# Run on avaliable device or simulator
cargo xcodebuild run

Project setup

Make sure your Cargo.toml contains staticlib crate type and required build targets:

[package]
name = "cargo_xcodebuild_minimal_example"
version = "0.1.0"
edition = "2021"

[lib]
# Required
crate-type = ["staticlib"]

[dependencies]

[package.metadata.ios]
# Required
build_targets = ["aarch64-apple-ios"]

And lib.rs contains main_rs function:

#[no_mangle]
pub extern "C" fn main_rs() {
    // start game code here
}

Following instruction to run on a simulator or a device.

Manifest

Following configuration options are supported by cargo xcodebuild under [package.metadata.ios]:

[package.metadata.ios]
# Specifies the array of targets to build for.
build_targets = ["aarch64-apple-ios", "aarch64-apple-ios-sim", "x86_64-apple-ios"]

# Specifies the array of dependencies sdk. Empty by default.
dependencies = ["OpenGLES.framework", "GLKit.framework", "Security.framework", "UIKit.framework"]

# Specifies deployment target. "12" by default.
deployment_target = "13.0"

# Specifies bundleIdPrefix. "com.rust" by default.
bundle_id_prefix = "com.rust.game"

# Specifies CODE_SIGN_IDENTITY.
code_sign_identity = "Apple Developer"

# Specifies DEVELOPMENT_TEAM.
development_team = "XXXXXX"

# Specifies device id and device type.
device_id = "XXXXXX"
device_type = "simulator" # or "device".

# Specifies an assets folder.
assets = ["assets/"]

Feel free to create an issue/PR if you need more!

Examples

  1. wgpu
  2. bevy
  3. miniquad
  4. macroquad

Inspired by a similar tool for Android - cargo apk.