Packaging for Bazel

Overview

These build rules are used for building various packaging such as tarball and debian package.

Basic Example

This example is a simplification of the debian packaging of Bazel:

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

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 = "debian-data",
    extension = "tar.gz",
    deps = [
        ":bazel-bin",
        ":bazel-tools",
    ],
)

pkg_deb(
    name = "bazel-debian",
    architecture = "amd64",
    built_using = "unzip (6.0.1)",
    data = ":debian-data",
    depends = [
        "zlib1g-dev",
        "unzip",
    ],
    description_file = "debian/description",
    homepage = "http://bazel.build",
    maintainer = "The Bazel Authors <bazel-dev@googlegroups.com>",
    package = "bazel",
    version = "0.1.1",
)

Here, the Debian 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,
  • debian-data creates a gzip-compressed tarball that merge the three previous tarballs.

debian-data is then used for the data content of the debian archive created by pkg_deb.

Future work

  • Support more format, especially pkg_zip.
  • Maybe a bit more integration with the docker_build rule.

pkg_tar

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

Creates a tar file from a list of inputs.

pkg_deb

pkg_deb(name, data, package, architecture, maintainer, preinst, postinst, prerm, postrm, version, version_file, description, description_file, built_using, built_using_file, priority, section, homepage, depends, suggests, enhances, conflicts, predepends, recommends)

Create a debian package. See http://www.debian.org/doc/debian-policy/ch-controlfields.html for more details on this.

pkg_rpm

pkg_rpm(name, spec_file, architecture, version, version_file, changelog, data)

Create an RPM package. See http://rpm.org/documentation.html for more details on this.