Skip to main content

Crate apple_platforms

Crate apple_platforms 

Source
Expand description

Apple platform metadata, target-triple conversion, and SDK name resolution.

This crate provides a typed Rust representation of every Apple platform defined in LLVM’s MachO.def — macOS, iOS, tvOS, watchOS, visionOS, Mac Catalyst, DriverKit, BridgeOS, and their simulator variants — together with utilities for converting Rust target triples to the strings that Apple’s toolchain expects.

It is primarily intended for use in build.rs scripts that invoke swiftc, xcrun, or clang.

§Quick start

use apple_platforms::{ApplePlatform, triple};

// Parse a Rust target triple into a typed platform value
let p = ApplePlatform::from_rust_triple("aarch64-apple-ios-sim").unwrap();
assert_eq!(p, ApplePlatform::IOSSimulator);

// SDK name for `xcrun --sdk <name>`
assert_eq!(p.sdk(),    Some("iphonesimulator"));

// Navigate sim ↔ device
assert_eq!(p.device(), ApplePlatform::IOS);
assert_eq!(ApplePlatform::IOS.simulator(), Some(ApplePlatform::IOSSimulator));

// Access full LLVM-sourced metadata
let meta = p.metadata();
assert_eq!(meta.marketing,   "iOS Simulator");
assert_eq!(meta.tapi_target, "ios-simulator");

// String-only path — useful when you only need strings
assert_eq!(triple::to_clang("aarch64-apple-darwin"), Some("arm64-apple-macosx"));
assert_eq!(triple::to_sdk("aarch64-apple-ios"),      Some("iphoneos"));

§Modules

§Typical build.rs pattern

fn main() {
    let target = std::env::var("TARGET").unwrap();

    let Some(clang_triple) = apple_platforms::triple::to_clang(&target) else {
        return; // not an Apple target
    };

    let platform = apple_platforms::ApplePlatform::from_rust_triple(&target).unwrap();
    let sdk_name  = platform.sdk().unwrap_or("macosx");

    // Pass to xcrun / swiftc / clang …
}

Re-exports§

pub use platform::ApplePlatform;
pub use platform::ParsePlatformError;
pub use platform::Platform;

Modules§

platform
Apple platform definitions from LLVM’s MachO.def.
prelude
Convenience re-exports for glob import (use apple_platforms::prelude::*).
triple
Rust target triple → Clang triple / SDK name conversion.