List of labels; optional; default default_visibility from package if specified, else private

The visibility attribute on a rule controls whether the rule can be used by other packages. Rules are always visible to other rules declared in the same package.

There are five forms (and one temporary form) a visibility label can take:

The visibility specifications of //visibility:public and //visibility:private can not be combined with any other visibility specifications. A visibility specification may contain a combination of package labels (i.e. //foo:__pkg__) and package_groups.

If a rule does not specify the visibility attribute, the default_visibility attribute of the package statement in the BUILD file containing the rule is used (except exports_files).

If the default visibility for the package is not specified, the rule is private.

Example:

File //frobber/bin/BUILD:

# This rule is visible to everyone
cc_binary(
    name = "executable",
    visibility = ["//visibility:public"],
    deps = [":library"],
)

# This rule is visible only to rules declared in the same package
cc_library(
    name = "library",
    visibility = ["//visibility:private"],
)

# This rule is visible to rules in package //object and //noun
cc_library(
    name = "subject",
    visibility = [
        "//noun:__pkg__",
        "//object:__pkg__",
    ],
)

# See package group "//frobber:friends" (below) for who can access this rule.
cc_library(
    name = thingy,
    visibility = ["//frobber:friends"],
)

File //frobber/BUILD:

# This is the package group declaration to which rule //frobber/bin:thingy refers.
#
# Our friends are packages //frobber, //fribber and any subpackage of //fribber.
package_group(
    name = "friends",
    packages = [
        "//fribber/...",
        "//frobber",
    ],
)