Posted on July 1, 2018

Questions to Ask Before Writing A Bazel Rule

  1. Do you need a rule? Can you write a macro to compose and reuse existing rules? Or an aspect to traverse the existing build graph and execute additional actions?

  2. What does your rule do? Does it already exist?

  3. What files, if any, does it take as inputs?

  4. What tool does it use? A compiler? A shell script?

  5. Is the tool deterministic? Does every invocation of the tool with the same inputs generate the same outputs?

  6. How is the tool provided to the rule? A binary installed in /usr/bin? A repository rule? Toolchains?

  7. What output files does it generate?

  8. Does the rule depend on the outputs of other rules using providers?

  9. Does the rule provide inputs to other rules using providers?

  10. What actions do you need to construct in order to generate the output files from the input files using the tool?