Skip to content

[build-script] Add swift-disable-dead-stripping option for disabling dead stripping #35538

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ endif()
set(SWIFT_USE_LINKER ${SWIFT_USE_LINKER_default} CACHE STRING
"Build Swift with a non-default linker")

option(SWIFT_DISABLE_DEAD_STRIPPING
"Turn off Darwin-specific dead stripping for Swift host tools." FALSE)

set(SWIFT_TOOLS_ENABLE_LTO OFF CACHE STRING "Build Swift tools with LTO. One
must specify the form of LTO by setting this to one of: 'full', 'thin'. This
option only affects the tools that run on the host (the compiler), and has
Expand Down
4 changes: 2 additions & 2 deletions cmake/modules/AddSwift.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,8 @@ function(_add_host_variant_link_flags target)
#
# TODO: Evaluate/enable -f{function,data}-sections --gc-sections for bfd,
# gold, and lld.
if(NOT CMAKE_BUILD_TYPE STREQUAL Debug)
if(CMAKE_SYSTEM_NAME MATCHES Darwin)
if(NOT CMAKE_BUILD_TYPE STREQUAL Debug AND CMAKE_SYSTEM_NAME MATCHES Darwin)
if (NOT SWIFT_DISABLE_DEAD_STRIPPING)
# See rdar://48283130: This gives 6MB+ size reductions for swift and
# SourceKitService, and much larger size reductions for sil-opt etc.
target_link_options(${target} PRIVATE
Expand Down
4 changes: 2 additions & 2 deletions docs/HowToGuides/GettingStarted.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,13 +246,13 @@ Phew, that's a lot to digest! Now let's proceed to the actual build itself!
```sh
utils/build-script --skip-build-benchmarks \
--skip-ios --skip-watchos --skip-tvos --swift-darwin-supported-archs "$(uname -m)" \
--sccache --release-debuginfo --test
--sccache --release-debuginfo --swift-disable-dead-stripping --test
```
- Via Xcode:
```sh
utils/build-script --skip-build-benchmarks \
--skip-ios --skip-watchos --skip-tvos --swift-darwin-supported-archs "$(uname -m)" \
--sccache --release-debuginfo --test \
--sccache --release-debuginfo --swift-disable-dead-stripping --test \
--xcode
```
This will create a directory
Expand Down
3 changes: 3 additions & 0 deletions utils/build-script
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,9 @@ class BuildScriptInvocation(object):
if not args.build_benchmarks:
impl_args += ["--skip-build-benchmarks"]

if args.swift_disable_dead_stripping:
args.extra_cmake_options.append('-DSWIFT_DISABLE_DEAD_STRIPPING:BOOL=TRUE')

# Then add subproject install flags that either skip building them /or/
# if we are going to build them and install_all is set, we also install
# them.
Expand Down
1 change: 1 addition & 0 deletions utils/build-script-impl
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ KNOWN_SETTINGS=(
swift-stdlib-single-threaded-runtime "0" "whether to build stdlib as a single-threaded runtime only"
swift-stdlib-os-versioning "1" "whether to build stdlib with availability based on OS versions (Darwin only)"
swift-stdlib-stable-abi "" "should stdlib be built with stable ABI, if not set defaults to true on Darwin, false otherwise"
swift-disable-dead-stripping "0" "turns off Darwin-specific dead stripping for Swift host tools"

## FREESTANDING Stdlib Options
swift-freestanding-sdk "" "which SDK to use when building the FREESTANDING stdlib"
Expand Down
3 changes: 3 additions & 0 deletions utils/build_swift/build_swift/driver_arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,9 @@ def create_argument_parser():
help='enable code coverage analysis in Swift (false, not-merged, '
'merged).')

option('--swift-disable-dead-stripping', toggle_true,
help="Turn off Darwin-specific dead stripping for Swift host tools")

option('--build-subdir', store,
metavar='PATH',
help='name of the directory under $SWIFT_BUILD_ROOT where the '
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,10 @@ def test_implied_defaults_host_test(self):
self.assertFalse(namespace.test_android_host)
self.assertFalse(namespace.build_libparser_only)

def test_implied_defaults_swift_disable_dead_stripping(self):
namespace = self.parse_default_args(['--swift-disable-dead-stripping'])
self.assertTrue(namespace.swift_disable_dead_stripping)

def test_build_lib_swiftsyntaxparser_only(self):
namespace = self.parse_default_args(['--build-libparser-only'])
self.assertTrue(namespace.build_libparser_only)
2 changes: 2 additions & 0 deletions utils/build_swift/tests/expected_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@
'swift_assertions': True,
'swift_build_variant': 'Debug',
'swift_compiler_version': None,
'swift_disable_dead_stripping': False,
'swift_darwin_module_archs': None,
'swift_darwin_supported_archs': None,
'swift_stdlib_assertions': True,
Expand Down Expand Up @@ -551,6 +552,7 @@ class BuildScriptImplOption(_BaseOption):
EnableOption('--verbose-build'),
EnableOption('--watchos'),
EnableOption('--xctest', dest='build_xctest'),
EnableOption('--swift-disable-dead-stripping'),

DisableOption('--skip-build-cmark', dest='build_cmark'),
DisableOption('--skip-build-llvm', dest='build_llvm'),
Expand Down