<html devsite>
<head>
  <meta name="project_path" value="/_project.yaml">
  <meta name="book_path" value="/versions/8.1.0/_book.yaml">
</head>
<body>

<h1 class="page-title" id="modules.rule_attributes">rule_attributes</h1>

{% dynamic setvar source_file "src/main/java/com/google/devtools/build/lib/starlarkbuildapi/StarlarkAttributesCollectionApi.java" %}
{% dynamic setvar version "8.1.0" %}
{% dynamic setvar original_path "/rules/lib/builtins/rule_attributes" %}
{% include "_buttons.html" %}
<!-- {% raw %} -->

Information about attributes of a rule an aspect is applied to.

<h2>Members</h2>
<ul>
    <li>
    <a href="#attr">attr</a>
  </li>
      <li>
    <a href="#exec_groups">exec_groups</a>
  </li>
      <li>
    <a href="#executable">executable</a>
  </li>
      <li>
    <a href="#file">file</a>
  </li>
      <li>
    <a href="#files">files</a>
  </li>
      <li>
    <a href="#kind">kind</a>
  </li>
      <li>
    <a href="#toolchains">toolchains</a>
  </li>
  </ul>

      <h2 id="attr">attr</h2>
        <p><pre class="rule-signature"><a class="anchor" href="../builtins/struct.html">struct</a> rule_attributes.attr</pre></p>

    A struct to access the values of the <a href='https://bazel.build/versions/8.1.0/extending/rules#attributes'>attributes</a>. The values are provided by the user (if not, a default value is used). The attributes of the struct and the types of their values correspond to the keys and values of the <a href='../globals/bzl.html#rule.attrs'><code>attrs</code> dict</a> provided to the <a href='../globals/bzl.html#rule'><code>rule</code> function</a>. <a href="https://github.com/bazelbuild/examples/blob/main/rules/attributes/printer.bzl">See example of use</a>.


        <h2 id="exec_groups">exec_groups</h2>
        <p><pre class="rule-signature"><a class="anchor" href="../builtins/ExecGroupCollection.html">ExecGroupCollection</a> rule_attributes.exec_groups</pre></p>

    A collection of the execution groups available for the rule the aspect is applied to, indexed by their names.


        <h2 id="executable">executable</h2>
        <p><pre class="rule-signature"><a class="anchor" href="../builtins/struct.html">struct</a> rule_attributes.executable</pre></p>

    A <code>struct</code> containing executable files defined in <a href='../toplevel/attr.html#label'>label type attributes</a> marked as <a href='../toplevel/attr.html#label.executable'><code>executable=True</code></a>. The struct fields correspond to the attribute names. Each value in the struct is either a <a href='../builtins/File.html'><code>File</code></a> or <code>None</code>. If an optional attribute is not specified in the rule then the corresponding struct value is <code>None</code>. If a label type is not marked as <code>executable=True</code>, no corresponding struct field is generated. <a href="https://github.com/bazelbuild/examples/blob/main/rules/actions_run/execute.bzl">See example of use</a>.


        <h2 id="file">file</h2>
        <p><pre class="rule-signature"><a class="anchor" href="../builtins/struct.html">struct</a> rule_attributes.file</pre></p>

    A <code>struct</code> containing files defined in <a href='../toplevel/attr.html#label'>label type attributes</a> marked as <a href='../toplevel/attr.html#label.allow_single_file'><code>allow_single_file</code></a>. The struct fields correspond to the attribute names. The struct value is always a <a href='../builtins/File.html'><code>File</code></a> or <code>None</code>. If an optional attribute is not specified in the rule then the corresponding struct value is <code>None</code>. If a label type is not marked as <code>allow_single_file</code>, no corresponding struct field is generated. It is a shortcut for:<pre class=language-python>list(ctx.attr.&lt;ATTR&gt;.files)[0]</pre>In other words, use <code>file</code> to access the (singular) <a href="https://bazel.build/versions/8.1.0/extending/rules#requesting_output_files">default output</a> of a dependency. <a href="https://github.com/bazelbuild/examples/blob/main/rules/expand_template/hello.bzl">See example of use</a>.


        <h2 id="files">files</h2>
        <p><pre class="rule-signature"><a class="anchor" href="../builtins/struct.html">struct</a> rule_attributes.files</pre></p>

    A <code>struct</code> containing files defined in <a href='../toplevel/attr.html#label'>label</a> or <a href='../toplevel/attr.html#label_list'>label list</a> type attributes. The struct fields correspond to the attribute names. The struct values are <code>list</code> of <a href='../builtins/File.html'><code>File</code></a>s.  It is a shortcut for:<pre class=language-python>[f for t in ctx.attr.&lt;ATTR&gt; for f in t.files]</pre> In other words, use <code>files</code> to access the <a href="https://bazel.build/versions/8.1.0/extending/rules#requesting_output_files"> default outputs</a> of a dependency. <a href="https://github.com/bazelbuild/examples/blob/main/rules/depsets/foo.bzl">See example of use</a>.


        <h2 id="kind">kind</h2>
        <p><pre class="rule-signature"><a class="anchor" href="../core/string.html">string</a> rule_attributes.kind</pre></p>

    The kind of a rule, such as 'cc_library'


        <h2 id="toolchains">toolchains</h2>
        <p><pre class="rule-signature"><a class="anchor" href="../builtins/ToolchainContext.html">ToolchainContext</a> rule_attributes.toolchains</pre></p>

    Toolchains for the default exec group of the rule the aspect is applied to.



</body>
</html>

<!-- {% endraw %} -->
