tree: 953f2e859edfac0eefee46a5f1b68015e03aa193
  1. legacy/
  2. private/
  3. releasing/
  4. rpm/
  5. .bazelignore
  6. __init__.py
  7. BUILD
  8. CHANGELOG.md
  9. deb.bzl
  10. deps.bzl
  11. filter_directory.py
  12. install.bzl
  13. make_rpm.py
  14. mappings.bzl
  15. package_variables.bzl
  16. path.bzl
  17. pkg.bzl
  18. providers.bzl
  19. README.md
  20. rpm.bzl
  21. rpm_pfg.bzl
  22. tar.bzl
  23. zip.bzl
pkg/README.md

rules_pkg - Archive building rules

Release Notes

Version 1.0.0 or later (including all currently in-development code) requires Bazel 4.0.0 or later.

Overview

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

WORKSPACE setup

See releases for the release specific notes.

If you want to use pkg_rpm() (either from rpm.bzl or legacy/rpm.bzl) you must instantiate a toolchain to provide the rpmbuild tool. Add this to WORKSPACE to use one installed on your system:

# Find rpmbuild provided on your system.
load("@rules_pkg//toolchains/rpm:rpmbuild_configure.bzl", "find_system_rpmbuild")
find_system_rpmbuild(name = "rules_pkg_rpmbuild")

Basic Example

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

load("@rules_pkg//pkg:tar.bzl", "pkg_tar")
load("@rules_pkg//pkg:deb.bzl", "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.

Roadmap

  • Add a pkg_filegroup rule to facilitate mapping Bazel targets into an the folder layout required by the archive.
  • Support assigning owners and modes to specific files in the archive.
  • Improve RPM support
  • Improve DEB support