Skip to content

Sysroot support - #254

Open
LittleHuba wants to merge 2 commits into
bazel-contrib:mainfrom
LittleHuba:sysroot_support
Open

LittleHuba wants to merge 2 commits into
bazel-contrib:mainfrom
LittleHuba:sysroot_support

Conversation

@LittleHuba

Copy link
Copy Markdown
Contributor

This is finally the PR to add sysroot support to rules_distroless.

This PR consits of two commits:

  1. The actual implementation for sysroot support
  2. A refactoring of translate_dependency_set.bzl to align the tests that are performed on the different call paths

I think the second piece is crucial to not end up with bugs appearing on one path while they were already fixed on the other.

An example and smoke test were added to exercise the new functionality in CI and show users how to create the sysroot and inject it into a toolchain.

LittleHuba and others added 2 commits August 26, 2026 12:02
Adds apt.sysroot(), a repository rule that unpacks a dependency_set's
packages into a flat, fetch-time sysroot directory for a single target
architecture, for use with toolchains like toolchains_llvm.

- New apt/private/sysroot_repository.bzl: for each transitively required
  package, downloads the .deb, extracts its data.tar member, and
  materializes the contents into a flat `sysroot/` directory with a
  generated BUILD.bazel exposing it as a `:sysroot` filegroup. Extraction
  uses a hermetic, prebuilt bsdtar binary (resolved per exec platform via
  @bazel_lib//lib:repo_utils.bzl and tar.bzl's bsd_tar_toolchains repos)
  rather than the host's `ar`/`tar`, since bsdtar/libarchive natively reads
  both the `ar` container format used by .deb files and the nested
  data.tar.* payload, making the unpack reproducible across machines
  regardless of what's installed on the host.
- apt.sysroot(name, dependency_set, architecture) tag class; wired up in
  the module extension alongside the existing apt.install() dependency
  sets. Fails with a clear error if the referenced dependency_set wasn't
  declared via apt.install().
- translate_dependency_set.bzl gains dependency_set_transitive_package_keys,
  which computes the architecture-scoped transitive closure of package
  keys for a dependency_set (used by sysroot_repository.bzl to decide
  which packages to unpack). Includes a renamed/expanded test
  (no_mixed_architectures_deps_test) plus new coverage for the transitive
  closure helper.
- MODULE.bazel: use_repo the per-platform bsd_tar_toolchains_* repos from
  tar.bzl so sysroot_repository.bzl can reference a concrete bsdtar
  binary label for the exec platform.
- README.md and new examples/sysroot/ example, plus e2e/smoke and
  examples/MODULE.bazel wiring, showing apt.sysroot() paired with
  toolchains_llvm's llvm.sysroot() for a hermetic C++ toolchain.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Restructuring to avoid code duplication while keeping the same
checks for both public call flows.
Some checks were shifted to lockfile.bzl since it is a globally
verifiable condition that all later logic should benefit from.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@LittleHuba
LittleHuba marked this pull request as ready for review August 26, 2026 18:54
@LittleHuba

Copy link
Copy Markdown
Contributor Author

@thesayyn anything I can do to help this progress?

@LittleHuba

Copy link
Copy Markdown
Contributor Author

Friendly reminder @thesayyn
This is the last PR necessary to actually resolve #124.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant