From 27cfec733fe799a9ff806de0114cf1b027f222ea Mon Sep 17 00:00:00 2001 From: Tony Allevato Date: Tue, 29 Jul 2025 05:59:15 -0700 Subject: [PATCH 1/2] Pass `-file-compilation-dir .` explicitly to the Swift driver so that .swiftmodule files are hermetic. PiperOrigin-RevId: 788420859 (cherry picked from commit 9c4fbaedfaca0932cdca51f7d8b6e882890a727a) --- swift/toolchains/config/compile_config.bzl | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/swift/toolchains/config/compile_config.bzl b/swift/toolchains/config/compile_config.bzl index dffefc13d..781c81e2e 100644 --- a/swift/toolchains/config/compile_config.bzl +++ b/swift/toolchains/config/compile_config.bzl @@ -642,6 +642,21 @@ def compile_action_configs( #### Flags controlling how Swift/Clang modular inputs are processed action_configs += [ + + # When `-g` is passed to the compiler, the driver will pass + # `-file-compilation-dir ` to the frontend, which in turn passes + # `-ffile-compilation-dir ` to Clang. This CWD is fully resolved so + # it contains the absolute path to the workspace. If we pass + # `-file-compilation-dir .`, then the driver/frontend preserve that + # spelling, ensuring that the ClangImporter options section of the + # `.swiftmodule` file is hermetic. + ActionConfigInfo( + actions = all_compile_action_names(), + configurators = [ + add_arg("-file-compilation-dir", "."), + ], + ), + # Treat paths in .modulemap files as workspace-relative, not modulemap- # relative. ActionConfigInfo( From 1522eb3a22b0cb37493048f72e528c0e06bb7375 Mon Sep 17 00:00:00 2001 From: Adin Cebic Date: Wed, 30 Jul 2025 07:06:59 +0200 Subject: [PATCH 2/2] Add all_compile_action_names convenience function --- swift/internal/action_names.bzl | 7 +++++++ swift/toolchains/config/compile_config.bzl | 1 + 2 files changed, 8 insertions(+) diff --git a/swift/internal/action_names.bzl b/swift/internal/action_names.bzl index 35c1de354..c14ad507c 100644 --- a/swift/internal/action_names.bzl +++ b/swift/internal/action_names.bzl @@ -62,3 +62,10 @@ def all_action_names(): SWIFT_ACTION_SYMBOL_GRAPH_EXTRACT, SWIFT_ACTION_SYNTHESIZE_INTERFACE, ) + +def all_compile_action_names(): + """Returns all actions that compile source files.""" + return [ + SWIFT_ACTION_COMPILE, + SWIFT_ACTION_COMPILE_MODULE_INTERFACE, + ] diff --git a/swift/toolchains/config/compile_config.bzl b/swift/toolchains/config/compile_config.bzl index 781c81e2e..689fb155f 100644 --- a/swift/toolchains/config/compile_config.bzl +++ b/swift/toolchains/config/compile_config.bzl @@ -26,6 +26,7 @@ load( "SWIFT_ACTION_PRECOMPILE_C_MODULE", "SWIFT_ACTION_SYMBOL_GRAPH_EXTRACT", "SWIFT_ACTION_SYNTHESIZE_INTERFACE", + "all_compile_action_names", ) load( "//swift/internal:developer_dirs.bzl",