Skip to content

Commit

Permalink
Allow configuring clang module dependencies for precompiled c modules
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 516571440
(cherry picked from commit cda3e7f)
Signed-off-by: Brentley Jones <github@brentleyjones.com>
  • Loading branch information
Googler authored and brentleyjones committed Oct 7, 2024
1 parent 993c400 commit c91987f
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions swift/toolchains/config/compile_config.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ def compile_action_configs(
*,
additional_objc_copts = [],
additional_swiftc_copts = [],
configure_precompile_c_module_clang_modules = None,
generated_header_rewriter = None):
"""Returns the list of action configs needed to perform Swift compilation.
Expand All @@ -112,6 +113,10 @@ def compile_action_configs(
additional_swiftc_copts: An optional list of additional Swift compiler
flags that should be passed to Swift compile actions only after any
other toolchain- or user-provided flags.
configure_precompile_c_module_clang_modules: An optional function that
configures clang module dependencies for precompiled c modules if
present. Takes the configurator for clang module dependencies as an
argument, and returns a list of action configs. Defaults to None.
generated_header_rewriter: An executable that will be invoked after
compilation to rewrite the generated header, or None if this is not
desired.
Expand Down Expand Up @@ -878,7 +883,6 @@ def compile_action_configs(
SWIFT_ACTION_COMPILE_MODULE_INTERFACE,
SWIFT_ACTION_DERIVE_FILES,
SWIFT_ACTION_DUMP_AST,
SWIFT_ACTION_PRECOMPILE_C_MODULE,
SWIFT_ACTION_SYMBOL_GRAPH_EXTRACT,
],
configurators = [_dependencies_clang_modules_configurator],
Expand All @@ -898,6 +902,19 @@ def compile_action_configs(
),
])

if configure_precompile_c_module_clang_modules:
action_configs.extend(configure_precompile_c_module_clang_modules(
_dependencies_clang_modules_configurator,
))
else:
action_configs.append(ActionConfigInfo(
actions = [
SWIFT_ACTION_PRECOMPILE_C_MODULE,
],
configurators = [_dependencies_clang_modules_configurator],
features = [SWIFT_FEATURE_USE_C_MODULES],
))

#### Various other Swift compilation flags
action_configs += [
# Request color diagnostics, since Bazel pipes the output and causes the
Expand Down Expand Up @@ -1579,13 +1596,16 @@ def _dependencies_clang_modulemaps_configurator(prerequisites, args):
prefer_precompiled_modules = False,
)

def _dependencies_clang_modules_configurator(prerequisites, args):
def _dependencies_clang_modules_configurator(prerequisites, args, include_modules = True):
"""Configures precompiled Clang modules from dependencies."""
modules = [
module
for module in prerequisites.transitive_modules
if module.clang
]
if include_modules:
modules = [
module
for module in prerequisites.transitive_modules
if module.clang
]
else:
modules = []

# Uniquify the arguments because different modules might be defined in the
# same module map file, so it only needs to be present once on the command
Expand Down

0 comments on commit c91987f

Please sign in to comment.