Skip to content

Commit

Permalink
Add cross-import overlay SwiftInfos to compilation prerequisites wh…
Browse files Browse the repository at this point in the history
…en needed

PiperOrigin-RevId: 491933710
(cherry picked from commit d4bb9bc)
Signed-off-by: Brentley Jones <github@brentleyjones.com>
  • Loading branch information
allevato authored and brentleyjones committed Oct 7, 2024
1 parent 7c91235 commit 6b55918
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion swift/internal/compiling.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,11 @@ def compile(
swift_infos = (
swift_infos +
private_swift_infos +
swift_toolchain.implicit_deps_providers.swift_infos
swift_toolchain.implicit_deps_providers.swift_infos +
_cross_imported_swift_infos(
swift_toolchain = swift_toolchain,
user_swift_infos = swift_infos + private_swift_infos,
)
),
)

Expand Down Expand Up @@ -1062,6 +1066,39 @@ def _create_cc_compilation_context(
transitive_compilation_contexts = compilation_contexts,
)

def _cross_imported_swift_infos(*, swift_toolchain, user_swift_infos):
"""Returns `SwiftInfo` providers for any cross-imported modules.
Args:
swift_toolchain: The `SwiftToolchainInfo` provider of the toolchain.
user_swift_infos: A list of `SwiftInfo` providers from regular and
private dependencies of the target being compiled. The direct
modules of these providers will be used to determine which
cross-import modules need to be implicitly added to the target's
compilation prerequisites, if any.
Returns:
A list of `SwiftInfo` providers representing cross-import overlays
needed for compilation.
"""
# Build a "set" containing the module names of direct dependencies so that
# we can do quicker hash-based lookups below.
direct_module_names = {}
for swift_info in user_swift_infos:
for module_context in swift_info.direct_modules:
direct_module_names[module_context.name] = True

# For each cross-import overlay registered with the toolchain, add its
# `SwiftInfo` providers to the list if both its declaring and bystanding
# modules were imported.
overlay_swift_infos = []
for overlay in swift_toolchain.cross_import_overlays:
if (overlay.declaring_module in direct_module_names and
overlay.bystanding_module in direct_module_names):
overlay_swift_infos.extend(overlay.swift_infos)

return overlay_swift_infos

def _declare_compile_outputs(
*,
actions,
Expand Down

0 comments on commit 6b55918

Please sign in to comment.