Buck: load()


The load() function is used to include definitions (macros and constants) from another file.

The load() function executes a file of build-file-style code in the context of the current build file, so code in the included file may reference Buck functions, such as java_library, java_test, etc., as well as load() itself!

The motivation behind load() is to avoid copy-and-pasting code across multiple build files. Often, loaded files will contain data declarations (as shown in the example below) or definitions of macros for creating more complex build rules.


  • label (required) #

    The label identifying file containing macros and constants. It's exactly the same as build target syntax but all macro files are assumed to be implicitly exported using

    with its original name, so a macro file
    pre> directory is accessible using
    pre> syntax.

  • symbols... (required) #

    Names of macros and constants to import from path. In load() function keyword arguments have special meaning and can be used to change names of imported symbols. For example, load("//tools/build_rules:build_defs", my_rule="some_rule") will export some_rule from build_defs and make it available under the name my_rule. This can be useful to avoid name collisions with local definitions.


Suppose the file core/DEFS contains the following:
Then another build file could include the array using load(). This eliminates the need to copy-and-paste definitions across build files:
load('//core:DEFS', 'JARS_TO_EXCLUDE_FROM_DX')

  name = 'example',
  # ...
Alternatively, to make an imported symbol available under a different name, keywords can be used instead:
load('//core:DEFS', no_dx='JARS_TO_EXCLUDE_FROM_DX')

  name = 'example',
  # ...
  no_dx = no_dx,