5

When I specify build rules in bazel, my dependencies are either full paths (from the root of the repo), or just the target name (since its in the same directory):

cc_binary(
    name = "program",
    srcs = ["main.cpp"],
    deps = ["//a/full/path/to/the/library:lib",
            "foo"]
)

Assume I'm writing a build rule from directory "the".
I was hoping to do something like this:

cc_binary(
    name = "program",
    srcs = ["main.cpp"],
    deps = ["library:lib",
            "foo"]
)

This does not seem to be possible. Is there some kind of way, where I can specify the target deeper starting from the location of the BUILD file?

Neil Traft
  • 18,367
  • 15
  • 63
  • 70
Trevor Hickey
  • 36,288
  • 32
  • 162
  • 271

1 Answers1

6

You cannot.

Relative labels cannot be used to refer to targets in other packages; the repository identifier and package name must always be specified in this case.

From Bazel labels documentation

bryant1410
  • 5,540
  • 4
  • 39
  • 40
Ittai
  • 5,625
  • 14
  • 60
  • 97