Skip to content

Commit b042682

Browse files
committed
Add swift_disable_dead_stripping option for disabling dead stripping in Swift build
1 parent 13ffb8b commit b042682

File tree

7 files changed

+15
-4
lines changed

7 files changed

+15
-4
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@ endif()
171171
set(SWIFT_USE_LINKER ${SWIFT_USE_LINKER_default} CACHE STRING
172172
"Build Swift with a non-default linker")
173173

174+
option(SWIFT_DISABLE_DEAD_STRIPPING
175+
"Turn off Darwin-specific dead stripping for Swift host tools." FALSE)
176+
174177
set(SWIFT_TOOLS_ENABLE_LTO OFF CACHE STRING "Build Swift tools with LTO. One
175178
must specify the form of LTO by setting this to one of: 'full', 'thin'. This
176179
option only affects the tools that run on the host (the compiler), and has

cmake/modules/AddSwift.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,8 +380,8 @@ function(_add_host_variant_link_flags target)
380380
#
381381
# TODO: Evaluate/enable -f{function,data}-sections --gc-sections for bfd,
382382
# gold, and lld.
383-
if(NOT CMAKE_BUILD_TYPE STREQUAL Debug)
384-
if(CMAKE_SYSTEM_NAME MATCHES Darwin)
383+
if(NOT CMAKE_BUILD_TYPE STREQUAL Debug AND CMAKE_SYSTEM_NAME MATCHES Darwin)
384+
if (NOT SWIFT_DISABLE_DEAD_STRIPPING)
385385
# See rdar://48283130: This gives 6MB+ size reductions for swift and
386386
# SourceKitService, and much larger size reductions for sil-opt etc.
387387
target_link_options(${target} PRIVATE

docs/HowToGuides/GettingStarted.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,13 +246,13 @@ Phew, that's a lot to digest! Now let's proceed to the actual build itself!
246246
```sh
247247
utils/build-script --skip-build-benchmarks \
248248
--skip-ios --skip-watchos --skip-tvos --swift-darwin-supported-archs "$(uname -m)" \
249-
--sccache --release-debuginfo --test
249+
--sccache --release-debuginfo --swift-disable-dead-stripping --test
250250
```
251251
- Via Xcode:
252252
```sh
253253
utils/build-script --skip-build-benchmarks \
254254
--skip-ios --skip-watchos --skip-tvos --swift-darwin-supported-archs "$(uname -m)" \
255-
--sccache --release-debuginfo --test \
255+
--sccache --release-debuginfo --swift-disable-dead-stripping --test \
256256
--xcode
257257
```
258258
This will create a directory

utils/build-script

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,9 @@ class BuildScriptInvocation(object):
600600
impl_args += ["--skip-build"]
601601
if not args.build_benchmarks:
602602
impl_args += ["--skip-build-benchmarks"]
603+
604+
if args.swift_disable_dead_stripping:
605+
args.extra_cmake_options.append('-DSWIFT_DISABLE_DEAD_STRIPPING:BOOL=TRUE')
603606

604607
# Then add subproject install flags that either skip building them /or/
605608
# if we are going to build them and install_all is set, we also install

utils/build-script-impl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ KNOWN_SETTINGS=(
199199
swift-stdlib-single-threaded-runtime "0" "whether to build stdlib as a single-threaded runtime only"
200200
swift-stdlib-os-versioning "1" "whether to build stdlib with availability based on OS versions (Darwin only)"
201201
swift-stdlib-stable-abi "" "should stdlib be built with stable ABI, if not set defaults to true on Darwin, false otherwise"
202+
swift-disable-dead-stripping "0" "turns off Darwin-specific dead stripping for Swift host tools"
202203

203204
## FREESTANDING Stdlib Options
204205
swift-freestanding-sdk "" "which SDK to use when building the FREESTANDING stdlib"

utils/build_swift/build_swift/driver_arguments.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,9 @@ def create_argument_parser():
334334
default=defaults.SWIFT_ANALYZE_CODE_COVERAGE,
335335
help='enable code coverage analysis in Swift (false, not-merged, '
336336
'merged).')
337+
338+
option('--swift-disable-dead-stripping', toggle_true,
339+
help="Turn off Darwin-specific dead stripping for Swift host tools")
337340

338341
option('--build-subdir', store,
339342
metavar='PATH',

utils/build_swift/tests/expected_options.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@
202202
'swift_assertions': True,
203203
'swift_build_variant': 'Debug',
204204
'swift_compiler_version': None,
205+
'swift_disable_dead_stripping': False,
205206
'swift_darwin_module_archs': None,
206207
'swift_darwin_supported_archs': None,
207208
'swift_stdlib_assertions': True,

0 commit comments

Comments
 (0)