Skip to content

Commit 004a738

Browse files
committed
[Build-Script]: Extend Swift cmake options
The existing swift-cmake-options flag overwrites all flags computed by build-script. Sometimes it is useful to be able to append additional CMake flags without overwriting the existing flags. This patch adds `--extra-swift-cmake-options` that adds the specified flags to the Swift CMake configuration instead of overwriting them. This also adds a similar `--extra-llvm-cmake-options`, which adds the new flags to the end, allowing one to replace and overwrite CMake flags that build-script computed. Due to the parameter passing mechanisms in build-script-impl, while this behavior would be useful for Swift, it is not immediately apparent how one would best implement this at this time.
1 parent 2838208 commit 004a738

File tree

6 files changed

+31
-8
lines changed

6 files changed

+31
-8
lines changed

utils/build-presets.ini

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3138,20 +3138,20 @@ build-swift-examples=0
31383138
build-runtime-with-host-compiler=0
31393139
build-swift-libexec=0
31403140
build-swift-remote-mirror=0
3141+
build-swift-static-sdk-overlay=0
3142+
build-swift-static-stdlib=0
3143+
enable-experimental-concurrency=1
3144+
enable-experimental-distributed=0
3145+
enable-experimental-observation=0
3146+
enable-experimental-differentiable-programming=0
31413147

3142-
extra-cmake-options=
3148+
extra-llvm-cmake-options=
31433149
-DLLVM_TARGETS_TO_BUILD=AArch64;X86
31443150

3145-
swift-cmake-options=
3146-
-DSWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY:BOOL=YES
3147-
-DSWIFT_ENABLE_EXPERIMENTAL_OBSERVATION:BOOL=NO
3148-
-DSWIFT_ENABLE_EXPERIMENTAL_DISTRIBUTED:BOOL=NO
3149-
-DSWIFT_ENABLE_EXPERIMENTAL_DIFFERENTIABLE_PROGRAMMING:BOOL=NO
3151+
extra-swift-cmake-options=
31503152
-DSWIFT_ENABLE_SWIFT_IN_SWIFT:BOOL=NO
31513153
-DSWIFT_INCLUDE_DOCS:BOOL=NO
31523154
-DSWIFT_BUILD_EXAMPLES:BOOL=OFF
3153-
-DSWIFT_BUILD_STATIC_SDK_OVERLAY:BOOL=NO
3154-
-DSWIFT_BUILD_STATIC_STDLIB:BOOL=NO
31553155

31563156
build-subdir=%(build_subdir)s
31573157
install-destdir=%(install_destdir)s

utils/build_swift/build_swift/driver_arguments.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,12 @@ def create_argument_parser():
592592
'will get little benefit from it (e.g. tools for '
593593
'bootstrapping or debugging Swift)')
594594

595+
option('--extra-swift-cmake-options', append,
596+
type=argparse.ShellSplitType(),
597+
help='Pass additional CMake options to the Swift build. '
598+
'Can be passed multiple times to add multiple options.',
599+
default=[])
600+
595601
option('--dsymutil-jobs', store_int,
596602
default=defaults.DSYMUTIL_JOBS,
597603
metavar='COUNT',
@@ -1403,6 +1409,13 @@ def create_argument_parser():
14031409
help='CMake options used for llvm in the form of comma '
14041410
'separated options "-DCMAKE_VAR1=YES,-DCMAKE_VAR2=/tmp". Can '
14051411
'be called multiple times to add multiple such options.')
1412+
option('--extra-llvm-cmake-options', append,
1413+
type=argparse.ShellSplitType(),
1414+
help='Pass additional CMake options to the LLVM build. '
1415+
'Can be passed multiple times to add multiple options. '
1416+
'These are the last arguments passed to CMake and can override '
1417+
'existing options.',
1418+
default=[])
14061419

