Build a bazel dependency inside a rule

24 Views Asked by At

I have a macro:

def py_layers(name, py_binary):
    layers = []
    # Do stuff
    some_bazel_rule(...)
    return layers

How can I make sure that the py_binary target is built by bazel before calling some_bazel_rule? From my understanding, looks like the proper way is to convert py_layers to a rule. However, it's still very unclear to me how I make py_binary an explicit dependency of py_layers. Can someone provide the correct implementation?

1

There are 1 best solutions below

0
ahumesky On

You would add the py_binary target as a dependency of the some_bazel_rule target.

One thing to keep in mind is that macros just instantiate instances of rules (targets) in a repeatable way (and can perform some limited code / logic). So once the macro executes, all that's left are the targets that it generated. So it's not really that py_layers has dependencies, but that the targets it creates has dependencies.