Skip to content

Commit 50babe2

Browse files
committed
Generalize computing SWIFT_MODULE_TRIPLE
This patch updates the logic for figuring out the Swift module triple from manually trying to patch something together to just asking the Swift driver to tell us what it is based on what we're compiling for.
1 parent 247e3ce commit 50babe2

File tree

1 file changed

+4
-15
lines changed

1 file changed

+4
-15
lines changed

CMakeLists.txt

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -63,23 +63,12 @@ endif()
6363

6464
# Determine the module triple.
6565
if("${SWIFT_HOST_MODULE_TRIPLE}" STREQUAL "")
66-
# FIXME: This is a hack. It's all a hack. Windows isn't setting
67-
# CMAKE_Swift_COMPILER_TARGET.
66+
set(module_triple_command "${CMAKE_Swift_COMPILER}" -print-target-info)
6867
if(CMAKE_Swift_COMPILER_TARGET)
69-
string(REGEX REPLACE "macosx[0-9]+([.][0-9]+)?" "macos" SWIFT_HOST_MODULE_TRIPLE
70-
${CMAKE_Swift_COMPILER_TARGET})
71-
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
72-
if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|AMD64")
73-
set(SWIFT_HOST_MODULE_TRIPLE "x86_64-unknown-windows-msvc")
74-
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|ARM64|arm64")
75-
set(SWIFT_HOST_MODULE_TRIPLE "aarch64-unknown-windows-msvc")
76-
else()
77-
message(FATAL_ERROR "Unrecognized architecture for Windows host")
78-
endif()
79-
else()
80-
execute_process(COMMAND ${CMAKE_Swift_COMPILER} -print-target-info OUTPUT_VARIABLE target_info)
81-
string(JSON SWIFT_HOST_MODULE_TRIPLE GET ${target_info} target moduleTriple)
68+
list(APPEND module_triple_command -target ${CMAKE_Swift_COMPILER_TARGET})
8269
endif()
70+
execute_process(COMMAND ${module_triple_command} OUTPUT_VARIABLE target_info_json)
71+
string(JSON SWIFT_HOST_MODULE_TRIPLE GET "${target_info_json}" "target" "moduleTriple")
8372
endif()
8473
message(STATUS "Module triple: ${SWIFT_HOST_MODULE_TRIPLE}")
8574

0 commit comments

Comments
 (0)