Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bazel Build Multiple Targets at Once

I want a Bazel rule that is able to build multiple targets at once. So basically something like this:

build_all(
  name = "build_all",
  targets = [
    "//services/service1:build",
    "//services/service2:build",
    "//services/service3:build",
  ]
)

So I would just run

bazel build //:build_all

to build all my services with one simple command (and the same for testing). But I couldn't find any current solutions.

Is there a way to achieve this?

like image 773
Flo Avatar asked Dec 03 '22 17:12

Flo


2 Answers

It would appear that filegroup would be a ready made rule that could be abused for the purpose:

filegroup(
  name = "build_all",
  srcs = [
    "//services/service1:build",
    "//services/service2:build",
    "//services/service3:build",
  ]
)

It otherwise allows you to give a collective name to bunch of files (labels) to be passed conveniently along, but seems to work just as well as a summary target to use on the command line.

like image 196
Ondrej K. Avatar answered Jan 22 '23 10:01

Ondrej K.


Because I was trying to deploy multiple Kubernetes configurations I ended up using Multi-Object Actions for rules_k8s which then looks like:

load("@io_bazel_rules_k8s//k8s:objects.bzl", "k8s_objects")

k8s_objects(
   name = "deployments",
   objects = [
      "//services/service1:build",
      "//services/service2:build",
      "//services/service3:build",
   ]
)
like image 45
Flo Avatar answered Jan 22 '23 10:01

Flo