title: Bazel - ":target" does not have mandatory providers: 'TemplateVariableInfo'
body: <p>I wanna create a toolchain in bazel for my genrule. I created a file named toolchain.bzl and the source in this file is this:</p>
  
  <pre><code>BarInfo = provider(
      fields = {
          "bar": "path to bar executable",
      },
      doc = "Defines a Bar toolchain based on an SDK",
  )
  
  def _bar_toolchain_impl(ctx):
      bar_info = ctx.attr.path
      platform_bar_info = platform_common.ToolchainInfo(
          bar_info = BarInfo(bar = bar_info),
      )
      return [platform_bar_info]
  
  bar_toolchain = rule(
      implementation = _bar_toolchain_impl,
      attrs = {
          "path": attr.string(
              doc = "path to bar executable",
              mandatory = False,
          ),
      },
  )
  </code></pre>
  
  <p>And I wrote this in BUILD file.</p>
  
  <pre><code>load(":toolchain.bzl", "bar_toolchain")
  
  toolchain_type(
      name = "toolchain_type",
      visibility = ["//visibility:public"],
  )
  
  bar_toolchain(
      name = "bar_toolchain",
      path = "/usr/local/bin/bar",
      visibility = ["//visibility:public"],
  )
  
  toolchain(
      name = "bar_linux",
      target_compatible_with = [
          "@platforms//os:linux",
          "@platforms//cpu:x86_64",
      ],
      toolchain = "//:bar_toolchain",
      toolchain_type = "//:toolchain_type",
      visibility = ["//visibility:public"],
  )
  
  genrule(
      name = "build_bar",
      srcs = glob(["**/*.bar"]),
      outs = ["a.sh"],
      cmd = """
          touch a.sh
      """,
      toolchains = ["//:toolchain_type"],
  )
  </code></pre>
  
  <p>But when I run </p>
  
  <blockquote>
    <p>bazel build //:build_bar</p>
  </blockquote>
  
  <p>I get this error</p>
  
  <blockquote>
    <p>'//:toolchain_type' does not have mandatory providers: 'TemplateVariableInfo'.</p>
  </blockquote>
  
  <p>What can I do to solve this problem?</p>