Helps cargo build and run apps for iOS

Overview

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:

  • aarch64-apple-ios: iOS devices
  • x86_64-apple-ios: iOS simulator on x86 processors
  • aarch64-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 xcodeproject
  • build: Compiles the current package and create xcodeproject
  • run: Run a project on device or simulator
  • generate Generate xcodeproject without building it
  • open: Open generated project with Xcode
  • devices: List of booted simulator devices and connected devices
  • teams: List of signing teams
  • boot: 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

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

Inspired by a similar tool for Android - cargo apk.

You might also like...
A simple tool for extracting files from iOS backup archive.
A simple tool for extracting files from iOS backup archive.

iBackupExtractor A simple tool for extracting files from iOS backup archive. iOS backup files are not stored with their original directory layouts. Re

An extremely high performance logging system for clients (iOS, Android, Desktop), written in Rust.

Pinenut Log δΈ­ζ–‡ζ–‡ζ‘£ ・ English An extremely high performance logging system for clients (iOS, Android, Desktop), written in Rust. Overview Compression Pin

Build Java applications without fighting your build tool. Drink some espresso.
Build Java applications without fighting your build tool. Drink some espresso.

Espresso Build Java applications without fighting your build tool. Drink some espresso. Features Modern Look & Feel Command line interface inspired by

A Yocto setup and management tool that helps you keep your environment up-to-date and in-sync with your team
A Yocto setup and management tool that helps you keep your environment up-to-date and in-sync with your team

yb (Yocto Buddy) yb is designed to make it easy to setup and (perhaps more importantly) keep Yocto environments up-to-date and in-sync with your team.

A Rust CLI tool that helps you enforce Git policies through Git hooks both server and client side

GitPolicyEnforcer This is a command line utility written in Rust, that helps you utilize Git hooks, to enforce various policies. It currently supports

Safer Nostr is a service that helps protect users by loading sensitive information (IP leak) and using AI to prevent inappropriate images from being uploaded.

Safer Nostr is a service that helps protect users by loading sensitive information (IP leak) and using AI to prevent inappropriate images from being uploaded. It also offers image optimization and storage options. It has configurable privacy and storage settings, as well as custom cache expiration.

Sleek is a CLI tool for formatting SQL. It helps you maintain a consistent style across your SQL code, enhancing readability and productivity.

Sleek: SQL Formatter ✨ Sleek is a CLI tool for formatting SQL. It helps you maintain a consistent style across your SQL code, enhancing readability an

Deadliner helps you keep track of the time left for your deadline by dynamically updating the wallpaper of your desktop with the time left.
Deadliner helps you keep track of the time left for your deadline by dynamically updating the wallpaper of your desktop with the time left.

Deadliner Watch the YouTube video What's Deadliner? Deadliner is a cross-platform desktop application for setting deadline for a project and keeping t

gfold is a CLI-driven application that helps you keep track of multiple Git repositories.

gfold is a CLI-driven application that helps you keep track of multiple Git repositories.

