Skip to content

Commit 40bbed1

Browse files
committed
build: enable control over the C++ interop modules
Treat the C++ interop modules similar to the Concurrency and StringProcessing modules, enabled through a top-level global flag. The flag now enables disabling the C++ interop modules when the standard library is built. Based on the original work by Egor Zhdan!
1 parent 0c0ec72 commit 40bbed1

File tree

7 files changed

+38
-3
lines changed

7 files changed

+38
-3
lines changed

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,10 @@ option(SWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY
605605
"Enable build of the Swift concurrency module"
606606
FALSE)
607607

608+
option(SWIFT_ENABLE_EXPERIMENTAL_CXX_INTEROP
609+
"Enable experimental C++ interop modules"
610+
FALSE)
611+
608612
option(SWIFT_ENABLE_EXPERIMENTAL_DISTRIBUTED
609613
"Enable experimental distributed actors and functions"
610614
FALSE)

stdlib/public/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ endif()
6565

6666
add_subdirectory(SwiftShims/swift/shims)
6767
add_subdirectory(CommandLineSupport)
68-
add_subdirectory(Cxx)
68+
if(SWIFT_ENABLE_EXPERIMENTAL_CXX_INTEROP)
69+
add_subdirectory(Cxx)
70+
endif()
6971
add_subdirectory(Threading)
7072

7173
# This static library is shared across swiftCore and swiftRemoteInspection

utils/build-windows-toolchain.bat

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ cmake ^
212212
-D LLVM_VERSION_SUFFIX="" ^
213213

214214
-D SWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY=YES ^
215+
-D SWIFT_ENABLE_EXPERIMENTAL_CXX_INTEROP=YES ^
215216
-D SWIFT_ENABLE_EXPERIMENTAL_DISTRIBUTED=YES ^
216217
-D SWIFT_ENABLE_EXPERIMENTAL_DIFFERENTIABLE_PROGRAMMING=YES ^
217218
-D SWIFT_ENABLE_EXPERIMENTAL_STRING_PROCESSING=YES ^
@@ -254,6 +255,7 @@ cmake ^
254255
-D SWIFT_PATH_TO_STRING_PROCESSING_SOURCE=%SourceRoot%\swift-experimental-string-processing ^
255256

256257
-D SWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY=YES ^
258+
-D SWIFT_ENABLE_EXPERIMENTAL_CXX_INTEROP=YES ^
257259
-D SWIFT_ENABLE_EXPERIMENTAL_DISTRIBUTED=YES ^
258260
-D SWIFT_ENABLE_EXPERIMENTAL_DIFFERENTIABLE_PROGRAMMING=YES ^
259261
-D SWIFT_ENABLE_EXPERIMENTAL_STRING_PROCESSING=YES ^

utils/build-windows.bat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ cmake^
262262
-DSWIFT_BUILD_SOURCEKIT:BOOL=YES^
263263
-DSWIFT_ENABLE_SOURCEKIT_TESTS:BOOL=YES^
264264
-DSWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY=YES^
265+
-DSWIFT_ENABLE_EXPERIMENTAL_CXX_INTEROP=YES^
265266
-DSWIFT_ENABLE_EXPERIMENTAL_DISTRIBUTED=YES^
266267
-DSWIFT_ENABLE_EXPERIMENTAL_DIFFERENTIABLE_PROGRAMMING=YES^
267268
-DSWIFT_ENABLE_EXPERIMENTAL_STRING_PROCESSING=YES^

utils/build_swift/build_swift/driver_arguments.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,10 +1321,13 @@ def create_argument_parser():
13211321
default=True,
13221322
help='Enable experimental Swift differentiable programming.')
13231323

