Buck: zip_file()


This is liable to change in the future.

A zip_file() allows builds to create basic zip files in a platform-agnostic way.


  • name (required) #

    The name of the rule.

  • out (defaults to name.zip) #

    The name of the zip file that should be generated. This allows builds to use a meaningful target name coupled with a meaningful zip file name. The default value takes the rule's name and appends .zip.

  • srcs (required) #

    The set of files to include in the zip. If any of these are source zips (indicated by a file name ending in -sources.jar or .src.zip) the contents of the source zip will be added to the generated zip, rather than the source zip itself. This provides a mechanism to roll up multiple source zips into a single unit.

    Each src will be added to the zip as follows:

    • If the src is the output of another rule, the output will be included using just the output's file name.
    • If the src is a file relative to the rule's declaration, it will be included in the zip with its relative file name.
    • If the src is a source zip, the contents of the source zip will be added to the generated zip.

  • visibility (defaults to []) #

    List of build target patterns that identify the build rules that can include this rule as a dependency, for example, by listing it in their deps or exported_deps attributes. For more information, see visibility.

  • licenses (defaults to []) #

    Set of license files for this library. To get the list of license files for a given build rule and all of its dependencies, you can use buck query.

  • labels (defaults to []) #

    Set of arbitrary strings which allow you to annotate a build rule with tags that can be searched for over an entire dependency tree using buck query attrfilter().


This example will create a simple zip file.

  # The output will be "example.zip"
  name = 'example',
  srcs = 
    # These files will be found in the zip under "dir/"
    glob(['dir/**/*']) +
      # Imagine this generates the output 
      # "buck-out/gen/foo/hello.txt". This output will 
      # be found in the zip at "hello.txt"
      # Whereas the contents of this zip will be added
      # to the generated zip.
If you were to examine the generated zip, the contents would look something like (assuming the output of "//some/other:target" was a file who's path ended with hello.txt, the "dir" glob found two files, and "amazing-library-1.0-sources.zip" contained two Java source files):