rules_pkg - 1.0.0

Common Attributes

These attributes are used in several rules within this module.

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
outName of the output file. This file will always be created and used to access the package content. If package_file_name is also specified, out will be a symlink.Stringrequired
package_file_nameThe name of the file which will contain the package. The name may contain variables in the forms {var} and $(var). The values for substitution are specified through package_variables` or taken from ctx.var.Stringoptionalpackage type specific
package_variablesA target that provides PackageVariablesInfo to substitute into package_file_name. pkg_zip and pkg_tar also support this in package_dirLabeloptionalNone
attributesAttributes to set on entities created within packages. Not to be confused with bazel rule attributes. See ‘Mapping “Attributes”’ belowUndefined.optionalVaries. Consult individual rule documentation for details.

See examples/naming_package_files for examples of how out, package_file_name, and package_variables interact.

Mapping “Attributes”

The “attributes” attribute specifies properties of package contents as used in rules such as pkg_files, and pkg_mkdirs. These allow fine-grained control of the contents of your package. For example:

attributes = pkg_attributes(
    mode = "0644",
    user = "root",
    group = "wheel",
    my_custom_attribute = "some custom value",
)

mode, user, and group correspond to common UNIX-style filesystem permissions. Attributes should always be specified using the pkg_attributes helper macro.

Each mapping rule has some default mapping attributes. At this time, the only default is “mode”, which will be set if it is not otherwise overridden by the user.

If user and group are not specified, then defaults for them will be chosen by the underlying package builder. Any specific behavior from package builders should not be relied upon.

Any other attributes should be specified as additional arguments to pkg_attributes.

Rule for creating Debian packages.

pkg_deb

Create a Debian package.

This rule produces 2 artifacts: a .deb and a .changes file. The DefaultInfo will include both. If you need downstream rule to specifically depend on only the .deb or .changes file then you can use filegroup to select distinct output groups.

OutputGroupInfo

  • out the Debian package or a symlink to the actual package.
  • deb the package with any precise file name created with package_file_name.
  • changes the .changes file.

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
dataA tar file that contains the data for the debian package.Labelrequired
outSee Common AttributesLabelrequired
architecturePackage architecture. Must not be used with architecture_file.Stringoptional"all"
architecture_fileFile that contains the package architecture. Must not be used with architecture.LabeloptionalNone
breaksSee http://www.debian.org/doc/debian-policy/ch-relationships.html#s-binarydeps.List of stringsoptional[]
built_usingThe tool that were used to build this package provided either inline (with built_using) or from a file (with built_using_file).Stringoptional""
built_using_fileThe tool that were used to build this package provided either inline (with built_using) or from a file (with built_using_file).LabeloptionalNone
changelogThe package changelog. See https://www.debian.org/doc/debian-policy/ch-source.html#s-dpkgchangelog.LabeloptionalNone
conffilesThe list of conffiles or a file containing one conffile per line. Each item is an absolute path on the target system where the deb is installed. See https://www.debian.org/doc/debian-policy/ch-files.html#s-config-files.List of stringsoptional[]
conffiles_fileThe list of conffiles or a file containing one conffile per line. Each item is an absolute path on the target system where the deb is installed. See https://www.debian.org/doc/debian-policy/ch-files.html#s-config-files.LabeloptionalNone
configconfig file used for debconf integration. See https://www.debian.org/doc/debian-policy/ch-binary.html#prompting-in-maintainer-scripts.LabeloptionalNone
conflictsSee http://www.debian.org/doc/debian-policy/ch-relationships.html#s-binarydeps.List of stringsoptional[]
dependsSee http://www.debian.org/doc/debian-policy/ch-relationships.html#s-binarydeps.List of stringsoptional[]
depends_fileFile that contains a list of package dependencies. Must not be used with depends. See http://www.debian.org/doc/debian-policy/ch-relationships.html#s-binarydeps.LabeloptionalNone
descriptionThe package description. Must not be used with description_file.Stringoptional""
description_fileThe package description. Must not be used with description.LabeloptionalNone
distribution"distribution: See http://www.debian.org/doc/debian-policy.Stringoptional"unstable"
enhancesSee http://www.debian.org/doc/debian-policy/ch-relationships.html#s-binarydeps.List of stringsoptional[]
homepageThe homepage of the project.Stringoptional""
licenseThe license of the project.Stringoptional""
maintainerThe maintainer of the package.Stringrequired
packageThe name of the packageStringrequired
package_file_nameSee Common Attributes. Default: "{package}-{version}-{architecture}.debStringoptional""
package_variablesSee Common AttributesLabeloptionalNone
postinstThe post-install script for the package. See http://www.debian.org/doc/debian-policy/ch-maintainerscripts.html.LabeloptionalNone
postrmThe post-remove script for the package. See http://www.debian.org/doc/debian-policy/ch-maintainerscripts.html.LabeloptionalNone
predependsSee http://www.debian.org/doc/debian-policy/ch-relationships.html#s-binarydeps.List of stringsoptional[]
preinst"The pre-install script for the package. See http://www.debian.org/doc/debian-policy/ch-maintainerscripts.html.LabeloptionalNone
prermThe pre-remove script for the package. See http://www.debian.org/doc/debian-policy/ch-maintainerscripts.html.LabeloptionalNone
priorityThe priority of the package. See http://www.debian.org/doc/debian-policy/ch-archive.html#s-priorities.Stringoptional""
providesSee http://www.debian.org/doc/debian-policy/ch-relationships.html#s-binarydeps.List of stringsoptional[]
recommendsSee http://www.debian.org/doc/debian-policy/ch-relationships.html#s-binarydeps.List of stringsoptional[]
replacesSee http://www.debian.org/doc/debian-policy/ch-relationships.html#s-binarydeps.List of stringsoptional[]
sectionThe section of the package. See http://www.debian.org/doc/debian-policy/ch-archive.html#s-subsections.Stringoptional""
suggestsSee http://www.debian.org/doc/debian-policy/ch-relationships.html#s-binarydeps.List of stringsoptional[]
templatestemplates file used for debconf integration. See https://www.debian.org/doc/debian-policy/ch-binary.html#prompting-in-maintainer-scripts.LabeloptionalNone
triggerstriggers file for configuring installation events exchanged by packages. See https://wiki.debian.org/DpkgTriggers.LabeloptionalNone
urgency"urgency: See http://www.debian.org/doc/debian-policy.Stringoptional"medium"
versionPackage version. Must not be used with version_file.Stringoptional""
version_fileFile that contains the package version. Must not be used with version.LabeloptionalNone

Provides rules for creating RPM packages via pkg_filegroup and friends.

pkg_rpm() depends on the existence of an rpmbuild toolchain. Many users will find to convenient to use the one provided with their system. To enable that toolchain add the following stanza to WORKSPACE:

# Find rpmbuild if it exists.
load("@rules_pkg//toolchains/rpm:rpmbuild_configure.bzl", "find_system_rpmbuild")
find_system_rpmbuild(name="rules_pkg_rpmbuild")

pkg_sub_rpm

Define a sub RPM to be built as part of a parent RPM

This rule uses the outputs of the rules in mappings.bzl to define an sub RPM that will be built as part of a larger RPM defined by a pkg_rpm instance.

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
srcsMapping groups to include in this RPMList of labelsrequired
architectureSub RPM architectureStringoptional""
conflictsList of RPM capability expressions that conflict with this packageList of stringsoptional[]
descriptionMulti-line description of this subrpmStringoptional""
epochRPM Epoch tag for this subrpmStringoptional""
groupOptional; RPM “Group” tag.

NOTE: some distributions (as of writing, Fedora > 17 and CentOS/RHEL > 5) have deprecated this tag. Other distributions may require it, but it is harmless in any case.
Stringoptional""
obsoletesList of RPM capability expressions that this package obsoletesList of stringsoptional[]
package_namename of the subrpmStringoptional""
post_scriptletRPM %post scriplet for this subrpmStringoptional""
providesList of RPM capability expressions that this package providesList of stringsoptional[]
requiresList of RPM capability expressions that this package requiresList of stringsoptional[]
summarySub RPM Summary tagStringoptional""
versionRPM Version tag for this subrpmStringoptional""

Provides rules for creating RPM packages via pkg_filegroup and friends.

pkg_rpm() depends on the existence of an rpmbuild toolchain. Many users will find to convenient to use the one provided with their system. To enable that toolchain add the following stanza to WORKSPACE:

# Find rpmbuild if it exists.
load("@rules_pkg//toolchains/rpm:rpmbuild_configure.bzl", "find_system_rpmbuild")
find_system_rpmbuild(name="rules_pkg_rpmbuild")

pkg_rpm

Creates an RPM format package via pkg_filegroup and friends.

The uses the outputs of the rules in mappings.bzl to construct arbitrary RPM packages. Attributes of this rule provide preamble information and scriptlets, which are then used to compose a valid RPM spec file.

This rule will fail at analysis time if:

  • Any srcs input creates the same destination, regardless of other attributes.

This rule only functions on UNIXy platforms. The following tools must be available on your system for this to function properly:

  • rpmbuild (as specified in rpmbuild_path, or available in $PATH)

  • GNU coreutils. BSD coreutils may work, but are not tested.

To set RPM file attributes (like %config and friends), set the rpm_filetag in corresponding packaging rule (pkg_files, etc). The value is prepended with “%” and added to the %files list, for example:

attrs = {"rpm_filetag": ("config(missingok, noreplace)",)},

Is the equivalent to %config(missingok, noreplace) in the %files list.

This rule produces 2 artifacts: an .rpm and a .changes file. The DefaultInfo will include both. If you need downstream rule to specifically depend on only the .rpm or .changes file then you can use filegroup to select distinct output groups.

OutputGroupInfo

  • out the RPM or a symlink to the actual package.
  • rpm the package with any precise file name created with package_file_name.
  • changes the .changes file.

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
srcsMapping groups to include in this RPM.

These are typically brought into life as pkg_filegroups.
List of labelsrequired
architecturePackage architecture.

This currently sets the BuildArch tag, which influences the output architecture of the package.

Typically, BuildArch only needs to be set when the package is known to be cross-platform (e.g. written in an interpreted language), or, less common, when it is known that the application is only valid for specific architectures.

When no attribute is provided, this will default to your host's architecture. This is usually what you want.
Stringoptional""
binary_payload_compressionCompression mode used for this RPM

Must be a form that rpmbuild(8) knows how to process, which will depend on the version of rpmbuild in use. The value corresponds to the %_binary_payload macro and is set on the rpmbuild(8) command line if provided.

Some examples of valid values (which may not be supported on your system) can be found here. On CentOS systems (also likely Red Hat and Fedora), you can find some supported values by looking for %_binary_payload in /usr/lib/rpm/macros. Other systems have similar files and configurations.

If not provided, the compression mode will be computed by rpmbuild itself. Defaults may vary per distribution or build of rpm; consult the relevant documentation for more details.

WARNING: Bazel is currently not aware of action threading requirements for non-test actions. Using threaded compression may result in overcommitting your system.
Stringoptional""
changelog-LabeloptionalNone
conflictsList of capabilities that conflict with this package when it is installed.

Corresponds to the “Conflicts” preamble tag.

See also: https://rpm-software-management.github.io/rpm/manual/dependencies.html
List of stringsoptional[]
debugDebug the RPM helper script and RPM generationBooleanoptionalFalse
debuginfoEnable generation of debuginfo RPMs

For supported platforms this will enable the generation of debuginfo RPMs adjacent to the regular RPMs. Currently this is supported by Fedora 40, CentOS7 and CentOS Stream 9.
BooleanoptionalFalse
definesAdditional definitions to pass to rpmbuildDictionary: String -> Stringoptional{}
descriptionMulti-line description of this package, corresponds to RPM %description.

Exactly one of description or description_file must be provided.
Stringoptional""
description_fileFile containing a multi-line description of this package, corresponds to RPM %description.LabeloptionalNone
epochOptional; RPM “Epoch” tag.Stringoptional""
groupOptional; RPM “Group” tag.

NOTE: some distributions (as of writing, Fedora > 17 and CentOS/RHEL > 5) have deprecated this tag. Other distributions may require it, but it is harmless in any case.
Stringoptional""
licenseRPM “License” tag.

The software license for the code distributed in this package.

The underlying RPM builder requires you to put something here; if your package is not going to be distributed, feel free to set this to something like “Internal”.
Stringrequired
obsoletesList of rpm capability expressions that this package obsoletes.

Corresponds to the “Obsoletes” preamble tag.

See also: https://rpm-software-management.github.io/rpm/manual/dependencies.html
List of stringsoptional[]
package_file_nameSee ‘Common Attributes’ in the rules_pkg reference.

If this is not provided, the package file given a NVRA-style (name-version-release.arch) output, which is preferred by most RPM repositories.
Stringoptional""
package_nameOptional; RPM name override.

If not provided, the name attribute of this rule will be used instead.

This influences values like the spec file name.
Stringoptional""
package_variablesSee ‘Common Attributes’ in the rules_pkg referenceLabeloptionalNone
post_scriptletRPM %post scriptlet. Currently only allowed to be a shell script.

post_scriptlet and post_scriptlet_file are mutually exclusive.
Stringoptional""
post_scriptlet_fileFile containing the RPM %post scriptletLabeloptionalNone
posttrans_scriptletRPM %posttrans scriptlet. Currently only allowed to be a shell script.

posttrans_scriptlet and posttrans_scriptlet_file are mutually exclusive.
Stringoptional""
posttrans_scriptlet_fileFile containing the RPM %posttrans scriptletLabeloptionalNone
postun_scriptletRPM %postun scriptlet. Currently only allowed to be a shell script.

postun_scriptlet and postun_scriptlet_file are mutually exclusive.
Stringoptional""
postun_scriptlet_fileFile containing the RPM %postun scriptletLabeloptionalNone
pre_scriptletRPM %pre scriptlet. Currently only allowed to be a shell script.

pre_scriptlet and pre_scriptlet_file are mutually exclusive.
Stringoptional""
pre_scriptlet_fileFile containing the RPM %pre scriptletLabeloptionalNone
preun_scriptletRPM %preun scriptlet. Currently only allowed to be a shell script.

preun_scriptlet and preun_scriptlet_file are mutually exclusive.
Stringoptional""
preun_scriptlet_fileFile containing the RPM %preun scriptletLabeloptionalNone
providesList of rpm capabilities that this package provides.

Corresponds to the “Provides” preamble tag.

See also: https://rpm-software-management.github.io/rpm/manual/dependencies.html
List of stringsoptional[]
releaseRPM “Release” tag

Exactly one of release or release_file must be provided.
Stringoptional""
release_fileFile containing RPM “Release” tag.LabeloptionalNone
requiresList of rpm capability expressions that this package requires.

Corresponds to the “Requires” preamble tag.

See also: https://rpm-software-management.github.io/rpm/manual/dependencies.html
List of stringsoptional[]
requires_contextualContextualized requirement specifications

This is a map of various properties (often scriptlet types) to capability name specifications, e.g.:

{“pre”: [“GConf2”],“post”: [“GConf2”], “postun”: [“GConf2”]}

Which causes the below to be added to the spec file's preamble:

Requires(pre): GConf2 Requires(post): GConf2 Requires(postun): GConf2

This is most useful for ensuring that required tools exist when scriptlets are run, although there may be other valid use cases. Valid keys for this attribute may include, but are not limited to:

- pre - post - preun - postun - pretrans - posttrans

For capabilities that are always required by packages at runtime, use the requires attribute instead.

See also: https://rpm-software-management.github.io/rpm/manual/more_dependencies.html

NOTE: pkg_rpm does not check if the keys of this dictionary are acceptable to rpm(8).
Dictionary: String -> List of stringsoptional{}
rpmbuild_pathPath to a rpmbuild binary. Deprecated in favor of the rpmbuild toolchainStringoptional""
source_date_epochValue to export as SOURCE_DATE_EPOCH to facilitate reproducible builds

Implicitly sets the %clamp_mtime_to_source_date_epoch in the subordinate call to rpmbuild to facilitate more consistent in-RPM file timestamps.

Negative values (like the default) disable this feature.
Integeroptional-1
source_date_epoch_fileFile containing the SOURCE_DATE_EPOCH value.

Implicitly sets the %clamp_mtime_to_source_date_epoch in the subordinate call to rpmbuild to facilitate more consistent in-RPM file timestamps.
LabeloptionalNone
spec_templateSpec file template.

Use this if you need to add additional logic to your spec files that is not available by default.

In most cases, you should not need to override this attribute.
Labeloptional"@rules_pkg//pkg/rpm:template.spec.tpl"
subrpmsSub RPMs to build with this RPM

A list of pkg_sub_rpm instances that can be used to create sub RPMs as part of the overall package build.

NOTE: use of subrpms is incompatible with the legacy spec_file mode
List of labelsoptional[]
summaryRPM “Summary” tag.

One-line summary of this package. Must not contain newlines.
Stringrequired
urlRPM “URL” tag; this project/vendor's home on the Internet.Stringoptional""
versionRPM “Version” tag.

Exactly one of version or version_file must be provided.
Stringoptional""
version_fileFile containing RPM “Version” tag.LabeloptionalNone

Rules for making .tar files.

pkg_tar

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
depstar files which will be unpacked and repacked into the archive.List of labelsoptional[]
srcsInputs which will become part of the tar archive.List of labelsoptional[]
out-Labelrequired
allow_duplicates_from_deps-BooleanoptionalFalse
allow_duplicates_with_different_contentIf true, will allow you to reference multiple pkg_* which conflict (writing different content or metadata to the same destination). Such behaviour is always incorrect, but we provide a flag to support it in case old builds were accidentally doing it. Never explicitly set this to true for new code.BooleanoptionalTrue
compressorExternal tool which can compress the archive.LabeloptionalNone
compressor_argsArg list for compressor.Stringoptional""
create_parents-BooleanoptionalTrue
empty_dirs-List of stringsoptional[]
empty_files-List of stringsoptional[]
extension-Stringoptional"tar"
filesObsolete. Do not use.Dictionary: Label -> Stringoptional{}
include_runfilesInclude runfiles for executables. These appear as they would in bazel-bin.For example: ‘path/to/myprog.runfiles/path/to/my_data.txt’.BooleanoptionalFalse
mode-Stringoptional"0555"
modes-Dictionary: String -> Stringoptional{}
mtime-Integeroptional-1
ownerDefault numeric owner.group to apply to files when not set via pkg_attributes.Stringoptional"0.0"
ownername-Stringoptional"."
ownernames-Dictionary: String -> Stringoptional{}
owners-Dictionary: String -> Stringoptional{}
package_dirPrefix to be prepend to all paths written.

This is applied as a final step, while writing to the archive. Any other attributes (e.g. symlinks) which specify a path, must do so relative to package_dir. The value may contain variables. See package_file_name for examples.
Stringoptional""
package_dir_file-LabeloptionalNone
package_file_nameSee Common AttributesStringoptional""
package_variablesSee Common AttributesLabeloptionalNone
portable_mtime-BooleanoptionalTrue
private_stamp_detect-BooleanoptionalFalse
remap_paths-Dictionary: String -> Stringoptional{}
stampEnable file time stamping. Possible values: stamp = 1: Use the time of the build as the modification time of each file in the archive. stamp = 0: Use an “epoch” time for the modification time of each file. This gives good build result caching. stamp = -1: Control the chosen modification time using the --[no]stamp flag. Since 0.5.0Integeroptional0
strip_prefix(note: Use strip_prefix = “.” to strip path to the package but preserve relative paths of sub directories beneath the package.)Stringoptional""
symlinks-Dictionary: String -> Stringoptional{}

Zip archive creation rule and associated logic.

pkg_zip

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
srcsList of files that should be included in the archive.List of labelsoptional[]
outoutput file name. Default: name + “.zip”.Labelrequired
allow_duplicates_with_different_contentIf true, will allow you to reference multiple pkg_* which conflict (writing different content or metadata to the same destination). Such behaviour is always incorrect, but we provide a flag to support it in case old builds were accidentally doing it. Never explicitly set this to true for new code.BooleanoptionalTrue
compression_levelThe compression level to use, 1 is the fastest, 9 gives the smallest results. 0 skips compression, depending on the method usedIntegeroptional6
compression_typeThe compression to use. Note that lzma and bzip2 might not be supported by all readers. The list of compressions is the same as Python's ZipFile: https://docs.python.org/3/library/zipfile.html#zipfile.ZIP_STOREDStringoptional"deflated"
include_runfilesSee standard attributes.BooleanoptionalFalse
modeThe default mode for all files in the archive.Stringoptional"0555"
package_dirPrefix to be prepend to all paths written. The name may contain variables, same as package_file_nameStringoptional"/"
package_file_nameSee Common AttributesStringoptional""
package_variablesSee Common AttributesLabeloptionalNone
private_stamp_detect-BooleanoptionalFalse
stampEnable file time stamping. Possible values: stamp = 1: Use the time of the build as the modification time of each file in the archive. stamp = 0: Use an “epoch” time for the modification time of each file. This gives good build result caching. stamp = -1: Control the chosen modification time using the --[no]stamp flag.Integeroptional0
strip_prefix-Stringoptional""
timestampTime stamp to place on all files in the archive, expressed as seconds since the Unix Epoch, as per RFC 3339. The default is January 01, 1980, 00:00 UTC.

Due to limitations in the format of zip files, values before Jan 1, 1980 will be rounded up and the precision in the zip file is limited to a granularity of 2 seconds.
Integeroptional315532800

Package creation helper mapping rules.

This module declares Provider interfaces and rules for specifying the contents of packages in a package-type-agnostic way. The main rules supported here are the following:

  • pkg_files describes destinations for rule outputs
  • pkg_mkdirs describes directory structures
  • pkg_mklink describes symbolic links
  • pkg_filegroup creates groupings of above to add to packages

Rules that actually make use of the outputs of the above rules are not specified here.

filter_directory

Transform directories (TreeArtifacts) using pkg_filegroup-like semantics.

Effective order of operations:

  1. Files are excluded
  2. renames or strip_prefix is applied.
  3. prefix is applied

In particular, if a rename applies to an individual file, strip_prefix will not be applied to that particular file.

Each non-`rename``d path will look like this:

