Search code examples
global-variablesglobalbazel

Is it possible to define custom bazel macro or rule and load it in workspace for all packages?


I wrote a custom bazel macro, in order to shorten code in my BUILD files. I want it to be available in all BUILD files, and I don't want to call load statement each time.

So I want to use it just like I use symbols from native module.

Is it possible to do such thing without changing bazel sources?

Thank you!


Solution

  • This can be achieved by adding a prelude_bazel file at //tools/build_rules:prelude_bazel (this must be a package, so tools/build_rules must contain a BUILD file). This will be loaded and prepended to all BUILD files loaded by Bazel.

    Reference