Skip to content

Commit bc513d9

Browse files
committed
[cxx-interop][SwiftCompilerSources] Enable libstdc++ on platforms that use it
Since libstdc++ doesn't come with a Clang modulemap, Swift provides its own modulemap for libstdc++. This change makes the modulemap available while building SwiftCompilerSources.
1 parent 0157631 commit bc513d9

File tree

4 files changed

+45
-5
lines changed

4 files changed

+45
-5
lines changed

SwiftCompilerSources/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,10 @@ else()
212212
list(APPEND b0_deps swiftDarwin-bootstrapping0)
213213
list(APPEND b1_deps swiftDarwin-bootstrapping1)
214214
endif()
215+
if(${SWIFT_HOST_VARIANT_SDK} IN_LIST SWIFT_LIBSTDCXX_PLATFORMS)
216+
list(APPEND b0_deps copy-libstdcxx-modulemap-bootstrapping0 copy-libstdcxx-header-bootstrapping0)
217+
list(APPEND b1_deps copy-libstdcxx-modulemap-bootstrapping1 copy-libstdcxx-header-bootstrapping1)
218+
endif()
215219
endif()
216220
if(SWIFT_HOST_VARIANT_SDK IN_LIST SWIFT_DARWIN_PLATFORMS)
217221
set(platform ${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR})

cmake/modules/AddSwift.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ include(SwiftList)
33
include(SwiftXcodeSupport)
44
include(SwiftWindowsSupport)
55
include(SwiftAndroidSupport)
6+
include(SwiftCXXUtils)
67

78
function(_swift_gyb_target_sources target scope)
89
file(GLOB GYB_UNICODE_DATA ${SWIFT_SOURCE_DIR}/utils/UnicodeData/*)

cmake/modules/SwiftCXXUtils.cmake

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Platforms that use libstdc++ as the system-wide default C++ standard library.
2+
set(SWIFT_LIBSTDCXX_PLATFORMS
3+
"LINUX"
4+
"FREEBSD"
5+
"OPENBSD"
6+
"CYGWIN"
7+
"HAIKU")

stdlib/public/Cxx/CMakeLists.txt

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
set(libstdcxx_modulemap_target_list)
22
foreach(sdk ${SWIFT_SDKS})
3-
if(NOT "${sdk}" STREQUAL "LINUX" AND
4-
NOT "${sdk}" STREQUAL "FREEBSD" AND
5-
NOT "${sdk}" STREQUAL "OPENBSD" AND
6-
NOT "${sdk}" STREQUAL "CYGWIN" AND
7-
NOT "${sdk}" STREQUAL "HAIKU")
3+
if(NOT ${sdk} IN_LIST SWIFT_LIBSTDCXX_PLATFORMS)
84
continue()
95
endif()
106

@@ -89,6 +85,38 @@ foreach(sdk ${SWIFT_SDKS})
8985
DESTINATION "lib/swift_static/${arch_subdir}"
9086
COMPONENT sdk-overlay)
9187
endif()
88+
89+
if(${BOOTSTRAPPING_MODE} MATCHES "BOOTSTRAPPING.*")
90+
foreach(bootstrapping "0" "1")
91+
get_bootstrapping_path(bootstrapping_dir ${module_dir} ${bootstrapping})
92+
set(libstdcxx_modulemap_out_bootstrapping "${bootstrapping_dir}/libstdcxx.modulemap")
93+
set(libstdcxx_header_out_bootstrapping "${bootstrapping_dir}/libstdcxx.h")
94+
95+
add_custom_command_target(unused_var
96+
COMMAND
97+
"${CMAKE_COMMAND}" "-E" "make_directory" "${bootstrapping_dir}"
98+
COMMAND
99+
"${CMAKE_COMMAND}" "-E" "copy"
100+
"${CMAKE_CURRENT_SOURCE_DIR}/${libstdcxx_modulemap}" "${libstdcxx_modulemap_out_bootstrapping}"
101+
102+
CUSTOM_TARGET_NAME "copy-libstdcxx-modulemap-bootstrapping${bootstrapping}"
103+
OUTPUT "${libstdcxx_modulemap_out_bootstrapping}"
104+
DEPENDS ${libstdcxx_modulemap}
105+
COMMENT "Copying libstdcxx modulemap to resources for bootstrapping${bootstrapping}")
106+
107+
add_custom_command_target(unused_var
108+
COMMAND
109+
"${CMAKE_COMMAND}" "-E" "make_directory" "${bootstrapping_dir}"
110+
COMMAND
111+
"${CMAKE_COMMAND}" "-E" "copy"
112+
"${CMAKE_CURRENT_SOURCE_DIR}/${libstdcxx_header}" "${libstdcxx_header_out_bootstrapping}"
113+
114+
CUSTOM_TARGET_NAME "copy-libstdcxx-header-bootstrapping${bootstrapping}"
115+
OUTPUT "${libstdcxx_header_out_bootstrapping}"
116+
DEPENDS ${libstdcxx_header}
117+
COMMENT "Copying libstdcxx header to resources for bootstrapping${bootstrapping}")
118+
endforeach()
119+
endif()
92120
endforeach()
93121
endforeach()
94122
add_custom_target(libstdcxx-modulemap DEPENDS ${libstdcxx_modulemap_target_list})

0 commit comments

Comments
 (0)