Skip to content

Commit c445097

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 5264dd5 commit c445097

File tree

6 files changed

+143
-4
lines changed

6 files changed

+143
-4
lines changed

Runtimes/Overlay/CMakeLists.txt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,18 @@ option(SwiftOverlay_ENABLE_BACKDEPLOYMENT_SUPPORT "Add symbols for runtime backd
7070
add_compile_options(
7171
$<$<COMPILE_LANGUAGE:Swift>:-explicit-module-build>
7272
$<$<COMPILE_LANGUAGE:Swift>:-nostdlibimport>
73+
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -disable-implicit-concurrency-module-import>"
74+
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -disable-implicit-string-processing-module-import>")
75+
76+
# NOTE: we add this subdirectory early to avoid the shared flags. Cxx is not
77+
# ready for any of the additional features such as library evolution.
78+
add_subdirectory(Cxx)
79+
80+
add_compile_options(
7381
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -enforce-exclusivity=unchecked>"
7482
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -target-min-inlining-version -Xfrontend min>"
7583
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -enable-lexical-lifetimes=false>"
76-
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -enable-ossa-modules>"
77-
"$<$<AND:$<BOOL:${SwiftOverlay_ENABLE_LIBRARY_EVOLUTION}>,$<COMPILE_LANGUAGE:Swift>>:-enable-library-evolution>"
78-
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -disable-implicit-concurrency-module-import>"
79-
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -disable-implicit-string-processing-module-import>")
84+
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -enable-ossa-modules>")
8085

8186
# LNK4049: symbol 'symbol' defined in 'filename.obj' is imported
8287
# LNK4286: symbol 'symbol' defined in 'filename_1.obj' is imported by 'filename_2.obj'

Runtimes/Overlay/Cxx/CMakeLists.txt

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
2+
if(NOT APPLE)
3+
add_subdirectory(cxxshim)
4+
endif()
5+
if(LINUX)
6+
add_ubdirectory(libstdcxx)
7+
endif()
8+
add_subdirectory(std)
9+
10+
add_library(swiftCxx STATIC
11+
CxxConvertibleToBool.swift
12+
CxxConvertibleToCollection.swift
13+
CxxDictionary.swift
14+
CxxOptional.swift
15+
CxxPair.swift
16+
CxxRandomAccessCollection.swift
17+
CxxSequence.swift
18+
CxxSet.swift
19+
CxxSpan.swift
20+
CxxVector.swift
21+
UnsafeCxxIterators.swift)
22+
set_target_properties(swiftCxx PROPERTIES
23+
Swift_MODULE_NAME Cxx)
24+
target_compile_options(swiftCxx PRIVATE
25+
"-strict-memory-safety"
26+
"-cxx-interoperability-mode=default"
27+
"-warn-implicit-overrides"
28+
"SHELL:-Xfrontend -enable-lexical-lifetimes=false"
29+
"SHELL:-Xfrontend -enable-ossa-modules"
30+
# This module should not pull in the C++ standard library, so we disable it
31+
# explicitly. For functionality that depends on the C++ stdlib, use C++
32+
# stdlib overlay (`swiftstd` module).
33+
"SHELL:-Xcc -nostdinc++"
34+
"SHELL:-enable-experimental-feature AllowUnsafeAttribute"
35+
"SHELL:-enable-experimental-feature BuiltinModule"
36+
"SHELL:-enable-experimental-feature InoutLifetimeDependence"
37+
"SHELL:-enable-experimental-feature LifetimeDependence"
38+
"SHELL:-enable-experimental-feature LifetimeDependenceMutableAccessors"
39+
"SHELL:-enable-experimental-feature MemberImportVisibility"
40+
"SHELL:-enable-experimental-feature NoncopyableGenerics2"
41+
"SHELL:-enable-experimental-feature NonescapableTypes"
42+
"SHELL:-enable-experimental-feature Span"
43+
"SHELL:-enable-experimental-feature SE427NoInferenceOnExtension"
44+
"SHELL:-enable-experimental-feature SuppressedAssociatedTypes")
45+
target_link_libraries(swiftCxx PRIVATE
46+
swiftCore)
47+
48+
install(TARGETS swiftCxx
49+
EXPORT SwiftOverlayTargets
50+
ARCHIVE DESTINATION "${SwiftOverlay_INSTALL_LIBDIR}"
51+
LIBRARY DESTINATION "${SwiftOverlay_INSTALL_LIBDIR}"
52+
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
53+
emit_swift_interface(swiftCxx)
54+
install_swift_interface(swiftCxx)
55+
56+
embed_manifest(swiftCxx)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
add_library(cxxshim INTERFACE)
3+
target_compile_options(cxxshim INTERFACE
4+
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xcc -fmodule-map-file=${CMAKE_CURRENT_SOURCE_DIR}/libcxxshim.modulemap>")
5+
target_include_directories(cxxshim INTERFACE
6+
$<$<COMPILE_LANGUAGE:Swift>:$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>>)
7+
8+
install(TARGETS cxxshim
9+
EXPORT SwiftOverlayTargets
10+
ARCHIVE DESTINATION "${SwiftOverlay_INSTALL_LIBDIR}"
11+
LIBRARY DESTINATION "${SwiftOverlay_INSTALL_LIBDIR}"
12+
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
13+
install(FILES
14+
libcxxshim.h
15+
libcxxshim.modulemap
16+
libcxxstdlibshim.h
17+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/swift/${SwiftOverlay_PLATFORM_SUBDIR}")
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
add_library(libstdcxx INTERFACE)
3+
target_compile_options(libstdcxx INTERFACE
4+
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xcc -fmodule-map-file=${CMAKE_CURRENT_SOURCE_DIR}/libstdcxx.modulemap>")
5+
target_include_directories(libstdcxx INTERFACE
6+
$<$<COMPILE_LANGUAGE:Swift>:$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>>)
7+
8+
install(TARGETS libstdcxx
9+
EXPORT SwiftOverlayTargets
10+
ARCHIVE DESTINATION "${SwiftOverlay_INSTALL_LIBDIR}"
11+
LIBRARY DESTINATION "${SwiftOverlay_INSTALL_LIBDIR}"
12+
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
13+
install(FILES
14+
libstdcxx.h
15+
libstdcxx.modulemap
16+
DESTINATION "${SwiftOverlay_INSTALL_LIBDIR}")
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
# NOTE: We need to setup the sysroot here as we need to ensure that we pick up
21+
# the module.map from the C++ runtime for the `std` (spelt `CxxStdlib`) import.
22+
target_compile_options(swiftCxxStdlib PRIVATE
23+
"$<$<PLATFORM_ID:Android>:SHELL:-Xcc --sysroot -Xcc ${CMAKE_ANDROID_NDK_TOOLCHAIN_UNIFIED}/sysroot>")
24+
target_link_libraries(swiftCxxStdlib PRIVATE
25+
$<$<PLATFORM_ID:Linux>:libstdcxx>
26+
$<$<NOT:$<PLATFORM_ID:Darwin>>:cxxshim>
27+
swiftCxx
28+
swiftCore
29+
swift_Builtin_float
30+
$<$<PLATFORM_ID:Android>:SwiftAndroid>
31+
$<$<PLATFORM_ID:Windows>:ClangModules>)
32+
33+
install(FILES std.apinotes
34+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/swift/apinotes)
35+
install(TARGETS swiftCxxStdlib
36+
EXPORT SwiftOverlayTargets
37+
ARCHIVE DESTINATION "${SwiftOverlay_INSTALL_LIBDIR}"
38+
LIBRARY DESTINATION "${SwiftOverlay_INSTALL_LIBDIR}"
39+
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
40+
emit_swift_interface(swiftCxxStdlib)
41+
install_swift_interface(swiftCxxStdlib)
42+
43+
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)