bazelbuild/bazel

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

Open

#12.781 geöffnet am 6. Jan. 2021

Auf GitHub ansehen
 (3 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)Java (4.465 Forks)batch import
P3help wantedteam-Configurabilityteam-Documentationtype: documentation (cleanup)

Repository-Metriken

Stars
 (25.384 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 22T 20h) (77 gemergte PRs in 30 T)

Beschreibung

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

This documentation lacks guidance on whether, or in what situations, a rule() should be favored over a genrule() (or vice-versa).

IMHO, rules are preferable because:

  • They can return providers, thus allowing references to their targets to be typechecked.
  • The Make variable syntax of genrules 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