Skip to content

[cxx-interop] add a build setting to control whether the <swift/bridg… #65786

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 9, 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
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,10 @@ option(SWIFT_ENABLE_EXPERIMENTAL_CXX_INTEROP
"Enable experimental C++ interop modules"
FALSE)

option(SWIFT_ENABLE_CXX_INTEROP_SWIFT_BRIDGING_HEADER
"Install the <swift/bridging> C++ interoperability header alongside compiler"
TRUE)

option(SWIFT_ENABLE_EXPERIMENTAL_DISTRIBUTED
"Enable experimental distributed actors and functions"
FALSE)
Expand Down
38 changes: 20 additions & 18 deletions lib/ClangImporter/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,25 +43,27 @@ add_dependencies(swiftClangImporter

set_swift_llvm_is_available(swiftClangImporter)

# Mark - copy "bridging" (support header) into the local include directory and
# install it into the compiler toolchain.
set(SWIFTINC_DIR
"${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/include/swift")
if(SWIFT_ENABLE_CXX_INTEROP_SWIFT_BRIDGING_HEADER)
# Mark - copy "bridging" (support header) into the local include directory and
# install it into the compiler toolchain.
set(SWIFTINC_DIR
"${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/include/swift")

add_custom_command(
OUTPUT "${SWIFTINC_DIR}/bridging"
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/bridging"
COMMAND "${CMAKE_COMMAND}" "-E" "copy" "${CMAKE_CURRENT_SOURCE_DIR}/bridging" "${SWIFTINC_DIR}")
add_custom_command(
OUTPUT "${SWIFTINC_DIR}/bridging"
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/bridging"
COMMAND "${CMAKE_COMMAND}" "-E" "copy" "${CMAKE_CURRENT_SOURCE_DIR}/bridging" "${SWIFTINC_DIR}")

add_custom_target("copy_cxxInterop_support_header"
DEPENDS "${SWIFTINC_DIR}/bridging"
COMMENT "Copying C++ interop support header to ${SWIFTINC_DIR}")
add_custom_target("copy_cxxInterop_support_header"
DEPENDS "${SWIFTINC_DIR}/bridging"
COMMENT "Copying C++ interop support header to ${SWIFTINC_DIR}")

swift_install_in_component(FILES
"${CMAKE_CURRENT_SOURCE_DIR}/bridging"
"${CMAKE_CURRENT_SOURCE_DIR}/module.modulemap"
DESTINATION "include/swift"
COMPONENT compiler)
swift_install_in_component(FILES
"${CMAKE_CURRENT_SOURCE_DIR}/bridging"
"${CMAKE_CURRENT_SOURCE_DIR}/module.modulemap"
DESTINATION "include/swift"
COMPONENT compiler)

add_dependencies(swiftClangImporter
"copy_cxxInterop_support_header")
add_dependencies(swiftClangImporter
"copy_cxxInterop_support_header")
endif()
4 changes: 4 additions & 0 deletions utils/build_swift/build_swift/driver_arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -1319,6 +1319,10 @@ def create_argument_parser():
default=True,
help='Enable experimental C++ interop.')

option('--enable-cxx-interop-swift-bridging-header', toggle_true,
default=True,
help='Ship the <swift/bridging> header for C++ interop')

