Skip to content

Commit 293fb3c

Browse files
Simplify swift_library_group (#1292)
While working on something else I realized that the code for `swift_library_group` was more complex than it needed to be. Signed-off-by: Brentley Jones <[email protected]>
1 parent 66e5842 commit 293fb3c

File tree

3 files changed

+14
-54
lines changed

3 files changed

+14
-54
lines changed

doc/rules.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ need to import the grouped libraries directly.
429429
| Name | Description | Type | Mandatory | Default |
430430
| :------------- | :------------- | :------------- | :------------- | :------------- |
431431
| <a id="swift_library_group-name"></a>name | A unique name for this target. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | |
432-
| <a id="swift_library_group-deps"></a>deps | A list of targets that should be included in the group.<br><br>Allowed kinds of dependencies are:<br><br>* `swift_library` (or anything propagating `SwiftInfo`)<br><br>* `cc_library` (or anything propagating `CcInfo`)<br><br>Additionally, on platforms that support Objective-C interop, `objc_library` targets (or anything propagating the `apple_common.Objc` provider) are allowed as dependencies. On platforms that do not support Objective-C interop (such as Linux), those dependencies will be **ignored.** | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` |
432+
| <a id="swift_library_group-deps"></a>deps | A list of targets that should be included in the group. Allowed kinds of dependencies are:<br><br>* `swift_library` (or anything propagating `SwiftInfo`)<br><br>* `cc_library` (or anything propagating `CcInfo`)<br><br>Additionally, on platforms that support Objective-C interop, `objc_library` targets (or anything propagating the `apple_common.Objc` provider) are allowed as dependencies. On platforms that do not support Objective-C interop (such as Linux), those dependencies will be **ignored.** | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` |
433433

434434

435435
<a id="swift_module_alias"></a>

swift/BUILD

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,9 @@ bzl_library(
203203
deps = [
204204
":providers",
205205
":swift_clang_module_aspect",
206-
":swift_common",
207206
"//swift/internal:attrs",
208-
"//swift/internal:toolchain_utils",
207+
"//swift/internal:providers",
209208
"//swift/internal:utils",
210-
"@bazel_skylib//lib:dicts",
211209
],
212210
)
213211

swift/swift_library_group.bzl

Lines changed: 12 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -14,54 +14,25 @@
1414

1515
"""Implementation of the `swift_library_group` rule."""
1616

17-
load("@bazel_skylib//lib:dicts.bzl", "dicts")
18-
load("//swift/internal:attrs.bzl", "swift_deps_attr", "swift_toolchain_attrs")
19-
load("//swift/internal:toolchain_utils.bzl", "use_swift_toolchain")
17+
load("//swift/internal:attrs.bzl", "swift_deps_attr")
18+
load("//swift/internal:providers.bzl", "create_swift_info")
2019
load("//swift/internal:utils.bzl", "get_providers")
2120
load(":providers.bzl", "SwiftInfo")
2221
load(":swift_clang_module_aspect.bzl", "swift_clang_module_aspect")
23-
load(":swift_common.bzl", "swift_common")
2422

2523
def _swift_library_group_impl(ctx):
2624
deps = ctx.attr.deps
27-
deps_cc_infos = [
28-
dep[CcInfo]
29-
for dep in deps
30-
if CcInfo in dep
31-
]
32-
swift_toolchain = swift_common.get_toolchain(ctx)
3325

3426
return [
3527
DefaultInfo(),
36-
CcInfo(
37-
compilation_context = cc_common.merge_cc_infos(
38-
cc_infos = deps_cc_infos,
39-
).compilation_context,
40-
linking_context = cc_common.merge_linking_contexts(
41-
linking_contexts = [
42-
cc_info.linking_context
43-
for cc_info in (
44-
deps_cc_infos +
45-
swift_toolchain.implicit_deps_providers.cc_infos
46-
)
47-
] + [
48-
cc_common.create_linking_context(
49-
linker_inputs = depset(
50-
direct = [
51-
cc_common.create_linker_input(
52-
owner = ctx.label,
53-
),
54-
],
55-
),
56-
),
57-
],
58-
),
28+
cc_common.merge_cc_infos(
29+
cc_infos = [dep[CcInfo] for dep in deps if CcInfo in dep],
5930
),
6031
coverage_common.instrumented_files_info(
6132
ctx,
6233
dependency_attributes = ["deps"],
6334
),
64-
swift_common.create_swift_info(
35+
create_swift_info(
6536
swift_infos = get_providers(deps, SwiftInfo),
6637
),
6738
# Propagate an `apple_common.Objc` provider with linking info about the
@@ -70,25 +41,17 @@ def _swift_library_group_impl(ctx):
7041
# TODO(b/171413861): This can be removed when the Obj-C rules are
7142
# migrated to use `CcLinkingContext`.
7243
apple_common.new_objc_provider(
73-
providers = get_providers(
74-
deps,
75-
apple_common.Objc,
76-
) + swift_toolchain.implicit_deps_providers.objc_infos,
44+
providers = get_providers(deps, apple_common.Objc),
7745
),
7846
]
7947

8048
swift_library_group = rule(
81-
attrs = dicts.add(
82-
swift_toolchain_attrs(),
83-
{
84-
"deps": swift_deps_attr(
85-
aspects = [swift_clang_module_aspect],
86-
doc = """\
87-
A list of targets that should be included in the group.
88-
""",
89-
),
90-
},
91-
),
49+
attrs = {
50+
"deps": swift_deps_attr(
51+
aspects = [swift_clang_module_aspect],
52+
doc = "A list of targets that should be included in the group.",
53+
),
54+
},
9255
doc = """\
9356
Groups Swift compatible libraries (e.g. `swift_library` and `objc_library`).
9457
The target can be used anywhere a `swift_library` can be used. It behaves
@@ -98,5 +61,4 @@ Unlike `swift_module_alias`, a new module isn't created for this target, you
9861
need to import the grouped libraries directly.
9962
""",
10063
implementation = _swift_library_group_impl,
101-
toolchains = use_swift_toolchain(),
10264
)

0 commit comments

Comments
 (0)