Reputation: 483
I'm studying Bazel building system at present. I always see the @ symbol in Bazel script, but I cannot find any documentation about it. I searched it on the website of Bazel but the result seems useless. @ in Bazel. For example:
filegroup(
name = "toolchain_fg",
srcs = [
":cc-compiler-amd64",
"@x86_64_unknown_linux_gnu_gcc_730//:compiler_components",
],
)
Could anybody explain the @ symbol here for me?
Upvotes: 13
Views: 6139
Reputation: 11
In Bazel, targets are referred by labels.
Bazel labels have the following format:
@repoName//packageName:target
For example, in the following packages found in myRepo
:
myRepo
├── WORKSPACE
├── package1
│ └── BUILD
│ └── src
└── package2
├── BUILD
└── src
a target called myTarget
in package1/BUILD
can be labeled as as @myRepo//package1:myTarget
globally.
If referenced from the same repo, for example from package2/BUILD
, then the @myRepo
prefix can be omitted and you can use //package1:myTarget
.
If referenced from the same package, for example in another target from package1/BUILD
, then the package name can be omitted and you can use :myTarget
. The colon can also be omitted if it does not create confusion with a name. Such short form labels should not be confused with the names. Labels start with '//' or ':'. But names never do. For example, the name of the first package is package1
but its label is //package1
.
Reference: https://docs.bazel.build/versions/master/build-ref.html
Upvotes: 1
Reputation: 26974
This is to reference a remote repository.
From the doc, depending on other Bazel projects
local_repository( name = "coworkers_project", path = "/path/to/coworkers-project", )
If your coworker has a target
//foo:bar
, your project can refer to it as@coworkers_project//foo:bar
.
See also the design doc of remote repository and bind example in workspace rules.
Upvotes: 13