From 1c6974c2473765449e7c4649f9f96f1b751420c3 Mon Sep 17 00:00:00 2001 From: Igor Khanin Date: Tue, 8 Oct 2024 21:19:36 +0300 Subject: [PATCH] Propagate Apple deployment target version from CMake to `cc` (#567) * Propagate Apple deployment target version from CMake to `cc` `rustc` always targets the earliest deployment platform version possible for Rust code, but the `cc` crate defaults to the host's SDK version which is typically very recent. When the CMake uses a toolchain that has its' own minimal supported macOS version (for example Qt), this leads to linker errors and possible crashes when deploying to older yet supported systems. --- cmake/Corrosion.cmake | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cmake/Corrosion.cmake b/cmake/Corrosion.cmake index b2c39992..71f9ec4f 100644 --- a/cmake/Corrosion.cmake +++ b/cmake/Corrosion.cmake @@ -703,6 +703,11 @@ function(_add_cargo_build out_cargo_build_out_dir) list(APPEND corrosion_cc_rs_flags "SDKROOT=${CMAKE_OSX_SYSROOT}") endif() + # Ensure that cc-rs targets same Apple platform version as the CMake build + if(CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND CMAKE_OSX_DEPLOYMENT_TARGET) + list(APPEND corrosion_cc_rs_flags "MACOSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET}") + endif() + corrosion_add_target_local_rustflags("${target_name}" "$<$:-Clink-args=${corrosion_link_args}>") # todo: this should probably also be guarded by if_not_host_build_condition.