Skip to content

[cxx-interop] Fix Linux build with SWIFT_ENABLE_EXPERIMENTAL_CXX_INTEROP=NO #65584

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

Merged
merged 1 commit into from
May 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions stdlib/public/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ add_subdirectory(SwiftShims/swift/shims)
add_subdirectory(CommandLineSupport)
if(SWIFT_ENABLE_EXPERIMENTAL_CXX_INTEROP)
add_subdirectory(Cxx)
else()
# SwiftCompilerSources rely on C++ interop, specifically on being able to
# import the C++ standard library into Swift. On Linux, this is only possible
# when using the modulemap that Swift provides for libstdc++. Make sure we
# include the libstdc++ modulemap into the build even when not building
# C++ interop modules.
add_subdirectory(Cxx/libstdcxx)
endif()
add_subdirectory(Threading)

Expand Down
1 change: 1 addition & 0 deletions stdlib/public/Cxx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ add_swift_target_library(swiftCxx ${SWIFT_CXX_LIBRARY_KIND} NO_LINK_NAME IS_STDL
INSTALL_IN_COMPONENT compiler
INSTALL_WITH_SHARED)

add_subdirectory(libstdcxx)
add_subdirectory(std)
add_subdirectory(cxxshim)
124 changes: 124 additions & 0 deletions stdlib/public/Cxx/libstdcxx/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
set(libstdcxx_modulemap_target_list)
foreach(sdk ${SWIFT_SDKS})
if(NOT ${sdk} IN_LIST SWIFT_LIBSTDCXX_PLATFORMS)
continue()
endif()

foreach(arch ${SWIFT_SDK_${sdk}_ARCHITECTURES})
set(arch_suffix "${SWIFT_SDK_${sdk}_LIB_SUBDIR}-${arch}")
set(arch_subdir "${SWIFT_SDK_${sdk}_LIB_SUBDIR}/${arch}")

set(module_dir "${SWIFTLIB_DIR}/${arch_subdir}")
set(module_dir_static "${SWIFTSTATICLIB_DIR}/${arch_subdir}")

set(libstdcxx_header "libstdcxx.h")
set(libstdcxx_header_out "${module_dir}/libstdcxx.h")
set(libstdcxx_header_out_static "${module_dir_static}/libstdcxx.h")
set(libstdcxx_modulemap "libstdcxx.modulemap")
set(libstdcxx_modulemap_out "${module_dir}/libstdcxx.modulemap")
set(libstdcxx_modulemap_out_static "${module_dir_static}/libstdcxx.modulemap")

add_custom_command_target(
copy_libstdcxx_modulemap
COMMAND
"${CMAKE_COMMAND}" "-E" "make_directory" ${module_dir}
COMMAND
"${CMAKE_COMMAND}" "-E" "copy_if_different" "${CMAKE_CURRENT_SOURCE_DIR}/${libstdcxx_modulemap}" "${libstdcxx_modulemap_out}"
OUTPUT ${libstdcxx_modulemap_out}
DEPENDS ${libstdcxx_modulemap}
COMMENT "Copying libstdcxx modulemap to resources")
list(APPEND libstdcxx_modulemap_target_list ${copy_libstdcxx_modulemap})
add_dependencies(swift-stdlib-${arch_suffix} ${copy_libstdcxx_modulemap})

add_custom_command_target(
copy_libstdcxx_header
COMMAND
"${CMAKE_COMMAND}" "-E" "make_directory" ${module_dir}
COMMAND
"${CMAKE_COMMAND}" "-E" "copy_if_different" "${CMAKE_CURRENT_SOURCE_DIR}/${libstdcxx_header}" "${libstdcxx_header_out}"
OUTPUT ${libstdcxx_header_out}
DEPENDS ${libstdcxx_header}
COMMENT "Copying libstdcxx header to resources")
list(APPEND libstdcxx_modulemap_target_list ${copy_libstdcxx_header})
add_dependencies(swift-stdlib-${arch_suffix} ${copy_libstdcxx_header})

