From d816b8b26469db31cef8214a07756c3aa5009d79 Mon Sep 17 00:00:00 2001 From: Brian M Date: Tue, 9 May 2023 00:14:14 -0700 Subject: [PATCH] Fix Mac Catalyst linking by adding build version Issue #106021 Apple LD requires build versions in object files for Catalyst --- .../rustc_codegen_ssa/src/back/metadata.rs | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/compiler/rustc_codegen_ssa/src/back/metadata.rs b/compiler/rustc_codegen_ssa/src/back/metadata.rs index 8bf84772f08..ad27b854d59 100644 --- a/compiler/rustc_codegen_ssa/src/back/metadata.rs +++ b/compiler/rustc_codegen_ssa/src/back/metadata.rs @@ -188,6 +188,11 @@ pub(crate) fn create_object_file(sess: &Session) -> Option { let arch = match sess.target.options.cpu.as_ref() { @@ -258,6 +263,33 @@ pub(crate) fn create_object_file(sess: &Session) -> Option Option { + if !target.llvm_target.ends_with("-macabi") { + return None; + } + /// The `object` crate demands "X.Y.Z encoded in nibbles as xxxx.yy.zz" + /// e.g. minOS 14.0 = 0x000E0000, or SDK 16.2 = 0x00100200 + fn pack_version((major, minor): (u32, u32)) -> u32 { + (major << 16) | (minor << 8) + } + + let platform = object::macho::PLATFORM_MACCATALYST; + let min_os = (14, 0); + let sdk = (16, 2); + + let mut build_version = object::write::MachOBuildVersion::default(); + build_version.platform = platform; + build_version.minos = pack_version(min_os); + build_version.sdk = pack_version(sdk); + Some(build_version) +} + pub enum MetadataPosition { First, Last,