Buck: Build Target

Build Target

A build target is a string that is used to identify a build rule in your project.

Here is an example of a fully-qualified build target:

A fully-qualified build target has three components:
  1. The // prefix indicates that this path is relative to the root of your project.
  2. The java/com/facebook/share component between the // prefix and the colon (:) indicates that the build file (typically named BUCK) is located in the directory java/com/facebook/share.
  3. The ui after the colon (:) indicates the name of the build rule within the build file. Build rule names must be unique within a build file.
The full regular expression of a valid build target is as follows:
|- cell name -|  | package path | |--- target name ---|
A relative build target can be used to reference another build target within the same build file. A relative build target starts with a colon (:) and is followed by only the third component (or short name) of the fully-qualified build target. For example, within java/com/facebook/share/BUCK, :ui can be used to reference //java/com/facebook/share:ui:
# This is in java/com/facebook/share/BUCK.
  name = 'ui_jar',
  deps = [
    # This would be the same as using:
    # '//java/com/facebook/share:ui'
Build targets are frequently used as arguments to build rules and to the command-line interface for Buck.

Command-line Pro Tips

Here are some ways that you can reduce your typing when you specify build targets as command-line arguments to the buck build command.

Consider the following example of a fully-qualified build target used with the buck build command:

buck build //java/com/facebook/share:share

Although Buck is always strict when parsing build targets in build files, Buck is flexible when parsing build targets on the command-line. Specifically, the leading // is optional on the command line, so the above could be:

buck build java/com/facebook/share:share

Also, if there is a forward slash before the colon, it is ignored, so this could also be written as:

buck build java/com/facebook/share/:share

which enables you to produce the red text shown below using tab-completion, which dramatically reduces how much you need to type:

buck build java/com/facebook/share/:share

Finally, if the final path element matches the value specified after the colon, it can be omitted:

# This is treated as //java/com/facebook/share:share.
buck build java/com/facebook/share/

which makes the build target even easier to tab-complete! For this reason, the name of the build rule for the primary deliverable in a build file is often named the same as the parent directory. That way, it can be built from the command-line with less typing.

See also

build target pattern