From fcc20d9d3c6156dbcafdb98c90d9712030062ff2 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sun, 8 Dec 2024 15:56:17 -0800 Subject: [PATCH 1/2] Identify macOS as OS X or Mac OS X on appropriate version ranges --- src/common/system.rs | 2 +- src/unix/apple/system.rs | 64 +++++++++++++++++++++------------------- 2 files changed, 34 insertions(+), 32 deletions(-) diff --git a/src/common/system.rs b/src/common/system.rs index 7c1907dad..1538fcdd5 100644 --- a/src/common/system.rs +++ b/src/common/system.rs @@ -753,7 +753,7 @@ impl System { /// |---|---| /// | linux laptop | "Linux 24.04 Ubuntu" | /// | android phone | "Android 15 Pixel 9 Pro" | - /// | apple laptop | "MacOS 15.1.1 Sequoia" | + /// | apple laptop | "macOS 15.1.1 Sequoia" | /// | windows server | "Windows Server 2022 Datacenter" | /// /// **Important**: this information is computed every time this function is called. diff --git a/src/unix/apple/system.rs b/src/unix/apple/system.rs index c4ca7549b..11b28f7cb 100644 --- a/src/unix/apple/system.rs +++ b/src/unix/apple/system.rs @@ -396,39 +396,41 @@ impl SystemInner { pub(crate) fn long_os_version() -> Option { #[cfg(target_os = "macos")] { - let mut long_name = "MacOS".to_owned(); - if let Some(os_version) = Self::os_version() { - long_name.push(' '); - long_name.push_str(&os_version); - if let Some(friendly_name) = match os_version.as_str() { - f_n if f_n.starts_with("15") => Some("Sequoia"), - f_n if f_n.starts_with("14") => Some("Sonoma"), - f_n if f_n.starts_with("13") => Some("Ventura"), - f_n if f_n.starts_with("12") => Some("Monterey"), - f_n if f_n.starts_with("11") | f_n.starts_with("10.16") => Some("Big Sur"), - f_n if f_n.starts_with("10.15") => Some("Catalina"), - f_n if f_n.starts_with("10.14") => Some("Mojave"), - f_n if f_n.starts_with("10.13") => Some("High Sierra"), - f_n if f_n.starts_with("10.12") => Some("Sierra"), - f_n if f_n.starts_with("10.11") => Some("El Capitan"), - f_n if f_n.starts_with("10.10") => Some("Yosemite"), - f_n if f_n.starts_with("10.9") => Some("Mavericks"), - f_n if f_n.starts_with("10.8") => Some("Mountain Lion"), - f_n if f_n.starts_with("10.7") => Some("Lion"), - f_n if f_n.starts_with("10.6") => Some("Snow Leopard"), - f_n if f_n.starts_with("10.5") => Some("Leopard"), - f_n if f_n.starts_with("10.4") => Some("Tiger"), - f_n if f_n.starts_with("10.3") => Some("Panther"), - f_n if f_n.starts_with("10.2") => Some("Jaguar"), - f_n if f_n.starts_with("10.1") => Some("Puma"), - f_n if f_n.starts_with("10.0") => Some("Cheetah"), - _ => None, - } { - long_name.push(' '); - long_name.push_str(friendly_name); + let Some(os_version) = Self::os_version() else { + return Some("macOS".to_owned()); + }; + // https://en.wikipedia.org/wiki/MacOS_version_history + for (version_prefix, macos_spelling, friendly_name) in [ + ("15", "macOS", "Sequoia"), + ("14", "macOS", "Sonoma"), + ("13", "macOS", "Ventura"), + ("12", "macOS", "Monterey"), + ("11", "macOS", "Big Sur"), + // Big Sur identifies itself as 10.16 in some situations. + // https://en.wikipedia.org/wiki/MacOS_Big_Sur#Development_history + ("10.16", "macOS", "Big Sur"), + ("10.15", "macOS", "Catalina"), + ("10.14", "macOS", "Mojave"), + ("10.13", "macOS", "High Sierra"), + ("10.12", "macOS", "Sierra"), + ("10.11", "OS X", "El Capitan"), + ("10.10", "OS X", "Yosemite"), + ("10.9", "OS X", "Mavericks"), + ("10.8", "OS X", "Mountain Lion"), + ("10.7", "Mac OS X", "Lion"), + ("10.6", "Mac OS X", "Snow Leopard"), + ("10.5", "Mac OS X", "Leopard"), + ("10.4", "Mac OS X", "Tiger"), + ("10.3", "Mac OS X", "Panther"), + ("10.2", "Mac OS X", "Jaguar"), + ("10.1", "Mac OS X", "Puma"), + ("10.0", "Mac OS X", "Cheetah"), + ] { + if os_version.starts_with(version_prefix) { + return Some(format!("{macos_spelling} {os_version} {friendly_name}")); } } - Some(long_name) + Some(format!("macOS {os_version}")) } #[cfg(target_os = "ios")] From 624c8c14f26b81cc91fd3f7db5016742b93937fb Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sun, 8 Dec 2024 15:57:52 -0800 Subject: [PATCH 2/2] Use macOS instead of MacOS in comments --- src/common/system.rs | 4 ++-- src/unix/apple/macos/ffi.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/common/system.rs b/src/common/system.rs index 1538fcdd5..4be9a95ff 100644 --- a/src/common/system.rs +++ b/src/common/system.rs @@ -726,7 +726,7 @@ impl System { SystemInner::kernel_version() } - /// Returns the system version (e.g. for MacOS this will return 15.1 rather than the kernel + /// Returns the system version (e.g. for macOS this will return 15.1 rather than the kernel /// version). /// /// | example platform | value of `System::os_version()` | @@ -1338,7 +1338,7 @@ impl Process { /// /// This value has limitations though. Depending on the operating system and type of process, /// this value might be a good indicator of the total memory that the process will be using over - /// its lifetime. However, for example, in the version 14 of MacOS this value is in the order of + /// its lifetime. However, for example, in the version 14 of macOS this value is in the order of /// the hundreds of gigabytes for every process, and thus not very informative. Moreover, if a /// process maps into memory a very large file, this value will increase accordingly, even if /// the process is not actively using the memory. diff --git a/src/unix/apple/macos/ffi.rs b/src/unix/apple/macos/ffi.rs index 662f7cf06..0bc21c83d 100644 --- a/src/unix/apple/macos/ffi.rs +++ b/src/unix/apple/macos/ffi.rs @@ -36,7 +36,7 @@ use libc::c_char; ))] use libc::kern_return_t; -// Note: IOKit is only available on MacOS up until very recent iOS versions: https://developer.apple.com/documentation/iokit +// Note: IOKit is only available on macOS up until very recent iOS versions: https://developer.apple.com/documentation/iokit #[cfg(any( feature = "system",