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.
Xcode
1. Install via App Store.
xcodegen
2. brew install xcodegen
Check xcodegen
installation guide for other options.
cargo-xcodebuild
:
2. 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:
aarch64-apple-ios
: iOS devicesx86_64-apple-ios
: iOS simulator on x86 processorsaarch64-apple-ios-sim
: iOS simulator on Apple processors
rustup target add aarch64-apple-ios x86_64-apple-ios aarch64-apple-ios-sim
Commands
check
: Checks that the current package builds without creating xcodeprojectbuild
: Compiles the current package and create xcodeprojectrun
: Run a project on device or simulatorgenerate
Generate xcodeproject without building itopen
: Open generated project with Xcodedevices
: List of booted simulator devices and connected devicesteams
: List of signing teamsboot
: Boot a simulator with specific device id
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
Inspired by a similar tool for Android - cargo apk
.