tree: a0fa3da81c7d7af4f0dafc2f9bb2301f07facfd6 [path history] [tgz]
  1. testdata/
  2. archive.py
  3. archive_test.py
  4. BUILD
  5. build_tar.py
  6. build_test.sh
  7. path.bzl
  8. path_test.py
  9. pkg.bzl
  10. README.md
  11. testenv.py
  12. testenv.sh
tools/build_defs/pkg/README.md

Packaging for Bazel

Deprecated

These rules have been extracted from the Bazel sources and are now available at bazelbuild/rules_pkg (docs).

Issues and PRs against the built-in versions of these rules will no longer be addressed. This page will exist for reference until the code is removed from Bazel.

For more information, follow issue 8857

rules_pkg

Overview

pkg_tar() is available for building a .tar file without depending on anything besides Bazel. Since this feature is deprecated and will eventually be removed from Bazel, you should migrate to @rules_pkg.

Basic Example

This example is a simplification of building Bazel and creating a distribution tarball.

load("@bazel_tools//tools/build_defs/pkg:pkg.bzl", "pkg_tar")

pkg_tar(
    name = "bazel-bin",
    strip_prefix = "/src",
    package_dir = "/usr/bin",
    srcs = ["//src:bazel"],
    mode = "0755",
)

pkg_tar(
    name = "bazel-tools",
    strip_prefix = "/",
    package_dir = "/usr/share/lib/bazel/tools",
    srcs = ["//tools:package-srcs"],
    mode = "0644",
)

pkg_tar(
    name = "bazel-all",
    extension = "tar.gz",
    deps = [
        ":bazel-bin",
        ":bazel-tools",
    ],
)

Here, a package is built from three pkg_tar targets:

  • bazel-bin creates a tarball with the main binary (mode 0755) in /usr/bin,
  • bazel-tools create a tarball with the base workspace (mode 0644) to /usr/share/bazel/tools ; the modes attribute let us specifies executable files,
  • bazel-all creates a gzip-compressed tarball that merge the two previous tarballs.

pkg_tar

pkg_tar(name, extension, strip_prefix, package_dir, srcs,
mode, modes, deps, symlinks)

Creates a tar file from a list of inputs.