bazel-contrib / SIG-rules-authors

Governance and admin for the rules authors Special Interest Group
https://bazel-contrib.github.io/SIG-rules-authors/
Apache License 2.0
28 stars 12 forks source link

Standardizing the shape of a rule set #6

Open gravypod opened 2 years ago

gravypod commented 2 years ago

One of the goals of Bazel is to abstract users from the specific toolchains underpinning the implementation of rules. Does it make sense for us to establish standardized functionality that rules should provide? For example:

  1. Should all rules for languages provide a *_binary, *_library, *_test? What about in languages where this doesn't exactly map to the real contents (ex: jsonnet's binary is a json file).
  2. Some things need 100% global support to be useful. We can either have one repo that needs to support all languages (impossible to keep up maintenance on, see: bazelbuild/rules_docker) or every language ruleset needs to implement something they aren't an expert in. Examples of this: should we require *_proto_library and *_grpc_library? What about *_thrift_library? etc

If we decide to go down this path we also need to remember:

  1. We shouldn't exclude rules from this group if they are not 100% ready. This will make it a hard value prop to try and open source internal rules from companies: "You want to spend how much time and have no guarantee they will help maintain this?"
  2. We should make 100% compliance something that a single person could implement and maintain.
alexeagle commented 2 years ago

I think the style guide at https://docs.bazel.build/versions/main/skylark/deploying.html mostly dictates this.

But I could take this issue to suggest that we do more to maintain the style guide for rules authors. It's something the Bazel tech writers have thought about as well.

aherrmann commented 2 years ago

Agreed, the style guide seems like a good place for things like providing _binary, _library, _test rules. As you already point out, there are cases where this set is not applicable. There should be a way to handle such exceptions, such that those rule sets don't end up being permanently non-compliant.

Aside from naming, there are other, more subtle, aspects to writing rules such that they fulfill the goal to abstract the specifics of the language toolchain and provide a familiar interface to a Bazel user, e.g.

I'm not sure that this can be meaningfully quantified for any given rule set. But, a style-guide or compatibility check-list may be a feasible way to document this.


2. Some things need 100% global support to be useful. We can either have one repo that needs to support all languages (impossible to keep up maintenance on, see: bazelbuild/rules_docker) or every language ruleset needs to implement something they aren't an expert in.

This is a tricky issue. rules_nixpkgs is in a similar situation, where we provide repo-rules for language toolchains provided by the Nix package manager. As I understand this will become more difficult with the upcoming Bazel modules as they don't support conditional dependencies. E.g. if rules_nixpkgs wants to provide a Go toolchain it will need to unconditionally depend on rules_go or if rules_haskell wants to provide Nix integration it will need to unconditionally depend on rules_nixpkgs. A way around this may be to define dedeciated mini-rule-sets, e.g. rules_nixpkgs_go, rules_nixpkgs_haskell, .... But, this is quite noisy.

As you point out, mandating that either side covers all cases seems infeasible. Perhaps a more feasible approach is to document a matrix with language rule set on one axis and things like proto, grpc, ... on the other where the cells document where the corresponding implementation is provided.

brentleyjones commented 2 years ago

A way around this may be to define dedeciated mini-rule-sets, e.g. rules_nixpkgs_go, rules_nixpkgs_haskell, .... But, this is quite noisy.

I actually like this route, as rules_nixpkgs or rules_nixpkgs_support (similar to https://github.com/bazelbuild/apple_support) can be the core, and rules_nixpkgs_go can be the glue between it and rules_go. It reduces the size/scope of rules_nixpkgs, and plays better with Bzlmod's compatibility_level.

alexeagle commented 2 years ago

We could take a page like https://docs.bazel.build/versions/main/skylark/deploying.html and update from there.

alexeagle commented 2 years ago

It looks like there's movement from the Bazel team at Google on this: https://github.com/bazelbuild/proposals/pull/247

alexeagle commented 2 years ago

Note, the upstream docs are being extended: https://github.com/bazelbuild/bazel/pull/15800