@@ -1301,10 +1301,14 @@ def rustc_compile_action(
13011301 include_coverage (bool, optional): Whether to generate coverage information or not.
13021302
13031303 Returns:
1304- list: A list of the following providers:
1305- - (CrateInfo): info for the crate we just built; same as `crate_info` parameter.
1306- - (DepInfo): The transitive dependencies of this crate.
1307- - (DefaultInfo): The output file for this crate, and its runfiles.
1304+ dict: A dict mapping provider types to provider instances. Keys include:
1305+ - DefaultInfo: The output file for this crate, and its runfiles.
1306+ - CrateInfo: info for the crate we just built (or TestCrateInfo for staticlib/cdylib).
1307+ - DepInfo: The transitive dependencies of this crate.
1308+ - InstrumentedFilesInfo: Coverage information (if include_coverage is True).
1309+ - CcInfo: C/C++ interop info (if applicable).
1310+ - OutputGroupInfo: Additional output groups (if any).
1311+ Callers should convert to a list via `list(providers.values())` when returning from a rule.
13081312 """
13091313 deps = crate_info_dict .pop ("deps" )
13101314 proc_macro_deps = crate_info_dict .pop ("proc_macro_deps" )
@@ -1695,25 +1699,23 @@ def rustc_compile_action(
16951699 "metadata_files" : coverage_runfiles + [executable ] if executable else [],
16961700 })
16971701
1698- providers = [
1699- DefaultInfo (
1702+ providers = {
1703+ DefaultInfo : DefaultInfo (
17001704 # nb. This field is required for cc_library to depend on our output.
17011705 files = depset (outputs ),
17021706 runfiles = runfiles ,
17031707 executable = executable ,
17041708 ),
1705- ]
1709+ }
17061710
17071711 # When invoked by aspects (and when running `bazel coverage`), the
17081712 # baseline_coverage.dat created here will conflict with the baseline_coverage.dat of the
17091713 # underlying target, which is a build failure. So we add an option to disable it so that this
17101714 # function can be invoked from aspects for rules that have its own InstrumentedFilesInfo.
17111715 if include_coverage :
1712- providers .append (
1713- coverage_common .instrumented_files_info (
1714- ctx ,
1715- ** instrumented_files_kwargs
1716- ),
1716+ providers ["InstrumentedFilesInfo" ] = coverage_common .instrumented_files_info (
1717+ ctx ,
1718+ ** instrumented_files_kwargs
17171719 )
17181720
17191721 if crate_info_dict != None :
@@ -1732,11 +1734,20 @@ def rustc_compile_action(
17321734 # as such they shouldn't provide a CrateInfo. However, one may still want to
17331735 # write a rust_test for them, so we provide the CrateInfo wrapped in a provider
17341736 # that rust_test understands.
1735- providers . extend ( [rust_common .test_crate_info (crate = crate_info ), dep_info ] )
1737+ providers [rust_common .test_crate_info ] = rust_common . test_crate_info (crate = crate_info )
17361738 else :
1737- providers .extend ([crate_info , dep_info ])
1739+ providers [rust_common .crate_info ] = crate_info
1740+
1741+ providers [rust_common .dep_info ] = dep_info
17381742
1739- providers += establish_cc_info (ctx , attr , crate_info , toolchain , cc_toolchain , feature_configuration , interface_library )
1743+ cc_info_providers = establish_cc_info (ctx , attr , crate_info , toolchain , cc_toolchain , feature_configuration , interface_library )
1744+ for cc_provider in cc_info_providers :
1745+ # establish_cc_info returns CcInfo and optionally AllocatorLibrariesImplInfo
1746+ if type (cc_provider ) == "CcInfo" :
1747+ providers [CcInfo ] = cc_provider
1748+ else :
1749+ # AllocatorLibrariesImplInfo
1750+ providers [AllocatorLibrariesImplInfo ] = cc_provider
17401751
17411752 output_group_info = {}
17421753
@@ -1752,12 +1763,12 @@ def rustc_compile_action(
17521763 output_group_info ["rustc_output" ] = depset ([rustc_output ])
17531764
17541765 if output_group_info :
1755- providers . append ( OutputGroupInfo (** output_group_info ) )
1766+ providers [ OutputGroupInfo ] = OutputGroupInfo (** output_group_info )
17561767
17571768 # A bit unfortunate, but sidecar the lints info so rustdoc can access the
17581769 # set of lints from the target it is documenting.
17591770 if hasattr (ctx .attr , "lint_config" ) and ctx .attr .lint_config :
1760- providers . append ( ctx .attr .lint_config [LintsInfo ])
1771+ providers [ LintsInfo ] = ctx .attr .lint_config [LintsInfo ]
17611772
17621773 return providers
17631774
0 commit comments