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?
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 .
Bazel is an open-source build tool developed by Google to automate build processes for large-scale software. Companies such as Pinterest, Adobe, SpaceX, Nvidia, and LinkedIn use it, amongst others.
This page covers Bazel's two visibility systems: target visibility and load visibility. Both types of visibility help other developers distinguish between your library's public API and its implementation details, and help enforce structure as your workspace grows.
This syntax is used in commands like build , test , or query . Whereas labels are used to specify individual targets, e.g. for declaring dependencies in BUILD files, Bazel's target patterns are a syntax for specifying multiple targets: they are a generalization of the label syntax for sets of targets, using wildcards.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With