Skip to content

Latest commit

 

History

History
156 lines (113 loc) · 16.1 KB

File metadata and controls

156 lines (113 loc) · 16.1 KB

The providers described below are propagated and required by various Swift build rules. Clients interested in writing custom rules that interface with the rules in this package should use these providers to communicate with the Swift build rules as needed.

On this page:

SwiftInfo

load("@rules_swift//doc:doc.bzl", "SwiftInfo")

SwiftInfo(*, direct_swift_infos, modules, swift_infos)

Contains 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 of SwiftInfo providers 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 by create_swift_module_context) that represent Clang and/or Swift module artifacts that are direct outputs of the target being built.
  • swift_infos: A list of SwiftInfo providers 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.

CONSTRUCTOR PARAMETERS

Name Description Default Value
direct_swift_infos

-

[]
modules

-

[]
swift_infos

-

[]

FIELDS

Name Description
direct_modules List of values returned from create_swift_module_context. The modules (both Swift and C/Objective-C) emitted by the library that propagated this provider.
transitive_modules Depset of values returned from create_swift_module_context. The transitive modules (both Swift and C/Objective-C) emitted by the library that propagated this provider and all of its dependencies.

SwiftProtoCompilerInfo

load("@rules_swift//doc:doc.bzl", "SwiftProtoCompilerInfo")

SwiftProtoCompilerInfo(bundled_proto_paths, compile, compiler_deps, internal)

Provides information needed to generate Swift code from ProtoInfo providers

FIELDS

Name Description
bundled_proto_paths List of proto paths for which to skip generation because they're built into the modules imported by the generated Swift proto code, e.g., SwiftProtobuf.
compile A function which compiles Swift source files from ProtoInfo providers.

Args: label: The label of the target for which the Swift files are being generated. actions: The actions object used to declare the files to be generated and the actions that generate them. swift_proto_compiler_info: This SwiftProtoCompilerInfo provider. additional_compiler_info: Additional information passed from the target target to the compiler. proto_infos: The list of ProtoInfo providers to compile. module_mappings: The module_mappings field of the SwiftProtoInfo for the target.

Returns: A list of .swift Files generated by the compiler.
compiler_deps List of targets providing SwiftInfo and CcInfo. These are added as dependencies to the swift compile action of the swift_proto_library. Typically these are proto runtime libraries.

Well Known Types should be added as dependencies of the swift_proto_library targets as needed to avoid compiling them unnecessarily.
internal Opaque struct passing information from the compiler target to the compile function.

SwiftProtoInfo

load("@rules_swift//doc:doc.bzl", "SwiftProtoInfo")

SwiftProtoInfo(module_name, module_mappings, direct_pbswift_files, pbswift_files)

Propagates Swift-specific information about a proto_library.

FIELDS

Name Description
module_name The name of the Swift module compiled from the swift_proto_library which produced this provider.
module_mappings list of structs. Each struct contains module_name and proto_file_paths fields that denote the transitive mappings from .proto files to Swift modules. This allows messages that reference messages in other libraries to import those modules in generated code.
direct_pbswift_files list of Files. The Swift source files (e.g. .pb.swift) generated from the ProtoInfo providers of the direct proto dependencies of the swift_proto_library target.
pbswift_files depset of Files. The Swift source files (e.g. .pb.swift) generated from the ProtoInfo providers of the direct and transitive transitive proto dependencies of the swift_proto_library target.

SwiftToolchainInfo

load("@rules_swift//doc:doc.bzl", "SwiftToolchainInfo")

SwiftToolchainInfo(action_configs, cc_language, cc_toolchain_info, clang_implicit_deps_providers,
                   const_protocols_to_gather, cross_import_overlays, debug_outputs_provider,
                   developer_dirs, entry_point_linkopts_provider, feature_allowlists,
                   generated_header_module_implicit_deps_providers, implicit_deps_providers,
                   module_aliases, package_configurations, requested_features, root_dir, swift_worker,
                   test_configuration, tool_configs, unsupported_features)

Propagates information about a Swift toolchain to compilation and linking rules that use the toolchain.

FIELDS

Name Description
action_configs This field is an internal implementation detail of the build rules.
cc_language The language that should be passed to cc_common APIs that take it as an argument.
cc_toolchain_info The cc_common.CcToolchainInfo provider from the Bazel C++ toolchain that this Swift toolchain depends on.
clang_implicit_deps_providers A struct with the following fields, which represent providers from targets that should be added as implicit dependencies of any precompiled explicit C/Objective-C modules:

