Skip to content

Commit

Permalink
Add -file-prefix-map support
Browse files Browse the repository at this point in the history
We can use -file-prefix-map instead of -debug-prefix-map starting in Xcode 14.
This has the main benefit of remapping debugging, indexing, and coverage paths, all with a single flag.

Keeping this opt-in for now, we'll test this out locally before a further rollout.

PiperOrigin-RevId: 477010867
(cherry picked from commit bead123)

Cherry-pick notes: we implemented this in 20d7d9d. This cherry-pick just adds a couple things from upstream’s versversion of the same change.

Signed-off-by: Brentley Jones <[email protected]>
  • Loading branch information
DavidGoldman authored and brentleyjones committed Oct 1, 2024
1 parent be8bc73 commit 3d0e490
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 8 deletions.
16 changes: 8 additions & 8 deletions swift/internal/feature_names.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ SWIFT_FEATURE_HEADERS_ALWAYS_ACTION_INPUTS = "swift.headers_always_action_inputs
# the note above about not depending on the C++ features.)
SWIFT_FEATURE_COVERAGE = "swift.coverage"

# If enabled, builds will use the `-file-prefix-map` feature to remap the
# current working directory to `.`, which avoids embedding non-hermetic
# absolute path information in build artifacts. Specifically what this flag
# does is subject to change in Swift, but it should imply all other
# `-*-prefix-map` flags. How those flags compose is potentially complicated, so
# using only this flag, or the same values for each flag, is recommended.
SWIFT_FEATURE_FILE_PREFIX_MAP = "swift.file_prefix_map"

# If enabled, debug builds will use the `-debug-prefix-map` feature to remap the
# current working directory to `.`, which permits debugging remote or sandboxed
# builds.
Expand All @@ -48,14 +56,6 @@ SWIFT_FEATURE_DEBUG_PREFIX_MAP = "swift.debug_prefix_map"
# of remote builds.
SWIFT_FEATURE_COVERAGE_PREFIX_MAP = "swift.coverage_prefix_map"

# If enabled, builds will use the `-file-prefix-map` feature to remap the
# current working directory to `.`, which avoids embedding non-hermetic
# absolute path information in build artifacts. Specifically what this flag
# does is subject to change in Swift, but it should imply all other
# `-*-prefix-map` flags. How those flags compose is potentially complicated, so
# using only this flag, or the same values for each flag, is recommended.
SWIFT_FEATURE_FILE_PREFIX_MAP = "swift.file_prefix_map"

# If enabled, C and Objective-C libraries that are direct or transitive
# dependencies of a Swift library will emit explicit precompiled modules that
# are compatible with Swift's ClangImporter and propagate them up the build
Expand Down
2 changes: 2 additions & 0 deletions swift/toolchains/config/compile_config.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -503,11 +503,13 @@ def compile_action_configs(
[SWIFT_FEATURE_DEBUG_PREFIX_MAP, SWIFT_FEATURE_FASTBUILD],
[SWIFT_FEATURE_DEBUG_PREFIX_MAP, SWIFT_FEATURE_FULL_DEBUG_INFO],
],
not_features = [SWIFT_FEATURE_FILE_PREFIX_MAP],
),
ActionConfigInfo(
actions = [
SWIFT_ACTION_COMPILE,
SWIFT_ACTION_DERIVE_FILES,
SWIFT_ACTION_PRECOMPILE_C_MODULE,
],
configurators = [
add_arg("-Xwrapped-swift=-file-prefix-pwd-is-dot"),
Expand Down
26 changes: 26 additions & 0 deletions test/debug_settings_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ DBG_CONFIG_SETTINGS = {
],
}

FILE_PREFIX_MAP_CONFIG_SETTINGS = {
"//command_line_option:compilation_mode": "dbg",
"//command_line_option:features": [
"swift.debug_prefix_map",
"swift.file_prefix_map",
],
}

CACHEABLE_DBG_CONFIG_SETTINGS = {
"//command_line_option:compilation_mode": "dbg",
"//command_line_option:features": [
Expand Down Expand Up @@ -74,6 +82,10 @@ dbg_action_command_line_test = make_action_command_line_test_rule(
config_settings = DBG_CONFIG_SETTINGS,
)

file_prefix_map_command_line_test = make_action_command_line_test_rule(
config_settings = FILE_PREFIX_MAP_CONFIG_SETTINGS,
)

cacheable_dbg_action_command_line_test = make_action_command_line_test_rule(
config_settings = CACHEABLE_DBG_CONFIG_SETTINGS,
)
Expand Down Expand Up @@ -133,6 +145,20 @@ def debug_settings_test_suite(name, tags = []):
target_under_test = "@build_bazel_rules_swift//test/fixtures/debug_settings:simple",
)

# Verify that the build is remapping paths with a file prefix map.
file_prefix_map_command_line_test(
name = "{}_file_prefix_map_build".format(name),
expected_argv = [
"-Xwrapped-swift=-file-prefix-pwd-is-dot",
],
not_expected_argv = [
"-Xwrapped-swift=-debug-prefix-pwd-is-dot",
],
mnemonic = "SwiftCompile",
tags = all_tags,
target_under_test = "@build_bazel_rules_swift//test/fixtures/debug_settings:simple",
)

# Verify that `-c dbg` builds with `swift.cacheable_modules` do NOT
# serialize debugging options, but are otherwise the same as regular `dbg`
# builds.
Expand Down
6 changes: 6 additions & 0 deletions tools/worker/swift_runner.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ extern bool ArgumentEnablesWMO(const std::string &arg);
// applied here because we do not know the current working directory at
// analysis time when the argument list is constructed.
//
// -Xwrapped-swift=-file-prefix-pwd-is-dot
// When specified, the Swift compiler will be directed to remap the current
// directory's path to the string "." in debug, coverage, and index info.
// This remapping must be applied here because we do not know the current
// working directory at analysis time when the argument list is constructed.
//
// -Xwrapped-swift=-ephemeral-module-cache
// When specified, the spawner will create a new temporary directory, pass
// that to the Swift compiler using `-module-cache-path`, and then delete
Expand Down

0 comments on commit 3d0e490

Please sign in to comment.