diff --git a/compiler-rt/cmake/Modules/CompilerRTDarwinUtils.cmake b/compiler-rt/cmake/Modules/CompilerRTDarwinUtils.cmake --- a/compiler-rt/cmake/Modules/CompilerRTDarwinUtils.cmake +++ b/compiler-rt/cmake/Modules/CompilerRTDarwinUtils.cmake @@ -113,25 +113,23 @@ endif() set(archs ${ARGN}) - if(NOT TEST_COMPILE_ONLY) - message(STATUS "Finding valid architectures for ${os}...") - set(SIMPLE_C ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/src.c) - file(WRITE ${SIMPLE_C} "#include \nint main() { printf(__FILE__); return 0; }\n") - - set(os_linker_flags) - foreach(flag ${DARWIN_${os}_LINK_FLAGS}) - set(os_linker_flags "${os_linker_flags} ${flag}") - endforeach() + message(STATUS "Finding valid architectures for ${os}...") + set(SIMPLE_C ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/src.c) + file(WRITE ${SIMPLE_C} "#include \nint main() { printf(__FILE__); return 0; }\n") - # Disable building for i386 for macOS SDK >= 10.15. The SDK doesn't support - # linking for i386 and the corresponding OS doesn't allow running macOS i386 - # binaries. - if ("${os}" STREQUAL "osx") - find_darwin_sdk_version(macosx_sdk_version "macosx") - if ("${macosx_sdk_version}" VERSION_GREATER 10.15 OR "${macosx_sdk_version}" VERSION_EQUAL 10.15) - message(STATUS "Disabling i386 slice for ${valid_archs}") - list(REMOVE_ITEM archs "i386") - endif() + set(os_linker_flags) + foreach(flag ${DARWIN_${os}_LINK_FLAGS}) + set(os_linker_flags "${os_linker_flags} ${flag}") + endforeach() + + # Disable building for i386 for macOS SDK >= 10.15. The SDK doesn't support + # linking for i386 and the corresponding OS doesn't allow running macOS i386 + # binaries. + if ("${os}" STREQUAL "osx") + find_darwin_sdk_version(macosx_sdk_version "macosx") + if ("${macosx_sdk_version}" VERSION_GREATER 10.15 OR "${macosx_sdk_version}" VERSION_EQUAL 10.15) + message(STATUS "Disabling i386 slice for ${valid_archs}") + list(REMOVE_ITEM archs "i386") endif() endif() @@ -146,17 +144,12 @@ foreach(arch ${archs}) set(arch_linker_flags "-arch ${arch} ${os_linker_flags}") - if(TEST_COMPILE_ONLY) - # `-w` is used to surpress compiler warnings which `try_compile_only()` treats as an error. - try_compile_only(CAN_TARGET_${os}_${arch} FLAGS -v -arch ${arch} ${DARWIN_${os}_CFLAGS} -w) - else() - set(SAVED_CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS}) - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${arch_linker_flags}") - try_compile(CAN_TARGET_${os}_${arch} ${CMAKE_BINARY_DIR} ${SIMPLE_C} - COMPILE_DEFINITIONS "-v -arch ${arch}" ${DARWIN_${os}_CFLAGS} - OUTPUT_VARIABLE TEST_OUTPUT) - set(CMAKE_EXE_LINKER_FLAGS ${SAVED_CMAKE_EXE_LINKER_FLAGS}) - endif() + set(SAVED_CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS}) + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${arch_linker_flags}") + try_compile(CAN_TARGET_${os}_${arch} ${CMAKE_BINARY_DIR} ${SIMPLE_C} + COMPILE_DEFINITIONS "-v -arch ${arch}" ${DARWIN_${os}_CFLAGS} + OUTPUT_VARIABLE TEST_OUTPUT) + set(CMAKE_EXE_LINKER_FLAGS ${SAVED_CMAKE_EXE_LINKER_FLAGS}) if(${CAN_TARGET_${os}_${arch}}) list(APPEND working_archs ${arch}) else() diff --git a/compiler-rt/cmake/builtin-config-ix.cmake b/compiler-rt/cmake/builtin-config-ix.cmake --- a/compiler-rt/cmake/builtin-config-ix.cmake +++ b/compiler-rt/cmake/builtin-config-ix.cmake @@ -115,7 +115,7 @@ set(DARWIN_ios_BUILTIN_MIN_VER_FLAG ${DARWIN_ios_MIN_VER_FLAG}=${DARWIN_ios_BUILTIN_MIN_VER}) set(DARWIN_ios_BUILTIN_ALL_POSSIBLE_ARCHS ${ARM64} ${ARM32}) - set(DARWIN_iossim_BUILTIN_ALL_POSSIBLE_ARCHS ${X86} ${X86_64}) + set(DARWIN_iossim_BUILTIN_ALL_POSSIBLE_ARCHS ${X86} ${X86_64} arm64) endif() if(COMPILER_RT_ENABLE_WATCHOS) list(APPEND DARWIN_EMBEDDED_PLATFORMS watchos) @@ -124,7 +124,7 @@ set(DARWIN_watchos_BUILTIN_MIN_VER_FLAG ${DARWIN_watchos_MIN_VER_FLAG}=${DARWIN_watchos_BUILTIN_MIN_VER}) set(DARWIN_watchos_BUILTIN_ALL_POSSIBLE_ARCHS armv7 armv7k arm64_32) - set(DARWIN_watchossim_BUILTIN_ALL_POSSIBLE_ARCHS ${X86}) + set(DARWIN_watchossim_BUILTIN_ALL_POSSIBLE_ARCHS ${X86} ${X86_64} arm64) endif() if(COMPILER_RT_ENABLE_TVOS) list(APPEND DARWIN_EMBEDDED_PLATFORMS tvos) @@ -133,7 +133,7 @@ set(DARWIN_tvos_BUILTIN_MIN_VER_FLAG ${DARWIN_tvos_MIN_VER_FLAG}=${DARWIN_tvos_BUILTIN_MIN_VER}) set(DARWIN_tvos_BUILTIN_ALL_POSSIBLE_ARCHS armv7 arm64) - set(DARWIN_tvossim_BUILTIN_ALL_POSSIBLE_ARCHS ${X86} ${X86_64}) + set(DARWIN_tvossim_BUILTIN_ALL_POSSIBLE_ARCHS ${X86} ${X86_64} arm64) endif() set(BUILTIN_SUPPORTED_OS osx)