Trigger multiple targets at once

37 Views Asked by At

I have multiple cc_binary targets which will be build independently to create elf files. I want to have single target command to build all at once to avoid multiple triggers and add the post build rule to copy all the required elf and other build files to a target folder in the Bazel.

Can I get some help on this?

2

There are 2 best solutions below

0
Vertexwahn On

You can build multiple targets via:

bazel build -- //folder:target1 //folder:target2 //folder:targetN

or

bazel build -- //folder:... -//folder:some_excluded_target

Have also a look at rules_multirun.

You can also make a kind of "virtual" binary that only has dependencies

cc_shell/cc_binary( 
   name = "build_targets",
   data = ["//folder:target1", "//folder:target2", "//folder:target3"],
)

And then just build "build_targets":

bazel build -- //:build_targets

Maybe also rules_pkg can help you do fetch together different binary an put them in an archive.

0
Ulrich Eckhardt On

I believe you can do this using a filegroup target, see https://bazel.build/reference/be/general#filegroup. This is kind-of a misnomer, but it explicitly says "collection of targets" and not "collection of files".