rules_apt
rules_apt
Pitch
A Bazel module extension for downloading a graph of Debian packages
API
module(name = "example")
apt = use_extension("@rules_apt//apt:defs.bzl", "apt")
# Overrides the source to use for this module
# By default, we will use a recent snapshot and the latest distribution
# Non-reproducible remotes can be used but a warning will be printed
apt.sources(
name = "snapshot-20241101T025324Z",
urls = ["https://snapshot.debian.org/archive/debian/20241101T025324Z"],
distribution = "bookworm",
reproducible = True,
default = True,
)
# Adds a package to download
# Later, we may allow version requirements, etc
# Downloads are de-duped across sources by using the SHA256 of the package
apt.package(name = "qemu-system-arm")#sources = "snapshot-20241101T025324Z") implicit default
apt.package(name = "qemu-system-x86", sources = "snapshot-20241101T025324Z")
# Use the downloaded packages
# Note: `buildozer` can generate this automatically
# These are convenience symlink repositories to underlying SHA256 repositories
use_repo(apt, "example-qemu-system-arm", "example-qemu-system-arm")
Each package repository would provide:
-
@<pkg>//pkg: The original package.debpackage -
@<pkg>//pkg:unpacked: The unpacked package (atar_unpacktarget on the.deb) -
@<pkg>//data: The data archive from inside the archive (atar_extracttarget on the.deb) -
@<pkg>//control: The data from inside the archive (atar_extracttarget on the.deb) -
@<pkg>//data:unpacked: The unpacked data (atar_unpacktarget on thedata.tar.xz) -
@<pkg>//control:unpacked: The unpacked control (atar_unpacktarget on thecontrol.tar.xz) -
@<pkg>//data:archives: The recursive data archives using the dependent package labels -
@<pkg>:aliasto@<pkg>//data:archives
Implementation
The extension would download the distribution lists from <remote>/dists/<distribution>/<section>/binary-<arch>/Packages.xz. It would parse the downloaded package data, resolve the package dependencies and output a stream of data that can be passed to the attributes of apt_download:
apt_download(
name = "<sha256-of-pkg>", # allows de-duping identical package repositories
urls = ["..."],
integrity = "...",
deps = ["@<sha256-of-dependency>"],
)
Usage
The downloaded packages could be used with rules_patchelf.
patchelf_interpreter_unpack(
name = "patched",
srcs = ["@example-qemu-system-arm"],
interpreter = "@rules_patchelf//patchelf/interpreter:debian",
)
However, it would be a generically useful, standalone, ruleset.
Edited by Matthew Clarkson