-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Overlay: add C++ interop libraries #83347
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
|
||
if(NOT APPLE) | ||
add_subdirectory(cxxshim) | ||
endif() | ||
Comment on lines
+2
to
+4
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't seem correct: CxxShim headers are used on all of the platforms, including Apple ones. |
||
if(LINUX) | ||
compnerd marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I actually need to target a Linux that does not have a libstdc++, but uses libcxx instead. This assumption is incorrect. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fair enough - I think that we can iterate on that subsequently. |
||
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) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}") |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}") |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
Uh oh!
There was an error while loading. Please reload this page.