diff --git a/doc/BUILD b/doc/BUILD
index 4e38d3cea..a1f53d47d 100644
--- a/doc/BUILD
+++ b/doc/BUILD
@@ -15,6 +15,7 @@ _DOC_SRCS = {
"SwiftInfo",
"SwiftToolchainInfo",
"SwiftProtoCompilerInfo",
+ "SwiftProtoCompilerCollectionInfo",
"SwiftProtoInfo",
"SwiftUsageInfo",
"DeprecatedSwiftGRPCInfo",
@@ -23,6 +24,7 @@ _DOC_SRCS = {
"swift_binary",
"swift_c_module",
"swift_compiler_plugin",
+ "swift_compiler_plugin_group",
"universal_swift_compiler_plugin",
"swift_feature_allowlist",
"swift_import",
diff --git a/doc/doc.bzl b/doc/doc.bzl
index 55a0966d5..a75838006 100644
--- a/doc/doc.bzl
+++ b/doc/doc.bzl
@@ -58,6 +58,7 @@ load(
# api
_swift_common = "swift_common",
_swift_compiler_plugin = "swift_compiler_plugin",
+ _swift_compiler_plugin_group = "swift_compiler_plugin_group",
_swift_feature_allowlist = "swift_feature_allowlist",
_swift_import = "swift_import",
_swift_library = "swift_library",
@@ -92,6 +93,7 @@ deprecated_swift_proto_library = _deprecated_swift_proto_library
swift_binary = _swift_binary
swift_c_module = _swift_c_module
swift_compiler_plugin = _swift_compiler_plugin
+swift_compiler_plugin_group = _swift_compiler_plugin_group
universal_swift_compiler_plugin = _universal_swift_compiler_plugin
swift_feature_allowlist = _swift_feature_allowlist
swift_import = _swift_import
diff --git a/doc/providers.md b/doc/providers.md
index aa4fb4546..8dca28cdd 100644
--- a/doc/providers.md
+++ b/doc/providers.md
@@ -10,6 +10,7 @@ On this page:
* [SwiftInfo](#SwiftInfo)
* [SwiftToolchainInfo](#SwiftToolchainInfo)
* [SwiftProtoCompilerInfo](#SwiftProtoCompilerInfo)
+ * [SwiftProtoCompilerCollectionInfo](#SwiftProtoCompilerCollectionInfo)
* [SwiftProtoInfo](#SwiftProtoInfo)
* [SwiftUsageInfo](#SwiftUsageInfo)
* [DeprecatedSwiftGRPCInfo](#DeprecatedSwiftGRPCInfo)
diff --git a/doc/rules.md b/doc/rules.md
index 46b838e00..e3d5f67cb 100644
--- a/doc/rules.md
+++ b/doc/rules.md
@@ -22,6 +22,7 @@ On this page:
* [swift_binary](#swift_binary)
* [swift_c_module](#swift_c_module)
* [swift_compiler_plugin](#swift_compiler_plugin)
+ * [swift_compiler_plugin_group](#swift_compiler_plugin_group)
* [universal_swift_compiler_plugin](#universal_swift_compiler_plugin)
* [swift_feature_allowlist](#swift_feature_allowlist)
* [swift_import](#swift_import)
@@ -401,6 +402,25 @@ swift_library(
| swiftc_inputs | Additional files that are referenced using `$(location ...)` in attributes that support location expansion. | List of labels | optional | `[]` |
+
+
+## swift_compiler_plugin_group
+
+
+swift_compiler_plugin_group(name, plugins)
+
+
+
+
+**ATTRIBUTES**
+
+
+| Name | Description | Type | Mandatory | Default |
+| :------------- | :------------- | :------------- | :------------- | :------------- |
+| name | A unique name for this target. | Name | required | |
+| plugins | A list of `swift_compiler_plugin` or `swift_compiler_plugin_group` targets that should be loaded by the compiler when compiling this module and any modules that directly depend on it. | List of labels | required | |
+
+
## swift_feature_allowlist
@@ -678,7 +698,7 @@ swift_proto_library(
| additional_compiler_info | Dictionary of additional information passed to the compiler targets. See the documentation of the respective compiler rules for more information on which fields are accepted and how they are used. | Dictionary: String -> String | optional | `{}` |
| always_include_developer_search_paths | If `True`, the developer framework search paths will be added to the compilation command. This enables a Swift module to access `XCTest` without having to mark the target as `testonly = True`. | Boolean | optional | `False` |
| alwayslink | If true, any binary that depends (directly or indirectly) on this Swift module will link in all the object files for the files listed in `srcs`, even if some contain no symbols referenced by the binary. This is useful if your code isn't explicitly called by code in the binary; for example, if you rely on runtime checks for protocol conformances added in extensions in the library but do not directly reference any other symbols in the object file that adds that conformance. | Boolean | optional | `False` |
-| compilers | One or more `swift_proto_compiler` targets (or targets producing `SwiftProtoCompilerInfo`), from which the Swift protos will be generated. | List of labels | optional | `["@build_bazel_rules_swift//proto/compilers:swift_proto"]` |
+| compilers | One or more `swift_proto_compiler` targets (or targets producing `SwiftProtoCompilerInfo`), from which the Swift protos will be generated. | List of labels | optional | `["@rules_swift//proto/compilers:swift_proto"]` |
| copts | Additional compiler options that should be passed to `swiftc`. These strings are subject to `$(location ...)` and ["Make" variable](https://docs.bazel.build/versions/master/be/make-variables.html) expansion. | List of strings | optional | `[]` |
| defines | A list of defines to add to the compilation command line.
Note that unlike C-family languages, Swift defines do not have values; they are simply identifiers that are either defined or undefined. So strings in this list should be simple identifiers, **not** `name=value` pairs.
Each string is prepended with `-D` and added to the command line. Unlike `copts`, these flags are added for the target and every target that depends on it, so use this attribute with caution. It is preferred that you add defines directly to `copts`, only using this feature in the rare case that a library needs to propagate a symbol up to those that depend on it. | List of strings | optional | `[]` |
| generated_header_name | The name of the generated Objective-C interface header. This name must end with a `.h` extension and cannot contain any path separators.
If this attribute is not specified, then the default behavior is to name the header `${target_name}-Swift.h`.
This attribute is ignored if the toolchain does not support generating headers. | String | optional | `""` |
@@ -893,6 +913,6 @@ swift_library(
| Name | Description | Type | Mandatory | Default |
| :------------- | :------------- | :------------- | :------------- | :------------- |
| name | A unique name for this target. | Name | required | |
-| plugin | Target to generate a 'fat' binary from. | Label | required | |
+| plugin | A `swift_compiler_plugin` target to generate a 'fat' binary for. | Label | required | |
diff --git a/examples/xplatform/macros/BUILD b/examples/xplatform/macros/BUILD
index 91bf32871..e016bf365 100644
--- a/examples/xplatform/macros/BUILD
+++ b/examples/xplatform/macros/BUILD
@@ -1,5 +1,10 @@
load("//swift:swift.bzl", "swift_binary", "swift_library", "swift_test")
-load("//swift:swift_compiler_plugin.bzl", "swift_compiler_plugin", "universal_swift_compiler_plugin")
+load(
+ "//swift:swift_compiler_plugin.bzl",
+ "swift_compiler_plugin",
+ "swift_compiler_plugin_group",
+ "universal_swift_compiler_plugin",
+)
licenses(["notice"])
@@ -12,14 +17,19 @@ swift_library(
name = "stringify",
srcs = ["Stringify.swift"],
module_name = "Stringify",
- plugins = [":stringify_macro"],
+ plugins = [":stringify_macro_group"],
)
swift_library(
name = "stringify_universal",
srcs = ["Stringify.swift"],
module_name = "StringifyUniversal",
- plugins = [":stringify_macro_universal"],
+ plugins = [
+ # We don't create and use a `stringify_macro_universal` here, but we
+ # could have if we wanted to
+ ":stringify_macro_universal",
+ ":stringify2_macro_universal",
+ ],
)
swift_compiler_plugin(
@@ -41,11 +51,43 @@ swift_compiler_plugin(
],
)
+swift_compiler_plugin(
+ name = "stringify2_macro",
+ srcs = [
+ "Stringify2Macro.swift",
+ "Stringify2MacroPlugin.swift",
+ ],
+ module_name = "Stringify2MacroPlugin",
+ target_compatible_with = select({
+ ":supports_macros": [],
+ "//conditions:default": ["@platforms//:incompatible"],
+ }),
+ deps = [
+ "@SwiftSyntax",
+ "@SwiftSyntax//:SwiftCompilerPlugin",
+ "@SwiftSyntax//:SwiftSyntaxBuilder",
+ "@SwiftSyntax//:SwiftSyntaxMacros",
+ ],
+)
+
+swift_compiler_plugin_group(
+ name = "stringify_macro_group",
+ plugins = [
+ ":stringify_macro",
+ ":stringify2_macro",
+ ],
+)
+
universal_swift_compiler_plugin(
name = "stringify_macro_universal",
plugin = ":stringify_macro",
)
+universal_swift_compiler_plugin(
+ name = "stringify2_macro_universal",
+ plugin = ":stringify_macro",
+)
+
swift_binary(
name = "stringify_client",
srcs = ["StringifyClient.swift"],
@@ -66,6 +108,9 @@ swift_test(
"//conditions:default": ["@platforms//:incompatible"],
}),
deps = [
+ ":stringify_macro_group",
+ # `stringify_macro` is in `stringify_macro_group`, but we list both to
+ # show that it handles that fine
":stringify_macro",
"@SwiftSyntax",
"@SwiftSyntax//:SwiftSyntaxBuilder",
diff --git a/examples/xplatform/macros/Stringify.swift b/examples/xplatform/macros/Stringify.swift
index 304af8120..331d58100 100644
--- a/examples/xplatform/macros/Stringify.swift
+++ b/examples/xplatform/macros/Stringify.swift
@@ -15,3 +15,7 @@
@freestanding(expression)
public macro stringify(_ value: T) -> (T, String) =
#externalMacro(module: "StringifyMacroPlugin", type: "StringifyMacro")
+
+@freestanding(expression)
+public macro stringify2(_ value: T) -> (T, String) =
+ #externalMacro(module: "Stringify2MacroPlugin", type: "Stringify2Macro")
diff --git a/examples/xplatform/macros/Stringify2Macro.swift b/examples/xplatform/macros/Stringify2Macro.swift
new file mode 100644
index 000000000..670e992a2
--- /dev/null
+++ b/examples/xplatform/macros/Stringify2Macro.swift
@@ -0,0 +1,29 @@
+// Copyright 2023 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+import SwiftSyntax
+import SwiftSyntaxBuilder
+import SwiftSyntaxMacros
+
+public struct Stringify2Macro: ExpressionMacro {
+ public static func expansion(
+ of node: some FreestandingMacroExpansionSyntax,
+ in context: some MacroExpansionContext
+ ) -> ExprSyntax {
+ guard let argument = node.argumentList.first?.expression else {
+ fatalError("compiler bug: the macro does not have any arguments")
+ }
+ return "(\(argument), \(literal: argument.description))"
+ }
+}
diff --git a/examples/xplatform/macros/Stringify2MacroPlugin.swift b/examples/xplatform/macros/Stringify2MacroPlugin.swift
new file mode 100644
index 000000000..9ef37e8bc
--- /dev/null
+++ b/examples/xplatform/macros/Stringify2MacroPlugin.swift
@@ -0,0 +1,25 @@
+// Copyright 2023 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#if canImport(SwiftCompilerPlugin)
+import SwiftCompilerPlugin
+import SwiftSyntaxMacros
+
+@main
+struct Stringify2MacroPlugin: CompilerPlugin {
+ let providingMacros: [Macro.Type] = [
+ Stringify2Macro.self
+ ]
+}
+#endif
diff --git a/examples/xplatform/macros/StringifyClient.swift b/examples/xplatform/macros/StringifyClient.swift
index dd75e2e5f..1b1500eb3 100644
--- a/examples/xplatform/macros/StringifyClient.swift
+++ b/examples/xplatform/macros/StringifyClient.swift
@@ -18,5 +18,6 @@ import Stringify
struct Main {
static func main() {
print(#stringify(1 + 2))
+ print(#stringify2(2 + 1))
}
}
diff --git a/examples/xplatform/macros/StringifyMacroTests.swift b/examples/xplatform/macros/StringifyMacroTests.swift
index 7fb9d6a6b..fe1be33e9 100644
--- a/examples/xplatform/macros/StringifyMacroTests.swift
+++ b/examples/xplatform/macros/StringifyMacroTests.swift
@@ -16,6 +16,7 @@ import SwiftSyntax
import SwiftSyntaxBuilder
import SwiftSyntaxMacros
import StringifyMacroPlugin
+import Stringify2MacroPlugin
import XCTest
class StringifyMacroTests: XCTestCase {
@@ -35,4 +36,21 @@ class StringifyMacroTests: XCTestCase {
"""#
)
}
+
+ func testStringify2() {
+ let sourceFile: SourceFileSyntax = #"""
+ _ = #stringify2(2 + 1)
+ """#
+ let context = BasicMacroExpansionContext(
+ sourceFiles: [sourceFile: .init(moduleName: "TestModule", fullFilePath: "Test.swift")]
+ )
+ let transformedSourceFile =
+ sourceFile.expand(macros: ["stringify2": Stringify2Macro.self], in: context)
+ XCTAssertEqual(
+ String(describing: transformedSourceFile),
+ #"""
+ _ = (2 + 1, "2 + 1")
+ """#
+ )
+ }
}
diff --git a/swift/deprecated_proto/deprecated_swift_grpc_library.bzl b/swift/deprecated_proto/deprecated_swift_grpc_library.bzl
index 616f4bba6..3fd5978b8 100644
--- a/swift/deprecated_proto/deprecated_swift_grpc_library.bzl
+++ b/swift/deprecated_proto/deprecated_swift_grpc_library.bzl
@@ -222,7 +222,7 @@ def _register_grpcswift_generate_action(
return generated_files
def _swift_grpc_library_impl(ctx):
- print("WARNING: This rule is deprecated. See [the proto migration doc](proto_migration.md) for more information.") # buildifier: disable=print
+ print("WARNING: This rule is deprecated. See proto_migration.md for more information.") # buildifier: disable=print
if len(ctx.attr.deps) != 1:
fail(
diff --git a/swift/internal/attrs.bzl b/swift/internal/attrs.bzl
index 42f8f13c4..e17e8852d 100644
--- a/swift/internal/attrs.bzl
+++ b/swift/internal/attrs.bzl
@@ -15,7 +15,13 @@
"""Common attributes used by multiple Swift build rules."""
load("@bazel_skylib//lib:dicts.bzl", "dicts")
-load(":providers.bzl", "SwiftCompilerPluginInfo", "SwiftInfo", "SwiftToolchainInfo")
+load(
+ ":providers.bzl",
+ "SwiftCompilerPluginInfo",
+ "SwiftCompilerPluginCollectionInfo",
+ "SwiftInfo",
+ "SwiftToolchainInfo",
+)
def swift_common_rule_attrs(
additional_deps_aspects = [],
@@ -146,7 +152,10 @@ Swift 5.9+.
A list of `swift_compiler_plugin` targets that should be loaded by the compiler
when compiling this module and any modules that directly depend on it.
""",
- providers = [[SwiftCompilerPluginInfo]],
+ providers = [
+ [SwiftCompilerPluginInfo],
+ [SwiftCompilerPluginCollectionInfo],
+ ],
),
"srcs": attr.label_list(
allow_empty = not requires_srcs,
diff --git a/swift/internal/feature_names.bzl b/swift/internal/feature_names.bzl
index ebad02d24..57f78a81a 100644
--- a/swift/internal/feature_names.bzl
+++ b/swift/internal/feature_names.bzl
@@ -209,13 +209,13 @@ SWIFT_FEATURE_USE_RESPONSE_FILES = "swift.use_response_files"
# If enabled, Swift linking actions will use `swift-autolink-extract` to extract
# the linker arguments. This is required for ELF targets. This is used
-# internally to determine the behaviour of the actions across different
+# internally to determine the behavior of the actions across different
# toolchain platforms, this is should not be set by users of the toolchain.
SWIFT_FEATURE_USE_AUTOLINK_EXTRACT = "swift.use_autolink_extract"
# If enabled, Swift will wrap the `.swiftmodule` into an object file and link it
# into the module. This is used internally to support the different platforms
-# which have differing behaviour for debug information handling. This should
+# which have differing behavior for debug information handling. This should
# not be used by users of the toolchain.
SWIFT_FEATURE_USE_MODULE_WRAP = "swift.use_module_wrap"
diff --git a/swift/internal/providers.bzl b/swift/internal/providers.bzl
index 9b3128f80..84b02683a 100644
--- a/swift/internal/providers.bzl
+++ b/swift/internal/providers.bzl
@@ -14,6 +14,13 @@
"""Defines Starlark providers that propagated by the Swift BUILD rules."""
+SwiftCompilerPluginCollectionInfo = provider(
+ doc = "Information about a collection of `SwiftCompilerPluginInfo` providers.",
+ fields = {
+ "plugins": "A `depset` of `SwiftCompilerPluginInfo` providers",
+ },
+)
+
SwiftCompilerPluginInfo = provider(
doc = "Information about compiler plugins, like macros.",
fields = {
@@ -548,3 +555,27 @@ def create_swift_info(
transitive = transitive_modules,
),
)
+
+def get_compiler_plugin_infos(targets):
+ """Returns effective `SwiftCompilerPluginInfo` providers from each target in the list.
+
+ The returned list may not be the same size as `targets` if some of the
+ targets do not contain a `SwiftCompilerPluginInfo` provider, or if they
+ contain a `SwiftCompilerPluginCollectionInfo` provider that expands to 0 or
+ more `SwiftCompilerPluginInfo` providers.
+
+ Args:
+ targets: A list of targets.
+
+ Returns:
+ A list of `SwiftCompilerPluginInfo` providers from the targets.
+ """
+ plugins = []
+ for target in targets:
+ if SwiftCompilerPluginInfo in target:
+ plugins.append(target[SwiftCompilerPluginInfo])
+ if SwiftCompilerPluginCollectionInfo in target:
+ plugins.extend(
+ target[SwiftCompilerPluginCollectionInfo].plugins.to_list(),
+ )
+ return plugins
diff --git a/swift/internal/swift_binary_test_rules.bzl b/swift/internal/swift_binary_test_rules.bzl
index 187c7488d..b89ce132f 100644
--- a/swift/internal/swift_binary_test_rules.bzl
+++ b/swift/internal/swift_binary_test_rules.bzl
@@ -20,9 +20,15 @@ load(":derived_files.bzl", "derived_files")
load(":env_expansion.bzl", "expanded_env")
load(":feature_names.bzl", "SWIFT_FEATURE_BUNDLED_XCTESTS")
load(":linking.bzl", "binary_rule_attrs", "configure_features_for_binary", "register_link_binary_action")
-load(":providers.bzl", "SwiftCompilerPluginInfo", "SwiftToolchainInfo")
+load(
+ ":providers.bzl",
+ "SwiftCompilerPluginInfo",
+ "SwiftCompilerPluginCollectionInfo",
+ "SwiftToolchainInfo",
+ "get_compiler_plugin_infos",
+)
load(":swift_common.bzl", "swift_common")
-load(":utils.bzl", "expand_locations", "get_providers", "include_developer_search_paths")
+load(":utils.bzl", "expand_locations", "include_developer_search_paths")
def _maybe_parse_as_library_copts(srcs):
"""Returns a list of compiler flags depending on `main.swift`'s presence.
@@ -110,7 +116,7 @@ def _swift_linking_rule_impl(
include_dev_srch_paths = include_dev_srch_paths,
module_name = module_name,
package_name = ctx.attr.package_name,
- plugins = get_providers(ctx.attr.plugins, SwiftCompilerPluginInfo),
+ plugins = get_compiler_plugin_infos(ctx.attr.plugins),
srcs = srcs,
swift_toolchain = swift_toolchain,
target_name = ctx.label.name,
@@ -287,11 +293,10 @@ def _swift_test_impl(ctx):
# since we support testing those.
extra_swift_infos = []
additional_linking_contexts = []
- for dep in ctx.attr.deps:
- if SwiftCompilerPluginInfo in dep:
- plugin_info = dep[SwiftCompilerPluginInfo]
- extra_swift_infos.append(plugin_info.swift_info)
- additional_linking_contexts.append(plugin_info.cc_info.linking_context)
+ plugin_infos = get_compiler_plugin_infos(ctx.attr.deps)
+ for plugin_info in plugin_infos:
+ extra_swift_infos.append(plugin_info.swift_info)
+ additional_linking_contexts.append(plugin_info.cc_info.linking_context)
_, linking_outputs, providers = _swift_linking_rule_impl(
ctx,
@@ -351,7 +356,10 @@ def _swift_test_impl(ctx):
swift_binary = rule(
attrs = binary_rule_attrs(
- additional_deps_providers = [[SwiftCompilerPluginInfo]],
+ additional_deps_providers = [
+ [SwiftCompilerPluginInfo],
+ [SwiftCompilerPluginCollectionInfo],
+ ],
stamp_default = -1,
),
doc = """\
@@ -377,7 +385,10 @@ please use one of the platform-specific application rules in
swift_test = rule(
attrs = dicts.add(
binary_rule_attrs(
- additional_deps_providers = [[SwiftCompilerPluginInfo]],
+ additional_deps_providers = [
+ [SwiftCompilerPluginInfo],
+ [SwiftCompilerPluginCollectionInfo],
+ ],
stamp_default = 0,
),
{
diff --git a/swift/internal/swift_library.bzl b/swift/internal/swift_library.bzl
index ad08efd58..e90296347 100644
--- a/swift/internal/swift_library.bzl
+++ b/swift/internal/swift_library.bzl
@@ -36,7 +36,13 @@ load(
"SWIFT_FEATURE_SUPPORTS_PRIVATE_DEPS",
)
load(":linking.bzl", "new_objc_provider")
-load(":providers.bzl", "SwiftCompilerPluginInfo", "SwiftInfo", "SwiftToolchainInfo")
+load(
+ ":providers.bzl",
+ "SwiftCompilerPluginInfo",
+ "SwiftInfo",
+ "SwiftToolchainInfo",
+ "get_compiler_plugin_infos",
+)
load(":swift_clang_module_aspect.bzl", "swift_clang_module_aspect")
load(":swift_common.bzl", "swift_common")
load(
@@ -191,7 +197,7 @@ def _swift_library_impl(ctx):
include_dev_srch_paths = include_dev_srch_paths,
module_name = module_name,
package_name = ctx.attr.package_name,
- plugins = get_providers(ctx.attr.plugins, SwiftCompilerPluginInfo),
+ plugins = get_compiler_plugin_infos(ctx.attr.plugins),
private_deps = private_deps,
srcs = srcs,
swift_toolchain = swift_toolchain,
diff --git a/swift/internal/swift_toolchain.bzl b/swift/internal/swift_toolchain.bzl
index 328da2c69..a0f305c08 100644
--- a/swift/internal/swift_toolchain.bzl
+++ b/swift/internal/swift_toolchain.bzl
@@ -322,6 +322,7 @@ def _swift_toolchain_impl(ctx):
SWIFT_FEATURE_OPT_USES_WMO,
SWIFT_FEATURE_USE_GLOBAL_MODULE_CACHE,
SWIFT_FEATURE_USE_RESPONSE_FILES,
+ "gcc_quoting_for_param_files",
])
requested_features.extend(ctx.features)
diff --git a/swift/internal/xcode_swift_toolchain.bzl b/swift/internal/xcode_swift_toolchain.bzl
index 94491b2ab..cb9666a94 100644
--- a/swift/internal/xcode_swift_toolchain.bzl
+++ b/swift/internal/xcode_swift_toolchain.bzl
@@ -48,6 +48,7 @@ load(
"SWIFT_FEATURE_SUPPORTS_LIBRARY_EVOLUTION",
"SWIFT_FEATURE_SUPPORTS_PRIVATE_DEPS",
"SWIFT_FEATURE_SUPPORTS_SYSTEM_MODULE_FLAG",
+ "SWIFT_FEATURE_USE_AUTOLINK_EXTRACT",
"SWIFT_FEATURE_USE_GLOBAL_MODULE_CACHE",
"SWIFT_FEATURE_USE_RESPONSE_FILES",
"SWIFT_FEATURE__FORCE_ALWAYSLINK_TRUE",
@@ -430,7 +431,8 @@ def _all_tool_configs(
execution_requirements,
generated_header_rewriter,
swift_executable,
- toolchain_root):
+ toolchain_root,
+ use_autolink_extract):
"""Returns the tool configurations for the Swift toolchain.
Args:
@@ -497,6 +499,14 @@ def _all_tool_configs(
),
}
+ if use_autolink_extract:
+ tool_configs[swift_action_names.AUTOLINK_EXTRACT] = swift_toolchain_config.driver_tool_config(
+ driver_mode = "swift-autolink-extract",
+ swift_executable = swift_executable,
+ toolchain_root = toolchain_root,
+ worker_mode = "wrap",
+ )
+
return tool_configs
def _is_xcode_at_least_version(xcode_config, desired_version):
@@ -649,6 +659,7 @@ def _xcode_swift_toolchain_impl(ctx):
generated_header_rewriter = generated_header_rewriter,
swift_executable = swift_executable,
toolchain_root = toolchain_root,
+ use_autolink_extract = SWIFT_FEATURE_USE_AUTOLINK_EXTRACT in ctx.features,
)
all_action_configs = _all_action_configs(
additional_objc_copts = _command_line_objc_copts(
diff --git a/swift/swift.bzl b/swift/swift.bzl
index 2bab57cfd..878d531dc 100644
--- a/swift/swift.bzl
+++ b/swift/swift.bzl
@@ -30,6 +30,7 @@ load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library")
load(
"@build_bazel_rules_swift//swift:swift_compiler_plugin.bzl",
_swift_compiler_plugin = "swift_compiler_plugin",
+ _swift_compiler_plugin_group = "swift_compiler_plugin_group",
_universal_swift_compiler_plugin = "universal_swift_compiler_plugin",
)
load(
@@ -109,6 +110,7 @@ swift_common = _swift_common
swift_binary = _swift_binary
swift_c_module = _swift_c_module
swift_compiler_plugin = _swift_compiler_plugin
+swift_compiler_plugin_group = _swift_compiler_plugin_group
universal_swift_compiler_plugin = _universal_swift_compiler_plugin
swift_feature_allowlist = _swift_feature_allowlist
swift_import = _swift_import
diff --git a/swift/swift_compiler_plugin.bzl b/swift/swift_compiler_plugin.bzl
index 17e8201d5..d9dbff9c5 100644
--- a/swift/swift_compiler_plugin.bzl
+++ b/swift/swift_compiler_plugin.bzl
@@ -41,7 +41,9 @@ load(
load(
"@build_bazel_rules_swift//swift/internal:providers.bzl",
"SwiftCompilerPluginInfo",
+ "SwiftCompilerPluginCollectionInfo",
"SwiftToolchainInfo",
+ "get_compiler_plugin_infos",
)
load(
"@build_bazel_rules_swift//swift/internal:swift_common.bzl",
@@ -50,7 +52,6 @@ load(
load(
"@build_bazel_rules_swift//swift/internal:utils.bzl",
"expand_locations",
- "get_providers",
)
load(":module_name.bzl", "derive_swift_module_name")
@@ -105,7 +106,7 @@ def _swift_compiler_plugin_impl(ctx):
include_dev_srch_paths = ctx.attr.testonly,
module_name = module_name,
package_name = ctx.attr.package_name,
- plugins = get_providers(ctx.attr.plugins, SwiftCompilerPluginInfo),
+ plugins = get_compiler_plugin_infos(ctx.attr.plugins),
srcs = srcs,
swift_toolchain = swift_toolchain,
target_name = ctx.label.name,
@@ -321,13 +322,51 @@ def _universal_swift_compiler_plugin_impl(ctx):
),
]
+def _swift_compiler_plugin_group_impl(ctx):
+ direct = []
+ transitive = []
+ for target in ctx.attr.plugins:
+ if SwiftCompilerPluginInfo in target:
+ direct.append(target[SwiftCompilerPluginInfo])
+ if SwiftCompilerPluginCollectionInfo in target:
+ transitive.append(target[SwiftCompilerPluginCollectionInfo].plugins)
+ return [
+ SwiftCompilerPluginCollectionInfo(
+ plugins = depset(
+ direct,
+ order = "preorder",
+ transitive = transitive,
+ ),
+ ),
+ ]
+
+swift_compiler_plugin_group = rule(
+ attrs = {
+ "plugins": attr.label_list(
+ doc = """\
+A list of `swift_compiler_plugin` or `swift_compiler_plugin_group` targets that
+should be loaded by the compiler when compiling this module and any modules that
+directly depend on it.
+""",
+ mandatory = True,
+ providers = [
+ [SwiftCompilerPluginInfo],
+ [SwiftCompilerPluginCollectionInfo],
+ ],
+ ),
+ },
+ implementation = _swift_compiler_plugin_group_impl,
+)
+
universal_swift_compiler_plugin = rule(
attrs = dicts.add(
apple_support.action_required_attrs(),
{
"plugin": attr.label(
cfg = macos_universal_transition,
- doc = "Target to generate a 'fat' binary from.",
+ doc = """
+A `swift_compiler_plugin` target to generate a 'fat' binary for.
+""",
mandatory = True,
providers = [SwiftCompilerPluginInfo],
),