title: custom cc_toolchain used in bazel rule
body: <p>I've been trying to write a bazel rule to wrap compiling for risc-v source files, does some other stuff, etc, but I've been having some trouble with getting a <code>CcToolchainInfo</code> provider.</p>
  
  <p>I have a rule that works that looks like </p>
  
  <pre><code>rv_cc_toolchain_config = rule(
      implementation = _impl,
      attrs = {},
      provides = [CcToolchainConfigInfo],
  ) 
  </code></pre>
  
  <p>in order to provide config info. I have the following in <code>toolchains/BUILD</code>:</p>
  
  <pre><code>load(":cc_toolchain_config.bzl", "rv_cc_toolchain_config")
  
  package(default_visibility = ['//visibility:public'])
  
  
  rv_cc_toolchain_config(name="rv_toolchain_cfg")
  
  
  cc_toolchain(
      name='rv_toolchain',
      toolchain_identifier='rv-toolchain',
      toolchain_config=':rv_toolchain_cfg',
      all_files=':nofile',
      strip_files=':nofile',
      objcopy_files=':nofile',
      dwp_files=':nofile',
      compiler_files=':nofile',
      linker_files=':nofile',
  )
  </code></pre>
  
  <p>This seems to all work fine; I then have my custom rule to compile with riscv:</p>
  
  <pre><code>def _compile_impl(ctx):
      deps = []
      cc_toolchain = find_cpp_toolchain(ctx)
      print(ctx.attr._cc_toolchain)
      compilation_contexts = [dep[CcInfo].compilation_context for dep in deps]
      print(type(cc_toolchain))
      feature_configuration = cc_common.configure_features( #fails here
          ctx = ctx,
          cc_toolchain = cc_toolchain,
          requested_features = ctx.features,  #currently does nothing
          unsupported_features = ctx.disabled_features,
      )
  
  
  
  
  rv_compile = rule(
      _compile_impl,
      output_to_genfiles = True,
      attrs = {
          "srcs": attr.label_list(
              doc = "List of source files",
              mandatory = False,
              allow_files = [".cc", ".cpp", ".h", ".c"],
          ),
          "hdrs": attr.label_list(
              doc = "List of header files",
              allow_files = [".h"],
          ),
          "_cc_toolchain": attr.label(
              #default = Label("@bazel_tools//tools/cpp:current_cc_toolchain"),
              default = Label("//toolchains:rv_toolchain")
          ),
      },
      provides = [
          DefaultInfo,
          CcInfo,
      ],
      toolchains = [
          "@bazel_tools//tools/cpp:toolchain_type",
      ],
      fragments = ["cpp"]
  )
  </code></pre>
  
  <p>Where I fail when trying to configure the toolchain because <code>cc_toolchain</code> is of type <code>ToolchainInfo</code> and not the required <code>CcToolchainInfo</code>. Does anyone have any insight on how to provide CcToolchainInfo within a rule? Or is there a better way of doing this? Documentation seems to go dark on this. </p>