Files
uv/crates/platform-host/src/mac_os.rs
T
konsti 29bd0a4ed8 Fix musl compilation (#234)
musl (which we already use in ruff) allows statically linked binaries on
linux. This PR switches to rustls and vendors and fixes the glibc
detection. Using static musl builds makes it easier to avoid glibc
errors in docker and we'll need it later for alpine users anyway.

An alternative is using vendored openssl.
2023-10-30 18:10:17 +01:00

37 lines
1.3 KiB
Rust

use crate::PlatformError;
use serde::Deserialize;
/// Get the macOS version from the SystemVersion.plist file.
pub(crate) fn get_mac_os_version() -> Result<(u16, u16), PlatformError> {
// This is actually what python does
// https://github.com/python/cpython/blob/cb2b3c8d3566ae46b3b8d0718019e1c98484589e/Lib/platform.py#L409-L428
#[derive(Deserialize)]
#[serde(rename_all = "PascalCase")]
struct SystemVersion {
product_version: String,
}
let system_version: SystemVersion =
plist::from_file("/System/Library/CoreServices/SystemVersion.plist")
.map_err(|err| PlatformError::OsVersionDetectionError(err.to_string()))?;
let invalid_mac_os_version = || {
PlatformError::OsVersionDetectionError(format!(
"Invalid macOS version {}",
system_version.product_version
))
};
match system_version
.product_version
.split('.')
.collect::<Vec<&str>>()
.as_slice()
{
[major, minor] | [major, minor, _] => {
let major = major.parse::<u16>().map_err(|_| invalid_mac_os_version())?;
let minor = minor.parse::<u16>().map_err(|_| invalid_mac_os_version())?;
Ok((major, minor))
}
_ => Err(invalid_mac_os_version()),
}
}