diff --git a/doc/providers.md b/doc/providers.md
index aa4860114..7292973fe 100644
--- a/doc/providers.md
+++ b/doc/providers.md
@@ -126,9 +126,9 @@ that use the toolchain.
| clang_implicit_deps_providers | A `struct` with the following fields, which represent providers from targets that should be added as implicit dependencies of any precompiled explicit C/Objective-C modules:
* `cc_infos`: A list of `CcInfo` providers from targets specified as the toolchain's implicit dependencies.
* `objc_infos`: A list of `apple_common.Objc` providers from targets specified as the toolchain's implicit dependencies.
* `swift_infos`: A list of `SwiftInfo` providers from targets specified as the toolchain's implicit dependencies.
For ease of use, this field is never `None`; it will always be a valid `struct` containing the fields described above, even if those lists are empty. |
| const_protocols_to_gather | `File`. A JSON file specifying a list of protocols for extraction of conformances' const values. |
| cross_import_overlays | A list of `SwiftCrossImportOverlayInfo` providers whose `SwiftInfo` providers will be automatically injected into the dependencies of Swift compilations if their declaring module and bystanding module are both already declared as dependencies. |
-| debug_outputs_provider | An optional function that provides toolchain-specific logic around the handling of additional debug outputs for `swift_binary` and `swift_test` targets. If specified, this function must take the following keyword arguments: * `ctx`: The rule context of the calling binary or test rule. It must return a `struct` with the following fields: * `additional_outputs`: Additional outputs expected from the linking action.
* `variables_extension`: A dictionary of additional crosstool variables to pass to the linking action. |
-| developer_dirs | A list of `structs` containing the following fields:* `developer_path_label`: A `string` representing the type of developer path. * `path`: A `string` representing the path to the developer framework. |
-| entry_point_linkopts_provider | A function that returns flags that should be passed to the linker to control the name of the entry point of a linked binary for rules that customize their entry point. This function must take the following keyword arguments: * `entry_point_name`: The name of the entry point function, as was passed to the Swift compiler using the `-entry-point-function-name` flag. It must return a `struct` with the following fields: * `linkopts`: A list of strings that will be passed as additional linker flags when linking a binary with a custom entry point. |
+| debug_outputs_provider | An optional function that provides toolchain-specific logic around the handling of additional debug outputs for `swift_binary` and `swift_test` targets.
If specified, this function must take the following keyword arguments:
* `ctx`: The rule context of the calling binary or test rule.
It must return a `struct` with the following fields:
* `additional_outputs`: Additional outputs expected from the linking action.
* `variables_extension`: A dictionary of additional crosstool variables to pass to the linking action. |
+| developer_dirs | A list of `structs` containing the following fields:
* `developer_path_label`: A `string` representing the type of developer path.
* `path`: A `string` representing the path to the developer framework. |
+| entry_point_linkopts_provider | A function that returns flags that should be passed to the linker to control the name of the entry point of a linked binary for rules that customize their entry point.
This function must take the following keyword arguments:
* `entry_point_name`: The name of the entry point function, as was passed to the Swift compiler using the `-entry-point-function-name` flag.
It must return a `struct` with the following fields:
* `linkopts`: A list of strings that will be passed as additional linker flags when linking a binary with a custom entry point. |
| feature_allowlists | A list of `SwiftFeatureAllowlistInfo` providers that allow or prohibit packages from requesting or disabling features. |
| generated_header_module_implicit_deps_providers | A `struct` with the following fields, which are providers from targets that should be treated as compile-time inputs to actions that precompile the explicit module for the generated Objective-C header of a Swift module:
* `cc_infos`: A list of `CcInfo` providers from targets specified as the toolchain's implicit dependencies.
* `objc_infos`: A list of `apple_common.Objc` providers from targets specified as the toolchain's implicit dependencies.
* `swift_infos`: A list of `SwiftInfo` providers from targets specified as the toolchain's implicit dependencies.
This is used to provide modular dependencies for the fixed inclusions (Darwin, Foundation) that are unconditionally emitted in those files.
For ease of use, this field is never `None`; it will always be a valid `struct` containing the fields described above, even if those lists are empty. |
| implicit_deps_providers | A `struct` with the following fields, which represent providers from targets that should be added as implicit dependencies of any Swift compilation or linking target (but not to precompiled explicit C/Objective-C modules):
* `cc_infos`: A list of `CcInfo` providers from targets specified as the toolchain's implicit dependencies.
* `objc_infos`: A list of `apple_common.Objc` providers from targets specified as the toolchain's implicit dependencies.
* `swift_infos`: A list of `SwiftInfo` providers from targets specified as the toolchain's implicit dependencies.
For ease of use, this field is never `None`; it will always be a valid `struct` containing the fields described above, even if those lists are empty. |
diff --git a/swift/BUILD b/swift/BUILD
index 33fc6d4aa..71c222d7f 100644
--- a/swift/BUILD
+++ b/swift/BUILD
@@ -62,6 +62,7 @@ bzl_library(
"//swift/internal:compiling",
"//swift/internal:feature_names",
"//swift/internal:linking",
+ "//swift/internal:providers",
"//swift/internal:toolchain_utils",
"//swift/internal:utils",
"@bazel_skylib//lib:dicts",
@@ -189,6 +190,7 @@ bzl_library(
"//swift/internal:features",
"//swift/internal:linking",
"//swift/internal:output_groups",
+ "//swift/internal:providers",
"//swift/internal:toolchain_utils",
"//swift/internal:utils",
"@bazel_skylib//lib:dicts",
@@ -270,9 +272,9 @@ bzl_library(
"//swift/internal:compiling",
"//swift/internal:env_expansion",
"//swift/internal:feature_names",
- "//swift/internal:features",
"//swift/internal:linking",
"//swift/internal:output_groups",
+ "//swift/internal:providers",
"//swift/internal:swift_symbol_graph_aspect",
"//swift/internal:symbol_graph_extracting",
"//swift/internal:toolchain_utils",
diff --git a/swift/internal/attrs.bzl b/swift/internal/attrs.bzl
index 07daab30e..f3b33bc90 100644
--- a/swift/internal/attrs.bzl
+++ b/swift/internal/attrs.bzl
@@ -15,7 +15,8 @@
"""Common attributes used by multiple Swift build rules."""
load("@bazel_skylib//lib:dicts.bzl", "dicts")
-load("//swift:providers.bzl", "SwiftCompilerPluginInfo", "SwiftInfo")
+load("//swift:providers.bzl", "SwiftInfo")
+load(":providers.bzl", "SwiftCompilerPluginInfo")
def swift_common_rule_attrs(
additional_deps_aspects = [],
diff --git a/swift/internal/compiling.bzl b/swift/internal/compiling.bzl
index f286a55f6..de7e9856d 100644
--- a/swift/internal/compiling.bzl
+++ b/swift/internal/compiling.bzl
@@ -622,7 +622,7 @@ def compile(
used_plugins = list(plugins)
for module_context in transitive_modules:
if module_context.swift and module_context.swift.plugins:
- used_plugins.extend(module_context.swift.plugins.to_list())
+ used_plugins.extend(module_context.swift.plugins)
if include_dev_srch_paths != None and is_test != None:
fail("""\
@@ -659,7 +659,7 @@ to use swift_common.compile(include_dev_srch_paths = ...) instead.\
objc_info = merged_objc_info,
original_module_name = original_module_name,
package_name = package_name,
- plugins = depset(used_plugins),
+ plugins = used_plugins,
source_files = srcs,
target_label = feature_configuration._label,
transitive_modules = transitive_modules,
@@ -793,7 +793,7 @@ to use swift_common.compile(include_dev_srch_paths = ...) instead.\
generated_header = compile_outputs.generated_header_file,
indexstore = compile_outputs.indexstore_directory,
original_module_name = original_module_name,
- plugins = depset(plugins),
+ plugins = plugins,
private_swiftinterface = compile_outputs.private_swiftinterface_file,
swiftdoc = compile_outputs.swiftdoc_file,
swiftinterface = compile_outputs.swiftinterface_file,
diff --git a/swift/internal/providers.bzl b/swift/internal/providers.bzl
index 089634ba1..aea89b105 100644
--- a/swift/internal/providers.bzl
+++ b/swift/internal/providers.bzl
@@ -14,6 +14,29 @@
"""Internal providers."""
+SwiftCompilerPluginInfo = provider(
+ doc = "Information about compiler plugins, like macros.",
+ fields = {
+ "cc_info": """\
+A `CcInfo` provider containing the `swift_compiler_plugin`'s code compiled as a
+static library, which is suitable for linking into a `swift_test` so that unit
+tests can be written against it.
+""",
+ "executable": "A `File` representing the plugin's binary executable.",
+ "module_names": """\
+A `depset` of strings denoting the names of the Swift modules that provide
+plugin types looked up by the compiler. This currently contains a single
+element, the name of the module created by the `swift_compiler_plugin` target.
+""",
+ "swift_info": """\
+A `SwiftInfo` provider representing the Swift module created by the
+`swift_compiler_plugin` target. This is used specifically by `swift_test` to
+allow test code to depend on the plugin's module without making it possible for
+arbitrary libraries/binaries to depend on a plugin.
+""",
+ },
+)
+
SwiftCrossImportOverlayInfo = provider(
doc = "Information about a cross-import overlay module.",
fields = {
diff --git a/swift/providers.bzl b/swift/providers.bzl
index cd628f3fd..d7afd7f0a 100644
--- a/swift/providers.bzl
+++ b/swift/providers.bzl
@@ -20,29 +20,6 @@ to the rule implementations do not unnecessarily cause reanalysis impacting
users who just load these providers to inspect and/or repropagate them.
"""
-SwiftCompilerPluginInfo = provider(
- doc = "Information about compiler plugins, like macros.",
- fields = {
- "cc_info": """\
-A `CcInfo` provider containing the `swift_compiler_plugin`'s code compiled as a
-static library, which is suitable for linking into a `swift_test` so that unit
-tests can be written against it.
-""",
- "executable": "A `File` representing the plugin's binary executable.",
- "module_names": """\
-A `depset` of strings denoting the names of the Swift modules that provide
-plugin types looked up by the compiler. This currently contains a single
-element, the name of the module created by the `swift_compiler_plugin` target.
-""",
- "swift_info": """\
-A `SwiftInfo` provider representing the Swift module created by the
-`swift_compiler_plugin` target. This is used specifically by `swift_test` to
-allow test code to depend on the plugin's module without making it possible for
-arbitrary libraries/binaries to depend on a plugin.
-""",
- },
-)
-
SwiftFeatureAllowlistInfo = provider(
doc = """\
Describes a set of features and the packages and aspects that are allowed to
@@ -296,27 +273,37 @@ dependencies.
"debug_outputs_provider": """\
An optional function that provides toolchain-specific logic around the handling
of additional debug outputs for `swift_binary` and `swift_test` targets.
+
If specified, this function must take the following keyword arguments:
+
* `ctx`: The rule context of the calling binary or test rule.
+
It must return a `struct` with the following fields:
+
* `additional_outputs`: Additional outputs expected from the linking action.
* `variables_extension`: A dictionary of additional crosstool variables to
pass to the linking action.
""",
- "developer_dirs": """
-A list of `structs` containing the following fields:\
+ "developer_dirs": """\
+A list of `structs` containing the following fields:
+
* `developer_path_label`: A `string` representing the type of developer path.
+
* `path`: A `string` representing the path to the developer framework.
""",
"entry_point_linkopts_provider": """\
A function that returns flags that should be passed to the linker to control the
name of the entry point of a linked binary for rules that customize their entry
point.
+
This function must take the following keyword arguments:
+
* `entry_point_name`: The name of the entry point function, as was passed to
the Swift compiler using the `-entry-point-function-name` flag.
+
It must return a `struct` with the following fields:
+
* `linkopts`: A list of strings that will be passed as additional linker flags
when linking a binary with a custom entry point.
""",
@@ -602,7 +589,7 @@ def create_swift_module_inputs(
defines = tuple(defines),
generated_header = generated_header,
indexstore = indexstore,
- plugins = plugins,
+ plugins = tuple(plugins),
private_swiftinterface = private_swiftinterface,
original_module_name = original_module_name,
swiftdoc = swiftdoc,
diff --git a/swift/swift_binary.bzl b/swift/swift_binary.bzl
index 49c4772ed..5fe06f3d7 100644
--- a/swift/swift_binary.bzl
+++ b/swift/swift_binary.bzl
@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-"""Implementation of the `swift_binary` and `swift_test` rules."""
+"""Implementation of the `swift_binary` rule."""
load("@bazel_skylib//lib:dicts.bzl", "dicts")
load("@bazel_skylib//lib:paths.bzl", "paths")
@@ -33,6 +33,7 @@ load(
"//swift/internal:output_groups.bzl",
"supplemental_compilation_output_groups",
)
+load("//swift/internal:providers.bzl", "SwiftCompilerPluginInfo")
load(
"//swift/internal:toolchain_utils.bzl",
"get_swift_toolchain",
@@ -45,12 +46,7 @@ load(
"include_developer_search_paths",
)
load(":module_name.bzl", "derive_swift_module_name")
-load(
- ":providers.bzl",
- "SwiftCompilerPluginInfo",
- "SwiftInfo",
- "create_swift_module_context",
-)
+load(":providers.bzl", "SwiftInfo", "create_swift_module_context")
def _maybe_parse_as_library_copts(srcs):
"""Returns a list of compiler flags depending on `main.swift`'s presence.
diff --git a/swift/swift_compiler_plugin.bzl b/swift/swift_compiler_plugin.bzl
index b499de3fe..c0c4ac7ee 100644
--- a/swift/swift_compiler_plugin.bzl
+++ b/swift/swift_compiler_plugin.bzl
@@ -39,6 +39,7 @@ load(
"//swift/internal:output_groups.bzl",
"supplemental_compilation_output_groups",
)
+load("//swift/internal:providers.bzl", "SwiftCompilerPluginInfo")
load(
"//swift/internal:toolchain_utils.bzl",
"get_swift_toolchain",
@@ -50,7 +51,7 @@ load(
"get_providers",
)
load(":module_name.bzl", "derive_swift_module_name")
-load(":providers.bzl", "SwiftCompilerPluginInfo", "SwiftInfo")
+load(":providers.bzl", "SwiftInfo")
def _swift_compiler_plugin_impl(ctx):
swift_toolchain = get_swift_toolchain(ctx)
@@ -112,6 +113,17 @@ def _swift_compiler_plugin_impl(ctx):
compilation_outputs = compile_result.compilation_outputs
supplemental_outputs = compile_result.supplemental_outputs
+ # Apply the optional debugging outputs extension if the toolchain defines
+ # one.
+ debug_outputs_provider = swift_toolchain.debug_outputs_provider
+ if debug_outputs_provider:
+ debug_extension = debug_outputs_provider(ctx = ctx)
+ additional_debug_outputs = debug_extension.additional_outputs
+ variables_extension = debug_extension.variables_extension
+ else:
+ additional_debug_outputs = []
+ variables_extension = {}
+
if is_feature_enabled(
feature_configuration = feature_configuration,
feature_name = SWIFT_FEATURE_ADD_TARGET_NAME_TO_OUTPUT,
@@ -125,6 +137,7 @@ def _swift_compiler_plugin_impl(ctx):
actions = ctx.actions,
additional_inputs = ctx.files.swiftc_inputs,
additional_linking_contexts = [malloc_linking_context(ctx)],
+ additional_outputs = additional_debug_outputs,
compilation_outputs = compilation_outputs,
deps = deps,
feature_configuration = feature_configuration,
@@ -145,6 +158,7 @@ def _swift_compiler_plugin_impl(ctx):
entry_point_name = entry_point_function_name,
).linkopts
),
+ variables_extension = variables_extension,
)
linking_context, _ = (
@@ -170,7 +184,9 @@ def _swift_compiler_plugin_impl(ctx):
return [
DefaultInfo(
executable = binary_linking_outputs.executable,
- files = depset([binary_linking_outputs.executable]),
+ files = depset(
+ [binary_linking_outputs.executable] + additional_debug_outputs,
+ ),
runfiles = ctx.runfiles(
collect_data = True,
collect_default = True,
diff --git a/swift/swift_library.bzl b/swift/swift_library.bzl
index 001db2cec..10e0abde7 100644
--- a/swift/swift_library.bzl
+++ b/swift/swift_library.bzl
@@ -44,6 +44,7 @@ load(
"//swift/internal:output_groups.bzl",
"supplemental_compilation_output_groups",
)
+load("//swift/internal:providers.bzl", "SwiftCompilerPluginInfo")
load(
"//swift/internal:toolchain_utils.bzl",
"get_swift_toolchain",
@@ -58,7 +59,7 @@ load(
"include_developer_search_paths",
)
load(":module_name.bzl", "derive_swift_module_name")
-load(":providers.bzl", "SwiftCompilerPluginInfo", "SwiftInfo")
+load(":providers.bzl", "SwiftInfo")
load(":swift_clang_module_aspect.bzl", "swift_clang_module_aspect")
def _maybe_parse_as_library_copts(srcs):
diff --git a/swift/swift_test.bzl b/swift/swift_test.bzl
index cb0e3b323..70b9047b6 100644
--- a/swift/swift_test.bzl
+++ b/swift/swift_test.bzl
@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-"""Implementation of the `swift_binary` and `swift_test` rules."""
+"""Implementation of the `swift_test` rule."""
load("@bazel_skylib//lib:dicts.bzl", "dicts")
load("@bazel_skylib//lib:paths.bzl", "paths")
@@ -34,6 +34,7 @@ load(
"//swift/internal:output_groups.bzl",
"supplemental_compilation_output_groups",
)
+load("//swift/internal:providers.bzl", "SwiftCompilerPluginInfo")
load(
"//swift/internal:swift_symbol_graph_aspect.bzl",
"make_swift_symbol_graph_aspect",
@@ -53,7 +54,6 @@ load(
load(":module_name.bzl", "derive_swift_module_name")
load(
":providers.bzl",
- "SwiftCompilerPluginInfo",
"SwiftInfo",
"SwiftSymbolGraphInfo",
"create_swift_module_context",
@@ -269,6 +269,7 @@ def _do_compile(
objc_infos,
name,
package_name,
+ plugins = [],
srcs,
swift_infos,
swift_toolchain,
@@ -291,6 +292,8 @@ def _do_compile(
provided as inputs to the compilation action.
package_name: The semantic package of the name of the Swift module
being compiled.
+ plugins: A list of `SwiftCompilerPluginInfo` providers that need to be
+ loaded when compiling this module.
srcs: The sources to compile.
swift_infos: A list of `SwiftInfo` providers that should be used to
determine the module inputs for the action.
@@ -316,6 +319,7 @@ def _do_compile(
include_dev_srch_paths = include_dev_srch_paths,
module_name = module_name,
package_name = package_name,
+ plugins = plugins,
objc_infos = objc_infos,
srcs = srcs,
swift_infos = swift_infos,
@@ -424,6 +428,7 @@ def _swift_test_impl(ctx):
module_name = module_name,
objc_infos = deps_objc_infos,
package_name = ctx.attr.package_name,
+ plugins = get_providers(ctx.attr.plugins, SwiftCompilerPluginInfo),
name = ctx.label.name,
srcs = srcs,
swift_infos = deps_swift_infos,
diff --git a/swift/toolchains/config/compile_config.bzl b/swift/toolchains/config/compile_config.bzl
index 5e2ed2519..adc753470 100644
--- a/swift/toolchains/config/compile_config.bzl
+++ b/swift/toolchains/config/compile_config.bzl
@@ -1912,7 +1912,7 @@ def _plugins_configurator(prerequisites, args):
)
return ConfigResultInfo(
- inputs = [p.executable for p in prerequisites.plugins.to_list()],
+ inputs = [p.executable for p in prerequisites.plugins],
)
def _macro_expansion_configurator(prerequisites, args):