Skip to content

Commit

Permalink
Add OperatingSystem::is_like_darwin
Browse files Browse the repository at this point in the history
To more easily determine if the OS is of Darwin lineage.
  • Loading branch information
madsmtm committed Oct 2, 2024
1 parent f2c0a56 commit 8bbab8d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
27 changes: 20 additions & 7 deletions src/targets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,25 @@ impl OperatingSystem {
XROS(deployment_target) => darwin_version("xros", deployment_target),
}
}

/// Whether the OS is similar to Darwin.
///
/// This matches on any of:
/// - [Darwin](Self::Darwin)
/// - [iOS](Self::IOS)
/// - [macOS](Self::MacOSX)
/// - [tvOS](Self::TvOS)
/// - [visionOS](Self::VisionOS)
/// - [watchOS](Self::WatchOS)
/// - [xrOS](Self::XROS)
pub fn is_like_darwin(&self) -> bool {
use OperatingSystem::*;

match self {
Darwin(_) | IOS(_) | MacOSX(_) | TvOS(_) | VisionOS(_) | WatchOS(_) | XROS(_) => true,
_ => false,
}
}
}

/// The "environment" field, which specifies an ABI environment on top of the
Expand Down Expand Up @@ -1043,13 +1062,7 @@ pub(crate) fn default_binary_format(triple: &Triple) -> BinaryFormat {
_ => BinaryFormat::Unknown,
},
OperatingSystem::Aix => BinaryFormat::Xcoff,
OperatingSystem::Darwin(_)
| OperatingSystem::IOS(_)
| OperatingSystem::MacOSX(_)
| OperatingSystem::VisionOS(_)
| OperatingSystem::WatchOS(_)
| OperatingSystem::TvOS(_)
| OperatingSystem::XROS(_) => BinaryFormat::Macho,
os if os.is_like_darwin() => BinaryFormat::Macho,
OperatingSystem::Windows => BinaryFormat::Coff,
OperatingSystem::Nebulet
| OperatingSystem::Emscripten
Expand Down
8 changes: 1 addition & 7 deletions src/triple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,7 @@ impl Triple {
/// Return the default calling convention for the given target triple.
pub fn default_calling_convention(&self) -> Result<CallingConvention, ()> {
Ok(match self.operating_system {
OperatingSystem::Darwin(_)
| OperatingSystem::IOS(_)
| OperatingSystem::TvOS(_)
| OperatingSystem::MacOSX(_)
| OperatingSystem::WatchOS(_)
| OperatingSystem::VisionOS(_)
| OperatingSystem::XROS(_) => match self.architecture {
os if os.is_like_darwin() => match self.architecture {
Architecture::Aarch64(_) => CallingConvention::AppleAarch64,
_ => CallingConvention::SystemV,
},
Expand Down

0 comments on commit 8bbab8d

Please sign in to comment.