@@ -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,24 @@ def rustc_compile_action(
16951699 "metadata_files" : coverage_runfiles + [executable ] if executable else [],
16961700 })
16971701
1698- providers = [
1699- DefaultInfo (
1702+ # Use string keys for providers since provider types are not hashable in all Bazel versions
1703+ providers = {
1704+ "DefaultInfo" : DefaultInfo (
17001705 # nb. This field is required for cc_library to depend on our output.
17011706 files = depset (outputs ),
17021707 runfiles = runfiles ,
17031708 executable = executable ,
17041709 ),
1705- ]
1710+ }
17061711
17071712 # When invoked by aspects (and when running `bazel coverage`), the
17081713 # baseline_coverage.dat created here will conflict with the baseline_coverage.dat of the
17091714 # underlying target, which is a build failure. So we add an option to disable it so that this
17101715 # function can be invoked from aspects for rules that have its own InstrumentedFilesInfo.
17111716 if include_coverage :
1712- providers .append (
1713- coverage_common .instrumented_files_info (
1714- ctx ,
1715- ** instrumented_files_kwargs
1716- ),
1717+ providers ["InstrumentedFilesInfo" ] = coverage_common .instrumented_files_info (
1718+ ctx ,
1719+ ** instrumented_files_kwargs
17171720 )
17181721
17191722 if crate_info_dict != None :
@@ -1732,11 +1735,20 @@ def rustc_compile_action(
17321735 # as such they shouldn't provide a CrateInfo. However, one may still want to
17331736 # write a rust_test for them, so we provide the CrateInfo wrapped in a provider
17341737 # that rust_test understands.
1735- providers . extend ([ rust_common .test_crate_info (crate = crate_info ), dep_info ] )
1738+ providers [ "test_crate_info" ] = rust_common .test_crate_info (crate = crate_info )
17361739 else :
1737- providers .extend ([crate_info , dep_info ])
1740+ providers ["crate_info" ] = crate_info
1741+
1742+ providers ["dep_info" ] = dep_info
17381743
1739- providers += establish_cc_info (ctx , attr , crate_info , toolchain , cc_toolchain , feature_configuration , interface_library )
1744+ cc_info_providers = establish_cc_info (ctx , attr , crate_info , toolchain , cc_toolchain , feature_configuration , interface_library )
1745+ for cc_provider in cc_info_providers :
1746+ # establish_cc_info returns CcInfo and optionally AllocatorLibrariesImplInfo
1747+ if type (cc_provider ) == "CcInfo" :
1748+ providers ["CcInfo" ] = cc_provider
1749+ else :
1750+ # AllocatorLibrariesImplInfo
1751+ providers ["AllocatorLibrariesImplInfo" ] = cc_provider
17401752
17411753 output_group_info = {}
17421754
@@ -1752,12 +1764,12 @@ def rustc_compile_action(
17521764 output_group_info ["rustc_output" ] = depset ([rustc_output ])
17531765
17541766 if output_group_info :
1755- providers . append ( OutputGroupInfo (** output_group_info ) )
1767+ providers [ " OutputGroupInfo" ] = OutputGroupInfo (** output_group_info )
17561768
17571769 # A bit unfortunate, but sidecar the lints info so rustdoc can access the
17581770 # set of lints from the target it is documenting.
17591771 if hasattr (ctx .attr , "lint_config" ) and ctx .attr .lint_config :
1760- providers . append ( ctx .attr .lint_config [LintsInfo ])
1772+ providers [ "LintsInfo" ] = ctx .attr .lint_config [LintsInfo ]
17611773
17621774 return providers
17631775
0 commit comments