Skip to content

Commit

Permalink
Enable -wmo with opt by default (bazelbuild#910)
Browse files Browse the repository at this point in the history
This matches Xcode's behavior and has a huge impact on performance in
some cases.
  • Loading branch information
keith authored Sep 28, 2022
1 parent 1543999 commit a666936
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
7 changes: 6 additions & 1 deletion swift/internal/swift_toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ load(
":feature_names.bzl",
"SWIFT_FEATURE_MODULE_MAP_HOME_IS_CWD",
"SWIFT_FEATURE_NO_GENERATED_MODULE_MAP",
"SWIFT_FEATURE_OPT_USES_WMO",
"SWIFT_FEATURE_USE_AUTOLINK_EXTRACT",
"SWIFT_FEATURE_USE_MODULE_WRAP",
"SWIFT_FEATURE_USE_RESPONSE_FILES",
Expand Down Expand Up @@ -281,7 +282,11 @@ def _swift_toolchain_impl(ctx):
features_for_build_modes(ctx) +
features_from_swiftcopts(swiftcopts = ctx.fragments.swift.copts())
)
requested_features.append(SWIFT_FEATURE_NO_GENERATED_MODULE_MAP)
requested_features.extend([
SWIFT_FEATURE_NO_GENERATED_MODULE_MAP,
SWIFT_FEATURE_OPT_USES_WMO,
])

requested_features.extend(ctx.features)

# Swift.org toolchains assume everything is just available on the PATH so we
Expand Down
2 changes: 2 additions & 0 deletions swift/internal/xcode_swift_toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ load(
"SWIFT_FEATURE_ENABLE_SKIP_FUNCTION_BODIES",
"SWIFT_FEATURE_FILE_PREFIX_MAP",
"SWIFT_FEATURE_MODULE_MAP_HOME_IS_CWD",
"SWIFT_FEATURE_OPT_USES_WMO",
"SWIFT_FEATURE_REMAP_XCODE_PATH",
"SWIFT_FEATURE_SUPPORTS_BARE_SLASH_REGEX",
"SWIFT_FEATURE_SUPPORTS_LIBRARY_EVOLUTION",
Expand Down Expand Up @@ -608,6 +609,7 @@ def _xcode_swift_toolchain_impl(ctx):
SWIFT_FEATURE_ENABLE_BATCH_MODE,
SWIFT_FEATURE_USE_RESPONSE_FILES,
SWIFT_FEATURE_DEBUG_PREFIX_MAP,
SWIFT_FEATURE_OPT_USES_WMO,
SWIFT_FEATURE_SUPPORTS_LIBRARY_EVOLUTION,
SWIFT_FEATURE_SUPPORTS_PRIVATE_DEPS,
])
Expand Down
31 changes: 31 additions & 0 deletions test/features_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@ load(
)

default_test = make_action_command_line_test_rule()
default_opt_test = make_action_command_line_test_rule(
config_settings = {
"//command_line_option:compilation_mode": "opt",
},
)

opt_no_wmo_test = make_action_command_line_test_rule(
config_settings = {
"//command_line_option:compilation_mode": "opt",
"//command_line_option:features": [
"-swift.opt_uses_wmo",
],
},
)

file_prefix_map_test = make_action_command_line_test_rule(
config_settings = {
Expand Down Expand Up @@ -64,3 +78,20 @@ def features_test_suite(name):
mnemonic = "SwiftCompile",
target_under_test = "@build_bazel_rules_swift//test/fixtures/debug_settings:simple",
)

default_opt_test(
name = "{}_default_opt_test".format(name),
tags = [name],
expected_argv = ["-emit-object", "-O", "-whole-module-optimization"],
mnemonic = "SwiftCompile",
target_under_test = "@build_bazel_rules_swift//test/fixtures/debug_settings:simple",
)

opt_no_wmo_test(
name = "{}_opt_no_wmo_test".format(name),
tags = [name],
expected_argv = ["-emit-object", "-O"],
not_expected_argv = ["-whole-module-optimization"],
mnemonic = "SwiftCompile",
target_under_test = "@build_bazel_rules_swift//test/fixtures/debug_settings:simple",
)

0 comments on commit a666936

Please sign in to comment.