apple-platforms
Apple platform metadata, target-triple conversion, and SDK name resolution for Rust build tooling.
[]
= "0.0.3"
What it does
Maps the full Apple platform landscape — every Mach-O platform ID from LLVM's
MachO.def — to a typed ApplePlatform enum and its associated metadata:
Clang target strings, TAPI targets, SDK names, marketing names, and simulator
relationships. Also converts Rust target triples to their Clang equivalents and
to xcrun --sdk names.
Primarily useful in build.rs scripts that need to invoke swiftc, xcrun,
or clang with the correct flags for the current Rust compilation target.
Quick start
use ;
// Parse a Rust target triple → typed platform
let platform = from_rust_triple.unwrap;
assert_eq!;
// SDK name for xcrun --sdk <name>
assert_eq!;
// Navigate sim ↔ device
assert_eq!;
assert_eq!;
assert_eq!;
// Access full static metadata
let meta = platform.metadata;
println!; // "iOS Simulator"
println!; // "ios-simulator"
// String-only path for build scripts
assert_eq!;
assert_eq!;
Usage in build.rs
// build.rs
Platform coverage
All platforms from LLVM MachO.def:
ApplePlatform |
Mach-O ID | SDK (xcrun --sdk) |
Marketing name |
|---|---|---|---|
Unknown |
0 | — | unknown |
MacOS |
1 | macosx |
macOS |
IOS |
2 | iphoneos |
iOS |
TvOS |
3 | appletvos |
tvOS |
WatchOS |
4 | watchos |
watchOS |
BridgeOS |
5 | bridgeos |
bridgeOS |
MacCatalyst |
6 | macosx ¹ |
macCatalyst |
IOSSimulator |
7 | iphonesimulator |
iOS Simulator |
TvOSSimulator |
8 | appletvsimulator |
tvOS Simulator |
WatchOSSimulator |
9 | watchsimulator |
watchOS Simulator |
DriverKit |
10 | driverkit |
DriverKit |
XrOS |
11 | xros |
visionOS |
XrOSSimulator |
12 | xrsimulator |
visionOS Simulator |
¹ Mac Catalyst uses the macOS SDK with the macabi ABI environment.
API surface
ApplePlatform — the central type
// Construction
from_rust_triple? // from Rust triple
from_id // from Mach-O ID → Option<Self>
try_from? // TryFrom<u32 / usize>
"visionos".? // FromStr
// Metadata
platform.id // → u32 Mach-O ID
platform.sdk // → Option<&'static str> e.g. "iphoneos"
platform.metadata // → &Platform (full struct)
platform.to_string // → marketing name via Display
// Simulator ↔ device
platform.is_simulator // bool
platform.is_device // bool (non-sim, non-Unknown)
platform.device // Self (sim → device, or self)
platform.simulator // Option<Self> (device → sim, or None)
// Iteration
iter // Iterator over all 13 variants
ALL // [ApplePlatform; 13]
triple — string-based build-script helpers
use triple;
to_clang // → Some("arm64-apple-ios-simulator")
to_sdk // → Some("iphonesimulator")
// Both return None for non-Apple / unrecognised triples
Platform — static metadata struct
Rust triple → Clang triple mapping
| Rust triple | Clang triple |
|---|---|
aarch64-apple-darwin |
arm64-apple-macosx |
x86_64-apple-darwin |
x86_64-apple-macosx |
aarch64-apple-ios |
arm64-apple-ios |
aarch64-apple-ios-sim |
arm64-apple-ios-simulator |
x86_64-apple-ios |
x86_64-apple-ios-simulator |
aarch64-apple-ios-macabi |
arm64-apple-ios-macabi |
aarch64-apple-tvos |
arm64-apple-tvos |
aarch64-apple-tvos-sim |
arm64-apple-tvos-simulator |
aarch64-apple-watchos |
arm64-apple-watchos |
armv7k-apple-watchos |
armv7k-apple-watchos |
arm64_32-apple-watchos |
arm64_32-apple-watchos |
aarch64-apple-watchos-sim |
arm64-apple-watchos-simulator |
aarch64-apple-visionos |
arm64-apple-xros |
aarch64-apple-visionos-sim |
arm64-apple-xros-simulator |
aarch64-apple-driverkit |
arm64-apple-driverkit |
x86_64-apple-driverkit |
x86_64-apple-driverkit |
| anything else | None |
Examples
Tests
Design notes
- No lifetime parameters.
Platformholds only&'static strfields; noPlatform<'a>in your signatures. NonenotUnknown.from_idandTryFromreturnNone/Errfor unrecognised IDs rather than silently falling back toUnknown.Optionnot passthrough.triple::to_clangandtriple::to_sdkreturnNonefor non-Apple triples; the old identity-passthrough behaviour masked typos silently.- Single source of truth.
triple::to_sdkdelegates toApplePlatform::from_rust_triple+.sdk(), so the triple→SDK mapping lives in exactly one place. - Ordered.
ApplePlatformderivesPartialOrd+Ordby Mach-O ID.
License
MIT — Copyright © 2025 Eugene Hauptmann