Can I provide a relative deps path in my bazel target?
Asked Answered
A

1

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?

Acerbity answered 8/6, 2018 at 21:50 Comment(0)
E
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

Epanaphora answered 9/6, 2018 at 14:41 Comment(1)
That's probably a good decision on bazel's part, but still an inconvenience in some situations.Acerbity

© 2022 - 2024 — McMap. All rights reserved.