Questions to Ask Before Writing A Bazel Rule
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?
What does your rule do? Does it already exist?
What files, if any, does it take as inputs?
What tool does it use? A compiler? A shell script?
Is the tool deterministic? Does every invocation of the tool with the same inputs generate the same outputs?
How is the tool provided to the rule? A binary installed in
/usr/bin
? A repository rule? Toolchains?What output files does it generate?
Does the rule depend on the outputs of other rules using providers?
Does the rule provide inputs to other rules using providers?
What actions do you need to construct in order to generate the output files from the input files using the tool?