$OUTPUT_DIR/$PREFIX/$FILE_WITHOUT_STRIP_PREFIX

Each renamed path will look like this:

$OUTPUT_DIR/$PREFIX/$FILE_RENAMED

If an operation cannot be applied (strip_prefix) to any component in the directory, or if one is unused (exclude, rename), the underlying command will fail. See the individual attributes for details.

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
srcDirectory (TreeArtifact) to process.Labelrequired
excludesFiles to exclude from the output directory.

Each element must refer to an individual file in src.

All exclusions must be used.
List of stringsoptional[]
outdir_nameName of output directory (otherwise defaults to the rule's name)Stringoptional""
prefixPrefix to add to all paths in the output directory.

This does not include the output directory name, which will be added regardless.
Stringoptional""
renamesFiles to rename in the output directory.

Keys are destinations, values are sources prior to any path modifications (e.g. via prefix or strip_prefix). Files that are excluded must not be renamed.

This currently only operates on individual files. strip_prefix does not apply to them.

All renames must be used.
Dictionary: String -> Stringoptional{}
strip_prefixPrefix to remove from all paths in the output directory.

Must apply to all paths in the directory, even those rename'd.
Stringoptional""

pkg_filegroup

Package contents grouping rule.

This rule represents a collection of packaging specifications (e.g. those created by pkg_files, pkg_mklink, etc.) that have something in common, such as a prefix or a human-readable category.

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
srcsA list of packaging specifications to be grouped together.List of labelsrequired
prefixA prefix to prepend to provided paths, applied like so:

- For files and directories, this is simply prepended to the destination - For symbolic links, this is prepended to the “destination” part.
Stringoptional""

pkg_files

General-purpose package target-to-destination mapping rule.

This rule provides a specification for the locations and attributes of targets when they are packaged. No outputs are created other than Providers that are intended to be consumed by other packaging rules, such as pkg_rpm. pkg_files targets may be consumed by other pkg_files or pkg_filegroup to build up complex layouts, or directly by top level packaging rules such as pkg_files.

Consumers of pkg_filess will, where possible, create the necessary directory structure for your files so you do not have to unless you have special requirements. Consult pkg_mkdirs for more details.

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
srcsFiles/Labels to include in the outputs of these rulesList of labelsrequired
attributesAttributes to set on packaged files.

Always use pkg_attributes() to set this rule attribute.

If not otherwise overridden, the file‘s mode will be set to UNIX “0644”, or the target platform’s equivalent.

Consult the “Mapping Attributes” documentation in the rules_pkg reference for more details.
Stringoptional"{}"
excludesList of files or labels to exclude from the inputs to this rule.

Mostly useful for removing files from generated outputs or preexisting filegroups.
List of labelsoptional[]
include_runfilesAdd runfiles for all srcs.

The runfiles are in the paths that Bazel uses. For example, for the target //my_prog:foo, we would see files under paths like foo.runfiles/<repo name>/my_prog/<file>
BooleanoptionalFalse
prefixInstallation prefix.

This may be an arbitrary string, but it should be understandable by the packaging system you are using to have the desired outcome. For example, RPM macros like %{_libdir} may work correctly in paths for RPM packages, not, say, Debian packages.

If any part of the directory structure of the computed destination of a file provided to pkg_filegroup or any similar rule does not already exist within a package, the package builder will create it for you with a reasonable set of default permissions (typically 0755 root.root).

It is possible to establish directory structures with arbitrary permissions using pkg_mkdirs.
Stringoptional""
renamesDestination override map.

This attribute allows the user to override destinations of files in pkg_files relative to the prefix attribute. Keys to the dict are source files/labels, values are destinations relative to the prefix, ignoring whatever value was provided for strip_prefix.

If the key refers to a TreeArtifact (directory output), you may specify the constant REMOVE_BASE_DIRECTORY as the value, which will result in all containing files and directories being installed relative to the otherwise specified install prefix (via the prefix and strip_prefix attributes), not the directory name.

The following keys are rejected:

- Any label that expands to more than one file (mappings must be one-to-one).

- Any label or file that was either not provided or explicitly excluded.

The following values result in undefined behavior:

- "" (the empty string)

- “.”

- Anything containing “..”
Dictionary: Label -> Stringoptional{}
strip_prefixWhat prefix of a file‘s path to discard prior to installation.

This specifies what prefix of an incoming file’s path should not be included in the output package at after being appended to the install prefix (the prefix attribute). Note that this is only applied to full directory names, see strip_prefix for more details.

Use the strip_prefix struct to define this attribute. If this attribute is not specified, all directories will be stripped from all files prior to being included in packages (strip_prefix.files_only()).

If prefix stripping fails on any file provided in srcs, the build will fail.

Note that this only functions on paths that are known at analysis time. Specifically, this will not consider directories within TreeArtifacts (directory outputs), or the directories themselves. See also #269.
Stringoptional"."

pkg_mkdirs

Defines creation and ownership of directories in packages

Use this if:

  1. You need to create an empty directory in your package.

  2. Your package needs to explicitly own a directory, even if it already owns files in those directories.

  3. You need nonstandard permissions (typically, not “0755”) on a directory in your package.

For some package management systems (e.g. RPM), directory ownership (2) may imply additional semantics. Consult your package manager‘s and target distribution’s documentation for more details.

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
attributesAttributes to set on packaged directories.

Always use pkg_attributes() to set this rule attribute.

If not otherwise overridden, the directory‘s mode will be set to UNIX “0755”, or the target platform’s equivalent.

Consult the “Mapping Attributes” documentation in the rules_pkg reference for more details.
Stringoptional"{}"
dirsDirectory names to make within the package

If any part of the requested directory structure does not already exist within a package, the package builder will create it for you with a reasonable set of default permissions (typically 0755 root.root).
List of stringsrequired

pkg_mklink_impl

Define a symlink within packages

This rule results in the creation of a single link within a package.

Symbolic links specified by this rule may point at files/directories outside of the package, or otherwise left dangling.

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
attributesAttributes to set on packaged symbolic links.

Always use pkg_attributes() to set this rule attribute.

Symlink permissions may have different meanings depending on your host operating system; consult its documentation for more details.

If not otherwise overridden, the link‘s mode will be set to UNIX “0777”, or the target platform’s equivalent.

Consult the “Mapping Attributes” documentation in the rules_pkg reference for more details.
Stringoptional"{}"
link_nameLink “destination”, a path within the package.

This is the actual created symbolic link.

If the directory structure provided by this attribute is not otherwise created when exist within the package when it is built, it will be created implicitly, much like with pkg_files.

This path may be prefixed or rooted by grouping or packaging rules.
Stringrequired
targetLink “target”, a path on the filesystem.

This is what the link “points” to, and may point to an arbitrary filesystem path, even relative paths.
Stringrequired

pkg_attributes

Format attributes for use in package mapping rules.

If “mode” is not provided, it will default to the mapping rule's default mode. These vary per mapping rule; consult the respective documentation for more details.

Not providing any of “user”, “group”, “uid”, or “gid” will result in the package builder choosing one for you. The chosen value should not be relied upon.

Well-known attributes outside of the above are documented in the rules_pkg reference.

This is the only supported means of passing in attributes to package mapping rules (e.g. pkg_files).

PARAMETERS

NameDescriptionDefault Value
modestring: UNIXy octal permissions, as a string.None
userstring: Filesystem owning user name.None
groupstring: Filesystem owning group name.None
uidint: Filesystem owning user id.None
gidint: Filesystem owning group id.None
kwargsany other desired attributes.none

RETURNS

A value usable in the “attributes” attribute in package mapping rules.

pkg_mklink

Create a symlink.

Wraps pkg_mklink_impl

PARAMETERS

NameDescriptionDefault Value
nametarget namenone
link_namethe path in the package that should point to the target.none
targettarget path that the link should point to.none
attributesfile attributes.None
src-None
kwargs-none

strip_prefix.files_only

strip_prefix.from_pkg

PARAMETERS

NameDescriptionDefault Value
path-""

strip_prefix.from_root

PARAMETERS

NameDescriptionDefault Value
path-""

Rules to create RPM archives.

NOTE: this module is deprecated in favor of pkg/rpm_pfg.bzl. For more information on the pkg_filegroup framework it uses, see pkg/mappings.bzl.

pkg_rpm() depends on the existence of an rpmbuild toolchain. Many users will find to convenient to use the one provided with their system. To enable that toolchain add the following stanza to WORKSPACE:

# Find rpmbuild if it exists.
load("@rules_pkg//toolchains/rpm:rpmbuild_configure.bzl", "find_system_rpmbuild")
find_system_rpmbuild(name="rules_pkg_rpmbuild")

pkg_rpm

Legacy version

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
data-List of labelsrequired
architecture-Stringoptional"all"
changelog-LabeloptionalNone
debug-BooleanoptionalFalse
release-Stringoptional""
release_file-LabeloptionalNone
rpmbuild_path-Stringoptional""
source_date_epoch-Integeroptional0
source_date_epoch_file-LabeloptionalNone
spec_file-Labelrequired
version-Stringoptional""
version_file-LabeloptionalNone