What's better than a genrule?
Blog post from Aspect Build
Bazel, a build and test tool, often confuses users about when to use custom rules, macros, or genrules due to differing practices, especially among those familiar with Google's internal system. The text emphasizes the practicality of using genrules, which allow developers to specify commands, inputs, outputs, and dependencies in a straightforward manner within BUILD files, without delving into complex Bazel internals. Despite genrules' limitations, enhancements like the run_binary from bazel-skylib and Aspect bazel-lib offer improvements, such as compatibility with Windows, better handling of output directories, and custom progress messages. Furthermore, rules from package managers like rules_python and rules_js can automate the creation of genrules for third-party developer tools, simplifying the process. While macros can help streamline the use of these tools in BUILD files, they can introduce complexities if not used carefully. Ultimately, the text suggests that writing custom Bazel rules is rarely necessary unless there's a need for advanced interoperability, performance optimization, or platform-specific toolchain management.