Skip to content

Commit

Permalink
Add feature to prevent embedded build paths in swiftmodules
Browse files Browse the repository at this point in the history
  • Loading branch information
kastiglione committed Aug 27, 2019
1 parent 0192f16 commit b0bdd2a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
22 changes: 16 additions & 6 deletions swift/internal/api.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -262,12 +262,22 @@ def _compilation_mode_copts(feature_configuration):
flags.append("-whole-module-optimization")

elif is_dbg or is_fastbuild:
# The Swift compiler only serializes debugging options in narrow
# circumstances (for example, for application binaries). Since we almost
# exclusively just compile to object files directly, we need to manually
# pass the following frontend option to ensure that LLDB has the necessary
# import search paths to find definitions during debugging.
flags.extend(["-Onone", "-DDEBUG", "-Xfrontend", "-serialize-debugging-options"])
flags.extend(["-Onone", "-DDEBUG"])
if _is_enabled(
feature_configuration = feature_configuration,
feature_name = SWIFT_FEATURE_CACHEABLE_SWIFTMODULES,
):
# For a swiftmodule to be usable from cache, it must not contain embedded paths. This
# behavior must be explicitly disabled, because swiftc will enable this by default under
# some circumstances.
flags.extend(["-Xfrontend", "-no-serialize-debugging-options"])
else:
# The Swift compiler only serializes debugging options in narrow
# circumstances (for example, for application binaries). Since we almost
# exclusively just compile to object files directly, we need to manually
# pass the following frontend option to ensure that LLDB has the necessary
# import search paths to find definitions during debugging.
flags.extend(["-Xfrontend", "-serialize-debugging-options"])

if _is_enabled(
feature_configuration = feature_configuration,
Expand Down
9 changes: 9 additions & 0 deletions swift/internal/features.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,15 @@ SWIFT_FEATURE_USE_GLOBAL_MODULE_CACHE = "swift.use_global_module_cache"
# typically set this automatically if using a sufficiently recent version of Swift (4.2 or higher).
SWIFT_FEATURE_USE_RESPONSE_FILES = "swift.use_response_files"

# If enabled, builds using the "dbg" compilation mode will explicitly disable swiftc from producing
# swiftmodules containing embedded file paths, which are inherently non-portable across machines.
#
# To used these modules from lldb, target settings must be correctly populated. For example:
# target.swift-module-search-paths
# target.swift-framework-search-paths
# target.swift-extra-clang-flags
SWIFT_FEATURE_CACHEABLE_SWIFTMODULES = "swift.cacheable_swiftmodules"

def features_for_build_modes(ctx, objc_fragment = None):
"""Returns a list of Swift toolchain features corresponding to current build modes.
Expand Down

0 comments on commit b0bdd2a

Please sign in to comment.