Skip to content

Commit 36b589d

Browse files
Merge pull request #35538 from mininny/disable-dead-stripping-option
[build-script] Add swift-disable-dead-stripping option for disabling dead stripping
2 parents f9e3f29 + 16e635b commit 36b589d

File tree

8 files changed

+20
-4
lines changed

8 files changed

+20
-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
@@ -248,13 +248,13 @@ Phew, that's a lot to digest! Now let's proceed to the actual build itself!
248248
```sh
249249
utils/build-script --skip-build-benchmarks \
250250
--skip-ios --skip-watchos --skip-tvos --swift-darwin-supported-archs "$(uname -m)" \
251-
--sccache --release-debuginfo --test
251+
--sccache --release-debuginfo --swift-disable-dead-stripping --test
252252
```
253253
- Via Xcode:
254254
```sh
255255
utils/build-script --skip-build-benchmarks \
256256
--skip-ios --skip-watchos --skip-tvos --swift-darwin-supported-archs "$(uname -m)" \
257-
--sccache --release-debuginfo --test \
257+
--sccache --release-debuginfo --swift-disable-dead-stripping --test \
258258
--xcode
259259
```
260260
This will create a directory

utils/build-script

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,9 @@ class BuildScriptInvocation(object):
601601
if not args.build_benchmarks:
602602
impl_args += ["--skip-build-benchmarks"]
603603

604+
if args.swift_disable_dead_stripping:
605+
args.extra_cmake_options.append('-DSWIFT_DISABLE_DEAD_STRIPPING:BOOL=TRUE')
606+
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
606609
# them.

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
@@ -335,6 +335,9 @@ def create_argument_parser():
335335
help='enable code coverage analysis in Swift (false, not-merged, '
336336
'merged).')
337337

338+
option('--swift-disable-dead-stripping', toggle_true,
339+
help="Turn off Darwin-specific dead stripping for Swift host tools")
340+
338341
option('--build-subdir', store,
339342
metavar='PATH',
340343
help='name of the directory under $SWIFT_BUILD_ROOT where the '

utils/build_swift/tests/build_swift/test_driver_arguments.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,10 @@ def test_implied_defaults_host_test(self):
631631
self.assertFalse(namespace.test_android_host)
632632
self.assertFalse(namespace.build_libparser_only)
633633

634+
def test_implied_defaults_swift_disable_dead_stripping(self):
635+
namespace = self.parse_default_args(['--swift-disable-dead-stripping'])
636+
self.assertTrue(namespace.swift_disable_dead_stripping)
637+
634638
def test_build_lib_swiftsyntaxparser_only(self):
635639
namespace = self.parse_default_args(['--build-libparser-only'])
636640
self.assertTrue(namespace.build_libparser_only)

utils/build_swift/tests/expected_options.py

Lines changed: 2 additions & 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,
@@ -551,6 +552,7 @@ class BuildScriptImplOption(_BaseOption):
551552
EnableOption('--verbose-build'),
552553
EnableOption('--watchos'),
553554
EnableOption('--xctest', dest='build_xctest'),
555+
EnableOption('--swift-disable-dead-stripping'),
554556

555557
DisableOption('--skip-build-cmark', dest='build_cmark'),
556558
DisableOption('--skip-build-llvm', dest='build_llvm'),

0 commit comments

Comments
 (0)