From 72a571b35d2b5a204c3a35cddb44e8919fa64771 Mon Sep 17 00:00:00 2001 From: Evan Wilde Date: Fri, 23 May 2025 11:47:44 -0700 Subject: [PATCH] Use full module triple in swiftmodule install This patch updates the CMake build to install the IndexStoreDB module with the full triple. This allows us to query the compiler for the appropriate module name instead of maintaining the long list of host architectures, making the build more resilient to changes in the future. --- Sources/IndexStoreDB/CMakeLists.txt | 6 +-- cmake/modules/SwiftSupport.cmake | 63 +++++++++++------------------ 2 files changed, 24 insertions(+), 45 deletions(-) diff --git a/Sources/IndexStoreDB/CMakeLists.txt b/Sources/IndexStoreDB/CMakeLists.txt index 290a96d3..cdc008c7 100644 --- a/Sources/IndexStoreDB/CMakeLists.txt +++ b/Sources/IndexStoreDB/CMakeLists.txt @@ -24,13 +24,9 @@ if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin) Foundation) endif() -get_swift_host_arch(swift_arch) install(TARGETS IndexStoreDB ARCHIVE DESTINATION lib/swift$<$>:_static>/$ LIBRARY DESTINATION lib/swift$<$>:_static>/$ RUNTIME DESTINATION bin) -install(FILES - ${CMAKE_BINARY_DIR}/swift/IndexStoreDB.swiftdoc - ${CMAKE_BINARY_DIR}/swift/IndexStoreDB.swiftmodule - DESTINATION lib/swift$<$>:_static>/$/${swift_arch}) +install_swiftmodule(IndexStoreDB) set_property(GLOBAL APPEND PROPERTY IndexStoreDB_EXPORTS IndexStoreDB) diff --git a/cmake/modules/SwiftSupport.cmake b/cmake/modules/SwiftSupport.cmake index 6ed68eff..22d11d48 100644 --- a/cmake/modules/SwiftSupport.cmake +++ b/cmake/modules/SwiftSupport.cmake @@ -1,43 +1,26 @@ - -# Returns the current architecture name in a variable -# -# Usage: -# get_swift_host_arch(result_var_name) -# -# If the current architecture is supported by Swift, sets ${result_var_name} -# with the sanitized host architecture name derived from CMAKE_SYSTEM_PROCESSOR. -function(get_swift_host_arch result_var_name) - if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64") - set("${result_var_name}" "x86_64" PARENT_SCOPE) - elseif("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "AArch64|aarch64|arm64|ARM64") - if(CMAKE_SYSTEM_NAME STREQUAL Darwin) - set("${result_var_name}" "arm64" PARENT_SCOPE) - else() - set("${result_var_name}" "aarch64" PARENT_SCOPE) +if(NOT IndexStoreDB_SWIFTMODULE_TRIPLE) + set(target_info_cmd "${CMAKE_Swift_COMPILER}" -print-target-info) + if(CMAKE_Swift_COMPILER_TARGET) + list(APPEND target_info_cmd -target ${CMAKE_Swift_COMPILER_TARGET}) endif() - elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "ppc64") - set("${result_var_name}" "powerpc64" PARENT_SCOPE) - elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "ppc64le") - set("${result_var_name}" "powerpc64le" PARENT_SCOPE) - elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "s390x") - set("${result_var_name}" "s390x" PARENT_SCOPE) - elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "armv6l") - set("${result_var_name}" "armv6" PARENT_SCOPE) - elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "armv7l") - set("${result_var_name}" "armv7" PARENT_SCOPE) - elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "armv7-a") - set("${result_var_name}" "armv7" PARENT_SCOPE) - elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "AMD64") - set("${result_var_name}" "x86_64" PARENT_SCOPE) - elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "IA64") - set("${result_var_name}" "itanium" PARENT_SCOPE) - elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86") - set("${result_var_name}" "i686" PARENT_SCOPE) - elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "i686") - set("${result_var_name}" "i686" PARENT_SCOPE) - elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "riscv64") - set("${result_var_name}" "riscv64" PARENT_SCOPE) - else() - message(FATAL_ERROR "Unrecognized architecture on host system: ${CMAKE_SYSTEM_PROCESSOR}") + execute_process(COMMAND ${target_info_cmd} OUTPUT_VARIABLE target_info) + string(JSON module_triple GET "${target_info}" "target" "moduleTriple") + set(IndexStoreDB_SWIFTMODULE_TRIPLE "${module_triple}" CACHE STRING "Triple used to install swift module files") + mark_as_advanced(IndexStoreDB_SWIFTMODULE_TRIPLE) + message(CONFIGURE_LOG "Swift module triple: ${module_triple}") +endif() + +function(install_swiftmodule target) + set(swift_os $) + set(swift_dir $,"STATIC_LIBRARY">,swift_static,swift>) + get_target_property(module_name ${target} Swift_MODULE_NAME) + if(NOT module_name) + set(module_name ${target}) endif() + install(FILES $/${module_name}.swiftdoc + DESTINATION "lib/${swift_dir}/${swift_os}/${module_name}.swiftmodule" + RENAME ${IndexStoreDB_SWIFTMODULE_TRIPLE}.swiftdoc) + install(FILES $/${module_name}.swiftmodule + DESTINATION "lib/${swift_dir}/${swift_os}/${module_name}.swiftmodule" + RENAME ${IndexStoreDB_SWIFTMODULE_TRIPLE}.swiftmodule) endfunction()