Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add -file-prefix-map support #1326

Merged
merged 1 commit into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
30 changes: 30 additions & 0 deletions test/debug_settings_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ DBG_CONFIG_SETTINGS = {
"//command_line_option:features": [
"-swift.cacheable_swiftmodules",
"swift.debug_prefix_map",
"-swift.file_prefix_map",
],
}

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

Expand All @@ -32,6 +41,7 @@ CACHEABLE_DBG_CONFIG_SETTINGS = {
"//command_line_option:features": [
"swift.cacheable_swiftmodules",
"swift.debug_prefix_map",
"-swift.file_prefix_map",
],
}

Expand All @@ -40,6 +50,7 @@ FASTBUILD_CONFIG_SETTINGS = {
"//command_line_option:features": [
"-swift.cacheable_swiftmodules",
"swift.debug_prefix_map",
"-swift.file_prefix_map",
],
}

Expand All @@ -48,6 +59,7 @@ FASTBUILD_FULL_DI_CONFIG_SETTINGS = {
"//command_line_option:features": [
"-swift.cacheable_swiftmodules",
"swift.debug_prefix_map",
"-swift.file_prefix_map",
"swift.full_debug_info",
],
}
Expand All @@ -74,6 +86,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 +149,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