@rules_swift@rules_swift//doc:api.bzl
Re-exports of API symbols for stardoc.
Functions & Macros
create_swift_interop_infoReturns a provider that lets a target expose C/Objective-C APIs to Swift.
The provider returned by this function allows custom build rules written in
Starlark to be uninvolved with much of the low-level machinery involved in
making a Swift-compatible module. Such a target should propagate a CcInfo
provider whose compilation context contains the headers that it wants to
make into a module, and then also propagate the provider returned from this
function.
The simplest usage is for a custom rule to do the following:
- Add
swift_clang_module_aspectto any attribute that provides
dependencies of the code that needs to interop with Swift (typically
deps, but could be other attributes as well, such as attributes
providing additional support libraries). - Have the rule implementation call
create_swift_interop_info, passing
it only the list ofSwiftInfoproviders from its dependencies. This
tellsswift_clang_module_aspectwhen it runs on this rule's target
to derive the module name from the target label and create a module map
using the headers from the compilation context of theCcInfoyou
propagate.
If the custom rule has reason to provide its own module name or module map,
then it can do so using the module_name and module_map arguments.
When a rule returns this provider, it must provide the full set of
SwiftInfo providers from dependencies that will be merged with the one
that swift_clang_module_aspect creates for the target itself. The aspect
will not collect dependency providers automatically. This allows the
rule to not only add extra dependencies (such as support libraries from
implicit attributes) but also to exclude dependencies if necessary.
Parameters
compilation_context | A Default: None |
direct_swift_infos | A list of Default: [] |
exclude_headers | A Default: [] |
module_map | A Default: None |
module_name | A string denoting the name of the module, or Default: None |
requested_features | A list of features (empty by default) that should be Default: [] |
suppressed | A Default: False |
swift_infos | A list of Default: [] |
unsupported_features | A list of features (empty by default) that should Default: [] |
derive_swift_module_nameReturns a derived module name from the given build label.
For targets whose module name is not explicitly specified, the module name
is computed using the following algorithm:
- The package and name components of the label are considered separately.
All interior sequences of non-identifier characters (anything other
thana-z,A-Z,0-9, and_) are replaced by a single underscore
(_). Any leading or trailing non-identifier characters are dropped. - If the package component is non-empty after the above transformation,
it is joined with the transformed name component using an underscore.
Otherwise, the transformed name is used by itself. - If this would result in a string that begins with a digit (
0-9), an
underscore is prepended to make it identifier-safe.
This mapping is intended to be fairly predictable, but not reversible.
Parameters
feature_configuration | The Swift feature configuration being used when Default: None |
args | Either a single argument of type |
is_swift_overlayReturns a value indicating whether the given target is a swift_overlay.
This is meant to be used by aspects that visit the aspect_hints of a
target to identify the swift_overlay target (if present) without making
the provider public or requiring those aspects to propagate the information
themselves.
Parameters
*target | A |
swift_common.cc_feature_configurationReturns the C++ feature configuration in a Swift feature configuration.
Parameters
*feature_configuration | The Swift feature configuration, as returned from |
swift_common.compileCompiles a Swift module.
Parameters
*actions | The context's |
additional_inputs | A list of Default: [] |
*cc_infos | A list of |
copts | A list of compiler flags that apply to the target being built. Default: [] |
defines | Symbols that should be defined by passing Default: [] |
exec_group | Runs the Swift compilation action under the given execution Default: None |
extra_swift_infos | Extra Default: [] |
*feature_configuration | A feature configuration obtained from |
generated_header_name | The name of the Objective-C generated header that Default: None |
is_test | Deprecated. This argument will be removed in the next major Default: None |
include_dev_srch_paths | A Default: None |
*module_name | The name of the Swift module being compiled. This must be |
*package_name | The semantic package of the name of the Swift module |
plugins | A list of Default: [] |
private_cc_infos | A list of Default: [] |
private_swift_infos | A list of Default: [] |
*srcs | The Swift source files to compile. |
*swift_infos | A list of |
swift_toolchain | The Default: None |
*target_name | The name of the target for which the code is being |
toolchains | The struct containing the Swift and C++ toolchain providers, Default: None |
toolchain_type | The toolchain type of the Default: Label("@rules_swift//toolchains:toolchain_type") |
*workspace_name | The name of the workspace for which the code is being |
swift_common.compile_module_interfaceCompiles a Swift module interface.
Parameters
*actions | The context's |
additional_inputs | A list of Default: [] |
clang_module | An optional underlying Clang module (as returned by Default: None |
*compilation_contexts | A list of |
copts | A list of compiler flags that apply to the target being built. Default: [] |
exec_group | Runs the Swift compilation action under the given execution Default: None |
*feature_configuration | A feature configuration obtained from |
is_framework | True if this module is a Framework module, false othwerise. Default: False |
*module_name | The name of the Swift module being compiled. This must be |
*swiftinterface_file | The Swift module interface file to compile. |
*swift_infos | A list of |
swift_toolchain | The Default: None |
*target_name | The name of the target for which the interface is being |
toolchains | The struct containing the Swift and C++ toolchain providers, Default: None |
toolchain_type | The toolchain type of the Default: Label("@rules_swift//toolchains:toolchain_type") |
swift_common.configure_featuresCreates a feature configuration to be passed to Swift build APIs.
This function calls through to cc_common.configure_features to configure
underlying C++ features as well, and nests the C++ feature configuration
inside the Swift one. Users who need to call C++ APIs that require a feature
configuration can extract it by calling
get_cc_feature_configuration(feature_configuration).
Parameters
*ctx | The rule context. |
swift_toolchain | The Default: None |
toolchains | The toolchains that are used to determine which features are Default: None |
requested_features | The list of features to be enabled. This is Default: [] |
unsupported_features | The list of features that are unsupported by the Default: [] |
swift_common.create_compilation_contextCretes a compilation context for a Swift target.
Parameters
*defines | A list of defines |
*srcs | A list of Swift source files used to compile the target. |
*transitive_modules | A list of modules (as returned by |
swift_common.create_linking_context_from_compilation_outputsCreates a linking context from the outputs of a Swift compilation.
On some platforms, this function will spawn additional post-compile actions
for the module in order to add their outputs to the linking context. For
example, if the toolchain that requires a "module-wrap" invocation to embed
the .swiftmodule into an object file for debugging purposes, or if it
extracts auto-linking information from the object files to generate a linker
command line parameters file, those actions will be created here.
Parameters
*actions | The context's |
additional_inputs | A Default: [] |
alwayslink | If Default: True |
*compilation_outputs | A |
*feature_configuration | A feature configuration obtained from |
is_test | Deprecated. This argument will be removed in the next major Default: None |
include_dev_srch_paths | A Default: None |
*label | The |
linking_contexts | A Default: [] |
*module_context | The module context returned by |
name | A string that is used to derive the name of the library or Default: None |
swift_toolchain | The Default: None |
toolchains | The struct containing the Swift and C++ toolchain providers, Default: None |
toolchain_type | The toolchain type of the Default: Label("@rules_swift//toolchains:toolchain_type") |
user_link_flags | A Default: [] |
swift_common.extract_symbol_graphExtracts the symbol graph from a Swift module.
Parameters
*actions | The object used to register actions. |
*compilation_contexts | A list of |
emit_extension_block_symbols | A Default: None |
exec_group | Runs the Swift compilation action under the given execution Default: None |
*feature_configuration | The Swift feature configuration. |
*include_dev_srch_paths | A |
minimum_access_level | The minimum access level of the declarations that Default: None |
*module_name | The name of the module whose symbol graph should be |
*output_dir | A directory-type |
*swift_infos | A list of |
swift_toolchain | The Default: None |
toolchains | The struct containing the Swift and C++ toolchain providers, Default: None |
toolchain_type | The toolchain type of the Default: Label("@rules_swift//toolchains:toolchain_type") |
swift_common.find_all_toolchainsFinds all toolchains required to build Swift code.
The Swift build APIs require the C++ toolchain to link libraries and
binaries, so this function finds both and returns them in a convenient
structure that should be passed to the other build APIs.
Parameters
*ctx | The rule or aspect context. |
exec_group | The name of the execution group that contains the Swift Default: None |
mandatory | If Default: True |
toolchain_type | The Swift toolchain type to use. Defaults to the Default: Label("@rules_swift//toolchains:toolchain_type") |
swift_common.get_toolchainGets the Swift toolchain associated with the rule or aspect.
WARNING: This function is deprecated and will be removed soon. Use
swift_common.find_all_toolchains()instead to request the Swift and the
C++ toolchains.
Parameters
*ctx | The rule or aspect context. |
exec_group | The name of the execution group that should contain the Default: None |
mandatory | If Default: True |
toolchain_type | The toolchain type to use. Defaults to the standard Default: Label("@rules_swift//toolchains:toolchain_type") |
attr | The name of the attribute on the calling rule or aspect that Default: "_toolchain" |
swift_common.is_action_enabledReturns True if the given action is enabled in the Swift toolchain.
This function should be used before invoking APIs that invoke actions that
might not be available depending on the version of the Swift toolchain. For
example, SwiftSynthesizeInterface actions (created by calling
swift_common.synthesize_interface) are only available starting from Swift
6.1.
Parameters
*action_name | The name of the action, which corresponds to the action's |
swift_toolchain | The Swift toolchain being used to build. Default: None |
toolchains | The struct containing the Swift and C++ toolchain providers, Default: None |
swift_common.is_enabledReturns True if the feature is enabled in the feature configuration.
This function handles both Swift-specific features and C++ features so that
users do not have to manually extract the C++ configuration in order to
check it.
Parameters
*feature_configuration | The Swift feature configuration, as returned by |
*feature_name | The name of the feature to check. |
swift_common.precompile_clang_modulePrecompiles an explicit Clang module that is compatible with Swift.
Parameters
*actions | The context's |
*cc_compilation_context | A |
exec_group | Runs the Swift compilation action under the given execution Default: None |
*feature_configuration | A feature configuration obtained from |
*module_map_file | A textual module map file that defines the Clang module |
*module_name | The name of the top-level module in the module map that |
swift_toolchain | The Default: None |
*target_name | The name of the target for which the code is being |
toolchains | The struct containing the Swift and C++ toolchain providers, Default: None |
toolchain_type | The toolchain type of the Swift toolchain. Default: Label("@rules_swift//toolchains:toolchain_type") |
swift_infos | A list of Default: [] |
user_compile_flags | Additional Clang flags to pass to the precompile Default: [] |
swift_common.synthesize_interfaceExtracts the symbol graph from a Swift module.
Parameters
*actions | The object used to register actions. |
*compilation_contexts | A list of |
*feature_configuration | The Swift feature configuration. |
*module_name | The name of the module whose symbol graph should be |
*output_file | A |
*swift_infos | A list of |
swift_toolchain | The Default: None |
toolchains | The struct containing the Swift and C++ toolchain providers, Default: None |
toolchain_type | The toolchain type of the Default: Label("@rules_swift//toolchains:toolchain_type") |
swift_common.use_all_toolchainsReturns a list of toolchain types required to build Swift code.
The Swift build APIs require the C++ toolchain to link libraries and
binaries, so this function requests both for convenience.
This function returns a list so that it can be easily composed with other
toolchains if necessary. For example, a rule that requires toolchains other
than Swift and C++ could write:
toolchains = swift_common.use_all_toolchains() + [other toolchains...]
Parameters
mandatory | Whether or not it should be an error if the toolchain cannot Default: True |
toolchain_type | The Swift toolchain type to use. Defaults to the Default: Label("@rules_swift//toolchains:toolchain_type") |
swift_common.use_toolchainReturns a list of toolchain types needed to use the Swift toolchain.
WARNING: This function is deprecated and will be removed soon. Use
swift_common.find_all_toolchains()instead to request the Swift and the
C++ toolchains.
This function returns a list so that it can be easily composed with other
toolchains if necessary. For example, a rule with multiple toolchain
dependencies could write:
toolchains = use_swift_toolchain() + [other toolchains...]
Parameters
mandatory | Whether or not it should be an error if the toolchain cannot Default: True |
toolchain_type | The toolchain type to use. Defaults to the standard Default: Label("@rules_swift//toolchains:toolchain_type") |
@rules_swift@rules_swift//doc:rules.bzl
Bazel rules to define Swift libraries and executable binaries.
Users should load these rules from .bzl files under the swift and proto
directories. Do not import definitions from the internal subdirectory
directly.
For example:
load("@rules_swift//swift:swift_library.bzl", "swift_library") load("@rules_swift//proto:swift_proto_library.bzl", "swift_proto_library")
Functions & Macros
mixed_language_libraryCreates a mixed language library from a Clang and Swift library target pair.
Note: In the future swift_library will support mixed-language libraries.
Once that is the case, this macro will be deprecated.
Parameters
*name | The name of the target. |
additional_objc_compiler_inputs | Additional files that are referenced Default: [] |
always_include_developer_search_paths | If Default: False |
alwayslink | If true, any binary that depends (directly or indirectly) on Default: False |
clang_copts | The compiler flags for the clang library. These will only Default: [] |
clang_defines | Extra clang Default: [] |
clang_deps | A list of targets that are dependencies of only the Default: [] |
*clang_srcs | The list of C, C++, Objective-C, or Objective-C++ sources |
data | The list of files needed by this target at runtime. Files and targets named in the Default: [] |
enable_modules | Enables clang module support (via Default: False |
hdrs | The list of C, C++, Objective-C, or Objective-C++ header files Default: [] |
includes | List of Default: [] |
linkopts | Extra flags to pass to the linker. Default: [] |
module_map | A Warning: If a module map (whether provided here or not) is able to Default: None |
module_name | The name of the Swift module being built. If left unspecified, the module name will be computed based on the Default: None |
non_arc_srcs | The list of Objective-C files that are processed to create Default: [] |
package_name | The semantic package of the Swift target being built. Targets Default: None |
private_deps | A list of targets that are implementation-only Default: [] |
sdk_dylibs | A list of of SDK Default: [] |
sdk_frameworks | A list of SDK frameworks to link with (e.g. When linking a top level Apple binary, all SDK frameworks listed in Default: [] |
swift_copts | The compiler flags for the swift library. Default: [] |
swift_defines | A list of Swift defines to add to the compilation command Note that unlike C-family languages, Swift defines do not have Each string is prepended with Default: [] |
swift_plugins | A list of Swift plugins for the swift library. Default: [] |
*swift_srcs | The sources for the swift library. |
swiftc_inputs | Additional files that are referenced using Default: [] |
textual_hdrs | The list of C, C++, Objective-C, or Objective-C++ files Default: [] |
umbrella_header | A Default: None |
weak_sdk_frameworks | A list of SDK frameworks to weakly link with. For Default: [] |
deps | A list of targets that are dependencies of the target being built. Default: [] |
kwargs | Additional arguments to pass to the underlying clang and swift |
Rules
swift_binaryCompiles and links Swift code into an executable binary.
On Linux, this rule produces an executable binary for the desired target
architecture.
On Apple platforms, this rule produces a single-architecture binary; it does
not produce universal binaries. As such, this rule is mainly useful for
creating Swift tools intended to run on the local build machine.
If you want to create a multi-architecture binary or a bundled application,
please use one of the platform-specific application rules in
rules_apple instead of
swift_binary.
| Attribute | Type | Description |
|---|---|---|
*name | name | A unique name for this target. |
data | list of labels | The list of files needed by this target at runtime. Files and targets named in the Default: [] |
deps | list of labels | A list of targets that are dependencies of the target being built, which will be If the Swift toolchain supports implementation-only imports ( Allowed kinds of dependencies are:
Default: [] |
copts | list of strings | Additional compiler options that should be passed to Default: [] |
defines | list of strings | 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 Each string is prepended with Default: [] |
module_name | string | The name of the Swift module being built. If left unspecified, the module name will be computed based on the target's Default: "" |
package_name | string | The semantic package of the Swift target being built. Targets with the same Default: "" |
plugins | list of labels | A list of Default: [] |
srcs | list of labels | A list of Except in very rare circumstances, a Swift source file should only appear in a Default: [] |
swiftc_inputs | list of labels | Additional files that are referenced using Default: [] |
additional_linker_inputs | list of labels | List of additional files needed by the linker. These files will be passed to the linker when linking the binary target. Default: [] |
linkopts | list of strings | Additional linker options that should be passed to Default: [] |
malloc | label | Override the default dependency on By default, Swift binaries are linked against Default: "@bazel_tools//tools/cpp:malloc" |
stamp | integer | Enable or disable link stamping; that is, whether to encode build information
Default: -1 |
env | dictionary: String → String | Specifies additional environment variables to set when the test is executed by The values of these environment variables are subject to NOTE: The environment variables are not set when you run the target outside of Default: {} |
swift_compiler_pluginCompiles and links a Swift compiler plugin (for example, a macro).
A compiler plugin is a standalone executable that minimally implements the
CompilerPlugin protocol from the SwiftCompilerPlugin module in swift-syntax.
As of the time of this writing (Xcode 15.0), a compiler plugin can contain one
or more macros, which can be associated with other Swift targets to perform
syntax-tree-based expansions.
When a swift_compiler_plugin target is listed in the plugins attribute of a
swift_library, it will be loaded by that library and any targets that directly
depend on it. (The plugins attribute also exists on swift_binary,
swift_test, and swift_compiler_plugin itself, to support plugins that are
only used within those targets.)
Compiler plugins also support being built as a library so that they can be
tested. The swift_test rule can contain swift_compiler_plugin targets in its
deps, and the plugin's module can be imported by the test's sources so that
unit tests can be written against the plugin.
Example:
# The actual macro code, using SwiftSyntax swift_compiler_plugin( name = "Macros", srcs = glob(["Macros/*.swift"]), deps = [ "@swift-syntax//:SwiftSyntax", "@swift-syntax//:SwiftCompilerPlugin", "@swift-syntax//:SwiftSyntaxMacros", ], ) # A target testing the macro itself swift_test( name = "MacrosTests", srcs = glob(["MacrosTests/*.swift"]), deps = [ ":Macros", "@swift-syntax//:SwiftSyntaxMacrosTestSupport", ], ) # The library that defines the macro hook for use in your project swift_library( name = "MacroLibrary", srcs = glob(["MacroLibrary/*.swift"]), plugins = [":Macros"], ) # A consumer of the macro library. This doesn't have to be separate from the # MacroLibrary depending on what makes sense for your project's organization swift_library( name = "MacroConsumer", srcs = glob(["Sources/*.swift"]), deps = [":MacroLibrary"], )
| Attribute | Type | Description |
|---|---|---|
*name | name | A unique name for this target. |
data | list of labels | The list of files needed by this target at runtime. Files and targets named in the Default: [] |
deps | list of labels | A list of targets that are dependencies of the target being built, which will be If the Swift toolchain supports implementation-only imports ( Allowed kinds of dependencies are:
Default: [] |
copts | list of strings | Additional compiler options that should be passed to Default: [] |
defines | list of strings | 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 Each string is prepended with Default: [] |
module_name | string | The name of the Swift module being built. If left unspecified, the module name will be computed based on the target's Default: "" |
package_name | string | The semantic package of the Swift target being built. Targets with the same Default: "" |
plugins | list of labels | A list of Default: [] |
srcs | list of labels | A list of Except in very rare circumstances, a Swift source file should only appear in a Default: [] |
swiftc_inputs | list of labels | Additional files that are referenced using Default: [] |
additional_linker_inputs | list of labels | List of additional files needed by the linker. These files will be passed to the linker when linking the binary target. Default: [] |
linkopts | list of strings | Additional linker options that should be passed to Default: [] |
malloc | label | Override the default dependency on By default, Swift binaries are linked against Default: "@bazel_tools//tools/cpp:malloc" |
stamp | integer | Enable or disable link stamping; that is, whether to encode build information
Default: 0 |
swift_compiler_plugin_importAllows for a Swift compiler plugin to be loaded from a prebuilt executable or
some other binary-propagating rule, instead of building the plugin from source
using swift_compiler_plugin.
| Attribute | Type | Description |
|---|---|---|
*name | name | A unique name for this target. |
*executable | label | The compiler plugin executable that will be passed to the Swift compiler when |
*module_names | list of strings | The list of names of Swift modules in the plugin executable that provide |
swift_cross_import_overlayDeclares a cross-import overlay that will be automatically added as a dependency
by the toolchain if its declaring and bystanding modules are both imported.
Since Bazel requires the dependency graph to be explicit, cross-import overlays
do not work correctly when the Swift compiler attempts to import them
automatically when they aren't represented in the graph. Users can explicitly
depend on the cross-import overlay module, but this is unsatisfying because
there is no single import declaration in the source code that indicates what
needs to be depended on.
To address this, the toolchain owner can define a swift_cross_import_overlay
target for each cross-import overlay that they wish to support and set them as
cross_import_overlays on the toolchain. During Swift compilation analysis, the
direct dependencies will be scanned and if any pair of dependencies matches a
cross-import overlay defined by the toolchain, the overlay module will be
automatically injected as a dependency as well.
NOTE: This rule and its associated APIs only exists to support cross-import
overlays already defined by Apple's SDKs. Since cross-import overlays are not
a public feature of the compiler and its design and implementation may change in
the future, this rule is not recommended for other widespread use.
| Attribute | Type | Description |
|---|---|---|
*name | name | A unique name for this target. |
*bystanding_module | label | A label for the target representing the second of the two modules (the other |
bystanding_module_name | string | The name of the bystanding module from the target specified by the Default: "" |
*declaring_module | label | A label for the target representing the first of the two modules (the other |
declaring_module_name | string | The name of the declaring module from the target specified by the Default: "" |
*deps | list of labels | A non-empty list of targets representing modules that should be passed as |
*swiftoverlay | string | The path to the SDK |
swift_feature_allowlistLimits the ability to request or disable certain features to a set of packages
(and possibly subpackages) in the workspace.
A Swift toolchain target can reference any number (zero or more) of
swift_feature_allowlist targets. The features managed by these allowlists may
overlap. For some package P, a feature is allowed to be used by targets in
that package if P matches the packages patterns in all of the allowlists
that manage that feature.
A feature that is not managed by any allowlist is allowed to be used by any
package.
| Attribute | Type | Description |
|---|---|---|
*name | name | A unique name for this target. |
aspect_ids | list of strings | A list of strings representing the identifiers of aspects that are allowed to Aspect identifiers are each expected to be of the form Default: [] |
managed_features | list of strings | A list of feature strings that are permitted to be specified by the targets in For example, Default: [] |
*packages | list of strings | A list of strings representing packages (possibly recursive) whose targets are
Exclusions always take priority over inclusions; order in the list is |
swift_importAllows for the use of Swift textual module interfaces and/or precompiled Swift
modules as dependencies in other swift_library and swift_binary targets.
To use swift_import targets across Xcode versions and/or OS versions, it is
required to use .swiftinterface files. These can be produced by the pre-built
target if built with:
--features=swift.enable_library_evolution--features=swift.emit_swiftinterface
If the pre-built target supports .private.swiftinterface files, these can be
used instead of .swiftinterface files in the swiftinterface attribute.
To import pre-built Swift modules that use @_spi when using swiftinterface,
the .private.swiftinterface files are required in order to build any code that
uses the API marked with @_spi.
| Attribute | Type | Description |
|---|---|---|
*name | name | A unique name for this target. |
data | list of labels | The list of files needed by this target at runtime. Files and targets named in the Default: [] |
deps | list of labels | A list of targets that are dependencies of the target being built, which will be If the Swift toolchain supports implementation-only imports ( Allowed kinds of dependencies are:
Default: [] |
archives | list of labels | The list of Default: [] |
*module_name | string | The name of the module represented by this target. |
plugins | list of labels | A list of Default: [] |
swiftdoc | label | The Default: None |
swiftinterface | label | The Default: None |
swiftmodule | label | The Default: None |
swift_interop_hintDefines an aspect hint that associates non-Swift BUILD targets with additional
information required for them to be imported by Swift.
Some build rules, such as objc_library, support interoperability with Swift
simply by depending on them; a module map is generated automatically. This is
for convenience, because the common case is that most objc_library targets
contain code that is compatible (i.e., capable of being imported) by Swift.
For other rules, like cc_library, additional information must be provided to
indicate that a particular target is compatible with Swift. This is done using
the aspect_hints attribute and the swift_interop_hint rule.
Using the automatically derived module name (recommended)
If you want to import a non-Swift, non-Objective-C target into Swift using the
module name that is automatically derived from the BUILD label, there is no need
to declare an instance of swift_interop_hint. A canonical one that requests
module name derivation has been provided in
@rules_swift//swift:auto_module. Simply add it to the aspect_hints of
the target you wish to import:
# //my/project/BUILD cc_library( name = "somelib", srcs = ["somelib.c"], hdrs = ["somelib.h"], aspect_hints = ["@rules_swift//swift:auto_module"], )
When this cc_library is a dependency of a Swift target, a module map will be
generated for it. In this case, the module's name would be my_project_somelib.
Using an explicit module name
If you need to provide an explicit name for the module (for example, if it is
part of a third-party library that expects to be imported with a specific name),
then you can declare your own swift_interop_hint target to define the name:
# //my/project/BUILD cc_library( name = "somelib", srcs = ["somelib.c"], hdrs = ["somelib.h"], aspect_hints = [":somelib_swift_interop"], ) swift_interop_hint( name = "somelib_swift_interop", module_name = "CSomeLib", )
When this cc_library is a dependency of a Swift target, a module map will be
generated for it with the module name CSomeLib.
Using a custom module map
In rare cases, the automatically generated module map may not be suitable. For
example, a Swift module may depend on a C module that defines specific
submodules, and this is not handled by the Swift build rules. In this case, you
can provide the module map file using the module_map attribute.
When setting the module_map attribute, module_name must also be set to the
name of the desired top-level module; it cannot be omitted.
# //my/project/BUILD cc_library( name = "somelib", srcs = ["somelib.c"], hdrs = ["somelib.h"], aspect_hints = [":somelib_swift_interop"], ) swift_interop_hint( name = "somelib_swift_interop", module_map = "module.modulemap", module_name = "CSomeLib", )
Suppressing a module
As mentioned above, objc_library and other Objective-C targets generate
modules by default, without an explicit hint, for convenience. In some
situations, this behavior may not be desirable. For example, an objc_library
might contain only Objective-C++ code in its headers that would not be possible
to import into Swift at all.
When building with implicit modules, this is not typically an issue because the
module map would only be used if Swift code tried to import it (although it does
create useless actions and compiler inputs during the build). When building with
explicit modules, however, Bazel needs to know which targets represent modules
that it can compile and which do not.
In these cases, there is no need to declare an instance of swift_interop_hint.
A canonical one that suppresses module generation has been provided in
@rules_swift//swift:no_module. Simply add it to the aspect_hints of
the target whose module you wish to suppress:
# //my/project/BUILD objc_library( name = "somelib", srcs = ["somelib.mm"], hdrs = ["somelib.h"], aspect_hints = ["@rules_swift//swift:no_module"], )
When this objc_library is a dependency of a Swift target, no module map or
explicit module will be generated for it, nor will any Swift information from
its transitive dependencies be propagated.
| Attribute | Type | Description |
|---|---|---|
*name | name | A unique name for this target. |
exclude_hdrs | list of labels | A list of header files that should be excluded from the Clang module generated This attribute may only be specified if a custom Default: [] |
module_map | label | An optional custom If this attribute is omitted, a module map will be automatically generated based If this attribute is provided, then Default: None |
module_name | string | The name that will be used to import the hinted module into Swift. If left unspecified, the module name will be computed based on the hinted Default: "" |
suppressed | boolean | If Default: False |
swift_libraryCompiles and links Swift code into a static library and Swift module.
| Attribute | Type | Description |
|---|---|---|
*name | name | A unique name for this target. |
data | list of labels | The list of files needed by this target at runtime. Files and targets named in the Default: [] |
deps | list of labels | A list of targets that are dependencies of the target being built, which will be If the Swift toolchain supports implementation-only imports ( Allowed kinds of dependencies are:
Default: [] |
copts | list of strings | Additional compiler options that should be passed to Default: [] |
defines | list of strings | 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 Each string is prepended with Default: [] |
module_name | string | The name of the Swift module being built. If left unspecified, the module name will be computed based on the target's Default: "" |
package_name | string | The semantic package of the Swift target being built. Targets with the same Default: "" |
plugins | list of labels | A list of Default: [] |
*srcs | list of labels | A list of Except in very rare circumstances, a Swift source file should only appear in a |
swiftc_inputs | list of labels | Additional files that are referenced using Default: [] |
always_include_developer_search_paths | boolean | If Default: False |
library_evolution | boolean | Indicates whether the Swift code should be compiled with library evolution mode This attribute should be used to compile a module that will be distributed as Default: False |
alwayslink | boolean | If Swift protocol conformances don't create linker references. Likewise, if the "All the object files" for this module is also somewhat fuzzy. Unlike C, C++, Swift Package Manager always passes the individual Note that by default, this value will default to True. But if the Default: True |
generated_header_name | string | The name of the generated Objective-C interface header. This name must end with If this attribute is not specified, then the default behavior is to name the This attribute is ignored if the toolchain does not support generating headers. Default: "" |
generates_header | boolean | If True, an Objective-C header will be generated for this target, in the same Targets should only set this attribute to True if they export Objective-C APIs. Default: False |
linkopts | list of strings | Additional linker options that should be passed to the linker for the binary Default: [] |
linkstatic | boolean | If True, the Swift module will be built for static linking. This will make all Default: True |
private_deps | list of labels | A list of targets that are implementation-only dependencies of the target being Allowed kinds of dependencies are:
Default: [] |
swift_library_groupGroups Swift compatible libraries (e.g. swift_library and objc_library).
The target can be used anywhere a swift_library can be used. It behaves
similar to source-less {cc,obj}_library targets.
A new module isn't created for this target, you need to import the grouped
libraries directly.
| Attribute | Type | Description |
|---|---|---|
*name | name | A unique name for this target. |
deps | list of labels | A list of targets that should be included in the group.
Default: [] |
swift_module_mappingDefines a set of
module aliases
that will be passed to the Swift compiler.
This rule defines a mapping from original module names to aliased names. This is
useful if you are building a library or framework for external use and want to
ensure that dependencies do not conflict with other versions of the same library
that another framework or the client may use.
To use this feature, first define a swift_module_mapping target that lists the
aliases you need:
# //some/package/BUILD swift_library( name = "Utils", srcs = [...], module_name = "Utils", ) swift_library( name = "Framework", srcs = [...], module_name = "Framework", deps = [":Utils"], ) swift_module_mapping( name = "mapping", aliases = { "Utils": "GameUtils", }, )
Then, pass the label of that target to Bazel using the
--@rules_swift//swift:module_mapping build flag:
bazel build //some/package:Framework \ --@rules_swift//swift:module_mapping=//some/package:mapping
When Utils is compiled, it will be given the module name GameUtils instead.
Then, when Framework is compiled, it will import GameUtils anywhere that the
source asked to import Utils.
| Attribute | Type | Description |
|---|---|---|
*name | name | A unique name for this target. |
*aliases | dictionary: String → String | A dictionary that remaps the names of Swift modules. Each key in the dictionary is the name of a module as it is written in source |
swift_module_mapping_testValidates that a swift_module_mapping target covers all the modules in the
transitive closure of a list of dependencies.
If you are building a static library or framework for external distribution and
you are using swift_module_mapping to rename some of the modules used by your
implementation, this rule will detect if any of your dependencies have taken on
a new dependency that you need to add to the mapping (otherwise, its symbols
would leak into your library with their original names).
When executed, this test will collect the names of all Swift modules in the
transitive closure of deps. System modules and modules whose names are listed
in the exclude attribute are omitted. Then, the test will fail if any of the
remaining modules collected are not present in the aliases of the
swift_module_mapping target specified by the mapping attribute.
| Attribute | Type | Description |
|---|---|---|
*name | name | A unique name for this target. |
exclude | list of strings | A list of module names that may be in the transitive closure of Default: [] |
*mapping | label | The label of a |
*deps | list of labels | A list of Swift targets whose transitive closure will be validated against the |
swift_overlayA Swift overlay that sits on top of a C/Objective-C library, allowing an author
of a C/Objective-C library to create additional Swift-specific APIs that are
automatically available when a Swift target depends on their C/Objective-C
library.
The Swift overlay will only be compiled when other Swift targets depend on the
original library that uses the overlay; non-Swift clients depending on the
original library will not cause the Swift overlay code to be built or linked.
This is done to retain optimium build performance and binary size for non-Swift
clients. For this reason, swift_overlay is not a general purpose mechanism
for creating mixed-language modules; swift_overlay does not support generation
of an Objective-C header.
The swift_overlay rule does not perform any compilation of its own. Instead,
it must be placed in the aspect_hints attribute of another rule such as
objc_library or cc_library. For example,
objc_library( name = "MyModule", srcs = ["MyModule.m"], hdrs = ["MyModule.h"], aspect_hints = [":MyModule_overlay"], deps = [...], ) swift_overlay( name = "MyModule_overlay", srcs = ["MyModule.swift"], deps = [...], )
When some other Swift target, such as a swift_library, depends on MyModule,
the Swift code in MyModule_overlay will be compiled into the same module.
Therefore, when that library imports MyModule, it will see the APIs from the
objc_library and the swift_overlay as a single combined module.
When writing a Swift overlay, the Swift code must do a re-exporting import of
its own module in order to access the C/Objective-C APIs; they are not available
automatically. Continuing the example above, any Swift sources that want to use
or extend the API from the C/Objective-C side of the module would need to write
the following:
@_exported import MyModule
The swift_overlay rule supports all the same attributes as swift_library,
except for the following:
module_nameis not supported because the overlay inherits the same module
name as the target it is attached to.generates_headerandgenerated_header_nameare not supported because it
is assumed that the overlay is pure Swift code that does not export any APIs
that would be of interest to C/Objective-C clients.
Aside from its module name and its underlying C/Objective-C module dependency,
swift_overlay does not inherit anything else from its associated target. If
the swift_overlay imports any modules other than its C/Objective-C side, the
overlay target must explicitly depend on them as well. This means that an
overlay can have a different set of dependencies than the underlying module, if
desired.
There is a tight coupling between a Swift overlay and the C/Objective-C module
to which it is being applied, so a specific swift_overlay target should only
be referenced by the aspect_hints of a single objc_library or cc_library
target. Referencing a swift_overlay from multiple targets' aspect_hints is
almost always an anti-pattern.
| Attribute | Type | Description |
|---|---|---|
*name | name | A unique name for this target. |
deps | list of labels | A list of targets that are dependencies of the target being built, which will be If the Swift toolchain supports implementation-only imports ( Allowed kinds of dependencies are:
Default: [] |
copts | list of strings | Additional compiler options that should be passed to Default: [] |
defines | list of strings | 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 Each string is prepended with Default: [] |
package_name | string | The semantic package of the Swift target being built. Targets with the same Default: "" |
plugins | list of labels | A list of Default: [] |
*srcs | list of labels | A list of Except in very rare circumstances, a Swift source file should only appear in a |
swiftc_inputs | list of labels | Additional files that are referenced using Default: [] |
always_include_developer_search_paths | boolean | If Default: False |
library_evolution | boolean | Indicates whether the Swift code should be compiled with library evolution mode This attribute should be used to compile a module that will be distributed as Default: False |
alwayslink | boolean | If Swift protocol conformances don't create linker references. Likewise, if the "All the object files" for this module is also somewhat fuzzy. Unlike C, C++, Swift Package Manager always passes the individual Note that by default, this value will default to True. But if the Default: True |
linkopts | list of strings | Additional linker options that should be passed to the linker for the binary Default: [] |
linkstatic | boolean | If True, the Swift module will be built for static linking. This will make all Default: True |
private_deps | list of labels | A list of targets that are implementation-only dependencies of the target being Allowed kinds of dependencies are:
Default: [] |
swift_package_configurationA compilation configuration to apply to the Swift targets in a set of packages.
A Swift toolchain target can reference any number (zero or more) of
swift_package_configuration targets. When the compilation action for a target
is being configured, those package configurations will be applied if the
target's label is included by the package specifications in the configuration.
| Attribute | Type | Description |
|---|---|---|
*name | name | A unique name for this target. |
configured_features | list of strings | A list of feature strings that will be applied by default to targets in the This list may include both feature names and/or negations (a name with a leading For example, Default: [] |
*packages | list of strings | A list of strings representing packages (possibly recursive) whose targets will
Exclusions always take priority over inclusions; order in the list is |
swift_proto_compiler| Attribute | Type | Description |
|---|---|---|
*name | name | A unique name for this target. |
bundled_proto_paths | list of strings | List of proto paths for which to skip generation because they're built into the modules Default: ["google/protobuf/any.proto", "google/protobuf/api.proto", "google/protobuf/descriptor.proto", "google/protobuf/duration.proto", "google/protobuf/empty.proto", "google/protobuf/field_mask.proto", "google/protobuf/source_context.proto", "google/protobuf/struct.proto", "google/protobuf/timestamp.proto", "google/protobuf/type.proto", "google/protobuf/wrappers.proto"] |
deps | list of labels | List of targets providing SwiftInfo and CcInfo. Default: [] |
protoc | label | Default: None |
*plugin | label | A proto compiler plugin executable binary. For example: |
*plugin_name | string | Name of the proto compiler plugin passed to protoc. For example:
This name will be used to prefix the option and output directory arguments. E.g.:
See the protobuf API reference for more information. |
*plugin_option_allowlist | list of strings | Allowlist of options allowed by the plugin. |
*plugin_options | dictionary: String → String | Dictionary of plugin options passed to the plugin. These are prefixed with the plugin_name + "_opt". E.g.:
Would be passed to protoc as: |
*suffixes | list of strings | Suffix used for Swift files generated by the plugin from protos. E.g.
Each compiler target should configure this based on the suffix applied to the generated files. |
swift_proto_libraryGenerates a Swift static library from one or more targets producing ProtoInfo.
load("@protobuf//bazel:proto_library.bzl", "proto_library") load("//proto:swift_proto_library.bzl", "swift_proto_library") proto_library( name = "foo", srcs = ["foo.proto"], ) swift_proto_library( name = "foo_swift", protos = [":foo"], )
If your protos depend on protos from other targets, add dependencies between the
swift_proto_library targets which mirror the dependencies between the proto targets.
load("@protobuf//bazel:proto_library.bzl", "proto_library") load("//proto:swift_proto_library.bzl", "swift_proto_library") proto_library( name = "bar", srcs = ["bar.proto"], deps = [":foo"], ) swift_proto_library( name = "bar_swift", protos = [":bar"], deps = [":foo_swift"], )
| Attribute | Type | Description |
|---|---|---|
*name | name | A unique name for this target. |
data | list of labels | The list of files needed by this target at runtime. Files and targets named in the Default: [] |
deps | list of labels | A list of targets that are dependencies of the target being built, which will be If the Swift toolchain supports implementation-only imports ( Allowed kinds of dependencies are:
Default: [] |
copts | list of strings | Additional compiler options that should be passed to Default: [] |
defines | list of strings | 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 Each string is prepended with Default: [] |
module_name | string | The name of the Swift module being built. If left unspecified, the module name will be computed based on the target's Default: "" |
package_name | string | The semantic package of the Swift target being built. Targets with the same Default: "" |
plugins | list of labels | A list of Default: [] |
srcs | list of labels | A list of Except in very rare circumstances, a Swift source file should only appear in a Default: [] |
swiftc_inputs | list of labels | Additional files that are referenced using Default: [] |
always_include_developer_search_paths | boolean | If Default: False |
library_evolution | boolean | Indicates whether the Swift code should be compiled with library evolution mode This attribute should be used to compile a module that will be distributed as Default: False |
alwayslink | boolean | If Swift protocol conformances don't create linker references. Likewise, if the "All the object files" for this module is also somewhat fuzzy. Unlike C, C++, Swift Package Manager always passes the individual Note that by default, this value will default to True. But if the Default: True |
generated_header_name | string | The name of the generated Objective-C interface header. This name must end with If this attribute is not specified, then the default behavior is to name the This attribute is ignored if the toolchain does not support generating headers. Default: "" |
generates_header | boolean | If True, an Objective-C header will be generated for this target, in the same Targets should only set this attribute to True if they export Objective-C APIs. Default: False |
linkopts | list of strings | Additional linker options that should be passed to the linker for the binary Default: [] |
linkstatic | boolean | If True, the Swift module will be built for static linking. This will make all Default: True |
protos | list of labels | A list of Default: [] |
compilers | list of labels | One or more Default: ["@rules_swift//proto/compilers:swift_proto"] |
additional_compiler_deps | list of labels | List of additional dependencies required by the generated Swift code at compile time, Allowed kinds of dependencies are:
Default: [] |
additional_compiler_info | dictionary: String → String | Dictionary of additional information passed to the compiler targets. Default: {} |
swift_proto_library_groupGenerates a collection of Swift static library from a target producing ProtoInfo and its dependencies.
This rule is intended to facilitate migration from the deprecated swift proto library rules to the new ones.
Unlike swift_proto_library which is a drop-in-replacement for swift_library,
this rule uses an aspect over the direct proto library dependency and its transitive dependencies,
compiling each into a swift static library.
For example, in the following targets, the proto_library_group_swift_proto target only depends on
package_2_proto target, and this transitively depends on package_1_proto.
When used as a dependency from a swift_library or swift_binary target,
two modules generated from these proto library targets are visible.
Because these are derived from the proto library targets via an aspect, though,
you cannot customize many of the attributes including the swift proto compiler targets or
the module names. The module names are derived from the proto library names.
In this case, the module names are:
import examples_xplatform_proto_library_group_package_1_package_1_proto
import examples_xplatform_proto_library_group_package_2_package_2_proto
For this reason, we would encourage new consumers of the proto rules to use
swift_proto_library when possible.
proto_library( name = "package_1_proto", srcs = glob(["*.proto"]), visibility = ["//visibility:public"], ) ... proto_library( name = "package_2_proto", srcs = glob(["*.proto"]), visibility = ["//visibility:public"], deps = ["//examples/xplatform/proto_library_group/package_1:package_1_proto"], ) ... swift_proto_library_group( name = "proto_library_group_swift_proto", proto = "//examples/xplatform/proto_library_group/package_2:package_2_proto", ) ... swift_binary( name = "proto_library_group_example", srcs = ["main.swift"], deps = [ ":proto_library_group_swift_proto", ], )
| Attribute | Type | Description |
|---|---|---|
*name | name | A unique name for this target. |
compiler | label | A Default: "@rules_swift//proto/compilers:swift_proto" |
*proto | label | Exactly one |
swift_testCompiles and links Swift code into an executable test target.
XCTest Test Discovery
By default, this rule performs test discovery that finds tests written with
the XCTest framework and executes them automatically, without the user
providing their own main entry point.
On Apple platforms, XCTest-style tests are automatically discovered and
executed using the Objective-C runtime. To provide the same behavior on Linux,
the swift_test rule performs its own scan for XCTest-style tests. In other
words, you can write a single swift_test target that executes the same tests
on either Linux or Apple platforms.
There are two approaches that one can take to write a swift_test that supports
test discovery:
-
Preferred approach: Write a
swift_testtarget whosesrcscontain
your tests. In this mode, only these sources will be scanned for tests;
direct dependencies will not be scanned. -
Write a
swift_testtarget with nosrcs. In this mode, all direct
dependencies of the target will be scanned for tests; indirect dependencies
will not be scanned. This approach is useful if you want to share tests
with an Apple-specific test target likeios_unit_test.
See the documentation of the discover_tests attribute for more information
about how this behavior affects the rule's outputs.
Test Bundles
The swift_test rule always produces a standard executable binary. This is true
even when targeting macOS, where the typical practice is to use a Mach-O bundle
binary. However, when targeting macOS, the executable binary is still generated
inside a bundle-like directory structure: {name}.xctest/Contents/MacOS/{name}.
This allows tests to still work if they contain logic that looks for the path to
their bundle.
Test Filtering
swift_test supports Bazel's --test_filter flag on all platforms (i.e., Apple
and Linux), which can be used to run only a subset of tests. The test filter can
be a test name of the form ClassName/MethodName or a regular expression that
matches names of that form.
For example,
-
--test_filter='ArrayTests/testAppend'would only run the test method
testAppendin theArrayTestsclass. -
--test_filter='ArrayTests/test(App.*|Ins.*)'would run all test methods
starting withtestApportestInsin theArrayTestsclass.
Xcode Integration
If integrating with Xcode, the relative paths in test binaries can prevent the
Issue navigator from working for test failures. To work around this, you can
have the paths made absolute via swizzling by enabling the
"apple.swizzle_absolute_xcttestsourcelocation" feature. You'll also need to
set the BUILD_WORKSPACE_DIRECTORY environment variable in your scheme to the
root of your workspace (i.e. $(SRCROOT)).
| Attribute | Type | Description |
|---|---|---|
*name | name | A unique name for this target. |
data | list of labels | The list of files needed by this target at runtime. Files and targets named in the Default: [] |
deps | list of labels | A list of targets that are dependencies of the target being built, which will be If the Swift toolchain supports implementation-only imports ( Allowed kinds of dependencies are:
Default: [] |
copts | list of strings | Additional compiler options that should be passed to Default: [] |
defines | list of strings | 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 Each string is prepended with Default: [] |
module_name | string | The name of the Swift module being built. If left unspecified, the module name will be computed based on the target's Default: "" |
package_name | string | The semantic package of the Swift target being built. Targets with the same Default: "" |
plugins | list of labels | A list of Default: [] |
srcs | list of labels | A list of Except in very rare circumstances, a Swift source file should only appear in a Default: [] |
swiftc_inputs | list of labels | Additional files that are referenced using Default: [] |
additional_linker_inputs | list of labels | List of additional files needed by the linker. These files will be passed to the linker when linking the binary target. Default: [] |
linkopts | list of strings | Additional linker options that should be passed to Default: [] |
malloc | label | Override the default dependency on By default, Swift binaries are linked against Default: "@bazel_tools//tools/cpp:malloc" |
stamp | integer | Enable or disable link stamping; that is, whether to encode build information
Default: 0 |
env | dictionary: String → String | Dictionary of environment variables that should be set during the test execution. Default: {} |
discover_tests | boolean | Determines whether or not tests are automatically discovered in the binary. The Tests are discovered in a platform-specific manner. On Apple platforms, they are If tests are discovered, then you should not provide your own Default: True |
env_inherit | list of strings | Specifies additional environment variables to inherit from the external Default: [] |
universal_swift_compiler_pluginWraps an existing swift_compiler_plugin target to produce a universal binary.
This is useful to allow sharing of caches between Intel and Apple Silicon Macs
at the cost of building everything twice.
Example:
# The actual macro code, using SwiftSyntax, as usual. swift_compiler_plugin( name = "Macros", srcs = glob(["Macros/*.swift"]), deps = [ "@swift-syntax//:SwiftSyntax", "@swift-syntax//:SwiftCompilerPlugin", "@swift-syntax//:SwiftSyntaxMacros", ], ) # Wrap your compiler plugin in this universal shim. universal_swift_compiler_plugin( name = "Macros.universal", plugin = ":Macros", ) # The library that defines the macro hook for use in your project, this # references the universal_swift_compiler_plugin. swift_library( name = "MacroLibrary", srcs = glob(["MacroLibrary/*.swift"]), plugins = [":Macros.universal"], )
@rules_swift@rules_swift//swift:providers.bzl
Defines providers propagated by the Swift BUILD rules and related utilities.
This file must be kept lightweight and not load any other .bzl files that may
update frequently (e.g., other files in rules_swift). This ensures that changes
to the rule implementations do not unnecessarily cause reanalysis impacting
users who just load these providers to inspect and/or repropagate them.
Functions & Macros
create_swift_module_contextCreates a value containing Clang/Swift module artifacts of a dependency.
It is possible for both clang and swift to be present; this is the case
for Swift modules that generate an Objective-C header, where the Swift
module artifacts are propagated in the swift context and the generated
header and module map are propagated in the clang context.
Though rare, it is also permitted for both the clang and swift arguments
to be None. One example of how this can be used is to model system
dependencies (like Apple SDK frameworks) that are implicitly available as
part of a non-hermetic SDK (Xcode) but do not propagate any artifacts of
their own. This would only apply in a build using implicit modules, however;
when using explicit modules, one would propagate the module artifacts
explicitly. But allowing for the empty case keeps the build graph consistent
if switching between the two modes is necessary, since it will not change
the set of transitive module names that are propagated by dependencies
(which other build rules may want to depend on for their own analysis).
Parameters
*name | The name of the module. |
clang | A value returned by Default: None |
const_gather_protocols | A list of protocol names from which constant Default: [] |
compilation_context | A value returned from Default: None |
is_framework | Indictates whether the module is a framework module. The Default: False |
is_system | Indicates whether the module is a system module. The default Default: False |
swift | A value returned by Default: None |
create_clang_module_inputsCreates a value representing a Clang module used as a Swift dependency.
Parameters
*compilation_context | A |
*module_map | The text module map file that defines this module. This |
precompiled_module | A Default: None |
strict_includes | A Default: None |
create_swift_module_inputsCreates a value representing a Swift module use as a Swift dependency.
Parameters
ast_files | A list of Default: [] |
const_protocols_to_gather | A list of protocol names from which constant Default: [] |
defines | A list of defines that will be provided as Default: [] |
generated_header | A Default: None |
indexstore | A Default: None |
original_module_name | The original name of the module if it was changed Default: None |
plugins | A list of Default: [] |
private_swiftinterface | The Default: None |
*swiftdoc | The |
swiftinterface | The Default: None |
*swiftmodule | The |
swiftsourceinfo | The Default: None |
Providers
SwiftBinaryInfoInformation about a binary target's module.
swift_binary and swift_compiler_plugin propagate this provider that wraps
CcInfo and SwiftInfo providers, instead of propagating them directly, so
that swift_test targets can depend on those binaries and test their modules
(similar to what Swift Package Manager allows) without allowing any
swift_library to depend on an arbitrary binary.
Fields
cc_info | A |
swift_info | A |
SwiftFeatureAllowlistInfoDescribes a set of features and the packages and aspects that are allowed to
request or disable them.
This provider is an internal implementation detail of the rules; users should
not rely on it or assume that its structure is stable.
Fields
allowlist_label | A string containing the label of the |
aspect_ids | A list of strings representing identifiers of aspects that are allowed to |
managed_features | A list of strings representing feature names or their negations that packages in |
package_specs | A list of |
SwiftInfoContains information about the compiled artifacts of a Swift module.
This provider has a custom initializer that will merge the transitive modules of
a list of SwiftInfo providers, rather than a separate "merge" function. The
correct signature when creating a new SwiftInfo provider is the following:
SwiftInfo( direct_swift_infos, modules, swift_infos, )
where the arguments are:
direct_swift_infos: A list ofSwiftInfoproviders from dependencies
whose direct modules should be treated as direct modules in the resulting
provider, in addition to their transitive modules being merged.modules: A list of values (as returned bycreate_swift_module_context)
that represent Clang and/or Swift module artifacts that are direct outputs
of the target being built.swift_infos: A list ofSwiftInfoproviders from dependencies whose
transitive modules should be merged into the resulting provider.
When reading an existing SwiftInfo provider, it has the two fields described
below.
Fields
direct_modules |
|
transitive_modules |
|
SwiftOverlayInfoContains additional artifacts from the Swift overlay for a C/Objective-C module
that also need to be propagated to clients of the module for it to work
properly.
Fields
linking_context |
|
SwiftPackageConfigurationInfoDescribes a compiler configuration that is applied by default to targets in a
specific set of packages.
This provider is an internal implementation detail of the rules; users should
not rely on it or assume that its structure is stable.
Fields
disabled_features |
|
enabled_features |
|
package_specs | A list of |
SwiftProtoCompilerInfoProvides information needed to generate Swift code from ProtoInfo providers
Fields
bundled_proto_paths | List of proto paths for which to skip generation because they're built into the modules |
compile | A function which compiles Swift source files from Args: Returns: |
compiler_deps | List of targets providing SwiftInfo and CcInfo. Well Known Types should be added as dependencies of the swift_proto_library |
internal | Opaque struct passing information from the compiler target to the compile function. |
SwiftProtoInfoPropagates Swift-specific information about a proto_library.
Fields
module_name | The name of the Swift module compiled from the |
module_mappings |
|
direct_pbswift_files |
|
pbswift_files |
|
SwiftSymbolGraphInfoPropagates extracted symbol graph files from Swift modules.
Fields
direct_symbol_graphs |
Each
|
transitive_symbol_graphs |
|
SwiftSynthesizedInterfaceInfoPropagates synthesized Swift interfaces for modules.
Fields
direct_modules |
Each
|
transitive_modules |
|
SwiftToolchainInfoPropagates information about a Swift toolchain to compilation and linking rules
that use the toolchain.
Fields
action_configs | This field is an internal implementation detail of the build rules. |
cc_language | The |
cc_toolchain_info | The |
clang_implicit_deps_providers | A
For ease of use, this field is never |
const_protocols_to_gather |
|
cross_import_overlays | A list of |
debug_outputs_provider | An optional function that provides toolchain-specific logic around the handling If specified, this function must take the following keyword arguments:
It must return a
|
developer_dirs | A list of
|
entry_point_linkopts_provider | A function that returns flags that should be passed to the linker to control the This function must take the following keyword arguments:
It must return a
|
feature_allowlists | A list of |
generated_header_module_implicit_deps_providers | A
This is used to provide modular dependencies for the fixed inclusions (Darwin, For ease of use, this field is never |
implicit_deps_providers | A
For ease of use, this field is never |
module_aliases | A |
package_configurations | A list of |
requested_features |
These features determine various compilation and debugging behaviors of the |
root_dir |
|
runtime |
|
swift_worker |
|
system_modules | A
For ease of use, this field is never |
implicit_system_modules | A |
test_configuration |
This is used, for example, with Xcode-based toolchains to ensure that the |
tool_configs | This field is an internal implementation detail of the build rules. |
unsupported_features |
These features determine various compilation and debugging behaviors of the |
SwiftToolsInfoPropagates information about Swift toolchain tools that can be specified as
labels to pull them into the input root.
This provider allows users to specify Swift toolchain executables as explicit
dependencies, ensuring they are available in the execution environment.
Fields
swift_driver |
|
swift_autolink_extract |
|
swift_symbolgraph_extract |
|
additional_inputs |
|
SwiftClangModuleAspectInfoA "marker provider" (i.e., it has no fields) that is always returned when
swift_clang_module_aspect is applied to a target.
This provider exists because swift_clang_module_aspect cannot advertise that
it returns SwiftInfo (since some code paths do not). Users who want to ensure
aspect ordering via the required_aspect_providers parameter to their own
aspect function can require this provider instead, which
swift_clang_module_aspect does advertise.