Skip to content

Commit a3d97ba

Browse files
committed
[5.5][build] explicitly set OSX_ARCHITECTURES for targets in stdlib
Our custom build code already sets the architecture of compilation commands by different means, and so far we were relying on setting `CMAKE_OSX_ARCHITECTURES` to an empty value to avoid CMake doing the same. However, on Apple Silicon, CMake 3.19+ enforces a default value in this scenario (https://gitlab.kitware.com/cmake/cmake/-/merge_requests/5291/diffs), and this would result in the inability to compile code for x86_64. Cherry-pick of #38415, #38444 Addresses SR-14035, rdar://80699579
1 parent 7a7c764 commit a3d97ba

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

stdlib/cmake/modules/AddSwiftStdlib.cmake

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2035,6 +2035,16 @@ function(add_swift_target_library name)
20352035
list(APPEND THIN_INPUT_TARGETS ${VARIANT_NAME})
20362036
endif()
20372037
endif()
2038+
2039+
if(sdk IN_LIST SWIFT_APPLE_PLATFORMS)
2040+
# In the past, we relied on unsetting globally
2041+
# CMAKE_OSX_ARCHITECTURES to ensure that CMake would
2042+
# not add the -arch flag
2043+
# This is no longer the case when running on Apple Silicon,
2044+
# when CMake will enforce a default (see
2045+
# https://gitlab.kitware.com/cmake/cmake/-/merge_requests/5291)
2046+
set_property(TARGET ${VARIANT_NAME} PROPERTY OSX_ARCHITECTURES "${arch}")
2047+
endif()
20382048
endforeach()
20392049

20402050
# Configure module-only targets
@@ -2473,6 +2483,14 @@ function(add_swift_target_executable name)
24732483
endif()
24742484

24752485
if(${sdk} IN_LIST SWIFT_APPLE_PLATFORMS)
2486+
# In the past, we relied on unsetting globally
2487+
# CMAKE_OSX_ARCHITECTURES to ensure that CMake would
2488+
# not add the -arch flag
2489+
# This is no longer the case when running on Apple Silicon,
2490+
# when CMake will enforce a default (see
2491+
# https://gitlab.kitware.com/cmake/cmake/-/merge_requests/5291)
2492+
set_property(TARGET ${VARIANT_NAME} PROPERTY OSX_ARCHITECTURES "${arch}")
2493+
24762494
add_custom_command_target(unused_var2
24772495
COMMAND "codesign" "-f" "-s" "-" "${SWIFT_RUNTIME_OUTPUT_INTDIR}/${VARIANT_NAME}"
24782496
CUSTOM_TARGET_NAME "${VARIANT_NAME}_signed"

0 commit comments

Comments
 (0)