if(SWIFT_BUILD_STATIC_STDLIB)
add_custom_command_target(
copy_libstdcxx_modulemap_static
COMMAND
"${CMAKE_COMMAND}" "-E" "make_directory" ${module_dir_static}
COMMAND
"${CMAKE_COMMAND}" "-E" "copy_if_different"
"${libstdcxx_modulemap_out}" "${libstdcxx_modulemap_out_static}"
OUTPUT ${libstdcxx_modulemap_out_static}
DEPENDS ${copy_libstdcxx_modulemap}
COMMENT "Copying libstdcxx modulemap to static resources")
list(APPEND libstdcxx_modulemap_target_list ${copy_libstdcxx_modulemap_static})
add_dependencies(swift-stdlib-${arch_suffix} ${copy_libstdcxx_modulemap_static})

add_custom_command_target(
copy_libstdcxx_header_static
COMMAND
"${CMAKE_COMMAND}" "-E" "make_directory" ${module_dir_static}
COMMAND
"${CMAKE_COMMAND}" "-E" "copy_if_different"
"${libstdcxx_header_out}" "${libstdcxx_header_out_static}"
OUTPUT ${libstdcxx_header_out_static}
DEPENDS ${copy_libstdcxx_header}
COMMENT "Copying libstdcxx header to static resources")
list(APPEND libstdcxx_modulemap_target_list ${copy_libstdcxx_header_static})
add_dependencies(swift-stdlib-${arch_suffix} ${copy_libstdcxx_header_static})
endif()

swift_install_in_component(FILES "${libstdcxx_modulemap_out}"
DESTINATION "lib/swift/${arch_subdir}"
COMPONENT sdk-overlay)
swift_install_in_component(FILES "${libstdcxx_header_out}"
DESTINATION "lib/swift/${arch_subdir}"
COMPONENT sdk-overlay)

if(SWIFT_BUILD_STATIC_STDLIB)
swift_install_in_component(FILES "${libstdcxx_modulemap_out_static}"
DESTINATION "lib/swift_static/${arch_subdir}"
COMPONENT sdk-overlay)
swift_install_in_component(FILES "${libstdcxx_header_out_static}"
DESTINATION "lib/swift_static/${arch_subdir}"
COMPONENT sdk-overlay)
endif()

if(${BOOTSTRAPPING_MODE} MATCHES "BOOTSTRAPPING.*")
foreach(bootstrapping "0" "1")
get_bootstrapping_path(bootstrapping_dir ${module_dir} ${bootstrapping})
set(libstdcxx_modulemap_out_bootstrapping "${bootstrapping_dir}/libstdcxx.modulemap")
set(libstdcxx_header_out_bootstrapping "${bootstrapping_dir}/libstdcxx.h")

add_custom_command_target(unused_var
COMMAND
"${CMAKE_COMMAND}" "-E" "make_directory" "${bootstrapping_dir}"
COMMAND
"${CMAKE_COMMAND}" "-E" "copy_if_different"
"${CMAKE_CURRENT_SOURCE_DIR}/${libstdcxx_modulemap}" "${libstdcxx_modulemap_out_bootstrapping}"

CUSTOM_TARGET_NAME "copy-libstdcxx-modulemap-bootstrapping${bootstrapping}"
OUTPUT "${libstdcxx_modulemap_out_bootstrapping}"
DEPENDS ${libstdcxx_modulemap}
COMMENT "Copying libstdcxx modulemap to resources for bootstrapping${bootstrapping}")

add_custom_command_target(unused_var
COMMAND
"${CMAKE_COMMAND}" "-E" "make_directory" "${bootstrapping_dir}"
COMMAND
"${CMAKE_COMMAND}" "-E" "copy_if_different"
"${CMAKE_CURRENT_SOURCE_DIR}/${libstdcxx_header}" "${libstdcxx_header_out_bootstrapping}"

CUSTOM_TARGET_NAME "copy-libstdcxx-header-bootstrapping${bootstrapping}"
OUTPUT "${libstdcxx_header_out_bootstrapping}"
DEPENDS ${libstdcxx_header}
COMMENT "Copying libstdcxx header to resources for bootstrapping${bootstrapping}")
endforeach()
endif()
endforeach()
endforeach()
add_custom_target(libstdcxx-modulemap DEPENDS ${libstdcxx_modulemap_target_list})
set_property(TARGET libstdcxx-modulemap PROPERTY FOLDER "Miscellaneous")
add_dependencies(sdk-overlay libstdcxx-modulemap)
126 changes: 0 additions & 126 deletions stdlib/public/Cxx/std/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,129 +1,3 @@
set(libstdcxx_modulemap_target_list)
foreach(sdk ${SWIFT_SDKS})
if(NOT ${sdk} IN_LIST SWIFT_LIBSTDCXX_PLATFORMS)
continue()
endif()

