diff --git a/compiler-rt/cmake/config-ix.cmake b/compiler-rt/cmake/config-ix.cmake --- a/compiler-rt/cmake/config-ix.cmake +++ b/compiler-rt/cmake/config-ix.cmake @@ -250,7 +250,31 @@ endif() set(test_cflags "") get_target_flags_for_arch(${arch} test_cflags) - list(APPEND test_cflags ${DARWIN_${platform}_CFLAGS}) + + if (NOT "${arch}" STREQUAL "arm64e") + list(APPEND test_cflags ${DARWIN_${platform}_CFLAGS}) + else() + # arm64e is not currently ABI stable so we need to build for the + # OS version being tested. Rather than querying the device under test + # we use the SDK version which "should" be the same as the + # device under test (it is a configuration error for these not to match). + # FIXME(dliew): We can remove this if we build the runtimes with the appropriate + # deployment target for arm64e. + foreach (flag ${DARWIN_${platform}_CFLAGS}) + if ("${flag}" MATCHES "^${DARWIN_${platform}_MIN_VER_FLAG}=.+") + # Find the SDK version + get_xcrun_platform_from_apple_platform("${platform}" xcrun_platform_name) + find_darwin_sdk_version(platform_sdk_version "${xcrun_platform_name}") + # Patch flag with correct deployment target + set(replacement_flag "${DARWIN_${platform}_MIN_VER_FLAG}=${platform_sdk_version}") + list(APPEND test_cflags "${replacement_flag}") + else() + # Copy through + list(APPEND test_cflags "${flag}") + endif() + endforeach() + endif() + string(REPLACE ";" " " test_cflags_str "${test_cflags}") string(APPEND test_cflags_str "${COMPILER_RT_TEST_COMPILER_CFLAGS}") set(${cflags_out} "${test_cflags_str}" PARENT_SCOPE) @@ -279,6 +303,30 @@ set(${is_valid_out} ${is_valid} PARENT_SCOPE) endfunction() +# Maps the Apple platform name used in Compiler-rt's CMake code +# to the name recognised by xcrun's `--sdk` argument +function(get_xcrun_platform_from_apple_platform platform out_var) + set(xcrun_platform "") + if ("${platform}" STREQUAL "osx") + set(xcrun_platform "macosx") + elseif ("${platform}" STREQUAL "iossim") + set(xcrun_platform "iphonesimulator") + elseif ("${platform}" STREQUAL "ios") + set(xcrun_platform "iphoneos") + elseif ("${platform}" STREQUAL "watchossim") + set(xcrun_platform "watchsimulator") + elseif ("${platform}" STREQUAL "watchos") + set(xcrun_platform "watchos") + elseif ("${platform}" STREQUAL "tvossim") + set(xcrun_platform "appletvsimulator") + elseif ("${platform}" STREQUAL "tvos") + set(xcrun_platform "appletvos") + else() + message(FATAL_ERROR "\"${platform}\" is not a handled apple platform") + endif() + set(${out_var} ${xcrun_platform} PARENT_SCOPE) +endfunction() + include(AllSupportedArchDefs) if(APPLE)