mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Overlay: add C++ interop libraries
This introduces a build of the C++ interop runtime support to the new runtime library build. Co-authored-by: Eric Miotto <1094986+edymtt@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
bf6bd5097d
commit
c040f97aff
@@ -57,6 +57,7 @@ include(ResourceEmbedding)
|
||||
include("${${PROJECT_NAME}_VENDOR_MODULE_DIR}/Settings.cmake" OPTIONAL)
|
||||
|
||||
defaulted_option(SwiftOverlay_ENABLE_REFLECTION "Enable runtime support for mirrors and reflection support")
|
||||
defaulted_option(SwiftOverlay_ENABLE_CXX_INTEROP "Enable C++ Interop support overlays")
|
||||
|
||||
option(SwiftOverlay_INSTALL_NESTED_SUBDIR "Install libraries under a platform and architecture subdirectory" ON)
|
||||
set(SwiftOverlay_INSTALL_LIBDIR "${CMAKE_INSTALL_LIBDIR}/swift$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:_static>$<$<BOOL:${SwiftOverlay_INSTALL_NESTED_SUBDIR}>:/${SwiftOverlay_PLATFORM_SUBDIR}/${SwiftOverlay_ARCH_SUBDIR}>")
|
||||
@@ -67,16 +68,23 @@ option(SwiftOverlay_ENABLE_LIBRARY_EVOLUTION "Generate ABI resilient runtime lib
|
||||
option(SwiftOverlay_ENABLE_BACKDEPLOYMENT_SUPPORT "Add symbols for runtime backdeployment"
|
||||
${SwiftCore_ENABLE_BACKDEPLOYMENT_SUPPORT})
|
||||
|
||||
add_compile_definitions(
|
||||
$<$<BOOL:${SwiftOverlay_ENABLE_BACKDEPLOYMENT_SUPPORT}>:SWIFT_STDLIB_SUPPORT_BACK_DEPLOYMENT>)
|
||||
|
||||
add_compile_options(
|
||||
$<$<COMPILE_LANGUAGE:Swift>:-explicit-module-build>
|
||||
$<$<COMPILE_LANGUAGE:Swift>:-nostdlibimport>
|
||||
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -enforce-exclusivity=unchecked>"
|
||||
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -target-min-inlining-version -Xfrontend min>"
|
||||
$<$<COMPILE_LANGUAGE:Swift>:-strict-memory-safety>
|
||||
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -enable-lexical-lifetimes=false>"
|
||||
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -enable-ossa-modules>"
|
||||
"$<$<AND:$<BOOL:${SwiftOverlay_ENABLE_LIBRARY_EVOLUTION}>,$<COMPILE_LANGUAGE:Swift>>:-enable-library-evolution>"
|
||||
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -disable-implicit-concurrency-module-import>"
|
||||
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -disable-implicit-string-processing-module-import>")
|
||||
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -disable-implicit-string-processing-module-import>"
|
||||
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -enforce-exclusivity=unchecked>"
|
||||
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -enable-ossa-modules>"
|
||||
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -target-min-inlining-version -Xfrontend min>"
|
||||
"$<$<AND:$<BOOL:${${PROJECT_NAME}_ENABLE_LIBRARY_EVOLUTION}>,$<COMPILE_LANGUAGE:Swift>>:-enable-library-evolution>"
|
||||
"$<$<AND:$<BOOL:${${PROJECT_NAME}_ENABLE_PRESPECIALIZATION}>,$<COMPILE_LANGUAGE:Swift>>:SHELL:-Xfrontend -prespecialize-generic-metadata>")
|
||||
|
||||
include(ExperimentalFeatures)
|
||||
|
||||
# LNK4049: symbol 'symbol' defined in 'filename.obj' is imported
|
||||
# LNK4286: symbol 'symbol' defined in 'filename_1.obj' is imported by 'filename_2.obj'
|
||||
@@ -87,9 +95,6 @@ add_compile_options(
|
||||
# a compromise, treat all linker warnings as errors.
|
||||
add_link_options($<$<PLATFORM_ID:Windows>:LINKER:/WX>)
|
||||
|
||||
add_compile_definitions(
|
||||
$<$<BOOL:${SwiftOverlay_ENABLE_BACKDEPLOYMENT_SUPPORT}>:SWIFT_STDLIB_SUPPORT_BACK_DEPLOYMENT>)
|
||||
|
||||
include(ExperimentalFeatures)
|
||||
|
||||
add_subdirectory(clang)
|
||||
@@ -100,6 +105,10 @@ if(WIN32)
|
||||
add_subdirectory(Windows)
|
||||
endif()
|
||||
|
||||
if(SwiftOverlay_ENABLE_CXX_INTEROP)
|
||||
add_subdirectory(Cxx)
|
||||
endif()
|
||||
|
||||
# Inter-project install info
|
||||
export(EXPORT SwiftOverlayTargets
|
||||
FILE "cmake/SwiftOverlay/SwiftOverlayTargets.cmake")
|
||||
|
||||
45
Runtimes/Overlay/Cxx/CMakeLists.txt
Normal file
45
Runtimes/Overlay/Cxx/CMakeLists.txt
Normal file
@@ -0,0 +1,45 @@
|
||||
|
||||
if(NOT APPLE)
|
||||
add_subdirectory(cxxshim)
|
||||
endif()
|
||||
if(LINUX)
|
||||
add_subdirectory(libstdcxx)
|
||||
endif()
|
||||
add_subdirectory(std)
|
||||
|
||||
add_library(swiftCxx STATIC
|
||||
CxxConvertibleToBool.swift
|
||||
CxxConvertibleToCollection.swift
|
||||
CxxDictionary.swift
|
||||
CxxOptional.swift
|
||||
CxxPair.swift
|
||||
CxxRandomAccessCollection.swift
|
||||
CxxSequence.swift
|
||||
CxxSet.swift
|
||||
CxxSpan.swift
|
||||
CxxVector.swift
|
||||
UnsafeCxxIterators.swift)
|
||||
set_target_properties(swiftCxx PROPERTIES
|
||||
Swift_MODULE_NAME Cxx)
|
||||
target_compile_options(swiftCxx PRIVATE
|
||||
"$<$<COMPILE_LANGUAGE:Swift>:-cxx-interoperability-mode=default>"
|
||||
"$<$<COMPILE_LANGUAGE:Swift>:-warn-implicit-overrides>"
|
||||
# This module should not pull in the C++ standard library, so we disable it
|
||||
# explicitly. For functionality that depends on the C++ stdlib, use C++
|
||||
# stdlib overlay (`swiftstd` module).
|
||||
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xcc -nostdinc++>"
|
||||
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature AllowUnsafeAttribute>"
|
||||
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature BuiltinModule>"
|
||||
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature Span>")
|
||||
target_link_libraries(swiftCxx PRIVATE
|
||||
swiftCore)
|
||||
|
||||
install(TARGETS swiftCxx
|
||||
EXPORT SwiftOverlayTargets
|
||||
ARCHIVE DESTINATION "${SwiftOverlay_INSTALL_LIBDIR}"
|
||||
LIBRARY DESTINATION "${SwiftOverlay_INSTALL_LIBDIR}"
|
||||
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
|
||||
emit_swift_interface(swiftCxx)
|
||||
install_swift_interface(swiftCxx)
|
||||
|
||||
embed_manifest(swiftCxx)
|
||||
17
Runtimes/Overlay/Cxx/cxxshim/CMakeLists.txt
Normal file
17
Runtimes/Overlay/Cxx/cxxshim/CMakeLists.txt
Normal file
@@ -0,0 +1,17 @@
|
||||
|
||||
add_library(cxxshim INTERFACE)
|
||||
target_compile_options(cxxshim INTERFACE
|
||||
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xcc -fmodule-map-file=${CMAKE_CURRENT_SOURCE_DIR}/libcxxshim.modulemap>")
|
||||
target_include_directories(cxxshim INTERFACE
|
||||
$<$<COMPILE_LANGUAGE:Swift>:$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>>)
|
||||
|
||||
install(TARGETS cxxshim
|
||||
EXPORT SwiftOverlayTargets
|
||||
ARCHIVE DESTINATION "${SwiftOverlay_INSTALL_LIBDIR}"
|
||||
LIBRARY DESTINATION "${SwiftOverlay_INSTALL_LIBDIR}"
|
||||
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
|
||||
install(FILES
|
||||
libcxxshim.h
|
||||
libcxxshim.modulemap
|
||||
libcxxstdlibshim.h
|
||||
DESTINATION "${CMAKE_INSTALL_LIBDIR}/swift/${SwiftOverlay_PLATFORM_SUBDIR}")
|
||||
16
Runtimes/Overlay/Cxx/libstdcxx/CMakeLists.txt
Normal file
16
Runtimes/Overlay/Cxx/libstdcxx/CMakeLists.txt
Normal file
@@ -0,0 +1,16 @@
|
||||
|
||||
add_library(libstdcxx INTERFACE)
|
||||
target_compile_options(libstdcxx INTERFACE
|
||||
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xcc -fmodule-map-file=${CMAKE_CURRENT_SOURCE_DIR}/libstdcxx.modulemap>")
|
||||
target_include_directories(libstdcxx INTERFACE
|
||||
$<$<COMPILE_LANGUAGE:Swift>:$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>>)
|
||||
|
||||
install(TARGETS libstdcxx
|
||||
EXPORT SwiftOverlayTargets
|
||||
ARCHIVE DESTINATION "${SwiftOverlay_INSTALL_LIBDIR}"
|
||||
LIBRARY DESTINATION "${SwiftOverlay_INSTALL_LIBDIR}"
|
||||
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
|
||||
install(FILES
|
||||
libstdcxx.h
|
||||
libstdcxx.modulemap
|
||||
DESTINATION "${SwiftOverlay_INSTALL_LIBDIR}")
|
||||
43
Runtimes/Overlay/Cxx/std/CMakeLists.txt
Normal file
43
Runtimes/Overlay/Cxx/std/CMakeLists.txt
Normal file
@@ -0,0 +1,43 @@
|
||||
|
||||
add_library(swiftCxxStdlib STATIC
|
||||
std.swift
|
||||
Chrono.swift
|
||||
String.swift)
|
||||
set_target_properties(swiftCxxStdlib PROPERTIES
|
||||
Swift_MODULE_NAME CxxStdlib)
|
||||
target_compile_options(swiftCxxStdlib PRIVATE
|
||||
"-strict-memory-safety"
|
||||
"-cxx-interoperability-mode=default"
|
||||
"SHELL:-enable-experimental-feature AllowUnsafeAttribute"
|
||||
# This flag is unnecessary when building with newer compilers that allow using
|
||||
# C++ symbols in resilient overlays (see f4204568).
|
||||
"SHELL:-enable-experimental-feature AssumeResilientCxxTypes"
|
||||
# The varying modularization of the C++ standard library on different
|
||||
# platforms makes it difficult to enable MemberImportVisibility for this
|
||||
# module
|
||||
"SHELL:-disable-upcoming-feature MemberImportVisibility"
|
||||
"SHELL:-Xfrontend -module-interface-preserve-types-as-written")
|
||||
# NOTE: We need to setup the sysroot here as we need to ensure that we pick up
|
||||
# the module.map from the C++ runtime for the `std` (spelt `CxxStdlib`) import.
|
||||
target_compile_options(swiftCxxStdlib PRIVATE
|
||||
"$<$<PLATFORM_ID:Android>:SHELL:-Xcc --sysroot -Xcc ${CMAKE_ANDROID_NDK_TOOLCHAIN_UNIFIED}/sysroot>")
|
||||
target_link_libraries(swiftCxxStdlib PRIVATE
|
||||
$<$<PLATFORM_ID:Linux>:libstdcxx>
|
||||
$<$<NOT:$<PLATFORM_ID:Darwin>>:cxxshim>
|
||||
swiftCxx
|
||||
swiftCore
|
||||
swift_Builtin_float
|
||||
$<$<PLATFORM_ID:Android>:SwiftAndroid>
|
||||
$<$<PLATFORM_ID:Windows>:ClangModules>)
|
||||
|
||||
install(FILES std.apinotes
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/swift/apinotes)
|
||||
install(TARGETS swiftCxxStdlib
|
||||
EXPORT SwiftOverlayTargets
|
||||
ARCHIVE DESTINATION "${SwiftOverlay_INSTALL_LIBDIR}"
|
||||
LIBRARY DESTINATION "${SwiftOverlay_INSTALL_LIBDIR}"
|
||||
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
|
||||
emit_swift_interface(swiftCxxStdlib)
|
||||
install_swift_interface(swiftCxxStdlib)
|
||||
|
||||
embed_manifest(swiftCxxStdlib)
|
||||
@@ -26,12 +26,16 @@ endmacro()
|
||||
|
||||
if(APPLE)
|
||||
set(SwiftOverlay_ENABLE_REFLECTION_default ON)
|
||||
set(SwiftOverlay_ENABLE_CXX_INTEROP_default OFF)
|
||||
elseif(CMAKE_SYSTEM_NAME STREQUAL "WASM")
|
||||
set(SwiftOverlay_ENABLE_REFLECTION_default OFF)
|
||||
set(SwiftOverlay_ENABLE_CXX_INTEROP_default OFF)
|
||||
elseif(LINUX OR ANDROID OR BSD)
|
||||
set(SwiftOverlay_ENABLE_REFLECTION_default OFF)
|
||||
set(SwiftOverlay_ENABLE_CXX_INTEROP_default OFF)
|
||||
elseif(WIN32)
|
||||
set(SwiftOverlay_ENABLE_REFLECTION_default ON)
|
||||
set(SwiftOverlay_ENABLE_CXX_INTEROP_default OFF)
|
||||
endif()
|
||||
|
||||
include("${SwiftOverlay_VENDOR_MODULE_DIR}/DefaultSettings.cmake" OPTIONAL)
|
||||
|
||||
@@ -122,6 +122,8 @@ copy_library_sources("linker-support" "public/ClangOverlays" "Overlay")
|
||||
message(STATUS "Clang[${StdlibSources}/public/ClangOverlays] -> ${CMAKE_CURRENT_LIST_DIR}/Overlay/clang")
|
||||
copy_files(public/ClangOverlays Overlay/clang FILES float.swift.gyb)
|
||||
|
||||
copy_library_sources("Cxx" "public" "Overlay")
|
||||
|
||||
# Android Overlay
|
||||
message(STATUS "Android modulemaps[${StdlibSources}/Platform] -> ${CMAKE_CURRENT_LIST_DIR}/Overlay/Android/clang")
|
||||
copy_files(public/Platform Overlay/Android/clang
|
||||
|
||||
Reference in New Issue
Block a user