bazelbuild / bazelbuild/bazel

Documentation issue: General Rules: When to use genrule vs. rule ?

Open
#12,781 3 comments 0 reactions 0 assignees View on GitHub
help wanted P3 team-Configurability team-Documentation type: documentation (cleanup)
Dominant language
Java
Stars
25.8k
Forks
4.6k
Avg merge
2d 18h
Merged PRs (30d)
75

Description

Documentation URL: https://docs.bazel.build/versions/master/be/general.html#genrule

This documentation lacks guidance on whether, or in what situations, a [`rule()`](https://docs.bazel.build/versions/master/skylark/rules.html) should be favored over a [`genrule()`](https://docs.bazel.build/versions/master/be/general.html#genrule) (or vice-versa).

IMHO, `rule`s are preferable because:
* They can return providers, thus allowing references to their targets to be typechecked.
* The Make variable syntax of `genrule`s is obscure and harder to look up.
* They're more explicit in general and support various `doc` fields for documentation.
* I seem to recall some quirks around inferring the relevant genrule from an output filename, but perhaps that's been fixed by now.

I guess maybe `genrule`'s terseness could be justified if the target and its generator are one-offs?

But that's just my opinion. I'd prefer official guidance from Bazel Team, hence this issue.

Contributor guide

Open the contributing guide

Research direction

Start with the General Rules documentation at https://docs.bazel.build/versions/master/be/general.html#genrule and compare it with the linked rule() documentation. Review the documented capabilities and trade-offs of rule() and genrule(), then add neutral official guidance explaining when each should be used and update the relevant documentation section.

Written by the indexing model from the issue text.

Assessment

Domain
build-system, documentation
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.