Here's something I tried to do, and it works well. I find it useful, but it feels like a hack, so I'm afraid it will break in the future.
I'm working on converting a large project to Bazel, and we have lots of local wrappers, something like:
my_cc_library(name='a', srcs=['lib.c'])
my_cc_binary(name='b', deps=['a'], srcs=['main.c'])
This requires lots of load
commands, which are annoying and a repeating source of errors.
If it was normal Python, I'd simply import a whole module. But Skylark requires loading functions one by one.
I can remove the need for individual loads, using a struct.
In my.bzl
:
def _my_cc_library(...): ...
def _my_cc_binary(...): ...
my = struct(cc_library=_my_cc_library, cc_binary=_my_cc_binary)
In various BUILD
files:
load('//my.bzl', 'my')
my.cc_library(name='a', srcs=['lib.c'])
my.cc_binary(name='b', deps=['a'], srcs=['main.c'])
As I wrote above, it all works well. I can use if for wrappers to native rules, and for various other functions.
But an I abusing the language? Is it prone to break in the future?
Thanks.