1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//! 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`][llvm-macho] — 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`.
//!
//! [llvm-macho]: https://github.com/llvm/llvm-project/blob/main/llvm/include/llvm/BinaryFormat/MachO.def
//!
//! # 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
//!
//! | Module | Contents |
//! |--------|----------|
//! | [`platform`] | [`ApplePlatform`] enum, [`Platform`] metadata struct, [`ParsePlatformError`] |
//! | [`triple`] | [`triple::to_clang`], [`triple::to_sdk`] free functions, [`triple::Architecture`] |
//!
//! # Typical `build.rs` pattern
//!
//! ```rust,ignore
//! 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 …
//! }
//! ```
// ── Top-level re-exports ─────────────────────────────────────────────────────
pub use ;
// ── Prelude ───────────────────────────────────────────────────────────────────
/// Convenience re-exports for glob import (`use apple_platforms::prelude::*`).
///
/// Brings in the types you'll need most often:
///
/// ```
/// use apple_platforms::prelude::*;
///
/// let p = ApplePlatform::MacOS;
/// assert_eq!(p.sdk(), Some("macosx"));
/// assert_eq!(to_sdk("aarch64-apple-darwin"), Some("macosx"));
/// ```