Rules
bind
View rule sourceopen_in_newbind() is not recommended. See “Consider removing bind” for a long
discussion of its issues and alternatives. In particular, consider the use of
repo_mapping repository attributes.
Warning: select() cannot be used in bind(). See the Configurable Attributes FAQ for
details.
Gives a target an alias in the //external package.
The //external package is not a “normal” package: there is no external/ directory,
so it can be thought of as a “virtual package” that contains all bound targets.
Examples
To give a target an alias,bind it in the WORKSPACE file. For example,
suppose there is a java_library target called
//third_party/javacc-v2. This can be aliased by adding the following to the
WORKSPACE file:
//external:javacc-latest instead of
//third_party/javacc-v2. If javacc-v3 is released, the bind rule can be
updated and all of the BUILD files depending on //external:javacc-latest will now
depend on javacc-v3 without needing to be edited.
Bind can also be used to make targets in external repositories available to your workspace.
For example, if there is a remote repository named @my-ssl imported in the
WORKSPACE file and it has a cc_library target //src:openssl-lib, you can
create an alias for this target using bind:
sign_in.cc and sign_in.h, the header files exposed by
//external:openssl can be referred to using their path relative to their repository
root. For example, if the rule definition for @my-ssl//src:openssl-lib looks like
this:
sign_in.cc’s includes might look like this:
Arguments
local_repository
View rule sourceopen_in_newExamples
Suppose the current repository is a chat client, rooted at the directory ~/chat-app. It would like to use an SSL library which is defined in a different repository: ~/ssl. The SSL library has a target//src:openssl-lib.
The user can add a dependency on this target by adding the following lines to
~/chat-app/WORKSPACE:
@my-ssl//src:openssl-lib as a dependency to depend on this
library.
Arguments
new_local_repository
View rule sourceopen_in_newpath. For directories that already contain a WORKSPACE file and a BUILD file, the
local_repository rule can be used.
Examples
Suppose the current repository is a chat client, rooted at the directory ~/chat-app. It would like to use an SSL library which is defined in a different directory: ~/ssl. The user can add a dependency by creating a BUILD file for the SSL library (~/chat-app/BUILD.my-ssl) containing:@my-ssl repository that symlinks to /home/user/ssl.
Targets can depend on this library by adding @my-ssl//:openssl to a target’s
dependencies.
You can also use new_local_repository to include single files, not just
directories. For example, suppose you had a jar file at /home/username/Downloads/piano.jar. You
could add just that file to your build by adding the following to your WORKSPACE file:
@piano//:play-music to use piano.jar.