1324-
option('--enable-experimental-concurrency', toggle_true,
1325-
default=True,
1324+
option('--enable-experimental-concurrency', toggle_true, default=True,
13261325
help='Enable experimental Swift concurrency model.')
13271326

1327+
option('--enable-experimental-cxx-interop', toggle_true,
1328+
default=True,
1329+
help='Enable experimental C++ interop.')
1330+
13281331
option('--enable-experimental-distributed', toggle_true,
13291332
default=True,
13301333
help='Enable experimental Swift distributed actors.')

utils/swift_build_support/swift_build_support/products/swift.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +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.
56+
self.cmake_options.extend(self._enable_experimental_cxx_interop)
57+
5558
# Add experimental distributed flag.
5659
self.cmake_options.extend(self._enable_experimental_distributed)
5760

@@ -168,6 +171,11 @@ def _enable_experimental_concurrency(self):
168171
return [('SWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY:BOOL',
169172
self.args.enable_experimental_concurrency)]
170173

174+
@property
175+
def _enable_experimental_cxx_interop(self):
176+
return [('SWIFT_ENABLE_EXPERIMENTAL_CXX_INTEROP:BOOL',
177+
self.args.enable_experimental_cxx_interop)]
178+
171179
@property
172180
def _enable_experimental_distributed(self):
173181
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
@@ -55,6 +55,7 @@ def setUp(self):
5555
enable_stdlibcore_exclusivity_checking=False,
5656
enable_experimental_differentiable_programming=False,
5757
enable_experimental_concurrency=False,
58+
enable_experimental_cxx_interop=False,
5859
enable_experimental_distributed=False,
5960
enable_experimental_observation=False,
6061
swift_enable_backtracing=False,
@@ -96,6 +97,7 @@ def test_by_default_no_cmake_options(self):
9697
'-DSWIFT_STDLIB_ENABLE_STDLIBCORE_EXCLUSIVITY_CHECKING:BOOL=FALSE',
9798
'-DSWIFT_ENABLE_EXPERIMENTAL_DIFFERENTIABLE_PROGRAMMING:BOOL=FALSE',
9899
'-DSWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY:BOOL=FALSE',
100+
'-DSWIFT_ENABLE_EXPERIMENTAL_CXX_INTEROP:BOOL=FALSE',
99101
'-DSWIFT_ENABLE_EXPERIMENTAL_DISTRIBUTED:BOOL=FALSE',
100102
'-DSWIFT_ENABLE_EXPERIMENTAL_OBSERVATION:BOOL=FALSE',
101103
'-DSWIFT_ENABLE_BACKTRACING:BOOL=FALSE',
@@ -121,6 +123,7 @@ def test_swift_runtime_tsan(self):
121123
'-DSWIFT_STDLIB_ENABLE_STDLIBCORE_EXCLUSIVITY_CHECKING:BOOL=FALSE',
122124
'-DSWIFT_ENABLE_EXPERIMENTAL_DIFFERENTIABLE_PROGRAMMING:BOOL=FALSE',
123125
'-DSWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY:BOOL=FALSE',
126+
'-DSWIFT_ENABLE_EXPERIMENTAL_CXX_INTEROP:BOOL=FALSE',
124127
'-DSWIFT_ENABLE_EXPERIMENTAL_DISTRIBUTED:BOOL=FALSE',
125128
'-DSWIFT_ENABLE_EXPERIMENTAL_OBSERVATION:BOOL=FALSE',
126129
'-DSWIFT_ENABLE_BACKTRACING:BOOL=FALSE',
@@ -355,6 +358,18 @@ def test_experimental_concurrency_flags(self):
355358
[x for x in swift.cmake_options
356359
if 'DSWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY' in x])
357360

361+
def test_experimental_cxx_interop_flags(self):
362+
self.args.enable_experimental_cxx_interop = True
363+
swift = Swift(
364+
args=self.args,
365+
toolchain=self.toolchain,
366+
source_dir='/path/to/src',
367+
build_dir='/path/to/build')
368+
self.assertEqual(
369+
['-DSWIFT_ENABLE_EXPERIMENTAL_CXX_INTEROP:BOOL=TRUE'],
370+
[option for option in swift.cmake_options
371+
if 'DSWIFT_ENABLE_EXPERIMENTAL_CXX_INTEROP' in option])
372+
358373
def test_experimental_distributed_flags(self):
359374
self.args.enable_experimental_distributed = True
360375
swift = Swift(

0 commit comments

Comments
 (0)