Skip to content

Commit

Permalink
Propagate Apple deployment target version from CMake to cc (#567)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
IgKh authored Oct 8, 2024
1 parent 3ec73d8 commit 1c6974c
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cmake/Corrosion.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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}" "$<$<BOOL:${corrosion_link_args}>:-Clink-args=${corrosion_link_args}>")

# todo: this should probably also be guarded by if_not_host_build_condition.
Expand Down

0 comments on commit 1c6974c

Please sign in to comment.