Skip to content

Commit

Permalink
Enable swift.cacheable_swiftmodules by default (#957)
Browse files Browse the repository at this point in the history
  • Loading branch information
brentleyjones committed Dec 21, 2022
1 parent c7ed06e commit cb64a41
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 12 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ bazel run @build_bazel_rules_swift//tools/dump_toolchains
**Linux hosts:** At this time, Bazel uses whichever `swift` executable is
encountered first on your `PATH`.

## Supporting remote builds
## Supporting debugging

To make remote builds work correctly with debugging and general
reproducibility see [this doc](doc/debuggable_remote_swift.md)
To make cacheable builds work correctly with debugging see
[this doc](doc/debuggable_remote_swift.md).

## Swift Package Manager Support

Expand Down
16 changes: 7 additions & 9 deletions doc/debuggable_remote_swift.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Debuggable Remotely Built Swift
# Debugging Cacheable Swift Modules

This is a guide to using remotely built Swift modules in local debug builds.
This is a guide to enable debugging of cacheable Swift modules in local debug builds.

At the time of writing, `lldb` depends on debugging options embedded in `.swiftmodule` files. These options include paths that are only valid on the build host. For local builds, this all just works, but for remote builds, it doesn't.

Expand All @@ -13,15 +13,13 @@ Globally disabling debugging options makes those `.swiftmodule`s usable on any m

An lldb bug has been filed here: https://bugs.swift.org/browse/SR-11485

### Disable Debugging Options Globally

To globally disable debugging options, use the `swift.cacheable_swiftmodules` feature in rules_swift. For example, your `.bazelrc` could look like this:
> **Note**
>
> If you don't care about cache misses, instead of following this guide you can instead disable the `swift.cacheable_swiftmodules` feature: `--features=-swift.cacheable_swiftmodules`. This is not recommended though if you use a remote cache.
```
build --features=swift.cacheable_swiftmodules
```
### Disable Debugging Options Globally

What this does is ensure all modules are built explicitly with `-no-serialize-debugging-options`. It has to be explicit because `swiftc` enables `-serialize-debugging-options` in some cases.
To globally disable debugging options, use the `swift.cacheable_swiftmodules` feature, which is enabled by default, in rules_swift. What this does is ensure all modules are built explicitly with `-no-serialize-debugging-options`. It has to be explicit because `swiftc` enables `-serialize-debugging-options` in some cases.

### Add Debug Build Config

Expand Down
2 changes: 2 additions & 0 deletions swift/internal/swift_toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ load(":compiling.bzl", "compile_action_configs", "features_from_swiftcopts")
load(":debugging.bzl", "modulewrap_action_configs")
load(
":feature_names.bzl",
"SWIFT_FEATURE_CACHEABLE_SWIFTMODULES",
"SWIFT_FEATURE_MODULE_MAP_HOME_IS_CWD",
"SWIFT_FEATURE_NO_GENERATED_MODULE_MAP",
"SWIFT_FEATURE_OPT_USES_WMO",
Expand Down Expand Up @@ -284,6 +285,7 @@ def _swift_toolchain_impl(ctx):
features_from_swiftcopts(swiftcopts = ctx.fragments.swift.copts())
)
requested_features.extend([
SWIFT_FEATURE_CACHEABLE_SWIFTMODULES,
SWIFT_FEATURE_NO_GENERATED_MODULE_MAP,
SWIFT_FEATURE_OPT_USES_WMO,
SWIFT_FEATURE_USE_GLOBAL_MODULE_CACHE,
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 @@ -31,6 +31,7 @@ load(
"SWIFT_FEATURE_BITCODE_EMBEDDED",
"SWIFT_FEATURE_BITCODE_EMBEDDED_MARKERS",
"SWIFT_FEATURE_BUNDLED_XCTESTS",
"SWIFT_FEATURE_CACHEABLE_SWIFTMODULES",
"SWIFT_FEATURE_COVERAGE",
"SWIFT_FEATURE_COVERAGE_PREFIX_MAP",
"SWIFT_FEATURE_DEBUG_PREFIX_MAP",
Expand Down Expand Up @@ -607,6 +608,7 @@ def _xcode_swift_toolchain_impl(ctx):
)
requested_features.extend([
SWIFT_FEATURE_BUNDLED_XCTESTS,
SWIFT_FEATURE_CACHEABLE_SWIFTMODULES,
SWIFT_FEATURE_ENABLE_BATCH_MODE,
SWIFT_FEATURE_DEBUG_PREFIX_MAP,
SWIFT_FEATURE_OPT_USES_WMO,
Expand Down
4 changes: 4 additions & 0 deletions test/debug_settings_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ load(
DBG_CONFIG_SETTINGS = {
"//command_line_option:compilation_mode": "dbg",
"//command_line_option:features": [
"-swift.cacheable_swiftmodules",
"swift.debug_prefix_map",
],
}
Expand All @@ -37,13 +38,15 @@ CACHEABLE_DBG_CONFIG_SETTINGS = {
FASTBUILD_CONFIG_SETTINGS = {
"//command_line_option:compilation_mode": "fastbuild",
"//command_line_option:features": [
"-swift.cacheable_swiftmodules",
"swift.debug_prefix_map",
],
}

FASTBUILD_FULL_DI_CONFIG_SETTINGS = {
"//command_line_option:compilation_mode": "fastbuild",
"//command_line_option:features": [
"-swift.cacheable_swiftmodules",
"swift.debug_prefix_map",
"swift.full_debug_info",
],
Expand All @@ -52,6 +55,7 @@ FASTBUILD_FULL_DI_CONFIG_SETTINGS = {
OPT_CONFIG_SETTINGS = {
"//command_line_option:compilation_mode": "opt",
"//command_line_option:features": [
"-swift.cacheable_swiftmodules",
# This feature indicates *support*, not unconditional enablement, which
# is why it is present for `opt` mode as well.
"swift.debug_prefix_map",
Expand Down

0 comments on commit cb64a41

Please sign in to comment.