Comments
  • 'cargo ios/app' might be much better than 'cargo xcodebuild'

    'cargo ios/app' might be much better than 'cargo xcodebuild'

    Hello there!

    I just wanted to share a thought with you:
    I've been searching for a tool just like this one for quite some time now. Essentially an cargo apk but for ios. But I never found this project due to its 'weird' naming.

    I always searched for "cargo ios" and similar tools and only by pure chance did I found a blog article talking about this tool while trying to figure out how to use xcodegen with Rust.

    My suggestion would be to rename this tool to cargo ios (following the same schema as cargo apk) or maybe cargo app. This would make it much more clearer what this project is about (building iOS apps with Rust!), without needing to know much about xcodegen. Furthermore, it would greatly improve the search index.

    If wanted/required I can assist and contribute as well :) Have a nice day!

    opened by Sakul6499 1
  • Support for Mac Catalyst?

    Support for Mac Catalyst?

    Hi, does the tool support Mac Catalyst builds, e.g. build_targets = ["x86_64-apple-ios-macabi", "aarch64-apple-ios-macabi"]? If not would it be possible to please add support for these targets? I think xcodegen already supports Mac Catalyst. Thanks!

    opened by coolbluewater 0
  • when building and running wgpu I get errors looking for Metal adapter.

    when building and running wgpu I get errors looking for Metal adapter.

    When attempting to run the wgpu on m1 mac example I encounter this error. I know it has to do with selecting the adapter and I'm not sure why it isn't finding Metal ..

    cargo xcodebuild run ✹ Compiling wgpu v0.1.0 (/Users/gennaroschiano/Documents/GitHub/cargo-xcodebuild/examples/wgpu) error[E0599]: no associated item namedMetalfound for structBackendsin the current scope --> examples/wgpu/src/framework.rs:89:86 | 89 | let backend = wgpu::util::backend_bits_from_env().unwrap_or_else(wgpu::Backends::Metal); | ^^^^^ associated item not found inBackends`

    For more information about this error, try rustc --explain E0599. error: could not compile wgpu due to previous error Compiling wgpu v0.1.0 (/Users/gennaroschiano/Documents/GitHub/cargo-xcodebuild/examples/wgpu) error[E0599]: no associated item named Metal found for struct Backends in the current scope --> examples/wgpu/src/framework.rs:89:86 | 89 | let backend = wgpu::util::backend_bits_from_env().unwrap_or_else(wgpu::Backends::Metal); | ^^^^^ associated item not found in Backends

    For more information about this error, try rustc --explain E0599. error: could not compile wgpu due to previous error Compiling wgpu v0.1.0 (/Users/gennaroschiano/Documents/GitHub/cargo-xcodebuild/examples/wgpu) error[E0599]: no associated item named Metal found for struct Backends in the current scope --> examples/wgpu/src/framework.rs:89:86 | 89 | let backend = wgpu::util::backend_bits_from_env().unwrap_or_else(wgpu::Backends::Metal); | ^^^^^ associated item not found in Backends

    For more information about this error, try rustc --explain E0599. error: could not compile wgpu due to previous error [2022-07-04T15:42:38Z ERROR mobile_device] Value from property DeviceClass is null thread 'main' panicked at 'called Option::unwrap() on a None value', /Users/gennaroschiano/.cargo/registry/src/github.com-1ecc6299db9ec823/mobile-device-0.1.0/src/lib.rs:115:76 stack backtrace: 0: rust_begin_unwind at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/panicking.rs:584:5 1: core::panicking::panic_fmt at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/core/src/panicking.rs:143:14 2: core::panicking::panic at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/core/src/panicking.rs:48:5 3: mobile_device::get_device_list 4: cargo_xcodebuild::xcodebuild::Xcodebuild::find_device 5: cargo_xcodebuild::xcodebuild::Xcodebuild::build 6: cargo_xcodebuild::main`

    thanks for any help in advance!

    opened by gschian0 3
Owner
Igor Shaposhnik
Igor Shaposhnik
Simple template to use csr and ssr leptos with tauri for ios/android/windows/macos/linux and web dev

Tailwind-Leptos-Tauri Template Simple template to use csr and ssr leptos with tauri for ios/android/windows/macos/linux and web dev Just clone the rep

Victor Batarse 11 Mar 10, 2024
A simple, modern fuzzy finder tool to run examples in a Cargo project.

cargo-rx cargo-rx is a simple, modern Runner for Examples in a Cargo project. This crate provides a single executable: rx. Basically anywhere you woul

Ritvik Nag 14 Dec 2, 2022
Cargo subcommand to easily run targets/examples

cargo-select Cargo subcommand to easily run targets/examples/tests Fuzzy match against targets, examples or tests in current rust project. cargo-selec

null 13 Sep 15, 2022
A cargo plugin to shrink cargo's output

cargo single-line A simple cargo plugin that shrinks the visible cargo output to a single line (okay, in the best case scenario). In principle, the pl

Denis 5 Oct 30, 2022
Cargo-eval - A cargo plugin to quickly evaluate some Rust source code.

cargo eval A cargo plugin to quickly evaluate some Rust source code. Installation $ cargo install --git https://github.com/timClicks/cargo-eval.git Us

Tim McNamara 9 Dec 21, 2022
Cargo-about - πŸ“œ Cargo plugin to generate list of all licenses for a crate πŸ¦€

?? cargo-about Cargo plugin for generating a license listing for all dependencies of a crate See the book ?? for in-depth documentation. Please Note:

Embark 281 Jan 1, 2023
Cargo subcommand for running cargo without dev-dependencies.

cargo-no-dev-deps Cargo subcommand for running cargo without dev-dependencies. This is an extraction of the --no-dev-deps flag of cargo-hack to be use

Taiki Endo 5 Jan 12, 2023
Dead simple, memoized cargo subcommand to hoist cargo-built binaries into the current working directory, written in Rust.

cargo-hoist Dead simple cargo subcommand to hoist cargo-built binaries into scope. stable Install | User Docs | Crate Docs | Reference | Contributing

refcell.eth 6 Nov 9, 2023
Middleware/ios shortcut to setup alarms automatically based on the first class

Webuntis alarm This is a small little "middleware" / web server intended to connect to a webuntis timetable used in german schools which i wrote when

raizo 3 Dec 30, 2022
A lightweight, embedded key-value database for mobile clients (i.e., iOS, Android), written in Rust.

A lightweight, embedded key-value database for mobile clients (i.e., iOS, Android), written in Rust. ⚠️ Still in testing, not yet ready for production

Tangent 6 Sep 25, 2023