Skip to content

Commit 80ea837

Browse files
adincebicallevatoaaronsky
authored
Pass -file-compilation-dir . explicitly to the Swift driver so that .swiftmodule files are hermetic. (#1554)
Cherry pick: [9c4fbae](9c4fbae) --------- Co-authored-by: Tony Allevato <[email protected]> Co-authored-by: Aaron Sky <[email protected]>
1 parent 884a46e commit 80ea837

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

swift/internal/action_names.bzl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,10 @@ def all_action_names():
6262
SWIFT_ACTION_SYMBOL_GRAPH_EXTRACT,
6363
SWIFT_ACTION_SYNTHESIZE_INTERFACE,
6464
)
65+
66+
def all_compile_action_names():
67+
"""Returns all actions that compile source files."""
68+
return [
69+
SWIFT_ACTION_COMPILE,
70+
SWIFT_ACTION_COMPILE_MODULE_INTERFACE,
71+
]

swift/toolchains/config/compile_config.bzl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ load(
2626
"SWIFT_ACTION_PRECOMPILE_C_MODULE",
2727
"SWIFT_ACTION_SYMBOL_GRAPH_EXTRACT",
2828
"SWIFT_ACTION_SYNTHESIZE_INTERFACE",
29+
"all_compile_action_names",
2930
)
3031
load(
3132
"//swift/internal:developer_dirs.bzl",
@@ -642,6 +643,21 @@ def compile_action_configs(
642643
#### Flags controlling how Swift/Clang modular inputs are processed
643644

644645
action_configs += [
646+
647+
# When `-g` is passed to the compiler, the driver will pass
648+
# `-file-compilation-dir <CWD>` to the frontend, which in turn passes
649+
# `-ffile-compilation-dir <CWD>` to Clang. This CWD is fully resolved so
650+
# it contains the absolute path to the workspace. If we pass
651+
# `-file-compilation-dir .`, then the driver/frontend preserve that
652+
# spelling, ensuring that the ClangImporter options section of the
653+
# `.swiftmodule` file is hermetic.
654+
ActionConfigInfo(
655+
actions = all_compile_action_names(),
656+
configurators = [
657+
add_arg("-file-compilation-dir", "."),
658+
],
659+
),
660+
645661
# Treat paths in .modulemap files as workspace-relative, not modulemap-
646662
# relative.
647663
ActionConfigInfo(

0 commit comments

Comments
 (0)