Skip to content

Commit 14b3e5c

Browse files
authored
Merge pull request #65786 from hyp/5.9/109050483
[cxx-interop] add a build setting to control whether the <swift/bridg…
2 parents 5556848 + e892d5b commit 14b3e5c

File tree

6 files changed

+52
-19
lines changed

6 files changed

+52
-19
lines changed

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,10 @@ option(SWIFT_ENABLE_EXPERIMENTAL_CXX_INTEROP
614614
"Enable experimental C++ interop modules"
615615
FALSE)
616616

617+
option(SWIFT_ENABLE_CXX_INTEROP_SWIFT_BRIDGING_HEADER
618+
"Install the <swift/bridging> C++ interoperability header alongside compiler"
619+
TRUE)
620+
617621
option(SWIFT_ENABLE_EXPERIMENTAL_DISTRIBUTED
618622
"Enable experimental distributed actors and functions"
619623
FALSE)

lib/ClangImporter/CMakeLists.txt

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -43,25 +43,27 @@ add_dependencies(swiftClangImporter
4343

4444
set_swift_llvm_is_available(swiftClangImporter)
4545

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

51-
add_custom_command(
52-
OUTPUT "${SWIFTINC_DIR}/bridging"
53-
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/bridging"
54-
COMMAND "${CMAKE_COMMAND}" "-E" "copy" "${CMAKE_CURRENT_SOURCE_DIR}/bridging" "${SWIFTINC_DIR}")
52+
add_custom_command(
53+
OUTPUT "${SWIFTINC_DIR}/bridging"
54+
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/bridging"
55+
COMMAND "${CMAKE_COMMAND}" "-E" "copy" "${CMAKE_CURRENT_SOURCE_DIR}/bridging" "${SWIFTINC_DIR}")
5556

56-
add_custom_target("copy_cxxInterop_support_header"
57-
DEPENDS "${SWIFTINC_DIR}/bridging"
58-
COMMENT "Copying C++ interop support header to ${SWIFTINC_DIR}")
57+
add_custom_target("copy_cxxInterop_support_header"
58+
DEPENDS "${SWIFTINC_DIR}/bridging"
59+
COMMENT "Copying C++ interop support header to ${SWIFTINC_DIR}")
5960

60-
swift_install_in_component(FILES
61-
"${CMAKE_CURRENT_SOURCE_DIR}/bridging"
62-
"${CMAKE_CURRENT_SOURCE_DIR}/module.modulemap"
63-
DESTINATION "include/swift"
64-
COMPONENT compiler)
61+
swift_install_in_component(FILES
62+
"${CMAKE_CURRENT_SOURCE_DIR}/bridging"
63+
"${CMAKE_CURRENT_SOURCE_DIR}/module.modulemap"
64+
DESTINATION "include/swift"
65+
COMPONENT compiler)
6566

66-
add_dependencies(swiftClangImporter
67-
"copy_cxxInterop_support_header")
67+
add_dependencies(swiftClangImporter
68+
"copy_cxxInterop_support_header")
69+
endif()

utils/build_swift/build_swift/driver_arguments.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,6 +1319,10 @@ def create_argument_parser():
13191319
default=True,
13201320
help='Enable experimental C++ interop.')
13211321

1322+
option('--enable-cxx-interop-swift-bridging-header', toggle_true,
1323+
default=True,
1324+
help='Ship the <swift/bridging> header for C++ interop')
1325+
13221326
option('--enable-experimental-distributed', toggle_true,
13231327
default=True,
13241328
help='Enable experimental Swift distributed actors.')

utils/build_swift/tests/expected_options.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@
161161
'enable_experimental_differentiable_programming': True,
162162
'enable_experimental_concurrency': True,
163163
'enable_experimental_cxx_interop': True,
164+
'enable_cxx_interop_swift_bridging_header': True,
164165
'enable_experimental_distributed': True,
165166
'enable_experimental_string_processing': True,
166167
'enable_experimental_observation': True,
@@ -579,6 +580,7 @@ class BuildScriptImplOption(_BaseOption):
579580
EnableOption('--enable-experimental-differentiable-programming'),
580581
EnableOption('--enable-experimental-concurrency'),
581582
EnableOption('--enable-experimental-cxx-interop'),
583+
EnableOption('--enable-cxx-interop-swift-bridging-header'),
582584
EnableOption('--enable-experimental-distributed'),
583585
EnableOption('--enable-experimental-string-processing'),
584586
EnableOption('--enable-experimental-observation'),