option('--enable-experimental-distributed', toggle_true,
default=True,
help='Enable experimental Swift distributed actors.')
Expand Down
2 changes: 2 additions & 0 deletions utils/build_swift/tests/expected_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@
'enable_experimental_differentiable_programming': True,
'enable_experimental_concurrency': True,
'enable_experimental_cxx_interop': True,
'enable_cxx_interop_swift_bridging_header': True,
'enable_experimental_distributed': True,
'enable_experimental_string_processing': True,
'enable_experimental_observation': True,
Expand Down Expand Up @@ -579,6 +580,7 @@ class BuildScriptImplOption(_BaseOption):
EnableOption('--enable-experimental-differentiable-programming'),
EnableOption('--enable-experimental-concurrency'),
EnableOption('--enable-experimental-cxx-interop'),
EnableOption('--enable-cxx-interop-swift-bridging-header'),
EnableOption('--enable-experimental-distributed'),
EnableOption('--enable-experimental-string-processing'),
EnableOption('--enable-experimental-observation'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ def __init__(self, args, toolchain, source_dir, build_dir):
# Add experimental concurrency flag.
self.cmake_options.extend(self._enable_experimental_concurrency)

# Add experimental cxx interop flag.
# Add experimental cxx interop flags.
self.cmake_options.extend(self._enable_experimental_cxx_interop)
self.cmake_options.extend(self._enable_cxx_interop_swift_bridging_header)

# Add experimental distributed flag.
self.cmake_options.extend(self._enable_experimental_distributed)
Expand Down Expand Up @@ -176,6 +177,11 @@ def _enable_experimental_cxx_interop(self):
return [('SWIFT_ENABLE_EXPERIMENTAL_CXX_INTEROP:BOOL',
self.args.enable_experimental_cxx_interop)]

@property
def _enable_cxx_interop_swift_bridging_header(self):
return [('SWIFT_ENABLE_CXX_INTEROP_SWIFT_BRIDGING_HEADER:BOOL',
self.args.enable_cxx_interop_swift_bridging_header)]

@property
def _enable_experimental_distributed(self):
return [('SWIFT_ENABLE_EXPERIMENTAL_DISTRIBUTED:BOOL',
Expand Down
15 changes: 15 additions & 0 deletions utils/swift_build_support/tests/products/test_swift.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def setUp(self):
enable_experimental_differentiable_programming=False,
enable_experimental_concurrency=False,
enable_experimental_cxx_interop=False,
enable_cxx_interop_swift_bridging_header=False,
enable_experimental_distributed=False,
enable_experimental_observation=False,
swift_enable_backtracing=False,
Expand Down Expand Up @@ -98,6 +99,7 @@ def test_by_default_no_cmake_options(self):
'-DSWIFT_ENABLE_EXPERIMENTAL_DIFFERENTIABLE_PROGRAMMING:BOOL=FALSE',
'-DSWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY:BOOL=FALSE',
'-DSWIFT_ENABLE_EXPERIMENTAL_CXX_INTEROP:BOOL=FALSE',
'-DSWIFT_ENABLE_CXX_INTEROP_SWIFT_BRIDGING_HEADER:BOOL=FALSE',
'-DSWIFT_ENABLE_EXPERIMENTAL_DISTRIBUTED:BOOL=FALSE',
'-DSWIFT_ENABLE_EXPERIMENTAL_OBSERVATION:BOOL=FALSE',
'-DSWIFT_ENABLE_BACKTRACING:BOOL=FALSE',
Expand All @@ -124,6 +126,7 @@ def test_swift_runtime_tsan(self):
'-DSWIFT_ENABLE_EXPERIMENTAL_DIFFERENTIABLE_PROGRAMMING:BOOL=FALSE',
'-DSWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY:BOOL=FALSE',
'-DSWIFT_ENABLE_EXPERIMENTAL_CXX_INTEROP:BOOL=FALSE',
'-DSWIFT_ENABLE_CXX_INTEROP_SWIFT_BRIDGING_HEADER:BOOL=FALSE',
'-DSWIFT_ENABLE_EXPERIMENTAL_DISTRIBUTED:BOOL=FALSE',
'-DSWIFT_ENABLE_EXPERIMENTAL_OBSERVATION:BOOL=FALSE',
'-DSWIFT_ENABLE_BACKTRACING:BOOL=FALSE',
Expand Down Expand Up @@ -370,6 +373,18 @@ def test_experimental_cxx_interop_flags(self):
[option for option in swift.cmake_options
if 'DSWIFT_ENABLE_EXPERIMENTAL_CXX_INTEROP' in option])

def test_experimental_cxx_interop_bridging_header_flags(self):
self.args.enable_cxx_interop_swift_bridging_header = True
swift = Swift(
args=self.args,
toolchain=self.toolchain,
source_dir='/path/to/src',
build_dir='/path/to/build')
self.assertEqual(
['-DSWIFT_ENABLE_CXX_INTEROP_SWIFT_BRIDGING_HEADER:BOOL=TRUE'],
[option for option in swift.cmake_options
if 'DSWIFT_ENABLE_CXX_INTEROP_SWIFT_BRIDGING_HEADER' in option])

def test_experimental_distributed_flags(self):
self.args.enable_experimental_distributed = True
swift = Swift(
Expand Down