Skip to content

Commit cc802a0

Browse files
allevatoswiple-rules-gardener
authored andcommitted
Rollback of commit fbe8272
*** Reason for rollback *** Broke some existing apps. *** Original change description *** Deprecate the `SwiftClangModuleInfo` provider. To lessen the number of providers that rules doing Swift compilation have to deal with, required C module maps are now being propagated in `SwiftInfo` rather than their own provider (the other three fields are obsolete thanks to `CcInfo`'s compilation context). This change retains the provider but moves it into an aspect that can be removed easily once the uses of it have been removed from Tulsi. RELNOTES: None. PiperOrigin-RevId: 247077488
1 parent e4f4743 commit cc802a0

14 files changed

+260
-211
lines changed

swift/internal/api.bzl

+4-9
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ _SANITIZER_FEATURE_FLAG_MAP = {
7575

7676
def _create_swift_info(
7777
defines = [],
78-
modulemaps = [],
7978
module_name = None,
8079
swiftdocs = [],
8180
swiftmodules = [],
@@ -94,8 +93,6 @@ def _create_swift_info(
9493
9594
Args:
9695
defines: A list of defines that will be provided as `copts` of the target being built.
97-
modulemaps: A list of module maps that should be passed to ClangImporter by any target
98-
that depends on the one propagating this provider.
9996
module_name: A string containing the name of the Swift module. If this is `None`, the
10097
provider does not represent a compiled module but rather a collection of modules (this
10198
happens, for example, with `proto_library` targets that have no sources of their own
@@ -113,12 +110,10 @@ def _create_swift_info(
113110
A new `SwiftInfo` provider with the given values.
114111
"""
115112
transitive_defines = []
116-
transitive_modulemaps = []
117113
transitive_swiftdocs = []
118114
transitive_swiftmodules = []
119115
for swift_info in swift_infos:
120116
transitive_defines.append(swift_info.transitive_defines)
121-
transitive_modulemaps.append(swift_info.transitive_modulemaps)
122117
transitive_swiftdocs.append(swift_info.transitive_swiftdocs)
123118
transitive_swiftmodules.append(swift_info.transitive_swiftmodules)
124119

@@ -129,7 +124,6 @@ def _create_swift_info(
129124
module_name = module_name,
130125
swift_version = swift_version,
131126
transitive_defines = depset(defines, transitive = transitive_defines),
132-
transitive_modulemaps = depset(modulemaps, transitive = transitive_modulemaps),
133127
transitive_swiftdocs = depset(swiftdocs, transitive = transitive_swiftdocs),
134128
transitive_swiftmodules = depset(swiftmodules, transitive = transitive_swiftmodules),
135129
)
@@ -449,7 +443,8 @@ def _compile(
449443
which affects the nature of the output files.
450444
defines: Symbols that should be defined by passing `-D` to the compiler.
451445
deps: Dependencies of the target being compiled. These targets must propagate one of the
452-
following providers: `CcInfo`, `SwiftInfo`, or `apple_common.Objc`.
446+
following providers: `CcInfo`, `SwiftClangModuleInfo`, `SwiftInfo`, or
447+
`apple_common.Objc`.
453448
genfiles_dir: The Bazel `*-genfiles` directory root. If provided, its path is added to
454449
ClangImporter's header search paths for compatibility with Bazel's C++ and Objective-C
455450
rules which support inclusions of generated headers from that location.
@@ -906,8 +901,8 @@ def _swiftc_command_line_and_inputs(
906901
requested, which affects the nature of the output files.
907902
defines: Symbols that should be defined by passing `-D` to the compiler.
908903
deps: Dependencies of the target being compiled. These targets must
909-
propagate one of the following providers: `CcInfo`, `SwiftInfo`, or
910-
`apple_common.Objc`.
904+
propagate one of the following providers: `CcInfo`,
905+
`SwiftClangModuleInfo`, `SwiftInfo`, or `apple_common.Objc`.
911906
genfiles_dir: The Bazel `*-genfiles` directory root. If provided, its path
912907
is added to ClangImporter's header search paths for compatibility with
913908
Bazel's C++ and Objective-C rules which support inclusions of generated

swift/internal/attrs.bzl

+6-5
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414

1515
"""Common attributes used by multiple Swift build rules."""
1616

17-
load(":legacy_swift_clang_module_info_aspect.bzl", "legacy_swift_clang_module_info_aspect")
18-
load(":providers.bzl", "SwiftInfo")
17+
load(":providers.bzl", "SwiftClangModuleInfo", "SwiftInfo")
1918

2019
def swift_common_rule_attrs(additional_deps_aspects = []):
2120
return {
@@ -30,13 +29,14 @@ binary or library, or other programs needed by it.
3029
""",
3130
),
3231
"deps": attr.label_list(
33-
aspects = [legacy_swift_clang_module_info_aspect] + additional_deps_aspects,
32+
aspects = additional_deps_aspects,
3433
doc = """
3534
A list of targets that are dependencies of the target being built, which will be
3635
linked into that target. Allowed kinds of dependencies are:
3736
38-
* `swift_c_module`, `swift_import` and `swift_library` (or anything propagating `SwiftInfo`)
39-
* `cc_library` (or anything propagating `CcInfo`)
37+
* `swift_c_module` (or anything propagating `SwiftClangModuleInfo`)
38+
* `swift_import` and `swift_library` (or anything propagating `SwiftInfo`)
39+
* `cc_library` (or anything propagating `CcInfo`)
4040
4141
Additionally, on platforms that support Objective-C interop, `objc_library`
4242
targets (or anything propagating the `apple_common.Objc` provider) are allowed
@@ -45,6 +45,7 @@ Linux), those dependencies will be **ignored.**
4545
""",
4646
providers = [
4747
[CcInfo],
48+
[SwiftClangModuleInfo],
4849
[SwiftInfo],
4950
[apple_common.Objc],
5051
],

swift/internal/compiling.bzl

+48-56
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@ load(
2222
)
2323
load(":actions.bzl", "run_toolchain_swift_action")
2424
load(":derived_files.bzl", "derived_files")
25-
load(":providers.bzl", "SwiftInfo")
25+
load(":providers.bzl", "SwiftClangModuleInfo", "SwiftInfo")
2626
load(
2727
":utils.bzl",
2828
"collect_cc_libraries",
29+
"collect_transitive",
2930
"get_providers",
3031
"objc_provider_framework_name",
3132
)
@@ -49,67 +50,58 @@ def collect_transitive_compile_inputs(args, deps, direct_defines = []):
4950
input_depsets = []
5051

5152
# Collect all the search paths, module maps, flags, and so forth from transitive dependencies.
52-
transitive_cc_defines = []
53-
transitive_cc_headers = []
54-
transitive_cc_includes = []
55-
transitive_cc_quote_includes = []
56-
transitive_cc_system_includes = []
57-
transitive_defines = []
58-
transitive_modulemaps = []
59-
transitive_swiftmodules = []
60-
for dep in deps:
61-
if SwiftInfo in dep:
62-
swift_info = dep[SwiftInfo]
63-
transitive_defines.append(swift_info.transitive_defines)
64-
transitive_modulemaps.append(swift_info.transitive_modulemaps)
65-
transitive_swiftmodules.append(swift_info.transitive_swiftmodules)
66-
if CcInfo in dep:
67-
compilation_context = dep[CcInfo].compilation_context
68-
transitive_cc_defines.append(compilation_context.defines)
69-
transitive_cc_headers.append(compilation_context.headers)
70-
transitive_cc_includes.append(compilation_context.includes)
71-
transitive_cc_quote_includes.append(compilation_context.quote_includes)
72-
transitive_cc_system_includes.append(compilation_context.system_includes)
73-
74-
# Add import paths for the directories containing dependencies' swiftmodules.
75-
all_swiftmodules = depset(transitive = transitive_swiftmodules)
76-
args.add_all(all_swiftmodules, format_each = "-I%s", map_each = _dirname_map_fn)
77-
input_depsets.append(all_swiftmodules)
78-
79-
# Pass Swift defines propagated by dependencies.
80-
all_defines = depset(direct_defines, transitive = transitive_defines)
81-
args.add_all(all_defines, format_each = "-D%s")
82-
83-
# Pass module maps from C/C++ dependencies to ClangImporter.
84-
# TODO(allevato): Will `CcInfo` eventually keep these in its compilation context?
85-
all_modulemaps = depset(transitive = transitive_modulemaps)
86-
input_depsets.append(all_modulemaps)
87-
args.add_all(all_modulemaps, before_each = "-Xcc", format_each = "-fmodule-map-file=%s")
88-
89-
# Add C++ headers from dependencies to the action inputs so the compiler can read them.
90-
input_depsets.append(depset(transitive = transitive_cc_headers))
91-
92-
# Pass any C++ defines and include search paths to ClangImporter.
93-
args.add_all(
94-
depset(transitive = transitive_cc_defines),
95-
before_each = "-Xcc",
96-
format_each = "-D%s",
53+
transitive_swiftmodules = collect_transitive(
54+
deps,
55+
SwiftInfo,
56+
"transitive_swiftmodules",
9757
)
98-
args.add_all(
99-
depset(transitive = transitive_cc_includes),
100-
before_each = "-Xcc",
101-
format_each = "-I%s",
58+
args.add_all(transitive_swiftmodules, format_each = "-I%s", map_each = _dirname_map_fn)
59+
input_depsets.append(transitive_swiftmodules)
60+
61+
transitive_defines = collect_transitive(
62+
deps,
63+
SwiftInfo,
64+
"transitive_defines",
65+
direct = direct_defines,
10266
)
103-
args.add_all(
104-
depset(transitive = transitive_cc_quote_includes),
105-
before_each = "-Xcc",
106-
format_each = "-iquote%s",
67+
args.add_all(transitive_defines, format_each = "-D%s")
68+
69+
transitive_modulemaps = collect_transitive(
70+
deps,
71+
SwiftClangModuleInfo,
72+
"transitive_modulemaps",
10773
)
74+
input_depsets.append(transitive_modulemaps)
10875
args.add_all(
109-
depset(transitive = transitive_cc_system_includes),
76+
transitive_modulemaps,
11077
before_each = "-Xcc",
111-
format_each = "-isystem%s",
78+
format_each = "-fmodule-map-file=%s",
79+
)
80+
81+
transitive_cc_headers = collect_transitive(
82+
deps,
83+
SwiftClangModuleInfo,
84+
"transitive_headers",
85+
)
86+
input_depsets.append(transitive_cc_headers)
87+
88+
transitive_cc_compile_flags = collect_transitive(
89+
deps,
90+
SwiftClangModuleInfo,
91+
"transitive_compile_flags",
92+
)
93+
94+
# Handle possible spaces in these arguments correctly (for example,
95+
# `-isystem foo`) by prepending `-Xcc` to each one.
96+
for arg in transitive_cc_compile_flags.to_list():
97+
args.add_all(arg.split(" "), before_each = "-Xcc")
98+
99+
transitive_cc_defines = collect_transitive(
100+
deps,
101+
SwiftClangModuleInfo,
102+
"transitive_defines",
112103
)
104+
args.add_all(transitive_cc_defines, before_each = "-Xcc", format_each = "-D%s")
113105

114106
return input_depsets
115107

swift/internal/legacy_swift_clang_module_info_aspect.bzl

-61
This file was deleted.

swift/internal/providers.bzl

+35-6
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414

1515
"""Defines Skylark providers that propagated by the Swift BUILD rules."""
1616

17+
load(":utils.bzl", "collect_transitive")
18+
1719
SwiftClangModuleInfo = provider(
1820
doc = """
1921
Contains information about a Clang module with relative paths that needs to be propagated up to
2022
other Swift compilation/link actions.
21-
22-
This provider is deprecated and will be removed in a future release.
2323
""",
2424
fields = {
2525
"transitive_compile_flags": """
@@ -78,10 +78,6 @@ was not set.
7878
"transitive_defines": """
7979
`Depset` of `string`s. The transitive `defines` specified for the library that propagated this
8080
provider and all of its dependencies.
81-
""",
82-
"transitive_modulemaps": """
83-
`Depset` of `File`s. The transitive module map files that will be passed to Clang using the
84-
`-fmodule-map-file` option.
8581
""",
8682
"transitive_swiftdocs": """
8783
`Depset` of `File`s. The transitive Swift documentation (`.swiftdoc`) files emitted by the library
@@ -224,3 +220,36 @@ The Swift toolchain that was used to build the targets propagating this provider
224220
""",
225221
},
226222
)
223+
224+
def merge_swift_clang_module_infos(targets):
225+
"""Merges transitive `SwiftClangModuleInfo` providers.
226+
227+
Args:
228+
targets: The targets whose `SwiftClangModuleInfo` providers should be merged.
229+
230+
Returns:
231+
A new `SwiftClangModuleInfo` that contains the transitive closure of all the
232+
`SwiftClangModuleInfo` providers of the given targets.
233+
"""
234+
return SwiftClangModuleInfo(
235+
transitive_compile_flags = collect_transitive(
236+
targets,
237+
SwiftClangModuleInfo,
238+
"transitive_compile_flags",
239+
),
240+
transitive_defines = collect_transitive(
241+
targets,
242+
SwiftClangModuleInfo,
243+
"transitive_defines",
244+
),
245+
transitive_headers = collect_transitive(
246+
targets,
247+
SwiftClangModuleInfo,
248+
"transitive_headers",
249+
),
250+
transitive_modulemaps = collect_transitive(
251+
targets,
252+
SwiftClangModuleInfo,
253+
"transitive_modulemaps",
254+
),
255+
)

swift/internal/swift_binary_test.bzl

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ load(":api.bzl", "swift_common")
2121
load(":derived_files.bzl", "derived_files")
2222
load(":features.bzl", "SWIFT_FEATURE_BUNDLED_XCTESTS")
2323
load(":linking.bzl", "register_link_executable_action")
24-
load(":non_swift_target_aspect.bzl", "non_swift_target_aspect")
2524
load(":providers.bzl", "SwiftToolchainInfo")
25+
load(":swift_c_module_aspect.bzl", "swift_c_module_aspect")
2626
load(":utils.bzl", "expand_locations")
2727

2828
# Attributes common to both `swift_binary` and `swift_test`.
2929
_BINARY_RULE_ATTRS = dicts.add(
30-
swift_common.compilation_attrs(additional_deps_aspects = [non_swift_target_aspect]),
30+
swift_common.compilation_attrs(additional_deps_aspects = [swift_c_module_aspect]),
3131
{
3232
"linkopts": attr.string_list(
3333
doc = """

0 commit comments

Comments
 (0)