Skip to content

Commit 2b6aef2

Browse files
allevatobrentleyjones
authored andcommitted
Allow swift_cross_import_overlay to specify a disambiguating explicit module name for the declaring and/or bystanding module
This can be used if either of those targets exports multiple modules. PiperOrigin-RevId: 665873940 (cherry picked from commit 8563c97) Signed-off-by: Brentley Jones <[email protected]>
1 parent 28419bc commit 2b6aef2

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

doc/rules.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,8 @@ using `swift_compiler_plugin`.
194194
## swift_cross_import_overlay
195195

196196
<pre>
197-
swift_cross_import_overlay(<a href="#swift_cross_import_overlay-name">name</a>, <a href="#swift_cross_import_overlay-deps">deps</a>, <a href="#swift_cross_import_overlay-bystanding_module">bystanding_module</a>, <a href="#swift_cross_import_overlay-declaring_module">declaring_module</a>)
197+
swift_cross_import_overlay(<a href="#swift_cross_import_overlay-name">name</a>, <a href="#swift_cross_import_overlay-deps">deps</a>, <a href="#swift_cross_import_overlay-bystanding_module">bystanding_module</a>, <a href="#swift_cross_import_overlay-bystanding_module_name">bystanding_module_name</a>, <a href="#swift_cross_import_overlay-declaring_module">declaring_module</a>,
198+
<a href="#swift_cross_import_overlay-declaring_module_name">declaring_module_name</a>)
198199
</pre>
199200

200201
Declares a cross-import overlay that will be automatically added as a dependency
@@ -227,7 +228,9 @@ the future, this rule is not recommended for other widespread use.
227228
| <a id="swift_cross_import_overlay-name"></a>name | A unique name for this target. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | |
228229
| <a id="swift_cross_import_overlay-deps"></a>deps | A non-empty list of targets representing modules that should be passed as dependencies when a target depends on both `declaring_module` and `bystanding_module`. | <a href="https://bazel.build/concepts/labels">List of labels</a> | required | |
229230
| <a id="swift_cross_import_overlay-bystanding_module"></a>bystanding_module | A label for the target representing the second of the two modules (the other being `declaring_module`) that must be imported for the cross-import overlay modules to be imported. It is completely passive in the cross-import process, having no definition with or other association to either the declaring module or the cross-import modules. | <a href="https://bazel.build/concepts/labels">Label</a> | required | |
231+
| <a id="swift_cross_import_overlay-bystanding_module_name"></a>bystanding_module_name | The name of the bystanding module from the target specified by the `bystanding_module` attribute. This is inferred if `bystanding_module` only exports a single direct module; this name must be specified if `bystanding_module` exports more than one. | String | optional | `""` |
230232
| <a id="swift_cross_import_overlay-declaring_module"></a>declaring_module | A label for the target representing the first of the two modules (the other being `bystanding_module`) that must be imported for the cross-import overlay modules to be imported. This is the module that contains the `.swiftcrossimport` overlay definition that connects it to the bystander and to the overlay modules. | <a href="https://bazel.build/concepts/labels">Label</a> | required | |
233+
| <a id="swift_cross_import_overlay-declaring_module_name"></a>declaring_module_name | The name of the declaring module from the target specified by the `declaring_module` attribute. This is inferred if `declaring_module` only exports a single direct module; this name must be specified if `declaring_module` exports more than one. | String | optional | `""` |
231234

232235

233236
<a id="swift_feature_allowlist"></a>

swift/swift_cross_import_overlay.bzl

+23-4
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,17 @@ load(":providers.bzl", "SwiftInfo")
1919

2020
def _get_sole_module_name(swift_info, attr):
2121
if len(swift_info.direct_modules) != 1:
22-
fail(("The target specified by '{}' must define exactly one Swift " +
23-
"and/or Clang module.").format(attr))
22+
fail(("The target specified by '{attr}' must define exactly one Swift " +
23+
"and/or Clang module, or you must specify '{attr}_name' to" +
24+
"disambiguate them.").format(attr = attr))
2425
return swift_info.direct_modules[0].name
2526

2627
def _swift_cross_import_overlay_impl(ctx):
27-
bystanding_module = _get_sole_module_name(
28+
bystanding_module = ctx.attr.bystanding_module_name or _get_sole_module_name(
2829
ctx.attr.bystanding_module[SwiftInfo],
2930
"bystanding_module",
3031
)
31-
declaring_module = _get_sole_module_name(
32+
declaring_module = ctx.attr.declaring_module_name or _get_sole_module_name(
3233
ctx.attr.declaring_module[SwiftInfo],
3334
"declaring_module",
3435
)
@@ -53,6 +54,15 @@ the cross-import modules.
5354
mandatory = True,
5455
providers = [[SwiftInfo]],
5556
),
57+
"bystanding_module_name": attr.string(
58+
doc = """\
59+
The name of the bystanding module from the target specified by the
60+
`bystanding_module` attribute. This is inferred if `bystanding_module` only
61+
exports a single direct module; this name must be specified if
62+
`bystanding_module` exports more than one.
63+
""",
64+
mandatory = False,
65+
),
5666
"declaring_module": attr.label(
5767
doc = """\
5868
A label for the target representing the first of the two modules (the other
@@ -63,6 +73,15 @@ overlay definition that connects it to the bystander and to the overlay modules.
6373
mandatory = True,
6474
providers = [[SwiftInfo]],
6575
),
76+
"declaring_module_name": attr.string(
77+
doc = """\
78+
The name of the declaring module from the target specified by the
79+
`declaring_module` attribute. This is inferred if `declaring_module` only
80+
exports a single direct module; this name must be specified if
81+
`declaring_module` exports more than one.
82+
""",
83+
mandatory = False,
84+
),
6685
"deps": attr.label_list(
6786
allow_empty = False,
6887
doc = """\

0 commit comments

Comments
 (0)