Skip to content

Commit 61906d0

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 436a279 commit 61906d0

File tree

6 files changed

+139
-5
lines changed

6 files changed

+139
-5
lines changed

Runtimes/Overlay/CMakeLists.txt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +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 -enforce-exclusivity=unchecked>"
74-
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -target-min-inlining-version -Xfrontend min>"
75-
"$<$<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>"
7873
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -disable-implicit-concurrency-module-import>"
7974
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -disable-implicit-string-processing-module-import>")
8075

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(
81+
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -enforce-exclusivity=unchecked>"
82+
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -target-min-inlining-version -Xfrontend min>"
83+
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -enable-lexical-lifetimes=false>"
84+
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -enable-ossa-modules>")
8185
add_compile_definitions(
8286
$<$<BOOL:${SwiftOverlay_ENABLE_BACKDEPLOYMENT_SUPPORT}>:SWIFT_STDLIB_SUPPORT_BACK_DEPLOYMENT>)
8387

Runtimes/Overlay/Cxx/CMakeLists.txt

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
2+
add_subdirectory(cxxshim)
3+
if(LINUX)
4+
add_ubdirectory(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+
"-warn-implicit-overrides"
26+
"SHELL:-Xfrontend -enable-lexical-lifetimes=false"
27+
"SHELL:-Xfrontend -enable-ossa-modules"
28+
# This module should not pull in the C++ standard library, so we disable it
29+
# explicitly. For functionality that depends on the C++ stdlib, use C++
30+
# stdlib overlay (`swiftstd` module).
31+
"SHELL:-Xcc -nostdinc++"
32+
"SHELL:-enable-experimental-feature AllowUnsafeAttribute"
33+
"SHELL:-enable-experimental-feature BuiltinModule"
34+
"SHELL:-enable-experimental-feature InoutLifetimeDependence"
35+
"SHELL:-enable-experimental-feature LifetimeDependence"
36+
"SHELL:-enable-experimental-feature LifetimeDependenceMutableAccessors"
37+
"SHELL:-enable-experimental-feature MemberImportVisibility"
38+
"SHELL:-enable-experimental-feature NoncopyableGenerics2"
39+
"SHELL:-enable-experimental-feature NonescapableTypes"
40+
"SHELL:-enable-experimental-feature Span"
41+
"SHELL:-enable-experimental-feature SE427NoInferenceOnExtension"
42+
"SHELL:-enable-experimental-feature SuppressedAssociatedTypes")
43+
target_link_libraries(swiftCxx PRIVATE
44+
swiftCore)
45+
46+
install(TARGETS swiftCxx
47+
EXPORT SwiftOverlayTargets
48+
ARCHIVE DESTINATION "${SwiftOverlay_INSTALL_LIBDIR}"
49+
LIBRARY DESTINATION "${SwiftOverlay_INSTALL_LIBDIR}"
50+
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
51+
emit_swift_interface(swiftCxx)
52+
install_swift_interface(swiftCxx)
53+
54+
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: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
cxxshim
26+
$<$<PLATFORM_ID:Linux>:libstdcxx>
27+
swiftCxx
28+
swiftCore
29+
swift_Builtin_float
30+
$<$<PLATFORM_ID:Android>:SwiftAndroid>
31+
$<$<PLATFORM_ID:Windows>:ClangModules>)
32+
33+
install(TARGETS swiftCxxStdlib
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(swiftCxxStdlib)
39+
install_swift_interface(swiftCxxStdlib)
40+
41+
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)