diff --git a/swift/internal/feature_names.bzl b/swift/internal/feature_names.bzl index de1d1fc18..7fbdc81fb 100644 --- a/swift/internal/feature_names.bzl +++ b/swift/internal/feature_names.bzl @@ -333,6 +333,12 @@ SWIFT_FEATURE_ENABLE_BARE_SLASH_REGEX = "swift.supports_bare_slash_regex" # Clang SPIs as Swift SPIs. SWIFT_FEATURE_DISABLE_CLANG_SPI = "swift.disable_clang_spi" +# If enabled, allow public symbols to be internalized at link time to support +# better dead-code stripping. This assumes that all clients of public types are +# part of the same link unit or that public symbols linked into frameworks are +# explicitly exported via `-exported_symbols_list`. +SWIFT_FEATURE_INTERNALIZE_AT_LINK = "swift.internalize_at_link" + # Disables Swift sandbox which prevents issues with nested sandboxing when Swift code contains system-provided macros. # If enabled '#Preview' macro provided by SwiftUI fails to build and probably other system-provided macros. # Enabled by default for Swift 5.10+ on macOS. diff --git a/swift/toolchains/config/compile_config.bzl b/swift/toolchains/config/compile_config.bzl index 9ad67c575..241dc9385 100644 --- a/swift/toolchains/config/compile_config.bzl +++ b/swift/toolchains/config/compile_config.bzl @@ -59,6 +59,7 @@ load( "SWIFT_FEATURE_GLOBAL_MODULE_CACHE_USES_TMPDIR", "SWIFT_FEATURE_INDEX_INCLUDE_LOCALS", "SWIFT_FEATURE_INDEX_WHILE_BUILDING", + "SWIFT_FEATURE_INTERNALIZE_AT_LINK", "SWIFT_FEATURE_LAYERING_CHECK", "SWIFT_FEATURE_MODULAR_INDEXING", "SWIFT_FEATURE_MODULE_MAP_HOME_IS_CWD", @@ -365,6 +366,13 @@ def compile_action_configs( ], ), + # Improve dead-code stripping. + ActionConfigInfo( + actions = [SWIFT_ACTION_COMPILE], + configurators = [add_arg("-Xfrontend", "-internalize-at-link")], + features = [SWIFT_FEATURE_INTERNALIZE_AT_LINK], + ), + # Enable or disable serialization of debugging options into # swiftmodules. ActionConfigInfo( diff --git a/swift/toolchains/swift_toolchain.bzl b/swift/toolchains/swift_toolchain.bzl index 8b724db6c..f43cbd306 100644 --- a/swift/toolchains/swift_toolchain.bzl +++ b/swift/toolchains/swift_toolchain.bzl @@ -55,6 +55,7 @@ load( "SWIFT_FEATURE_DISABLE_SYSTEM_INDEX", "SWIFT_FEATURE_EMIT_SWIFTDOC", "SWIFT_FEATURE_EMIT_SWIFTSOURCEINFO", + "SWIFT_FEATURE_INTERNALIZE_AT_LINK", "SWIFT_FEATURE_MODULE_MAP_HOME_IS_CWD", "SWIFT_FEATURE_NO_GENERATED_MODULE_MAP", "SWIFT_FEATURE_OPT_USES_WMO", @@ -469,6 +470,7 @@ def _swift_toolchain_impl(ctx): SWIFT_FEATURE_DISABLE_SYSTEM_INDEX, SWIFT_FEATURE_EMIT_SWIFTDOC, SWIFT_FEATURE_EMIT_SWIFTSOURCEINFO, + SWIFT_FEATURE_INTERNALIZE_AT_LINK, SWIFT_FEATURE_NO_GENERATED_MODULE_MAP, SWIFT_FEATURE_OPT_USES_WMO, SWIFT_FEATURE_USE_GLOBAL_MODULE_CACHE, diff --git a/swift/toolchains/xcode_swift_toolchain.bzl b/swift/toolchains/xcode_swift_toolchain.bzl index cb055a8b9..f5fb5877b 100644 --- a/swift/toolchains/xcode_swift_toolchain.bzl +++ b/swift/toolchains/xcode_swift_toolchain.bzl @@ -61,6 +61,7 @@ load( "SWIFT_FEATURE_ENABLE_BATCH_MODE", "SWIFT_FEATURE_ENABLE_SKIP_FUNCTION_BODIES", "SWIFT_FEATURE_FILE_PREFIX_MAP", + "SWIFT_FEATURE_INTERNALIZE_AT_LINK", "SWIFT_FEATURE_MODULE_MAP_HOME_IS_CWD", "SWIFT_FEATURE_OBJC_LINK_FLAGS", "SWIFT_FEATURE_OPT_USES_WMO", @@ -680,6 +681,7 @@ def _xcode_swift_toolchain_impl(ctx): SWIFT_FEATURE_ENABLE_BATCH_MODE, SWIFT_FEATURE_ENABLE_SKIP_FUNCTION_BODIES, SWIFT_FEATURE_FILE_PREFIX_MAP, + SWIFT_FEATURE_INTERNALIZE_AT_LINK, SWIFT_FEATURE_OBJC_LINK_FLAGS, SWIFT_FEATURE_OPT_USES_WMO, SWIFT_FEATURE_REMAP_XCODE_PATH,