Practical Bazel: Isolating Ruleset’s Public Interface
When writing a custom Bazel ruleset, it is important to carefully separate its public interface from its private implementation and be deliberate and careful about changes to the public interface. Here’s the pattern I use when I’m writing rulesets to handle this.
Consider a ruleset named rules_foo
. I will define the public
endpoints of the ruleset in a file named @rules_foo//foo:def.bzl
,
and put all implementation inside the folder @rules_foo//foo/private
.
The public endpoint definition file def.bzl
does nothing but
decide which pieces of Bazel code in the private implemtnation
define the ruleset’s public interface.
For example, here’s what the def.bzl
might look like:
|
|