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

Allow configuring clang module dependencies for precompiled c modules #1351

Merged
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
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 @@ -887,7 +892,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 @@ -907,6 +911,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 @@ -1588,13 +1605,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