Skip to content

Commit 4c41849

Browse files
allevatoswiple-rules-gardener
authored andcommitted
Update the API of swift_common.compile_module_interface.
This adds the `target_name` argument that is present in other compile APIs so that supplemental outputs can get unique names based on the name of the Bazel target being compiled (will be used in a follow-up change). Likewise, this changes the return type of the function from just the module context to a `struct` that contains two fields: `module_context` (the original value), and `supplemental_outputs`, which will eventually be used to provide an indexstore (supported starting from Swift 6.2/Xcode 16.3). PiperOrigin-RevId: 741516048
1 parent 634d0d1 commit 4c41849

File tree

2 files changed

+33
-10
lines changed

2 files changed

+33
-10
lines changed

swift/internal/compiling.bzl

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ def compile_module_interface(
9999
swiftinterface_file,
100100
swift_infos,
101101
swift_toolchain,
102+
target_name, # @unused
102103
toolchain_type = SWIFT_TOOLCHAIN_TYPE):
103104
"""Compiles a Swift module interface.
104105
@@ -124,16 +125,30 @@ def compile_module_interface(
124125
swift_infos: A list of `SwiftInfo` providers from dependencies of the
125126
target being compiled.
126127
swift_toolchain: The `SwiftToolchainInfo` provider of the toolchain.
127-
toolchain_type: A toolchain type of the `swift_toolchain` which is used for
128-
the proper selection of the execution platform inside `run_toolchain_action`.
128+
target_name: The name of the target for which the interface is being
129+
compiled, which is used to determine unique file paths for the
130+
outputs.
131+
toolchain_type: A toolchain type of the `swift_toolchain` which is used
132+
for the proper selection of the execution platform inside
133+
`run_toolchain_action`.
129134
130135
Returns:
131-
A Swift module context (as returned by `create_swift_module_context`)
132-
that contains the Swift (and potentially C/Objective-C) compilation
133-
prerequisites of the compiled module. This should typically be
134-
propagated by a `SwiftInfo` provider of the calling rule, and the
135-
`CcCompilationContext` inside the Clang module substructure should be
136-
propagated by the `CcInfo` provider of the calling rule.
136+
A `struct` with the following fields:
137+
138+
* `module_context`: A Swift module context (as returned by
139+
`create_swift_module_context`) that contains the Swift (and
140+
potentially C/Objective-C) compilation prerequisites of the compiled
141+
module. This should typically be propagated by a `SwiftInfo`
142+
provider of the calling rule, and the `CcCompilationContext` inside
143+
the Clang module substructure should be propagated by the `CcInfo`
144+
provider of the calling rule.
145+
146+
* `supplemental_outputs`: A `struct` representing supplemental,
147+
optional outputs. Its fields are:
148+
149+
* `indexstore_directory`: A directory-type `File` that represents
150+
the indexstore output files created when the feature
151+
`swift.index_while_building` is enabled.
137152
"""
138153
swiftmodule_file = actions.declare_file("{}.swiftmodule".format(module_name))
139154

@@ -230,7 +245,13 @@ def compile_module_interface(
230245
),
231246
)
232247

233-
return module_context
248+
return struct(
249+
module_context = module_context,
250+
supplemental_outputs = struct(
251+
# TODO: b/401305010 - Generate indexstore when requested.
252+
indexstore_directory = None,
253+
),
254+
)
234255

235256
def compile(
236257
*,

swift/swift_import.bzl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,17 @@ def _swift_import_impl(ctx):
100100
swift_infos = get_providers(deps, SwiftInfo)
101101

102102
if swiftinterface and not swiftmodule:
103-
module_context = compile_module_interface(
103+
compile_result = compile_module_interface(
104104
actions = ctx.actions,
105105
compilation_contexts = get_compilation_contexts(ctx.attr.deps),
106106
feature_configuration = feature_configuration,
107107
module_name = ctx.attr.module_name,
108108
swiftinterface_file = swiftinterface,
109109
swift_infos = swift_infos,
110110
swift_toolchain = swift_toolchain,
111+
target_name = ctx.label.name,
111112
)
113+
module_context = compile_result.module_context
112114
swift_outputs = [
113115
module_context.swift.swiftmodule,
114116
] + compact([module_context.swift.swiftdoc])

0 commit comments

Comments
 (0)