* cc_infos: A list of CcInfo providers from targets specified as the toolchain's implicit dependencies.

* swift_infos: A list of SwiftInfo providers from targets specified as the toolchain's implicit dependencies.

For ease of use, this field is never None; it will always be a valid struct containing the fields described above, even if those lists are empty.
const_protocols_to_gather File. A JSON file specifying a list of protocols for extraction of conformances' const values.
cross_import_overlays A list of SwiftCrossImportOverlayInfo providers whose SwiftInfo providers will be automatically injected into the dependencies of Swift compilations if their declaring module and bystanding module are both already declared as dependencies.
debug_outputs_provider An optional function that provides toolchain-specific logic around the handling of additional debug outputs for swift_binary and swift_test targets.

If specified, this function must take the following keyword arguments:

* ctx: The rule context of the calling binary or test rule.

It must return a struct with the following fields:

* additional_outputs: Additional outputs expected from the linking action.

* variables_extension: A dictionary of additional crosstool variables to pass to the linking action.
developer_dirs A list of structs containing the following fields:

* developer_path_label: A string representing the type of developer path.

* path: A string representing the path to the developer framework.
entry_point_linkopts_provider A function that returns flags that should be passed to the linker to control the name of the entry point of a linked binary for rules that customize their entry point.

This function must take the following keyword arguments:

* entry_point_name: The name of the entry point function, as was passed to the Swift compiler using the -entry-point-function-name flag.

It must return a struct with the following fields:

* linkopts: A list of strings that will be passed as additional linker flags when linking a binary with a custom entry point.
feature_allowlists A list of SwiftFeatureAllowlistInfo providers that allow or prohibit packages from requesting or disabling features.
generated_header_module_implicit_deps_providers A struct with the following fields, which are providers from targets that should be treated as compile-time inputs to actions that precompile the explicit module for the generated Objective-C header of a Swift module:

* cc_infos: A list of CcInfo providers from targets specified as the toolchain's implicit dependencies.

* swift_infos: A list of SwiftInfo providers from targets specified as the toolchain's implicit dependencies.

This is used to provide modular dependencies for the fixed inclusions (Darwin, Foundation) that are unconditionally emitted in those files.

For ease of use, this field is never None; it will always be a valid struct containing the fields described above, even if those lists are empty.
implicit_deps_providers A struct with the following fields, which represent providers from targets that should be added as implicit dependencies of any Swift compilation or linking target (but not to precompiled explicit C/Objective-C modules):

* cc_infos: A list of CcInfo providers from targets specified as the toolchain's implicit dependencies.

* swift_infos: A list of SwiftInfo providers from targets specified as the toolchain's implicit dependencies.

For ease of use, this field is never None; it will always be a valid struct containing the fields described above, even if those lists are empty.
module_aliases A SwiftModuleAliasesInfo provider that defines the module aliases to use during compilation.
package_configurations A list of SwiftPackageConfigurationInfo providers that specify additional compilation configuration options that are applied to targets on a per-package basis.
requested_features List of strings. Features that should be implicitly enabled by default for targets built using this toolchain, unless overridden by the user by listing their negation in the features attribute of a target/package or in the --features command line flag.

These features determine various compilation and debugging behaviors of the Swift build rules, and they are also passed to the C++ APIs used when linking (so features defined in CROSSTOOL may be used here).
root_dir String. The workspace-relative root directory of the toolchain.
swift_worker File. The executable representing the worker executable used to invoke the compiler and other Swift tools (for both incremental and non-incremental compiles).
test_configuration Struct containing the following fields:

* binary_name: A template string used to compute the name of the output binary for swift_test rules. Any occurrences of the string "{name}" will be substituted by the name of the target.

* env: A dict of environment variables to be set when running tests that were built with this toolchain.

* execution_requirements: A dict of execution requirements for tests that were built with this toolchain.

* objc_test_discovery: A Boolean value indicating whether test targets should discover tests dynamically using the Objective-C runtime.

* test_linking_contexts: A list of CcLinkingContexts that provide additional flags to use when linking test binaries.

This is used, for example, with Xcode-based toolchains to ensure that the xctest helper and coverage tools are found in the correct developer directory when running tests.
tool_configs This field is an internal implementation detail of the build rules.
unsupported_features List of strings. Features that should be implicitly disabled by default for targets built using this toolchain, unless overridden by the user by listing them in the features attribute of a target/package or in the --features command line flag.

These features determine various compilation and debugging behaviors of the Swift build rules, and they are also passed to the C++ APIs used when linking (so features defined in CROSSTOOL may be used here).