pkg_install: make callable from a symbolic macro (#1069)
`pkg_install` wires its internal `_pkg_install_script` rule to a
`py_binary` via the script's *output filename*:
py_binary(
name = name,
srcs = [":" + name + "_install_script"],
main = name + "_install_script.py", # <-- file-name-as-label
...
)
`_pkg_install_script` declared that file at analysis time via
`ctx.actions.declare_file(...)`, so the file `<name>_install_script.py`
existed only as an artifact in the rule's `DefaultInfo` — no
loading-time package label was ever registered for it. Legacy macros
tolerated the file-name-as-label shortcut, but in a symbolic macro,
label references must resolve to real loading-time targets in scope.
Bazel errors with:
no such target '//pkg:<name>_install_script.py': target
'<name>_install_script.py' not declared in package '<pkg>'
(did you mean <name>_install_script?)
Promote the script file to a predeclared output via `attr.output()`.
The caller passes `out = <name>_install_script.py`, which registers
`//pkg:<name>_install_script.py` as a real package label at loading
time. `py_binary.main` can then resolve that label in any macro
scope, and the rule impl reads the file through `ctx.outputs.out`
instead of `ctx.actions.declare_file`. No change to the user-facing
`pkg_install` API.Bazel rules for building tar, zip, deb, and rpm for packages.
For the latest version, see Releases (with WORKSPACE setup) / Documentation
Use rules-pkg-discuss@googlegroups.com for discussion.
As of Bazel 4.x, Bazel uses this rule set for packaging its distribution. Bazel still contains a limited version of pkg_tar but its feature set is frozen. Any new capabilities will be added here.
Sample, but see releases for the current release.
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") http_archive( name = "rules_pkg", urls = [ "https://mirror.bazel.build/github.com/bazelbuild/rules_pkg/releases/download/0.9.1/rules_pkg-0.9.1.tar.gz", "https://github.com/bazelbuild/rules_pkg/releases/download/0.9.1/rules_pkg-0.9.1.tar.gz", ], sha256 = "8f9ee2dc10c1ae514ee599a8b42ed99fa262b757058f65ad3c384289ff70c4b8", ) load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies") rules_pkg_dependencies()
To use pkg_rpm(), you must provide a copy of rpmbuild. You can use the system installed rpmbuild with this stanza.
load("@rules_pkg//toolchains/rpm:rpmbuild_configure.bzl", "find_system_rpmbuild") find_system_rpmbuild( name = "rules_pkg_rpmbuild", verbose = False, )
bazel_dep(name = "rules_pkg", version = "0.0.10")
To use pkg_rpm(), you must provide a copy of rpmbuild. You can use the system installed rpmbuild with this stanza.
find_rpm = use_extension("//toolchains/rpm:rpmbuild_configure.bzl", "find_system_rpmbuild_bzlmod") use_repo(find_rpm, "rules_pkg_rpmbuild") register_toolchains("@rules_pkg_rpmbuild//:all")
We hold an engineering status meeting on the first Monday of every month at 10am USA East coast time. Add to calendar / meeting notes