Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the "@" symbol mean in Bazel?

Tags:

bazel

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?

like image 578
Robin Lew Avatar asked Oct 14 '18 10:10

Robin Lew


People also ask

What does the at symbol mean in Bazel?

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 .

What does Bazel build mean?

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.

What is visibility in Bazel?

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.

What are Bazel targets?

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.


2 Answers

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.

like image 137
rds Avatar answered Sep 23 '22 10:09

rds


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

like image 24
Lord Komnick Avatar answered Sep 22 '22 10:09

Lord Komnick