foreach(arch ${SWIFT_SDK_${sdk}_ARCHITECTURES})
set(arch_suffix "${SWIFT_SDK_${sdk}_LIB_SUBDIR}-${arch}")
set(arch_subdir "${SWIFT_SDK_${sdk}_LIB_SUBDIR}/${arch}")

set(module_dir "${SWIFTLIB_DIR}/${arch_subdir}")
set(module_dir_static "${SWIFTSTATICLIB_DIR}/${arch_subdir}")

set(libstdcxx_header "libstdcxx.h")
set(libstdcxx_header_out "${module_dir}/libstdcxx.h")
set(libstdcxx_header_out_static "${module_dir_static}/libstdcxx.h")
set(libstdcxx_modulemap "libstdcxx.modulemap")
set(libstdcxx_modulemap_out "${module_dir}/libstdcxx.modulemap")
set(libstdcxx_modulemap_out_static "${module_dir_static}/libstdcxx.modulemap")

add_custom_command_target(
copy_libstdcxx_modulemap
COMMAND
"${CMAKE_COMMAND}" "-E" "make_directory" ${module_dir}
COMMAND
"${CMAKE_COMMAND}" "-E" "copy_if_different" "${CMAKE_CURRENT_SOURCE_DIR}/${libstdcxx_modulemap}" "${libstdcxx_modulemap_out}"
OUTPUT ${libstdcxx_modulemap_out}
DEPENDS ${libstdcxx_modulemap}
COMMENT "Copying libstdcxx modulemap to resources")
list(APPEND libstdcxx_modulemap_target_list ${copy_libstdcxx_modulemap})
add_dependencies(swift-stdlib-${arch_suffix} ${copy_libstdcxx_modulemap})

add_custom_command_target(
copy_libstdcxx_header
COMMAND
"${CMAKE_COMMAND}" "-E" "make_directory" ${module_dir}
COMMAND
"${CMAKE_COMMAND}" "-E" "copy_if_different" "${CMAKE_CURRENT_SOURCE_DIR}/${libstdcxx_header}" "${libstdcxx_header_out}"
OUTPUT ${libstdcxx_header_out}
DEPENDS ${libstdcxx_header}
COMMENT "Copying libstdcxx header to resources")
list(APPEND libstdcxx_modulemap_target_list ${copy_libstdcxx_header})
add_dependencies(swift-stdlib-${arch_suffix} ${copy_libstdcxx_header})

if(SWIFT_BUILD_STATIC_STDLIB)
add_custom_command_target(
copy_libstdcxx_modulemap_static
COMMAND
"${CMAKE_COMMAND}" "-E" "make_directory" ${module_dir_static}
COMMAND
"${CMAKE_COMMAND}" "-E" "copy_if_different"
"${libstdcxx_modulemap_out}" "${libstdcxx_modulemap_out_static}"
OUTPUT ${libstdcxx_modulemap_out_static}
DEPENDS ${copy_libstdcxx_modulemap}
COMMENT "Copying libstdcxx modulemap to static resources")
list(APPEND libstdcxx_modulemap_target_list ${copy_libstdcxx_modulemap_static})
add_dependencies(swift-stdlib-${arch_suffix} ${copy_libstdcxx_modulemap_static})

