From a9ff98fce615b1d1467ca29f7b53bad15e4826eb Mon Sep 17 00:00:00 2001 From: Evan Wilde Date: Mon, 12 May 2025 20:15:40 -0700 Subject: [PATCH 1/2] Remove CMP0091 check CMP0091 was added in CMake 3.15. The minimum version is CMake 3.16 so we don't need to do the check anymore. --- CMakeLists.txt | 4 ---- 1 file changed, 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8634c733..dd5689db 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,10 +7,6 @@ Licensed under Apache License v2.0 with Runtime Library Exception See https://swift.org/LICENSE.txt for license information #]] -if(POLICY CMP0091) - cmake_policy(SET CMP0091 NEW) -endif() - cmake_minimum_required(VERSION 3.16) project(SwiftCollections LANGUAGES C Swift) From a7fec81fc4c4af5e49d2ce19f3b39ef51202fd22 Mon Sep 17 00:00:00 2001 From: Evan Wilde Date: Mon, 12 May 2025 20:18:23 -0700 Subject: [PATCH 2/2] Use full module triple for swift modules Install swiftmodules with the full module triple expected by the compiler instead of attempting to compute the correct architecture name in CMake. --- CMakeLists.txt | 2 ++ Sources/CMakeLists.txt | 5 ++- cmake/modules/PlatformInfo.cmake | 24 +++++++++++++++ cmake/modules/SwiftSupport.cmake | 53 ++------------------------------ 4 files changed, 31 insertions(+), 53 deletions(-) create mode 100644 cmake/modules/PlatformInfo.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index dd5689db..eef85330 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,6 +13,8 @@ project(SwiftCollections list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/modules) +include(PlatformInfo) + set(CMAKE_Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift) set(CMAKE_Swift_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY MultiThreadedDLL) diff --git a/Sources/CMakeLists.txt b/Sources/CMakeLists.txt index ad39dd9b..6e1d3bde 100644 --- a/Sources/CMakeLists.txt +++ b/Sources/CMakeLists.txt @@ -40,13 +40,12 @@ if(COLLECTIONS_SINGLE_MODULE) LIBRARY DESTINATION lib/swift_static/${swift_os} RUNTIME DESTINATION bin) endif() - get_swift_host_arch(swift_arch) install(FILES $/${COLLECTIONS_MODULE_NAME}.swiftdoc DESTINATION lib/${swift}/${swift_os}/${COLLECTIONS_MODULE_NAME}.swiftmodule - RENAME ${swift_arch}.swiftdoc) + RENAME ${SwiftCollections_MODULE_TRIPLE}.swiftdoc) install(FILES $/${COLLECTIONS_MODULE_NAME}.swiftmodule DESTINATION lib/${swift}/${swift_os}/${COLLECTIONS_MODULE_NAME}.swiftmodule - RENAME ${swift_arch}.swiftmodule) + RENAME ${SwiftCollections_MODULE_TRIPLE}.swiftmodule) else() _install_target(${COLLECTIONS_MODULE_NAME}) endif() diff --git a/cmake/modules/PlatformInfo.cmake b/cmake/modules/PlatformInfo.cmake new file mode 100644 index 00000000..f1e40137 --- /dev/null +++ b/cmake/modules/PlatformInfo.cmake @@ -0,0 +1,24 @@ +#[[ +This source file is part of the Swift Collections Open Source Project + +Copyright (c) 2025 Apple Inc. and the Swift project authors +Licensed under Apache License v2.0 with Runtime Library Exception + +See https://swift.org/LICENSE.txt for license information +#]] + +set(target_info_cmd "${CMAKE_Swift_COMPILER}" -print-target-info) +if(CMAKE_Swfit_COMPILER_TARGET) + list(APPEND target_info_cmd -target ${CMAKE_Swift_COMPILER_TARGET}) +endif() +execute_process(COMMAND ${target_info_cmd} OUTPUT_VARIABLE target_info_json) +message(CONFIGURE_LOG "Swift target info: ${target_info_cmd}\n" +"${target_info_json}") + +if(NOT SwiftCollections_MODULE_TRIPLE) + string(JSON module_triple GET "${target_info_json}" "target" "moduleTriple") + set(SwiftCollections_MODULE_TRIPLE "${module_triple}" CACHE STRING "Triple used for installed swift{doc,module, interface} files") + mark_as_advanced(SwiftCollections_MODULE_TRIPLE) + + message(CONFIGURE_LOG "Swift module triple: ${module_triple}") +endif() diff --git a/cmake/modules/SwiftSupport.cmake b/cmake/modules/SwiftSupport.cmake index 21b9d693..1cc952fb 100644 --- a/cmake/modules/SwiftSupport.cmake +++ b/cmake/modules/SwiftSupport.cmake @@ -7,53 +7,6 @@ Licensed under Apache License v2.0 with Runtime Library Exception See https://swift.org/LICENSE.txt for license information #]] -# Returns the architecture name in a variable -# -# Usage: -# get_swift_host_arch(result_var_name) -# -# Sets ${result_var_name} with the converted 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 MATCHES Darwin) - set("${result_var_name}" "arm64" PARENT_SCOPE) - else() - set("${result_var_name}" "aarch64" PARENT_SCOPE) - 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}" "amd64" 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 "wasm32") - set("${result_var_name}" "wasm32" PARENT_SCOPE) - elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "wasm64") - set("${result_var_name}" "wasm64" PARENT_SCOPE) - else() - message(FATAL_ERROR "Unrecognized architecture on host system: ${CMAKE_SYSTEM_PROCESSOR}") - endif() -endfunction() - # Returns the os name in a variable # # Usage: @@ -89,7 +42,6 @@ function(_install_target module) return() endif() - get_swift_host_arch(swift_arch) get_target_property(module_name ${module} Swift_MODULE_NAME) if(NOT module_name) set(module_name ${module}) @@ -97,8 +49,9 @@ function(_install_target module) install(FILES $/${module_name}.swiftdoc DESTINATION lib/${swift}/${swift_os}/${module_name}.swiftmodule - RENAME ${swift_arch}.swiftdoc) + RENAME ${SwiftCollections_MODULE_TRIPLE}.swiftdoc) + install(FILES $/${module_name}.swiftmodule DESTINATION lib/${swift}/${swift_os}/${module_name}.swiftmodule - RENAME ${swift_arch}.swiftmodule) + RENAME ${SwiftCollections_MODULE_TRIPLE}.swiftmodule) endfunction()