14071420
option('--llvm-build-compiler-rt-with-use-runtimes', toggle_true, default=True,
14081421
help='Switch to LLVM_ENABLE_RUNTIMES as the mechanism to build compiler-rt'

utils/build_swift/tests/expected_options.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,9 @@
197197
'enable_ubsan': False,
198198
'export_compile_commands': False,
199199
'extra_cmake_options': [],
200+
'extra_llvm_cmake_options': [],
200201
'extra_swift_args': [],
202+
'extra_swift_cmake_options': [],
201203
'swift_debuginfo_non_lto_args': None,
202204
'force_optimized_typechecker': False,
203205
'foundation_build_variant': 'Debug',
@@ -803,6 +805,7 @@ class BuildScriptImplOption(_BaseOption):
803805
StrOption('--swift-darwin-module-archs'),
804806
StrOption('--swift-darwin-supported-archs'),
805807
SetTrueOption('--swift-freestanding-is-darwin'),
808+
AppendOption('--extra-swift-cmake-options'),
806809

807810
StrOption('--linux-archs'),
808811
StrOption('--linux-static-archs'),
@@ -853,6 +856,7 @@ class BuildScriptImplOption(_BaseOption):
853856
AppendOption('--llvm-ninja-targets'),
854857
AppendOption('--llvm-ninja-targets-for-cross-compile-hosts'),
855858
AppendOption('--llvm-cmake-options'),
859+
AppendOption('--extra-llvm-cmake-options'),
856860
EnableOption('--llvm-build-compiler-rt-with-use-runtimes'),
857861
AppendOption('--darwin-symroot-path-filters'),
858862

utils/swift_build_support/swift_build_support/products/llvm.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,7 @@ def build(self, host_target):
453453

454454
self.cmake_options.extend(host_config.cmake_options)
455455
self.cmake_options.extend(llvm_cmake_options)
456+
self.cmake_options.extend_raw(self.args.extra_llvm_cmake_options)
456457

457458
self._handle_cxx_headers(host_target, platform)
458459

utils/swift_build_support/swift_build_support/products/swift.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ def __init__(self, args, toolchain, source_dir, build_dir):
104104
self.cmake_options.extend(
105105
self._enable_new_runtime_build)
106106

107+
self.cmake_options.extend_raw(self.args.extra_swift_cmake_options)
108+
107109
@classmethod
108110
def product_source_name(cls):
109111
"""product_source_name() -> str

utils/swift_build_support/tests/products/test_swift.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ def setUp(self):
5252
benchmark_num_o_iterations=3,
5353
disable_guaranteed_normal_arguments=True,
5454
force_optimized_typechecker=False,
55+
extra_swift_cmake_options=["-DHELLO=YES"],
5556
enable_stdlibcore_exclusivity_checking=False,
5657
enable_experimental_differentiable_programming=False,
5758
enable_experimental_concurrency=False,
@@ -125,6 +126,7 @@ def test_by_default_no_cmake_options(self):
125126
'-USWIFT_DEBUGINFO_NON_LTO_ARGS',
126127
'-DSWIFT_STDLIB_BUILD_SYMBOL_GRAPHS:BOOL=FALSE',
127128
'-DSWIFT_ENABLE_NEW_RUNTIME_BUILD:BOOL=FALSE',
129+
'-DHELLO=YES',
128130
]
129131
self.assertEqual(set(swift.cmake_options), set(expected))
130132

@@ -161,6 +163,7 @@ def test_swift_runtime_tsan(self):
161163
'-USWIFT_DEBUGINFO_NON_LTO_ARGS',
162164
'-DSWIFT_STDLIB_BUILD_SYMBOL_GRAPHS:BOOL=FALSE',
163165
'-DSWIFT_ENABLE_NEW_RUNTIME_BUILD:BOOL=FALSE',
166+
'-DHELLO=YES',
164167
]
165168
self.assertEqual(set(swift.cmake_options), set(flags_set))
166169

0 commit comments

Comments
 (0)