Skip to main content

Module platform

Module platform 

Source
Expand description

Apple platform definitions from LLVM’s MachO.def.

This module exposes two closely related types:

  • ApplePlatform — a Copy enum whose variants map 1-to-1 to LLVM’s MachO::PlatformType identifiers. It is the primary API surface: parse from a Rust target triple, look up an SDK name, or navigate the simulator/device relationship.

  • Platform — a plain Copy struct of &'static str and u32 fields that carries the raw LLVM metadata for a single platform (the data that lives in the PLATFORM(…) macro rows in MachO.def). Obtain one via ApplePlatform::metadata() or Platform::from(platform).

§Error handling

All fallible constructors return ParsePlatformError on failure. It implements both Display and std::error::Error, so it composes naturally with anyhow, thiserror, or plain ? propagation.

§Examples

use apple_platforms::platform::ApplePlatform;

// Parse from a Rust target triple
let sim = ApplePlatform::from_rust_triple("aarch64-apple-ios-sim").unwrap();
assert_eq!(sim, ApplePlatform::IOSSimulator);
assert!(sim.is_simulator());
assert!(!sim.is_device());

// Navigate to the device platform
let device = sim.device();
assert_eq!(device, ApplePlatform::IOS);

// Navigate back to the simulator
assert_eq!(device.simulator(), Some(ApplePlatform::IOSSimulator));

// SDK name for xcrun
assert_eq!(sim.sdk(), Some("iphonesimulator"));

// Iterate all platforms
let count = ApplePlatform::iter().count();
assert_eq!(count, 13); // Unknown + 12 real platforms

// Sort by Mach-O ID (PartialOrd / Ord)
let mut platforms = vec![ApplePlatform::XrOS, ApplePlatform::MacOS];
platforms.sort();
assert_eq!(platforms[0], ApplePlatform::MacOS);

Source: https://github.com/llvm/llvm-project/blob/main/llvm/include/llvm/BinaryFormat/MachO.def

Structs§

ParsePlatformError
Error returned when a platform name, ID, or target triple cannot be recognised as a known Apple platform.
Platform
Static metadata for a single Apple platform.

Enums§

ApplePlatform
Apple platform enumeration.