Skip to content

Commit 14cc176

Browse files
committed
[cxx-interop][libswift] Enable libstdc++ in SwiftCompilerSources
1 parent 7af4973 commit 14cc176

File tree

9 files changed

+57
-6
lines changed

9 files changed

+57
-6
lines changed

SwiftCompilerSources/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,11 @@ else()
212212
list(APPEND b0_deps swiftDarwin-bootstrapping0)
213213
list(APPEND b1_deps swiftDarwin-bootstrapping1)
214214
endif()
215+
is_libstdcxx_module_required(${SWIFT_HOST_VARIANT_SDK} should_copy_libstdcxx)
216+
if(should_copy_libstdcxx)
217+
list(APPEND b0_deps copy-libstdcxx-modulemap-bootstrapping0 copy-libstdcxx-header-bootstrapping0)
218+
list(APPEND b1_deps copy-libstdcxx-modulemap-bootstrapping1 copy-libstdcxx-header-bootstrapping1)
219+
endif()
215220
endif()
216221
if(SWIFT_HOST_VARIANT_SDK IN_LIST SWIFT_DARWIN_PLATFORMS)
217222
set(platform ${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR})

SwiftCompilerSources/Sources/SIL/BasicBlock.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import Basic
1414
import SILBridging
15+
import std
1516

1617
final public class BasicBlock : ListNode, CustomStringConvertible, HasName {
1718
public var next: BasicBlock? { SILBasicBlock_next(bridged).block }

SwiftCompilerSources/Sources/SIL/Function.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import Basic
1414
import SILBridging
15+
import std
1516

1617
final public class Function : CustomStringConvertible, HasName {
1718
public private(set) var effects = FunctionEffects()

SwiftCompilerSources/Sources/SIL/GlobalVariable.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import Basic
1414
import SILBridging
15+
import std
1516

1617
final public class GlobalVariable : CustomStringConvertible, HasName {
1718
public var name: String {

SwiftCompilerSources/Sources/SIL/Instruction.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import Basic
1414
import SILBridging
15+
import std
1516

1617
//===----------------------------------------------------------------------===//
1718
// Instruction base classes

SwiftCompilerSources/Sources/SIL/Value.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import Basic
1414
import SILBridging
15+
import std
1516

1617
public protocol Value : AnyObject, CustomStringConvertible {
1718
var uses: UseList { get }

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: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
function(is_libstdcxx_module_required sdk result_var_name)
2+
if("${sdk}" STREQUAL "LINUX" OR
3+
"${sdk}" STREQUAL "FREEBSD" OR
4+
"${sdk}" STREQUAL "OPENBSD" OR
5+
"${sdk}" STREQUAL "ANDROID" OR
6+
"${sdk}" STREQUAL "CYGWIN" OR
7+
"${sdk}" STREQUAL "HAIKU")
8+
set("${result_var_name}" TRUE PARENT_SCOPE)
9+
else()
10+
set("${result_var_name}" FALSE PARENT_SCOPE)
11+
endif()
12+
endfunction()

stdlib/public/Cxx/CMakeLists.txt

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
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 "ANDROID" AND
7-
NOT "${sdk}" STREQUAL "CYGWIN" AND
8-
NOT "${sdk}" STREQUAL "HAIKU")
3+
is_libstdcxx_module_required(${sdk} should_copy_libstdcxx)
4+
if(NOT should_copy_libstdcxx)
95
continue()
106
endif()
117

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

0 commit comments

Comments
 (0)