Bazel library which allows dealing with the whole RPM dependency lifecycle solely with pure go rules and a static go binary.
The rpm rule represents a pure RPM dependency. This dependency is not
processed in any way. They can be added to your WORKSPACE file like this:
load("@bazeldnf//:deps.bzl", "rpm")
rpm(
name = "libvirt-devel-6.1.0-2.fc32.x86_64.rpm",
sha256 = "2ebb715341b57a74759aff415e0ff53df528c49abaa7ba5b794b4047461fa8d6",
urls = [
"https://download-ib01.fedoraproject.org/pub/fedora/linux/releases/32/Everything/x86_64/os/Packages/l/libvirt-devel-6.1.0-2.fc32.x86_64.rpm",
"https://storage.googleapis.com/builddeps/2ebb715341b57a74759aff415e0ff53df528c49abaa7ba5b794b4047461fa8d6",
],
)rpmtree Takes a list of rpm dependencies and merges them into a single
tar package. rpmtree rules can be added like this to your BUILD files:
load("@bazeldnf//:deps.bzl", "rpmtree")
rpmtree(
name = "rpmarchive",
rpms = [
"@libvirt-libs-6.1.0-2.fc32.x86_64.rpm//rpm",
"@libvirt-devel-6.1.0-2.fc32.x86_64.rpm//rpm",
],
)Since rpmarchive is just a tar archive, it can be put into a container
immediately:
container_layer(
name = "gcloud-layer",
tars = [
":rpmarchive",
],
)The bazeldnf repository needs to be added to your WORKSPACE:
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "bazeldnf",
sha256 = "74f977ab8f13e466168ff0c80322bcb665db9f79d1bc497c742f9512737b91ea",
strip_prefix = "bazeldnf-0.0.1",
urls = [
"https://github.com/rmohr/bazeldnf/archive/v0.0.1.tar.gz",
],
)
load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")
load("@bazeldnf//:deps.bzl", "bazeldnf_dependencies")
go_rules_dependencies()
go_register_toolchains()
bazeldnf_dependencies()Define the bazeldnf executable rule in your BUILD.bazel file:
load("@bazeldnf//:def.bzl", "bazeldnf")
bazeldnf(name = "bazeldnf")After adding this code, you can run bazeldnf with Bazel:
bazel run //:bazeldnf -- --helpNot yet implemented!
rpmtree can also be used to satisvy C and C++ dependencies like this:
cc_library(
name = "rpmlibs",
srcs = [
":rpmarchive/usr/lib64",
],
hdrs = [
":rpmarchive/usr/include/libvirt",
],
prefix= "libvirt",
)The include_dir attribute for rpmtree tells the target to include headers
in that directory in <target>/hdrs.tar. The same for the lib_dir attribute
on rpmtree for libarires. It can be accessed via <target>/libs.tar. These
two tar files have in addition include_dir and lib_dir prefixes stripped
from the resulting archive, which should make it unnecessary to use the strip
options on cc_library.
One key part of managing RPM dependencies and RPM repository updates via bazel
is the ability to resolve RPM dependencies from repos without external tools
like dnf or yum and write the resolved dependencies to your WORKSPACE.
Here an example on how to add libvirt and bash to your WORKSPACE and BUILD files.
First write the repo.yaml file which contains some basic rpm repos to query:
bazeldnf init --fc 32 # write a repo.yaml file containing the usual release and update repos for fc32Then write a rpmtree rule called libvirttree to your BUILD file and all
corresponding RPM dependencies into your WORKSPACE for libvirt:
bazeldnf rpmtree --workspace /my/WORKSPACE --buildfile /my/BUILD.bazel --name libvirttree libvirtDo the same for bash with a bashrpmtree target:
bazeldnf rpmtree --workspace /my/WORKSPACE --buildfile /my/BUILD.bazel --name bashtree bashFinally prune all unreferenced old RPM files:
bazeldnf prune --workspace /my/WORKSPACE --buildfile /my/BUILD.bazel- Weighting packages (like prefer
libcurl-minimaloverlibcurlif one of their resources is requested) - Resolving
requiresentries which contain boolean logic like(gcc if something) - If
--nobestis supplied, newer packages don't get a higher weight
The goal is to build minimal containers with RPMs based on scratch containers. Therefore the following RPM repository hints will be ignored:
recommendssupplementssuggestsenhances