add_custom_command_target(
copy_libstdcxx_header_static
COMMAND
"${CMAKE_COMMAND}" "-E" "make_directory" ${module_dir_static}
COMMAND
"${CMAKE_COMMAND}" "-E" "copy_if_different"
"${libstdcxx_header_out}" "${libstdcxx_header_out_static}"
OUTPUT ${libstdcxx_header_out_static}
DEPENDS ${copy_libstdcxx_header}
COMMENT "Copying libstdcxx header to static resources")
list(APPEND libstdcxx_modulemap_target_list ${copy_libstdcxx_header_static})
add_dependencies(swift-stdlib-${arch_suffix} ${copy_libstdcxx_header_static})
endif()

swift_install_in_component(FILES "${libstdcxx_modulemap_out}"
DESTINATION "lib/swift/${arch_subdir}"
COMPONENT sdk-overlay)
swift_install_in_component(FILES "${libstdcxx_header_out}"
DESTINATION "lib/swift/${arch_subdir}"
COMPONENT sdk-overlay)

if(SWIFT_BUILD_STATIC_STDLIB)
swift_install_in_component(FILES "${libstdcxx_modulemap_out_static}"
DESTINATION "lib/swift_static/${arch_subdir}"
COMPONENT sdk-overlay)
swift_install_in_component(FILES "${libstdcxx_header_out_static}"
DESTINATION "lib/swift_static/${arch_subdir}"
COMPONENT sdk-overlay)
endif()

if(${BOOTSTRAPPING_MODE} MATCHES "BOOTSTRAPPING.*")
foreach(bootstrapping "0" "1")
get_bootstrapping_path(bootstrapping_dir ${module_dir} ${bootstrapping})
set(libstdcxx_modulemap_out_bootstrapping "${bootstrapping_dir}/libstdcxx.modulemap")
set(libstdcxx_header_out_bootstrapping "${bootstrapping_dir}/libstdcxx.h")

add_custom_command_target(unused_var
COMMAND
"${CMAKE_COMMAND}" "-E" "make_directory" "${bootstrapping_dir}"
COMMAND
"${CMAKE_COMMAND}" "-E" "copy_if_different"
"${CMAKE_CURRENT_SOURCE_DIR}/${libstdcxx_modulemap}" "${libstdcxx_modulemap_out_bootstrapping}"

CUSTOM_TARGET_NAME "copy-libstdcxx-modulemap-bootstrapping${bootstrapping}"
OUTPUT "${libstdcxx_modulemap_out_bootstrapping}"
DEPENDS ${libstdcxx_modulemap}
COMMENT "Copying libstdcxx modulemap to resources for bootstrapping${bootstrapping}")

add_custom_command_target(unused_var
COMMAND
"${CMAKE_COMMAND}" "-E" "make_directory" "${bootstrapping_dir}"
COMMAND
"${CMAKE_COMMAND}" "-E" "copy_if_different"
"${CMAKE_CURRENT_SOURCE_DIR}/${libstdcxx_header}" "${libstdcxx_header_out_bootstrapping}"

CUSTOM_TARGET_NAME "copy-libstdcxx-header-bootstrapping${bootstrapping}"
OUTPUT "${libstdcxx_header_out_bootstrapping}"
DEPENDS ${libstdcxx_header}
COMMENT "Copying libstdcxx header to resources for bootstrapping${bootstrapping}")
endforeach()
endif()
endforeach()
endforeach()
add_custom_target(libstdcxx-modulemap DEPENDS ${libstdcxx_modulemap_target_list})
set_property(TARGET libstdcxx-modulemap PROPERTY FOLDER "Miscellaneous")
add_dependencies(sdk-overlay libstdcxx-modulemap)


#
# C++ Standard Library Overlay.
#
Expand Down
2 changes: 1 addition & 1 deletion unittests/ClangImporter/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
configure_file(${SWIFT_SOURCE_DIR}/stdlib/public/Cxx/std/libstdcxx.modulemap
configure_file(${SWIFT_SOURCE_DIR}/stdlib/public/Cxx/libstdcxx/libstdcxx.modulemap
${CMAKE_CURRENT_BINARY_DIR}/libstdcxx.modulemap COPYONLY)

add_swift_unittest(SwiftClangImporterTests
Expand Down