utils/swift_build_support/swift_build_support/products/swift.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@ def __init__(self, args, toolchain, source_dir, build_dir):
5252
# Add experimental concurrency flag.
5353
self.cmake_options.extend(self._enable_experimental_concurrency)
5454

55-
# Add experimental cxx interop flag.
55+
# Add experimental cxx interop flags.
5656
self.cmake_options.extend(self._enable_experimental_cxx_interop)
57+
self.cmake_options.extend(self._enable_cxx_interop_swift_bridging_header)
5758

5859
# Add experimental distributed flag.
5960
self.cmake_options.extend(self._enable_experimental_distributed)
@@ -176,6 +177,11 @@ def _enable_experimental_cxx_interop(self):
176177
return [('SWIFT_ENABLE_EXPERIMENTAL_CXX_INTEROP:BOOL',
177178
self.args.enable_experimental_cxx_interop)]
178179

180+
@property
181+
def _enable_cxx_interop_swift_bridging_header(self):
182+
return [('SWIFT_ENABLE_CXX_INTEROP_SWIFT_BRIDGING_HEADER:BOOL',
183+
self.args.enable_cxx_interop_swift_bridging_header)]
184+
179185
@property
180186
def _enable_experimental_distributed(self):
181187
return [('SWIFT_ENABLE_EXPERIMENTAL_DISTRIBUTED:BOOL',

utils/swift_build_support/tests/products/test_swift.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ def setUp(self):
5656
enable_experimental_differentiable_programming=False,
5757
enable_experimental_concurrency=False,
5858
enable_experimental_cxx_interop=False,
59+
enable_cxx_interop_swift_bridging_header=False,
5960
enable_experimental_distributed=False,
6061
enable_experimental_observation=False,
6162
swift_enable_backtracing=False,
@@ -98,6 +99,7 @@ def test_by_default_no_cmake_options(self):
9899
'-DSWIFT_ENABLE_EXPERIMENTAL_DIFFERENTIABLE_PROGRAMMING:BOOL=FALSE',
99100
'-DSWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY:BOOL=FALSE',
100101
'-DSWIFT_ENABLE_EXPERIMENTAL_CXX_INTEROP:BOOL=FALSE',
102+
'-DSWIFT_ENABLE_CXX_INTEROP_SWIFT_BRIDGING_HEADER:BOOL=FALSE',
101103
'-DSWIFT_ENABLE_EXPERIMENTAL_DISTRIBUTED:BOOL=FALSE',
102104
'-DSWIFT_ENABLE_EXPERIMENTAL_OBSERVATION:BOOL=FALSE',
103105
'-DSWIFT_ENABLE_BACKTRACING:BOOL=FALSE',
@@ -124,6 +126,7 @@ def test_swift_runtime_tsan(self):
124126
'-DSWIFT_ENABLE_EXPERIMENTAL_DIFFERENTIABLE_PROGRAMMING:BOOL=FALSE',
125127
'-DSWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY:BOOL=FALSE',
126128
'-DSWIFT_ENABLE_EXPERIMENTAL_CXX_INTEROP:BOOL=FALSE',
129+
'-DSWIFT_ENABLE_CXX_INTEROP_SWIFT_BRIDGING_HEADER:BOOL=FALSE',
127130
'-DSWIFT_ENABLE_EXPERIMENTAL_DISTRIBUTED:BOOL=FALSE',
128131
'-DSWIFT_ENABLE_EXPERIMENTAL_OBSERVATION:BOOL=FALSE',
129132
'-DSWIFT_ENABLE_BACKTRACING:BOOL=FALSE',
@@ -370,6 +373,18 @@ def test_experimental_cxx_interop_flags(self):
370373
[option for option in swift.cmake_options
371374
if 'DSWIFT_ENABLE_EXPERIMENTAL_CXX_INTEROP' in option])
372375

376+
def test_experimental_cxx_interop_bridging_header_flags(self):
377+
self.args.enable_cxx_interop_swift_bridging_header = True
378+
swift = Swift(
379+
args=self.args,
380+
toolchain=self.toolchain,
381+
source_dir='/path/to/src',
382+
build_dir='/path/to/build')
383+
self.assertEqual(
384+
['-DSWIFT_ENABLE_CXX_INTEROP_SWIFT_BRIDGING_HEADER:BOOL=TRUE'],
385+
[option for option in swift.cmake_options
386+
if 'DSWIFT_ENABLE_CXX_INTEROP_SWIFT_BRIDGING_HEADER' in option])
387+
373388
def test_experimental_distributed_flags(self):
374389
self.args.enable_experimental_distributed = True
375390
swift = Swift(

0 commit comments

Comments
 (0)