Skip to content

Commit 98bcd9b

Browse files
committed
Install nested Swift modules
Migrating to using the nested swiftmodule structure. This avoids needing to compute the architecture in the CMake script, using the compiler to tell us what the triple should be, making the build more robust. This also means that we can drop the architecture-specific subdirectory and install the dispatch modules alongside the swiftmodules for the other projects.
1 parent a1b9319 commit 98bcd9b

File tree

2 files changed

+26
-47
lines changed

2 files changed

+26
-47
lines changed

cmake/modules/SwiftSupport.cmake

Lines changed: 25 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,28 @@
1+
if(NOT dispatch_MODULE_TRIPLE)
2+
set(module_triple_command "${CMAKE_Swift_COMPILER}" -print-target-info)
3+
if(CMAKE_Swift_COMPILER_TARGET)
4+
list(APPEND module_triple_command -target ${CMAKE_Swift_COMPILER_TARGET})
5+
endif()
6+
execute_process(COMMAND ${module_triple_command} OUTPUT_VARIABLE target_info_json)
7+
8+
string(JSON module_triple GET "${target_info_json}" "target" "moduleTriple")
9+
set(dispatch_MODULE_TRIPLE "${module_triple}" CACHE STRING "Triple used to install swiftmodule files")
10+
mark_as_advanced(dispatch_MODULE_TRIPLE)
11+
12+
message(CONFIGURE_LOG "Swift module triple: ${module_triple}")
13+
endif()
114

2-
# Returns the current achitecture name in a variable
3-
#
4-
# Usage:
5-
# get_swift_host_arch(result_var_name)
6-
#
7-
# If the current architecture is supported by Swift, sets ${result_var_name}
8-
# with the sanitized host architecture name derived from CMAKE_SYSTEM_PROCESSOR.
9-
function(get_swift_host_arch result_var_name)
10-
if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64")
11-
set("${result_var_name}" "x86_64" PARENT_SCOPE)
12-
elseif ("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "AArch64|aarch64|arm64|ARM64")
13-
if(APPLE)
14-
set("${result_var_name}" "arm64" PARENT_SCOPE)
15-
else()
16-
set("${result_var_name}" "aarch64" PARENT_SCOPE)
17-
endif()
18-
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "ppc64")
19-
set("${result_var_name}" "powerpc64" PARENT_SCOPE)
20-
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "ppc64le")
21-
set("${result_var_name}" "powerpc64le" PARENT_SCOPE)
22-
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "s390x")
23-
set("${result_var_name}" "s390x" PARENT_SCOPE)
24-
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "armv6l")
25-
set("${result_var_name}" "armv6" PARENT_SCOPE)
26-
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "armv7-a")
27-
set("${result_var_name}" "armv7" PARENT_SCOPE)
28-
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "armv7l")
29-
set("${result_var_name}" "armv7" PARENT_SCOPE)
30-
elseif("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "amd64|AMD64")
31-
if(WIN32)
32-
set("${result_var_name}" "x86_64" PARENT_SCOPE)
33-
else()
34-
set("${result_var_name}" "amd64" PARENT_SCOPE)
35-
endif()
36-
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "IA64")
37-
set("${result_var_name}" "itanium" PARENT_SCOPE)
38-
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86")
39-
set("${result_var_name}" "i686" PARENT_SCOPE)
40-
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "i686")
41-
set("${result_var_name}" "i686" PARENT_SCOPE)
42-
else()
43-
message(FATAL_ERROR "Unrecognized architecture on host system: ${CMAKE_SYSTEM_PROCESSOR}")
15+
function(install_swift_module target)
16+
get_target_property(module ${target} Swift_MODULE_NAME)
17+
if(NOT module)
18+
set(module ${target})
4419
endif()
20+
install(
21+
FILES $<TARGET_PROPERTY:${target},Swift_MODULE_DIRECTORY>/${module}.swiftdoc
22+
DESTINATION ${INSTALL_TARGET_DIR}/${module}.swiftmodule
23+
RENAME ${dispatch_MODULE_TRIPLE}.swiftdoc)
24+
install(
25+
FILES $<TARGET_PROPERTY:${target},Swift_MODULE_DIRECTORY>/${module}.swiftmodule
26+
DESTINATION ${INSTALL_TARGET_DIR}/${module}.swiftmodule
27+
RENAME ${dispatch_MODULE_TRIPLE}.swiftmodule)
4528
endfunction()

src/swift/CMakeLists.txt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,7 @@ if(NOT APPLE AND NOT WIN32)
3636
set_target_properties(swiftDispatch PROPERTIES INSTALL_RPATH "$ORIGIN")
3737
endif()
3838

39-
get_swift_host_arch(swift_arch)
40-
install(FILES
41-
${CMAKE_CURRENT_BINARY_DIR}/swift/Dispatch.swiftmodule
42-
${CMAKE_CURRENT_BINARY_DIR}/swift/Dispatch.swiftdoc
43-
DESTINATION ${INSTALL_TARGET_DIR}/${swift_arch})
39+
install_swift_module(swiftDispatch)
4440
set_property(GLOBAL APPEND PROPERTY DISPATCH_EXPORTS swiftDispatch)
4541
install(TARGETS swiftDispatch
4642
EXPORT dispatchExports

0 commit comments

Comments
 (0)