Skip to content

Commit 0952926

Browse files
committed
Overlay: add C++ interop libraries
This introduces a build of the C++ interop runtime support to the new runtime library build.
1 parent c4e242e commit 0952926

File tree

6 files changed

+108
-0
lines changed

6 files changed

+108
-0
lines changed

Runtimes/Overlay/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ add_compile_definitions(
8484
include(ExperimentalFeatures)
8585

8686
add_subdirectory(clang)
87+
add_subdirectory(Cxx)
8788
if(ANDROID)
8889
add_subdirectory(Android)
8990
endif()

Runtimes/Overlay/Cxx/CMakeLists.txt

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
2+
add_subdirectory(cxxshim)
3+
if(LINUX)
4+
add_subdirectory(libstdcxx)
5+
endif()
6+
add_subdirectory(std)
7+
8+
add_library(swiftCxx STATIC
9+
CxxConvertibleToBool.swift
10+
CxxConvertibleToCollection.swift
11+
CxxDictionary.swift
12+
CxxOptional.swift
13+
CxxPair.swift
14+
CxxRandomAccessCollection.swift
15+
CxxSequence.swift
16+
CxxSet.swift
17+
CxxSpan.swift
18+
CxxVector.swift
19+
UnsafeCxxIterators.swift)
20+
set_target_properties(swiftCxx PROPERTIES
21+
Swift_MODULE_NAME Cxx)
22+
target_compile_options(swiftCxx PRIVATE
23+
"-strict-memory-safety"
24+
"-cxx-interoperability-mode=default"
25+
# This module should not pull in the C++ standard library, so we disable it
26+
# explicitly. For functionality that depends on the C++ stdlib, use C++
27+
# stdlib overlay (`swiftstd` module).
28+
"SHELL:-Xcc -nostdinc++"
29+
"SHELL:-enable-experimental-feature Span"
30+
"SHELL:-enable-experimental-feature BuiltinModule"
31+
"SHELL:-enable-experimental-feature AllowUnsafeAttribute")
32+
33+
install(TARGETS swiftCxx
34+
EXPORT SwiftOverlayTargets
35+
ARCHIVE DESTINATION "${SwiftOverlay_INSTALL_LIBDIR}"
36+
LIBRARY DESTINATION "${SwiftOverlay_INSTALL_LIBDIR}"
37+
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
38+
emit_swift_interface(swiftCxx)
39+
install_swift_interface(swiftCxx)
40+
41+
embed_manifest(swiftCxx)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
add_library(cxxshim INTERFACE)
3+
target_include_directories(cxxshim INTERFACE
4+
$<$<COMPILE_LANGUAGE:Swift>:$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>>)
5+
6+
install(TARGETS cxxshim
7+
EXPORT SwiftOverlayTargets
8+
ARCHIVE DESTINATION "${SwiftOverlay_INSTALL_LIBDIR}"
9+
LIBRARY DESTINATION "${SwiftOverlay_INSTALL_LIBDIR}"
10+
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
11+
install(FILES
12+
libcxxshim.h
13+
libcxxshim.modulemap
14+
libcxxstdlibshim.h
15+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/swift/${SwiftOverlay_PLATFORM_SUBDIR}")
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
add_library(libstdcxx INTERFACE)
3+
target_include_directories(libstdcxx INTERFACE
4+
$<$<COMPILE_LANGUAGE:Swift>:$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>>)
5+
6+
install(TARGETS libstdcxx
7+
EXPORT SwiftOverlayTargets
8+
ARCHIVE DESTINATION "${SwiftOverlay_INSTALL_LIBDIR}"
9+
LIBRARY DESTINATION "${SwiftOverlay_INSTALL_LIBDIR}"
10+
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
11+
install(FILES
12+
libstdcxx.h
13+
libstdcxx.modulemap
14+
DESTINATION "${SwiftOverlay_INSTALL_LIBDIR}")
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
add_library(swiftCxxStdlib STATIC
3+
std.swift
4+
Chrono.swift
5+
String.swift)
6+
set_target_properties(swiftCxxStdlib PROPERTIES
7+
Swift_MODULE_NAME CxxStdlib)
8+
target_compile_options(swiftCxxStdlib PRIVATE
9+
"-strict-memory-safety"
10+
"-cxx-interoperability-mode=default"
11+
"SHELL:-enable-experimental-feature AllowUnsafeAttribute"
12+
# This flag is unnecessary when building with newer compilers that allow using
13+
# C++ symbols in resilient overlays (see f4204568).
14+
"SHELL:-enable-experimental-feature AssumeResilientCxxTypes"
15+
# The varying modularization of the C++ standard library on different
16+
# platforms makes it difficult to enable MemberImportVisibility for this
17+
# module
18+
"SHELL:-disable-upcoming-feature MemberImportVisibility"
19+
"SHELL:-Xfrontend -module-interface-preserve-types-as-written")
20+
target_link_libraries(swiftCxxStdlib PRIVATE
21+
cxxshim
22+
swift_Builtin_float
23+
$<$<PLATFORM_ID:Android>:swiftAndroid>)
24+
target_link_libraries(swiftCxxStdlib PRIVATE
25+
$<$<PLATFORM_ID:Linux>:libstdcxx)
26+
27+
install(TARGETS swiftCxxStdlib
28+
EXPORT SwiftOverlayTargets
29+
ARCHIVE DESTINATION "${SwiftOverlay_INSTALL_LIBDIR}"
30+
LIBRARY DESTINATION "${SwiftOverlay_INSTALL_LIBDIR}"
31+
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
32+
emit_swift_interface(swiftCxxStdlib)
33+
install_swift_interface(swiftCxxStdlib)
34+
35+
embed_manifest(swiftCxxStdlib)

Runtimes/Resync.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ copy_library_sources("linker-support" "public/ClangOverlays" "Overlay")
110110
message(STATUS "Clang[${StdlibSources}/public/ClangOverlays] -> ${CMAKE_CURRENT_LIST_DIR}/Overlay/clang")
111111
copy_files(public/ClangOverlays Overlay/clang FILES float.swift.gyb)
112112

113+
copy_library_sources("Cxx" "public" "Overlay")
114+
113115
# Android Overlay
114116
message(STATUS "Android modulemaps[${StdlibSources}/Platform] -> ${CMAKE_CURRENT_LIST_DIR}/Overlay/Android/clang")
115117
copy_files(public/Platform Overlay/Android/clang

0 commit comments

Comments
 (0)