rustc_codegen_ssa::back::metadata

Function macho_object_build_version_for_target

source
fn macho_object_build_version_for_target(target: &Target) -> MachOBuildVersion
Expand description

Mach-O files contain information about:

  • The platform/OS they were built for (macOS/watchOS/Mac Catalyst/iOS simulator etc).
  • The minimum OS version / deployment target.
  • The version of the SDK they were targetting.

In the past, this was accomplished using the LC_VERSION_MIN_MACOSX, LC_VERSION_MIN_IPHONEOS, LC_VERSION_MIN_TVOS or LC_VERSION_MIN_WATCHOS load commands, which each contain information about the deployment target and SDK version, and implicitly, by their presence, which OS they target. Simulator targets were determined if the architecture was x86_64, but there was e.g. a LC_VERSION_MIN_IPHONEOS present.

This is of course brittle and limited, so modern tooling emit the LC_BUILD_VERSION load command (which contains all three pieces of information in one) when the deployment target is high enough, or the target is something that wouldn’t be encodable with the old load commands (such as Mac Catalyst, or Aarch64 iOS simulator).

Since Xcode 15, Apple’s LD apparently requires object files to use this load command, so this returns the MachOBuildVersion for the target to do so.