Skip to content

Ship cross toolchains as separate PyPI packages - #9

Merged
dwoz merged 9 commits into
mainfrom
add-cross-toolchain-packages
Nov 21, 2026
Merged

dwoz merged 9 commits into
mainfrom
add-cross-toolchain-packages

Conversation

@dwoz

@dwoz dwoz commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

Supersedes #8. Addresses the request for cross toolchains that don't
bloat the base ppbt wheel.

Design

Each cross toolchain is its own PyPI project rather than being bundled
into base ppbt:

  • ppbt — native host toolchain, ~40 MiB (unchanged from 0.1.8).
  • ppbt-cross-aarch64-linux-gnu — aarch64 target, x86_64 host wheel.
  • ppbt-cross-x86_64-linux-gnu — x86_64 target, aarch64 host wheel.

Users opt in via extras:

pip install ppbt                                   # native only
pip install ppbt[cross-aarch64-linux-gnu]          # + aarch64 cross
pip install ppbt[cross-x86_64-linux-gnu]           # + x86_64 cross
pip install ppbt[cross-all]                        # both cross

Cross packages register themselves via a ppbt.toolchains entry
point so base ppbt discovers them at import time — no name lookup
in downstream consumers.

New API

import ppbt
ppbt.available_triplets()                    # list of discovered triplets
ppbt.archive_for("aarch64-linux-gnu")        # Path to the tarball
ppbt.toolchain_for("aarch64-linux-gnu")      # Path to the extracted dir
env = ppbt.environ(triplet="aarch64-linux-gnu", auto_extract=True)

extract() / environ() default triplet= to the host, so
pre-0.2.0 callers keep working unchanged.

Repo layout

src/ppbt/                              # base package (unchanged shape)
packages/
  cross-aarch64-linux-gnu/
    pyproject.toml   setup.cfg   setup.py
    src/ppbt_cross_aarch64_linux_gnu/
      __init__.py                      # TRIPLET, TOOLCHAIN, ARCHIVE, DISTINFO
      build.py                         # PEP 517 backend
      _config/aarch64-linux-gnu-ct-ng.config
  cross-x86_64-linux-gnu/
    ... (mirrors above)

CI

  • package-action.yml: matrix has 4 cells (base x86_64,
    base aarch64, cross-aarch64-linux-gnu on x86_64 host,
    cross-x86_64-linux-gnu on aarch64 host). Each cell produces one
    wheel.
  • deploy-package-action.yml: globs all Python Wheel * artifacts
    into dist/ and lets pypa/gh-action-pypi-publish upload them;
    works for N packages without listing names.
  • github-release.yml: switched to softprops/action-gh-release
    with files: dist/* so it uploads whatever CI built (the
    hard-coded 3-asset pattern couldn't scale to 7 artifacts).

PyPI trusted-publisher config (manual, before first release)

I can't create these; someone with PyPI maintainer rights has to add
two pending publishers at https://pypi.org/manage/account/publishing/:

  • Project: ppbt-cross-aarch64-linux-gnu
    • Owner: saltstack
    • Repository: ppbt
    • Workflow: deploy-package-action.yml
    • Environment: release
  • Project: ppbt-cross-x86_64-linux-gnu — same except project name.

Both names are currently unclaimed on PyPI (verified 404 on their
pypi.org/pypi//json).

Test plan

  • pytest tests/ — 12 passing (new tests/test_common.py covers
    host/cross resolution, entry-point discovery, archive-missing
    fallback, and clear error on unregistered triplets).
  • pip install -e . -e packages/cross-aarch64-linux-gnu -e packages/cross-x86_64-linux-gnu
    • ppbt.available_triplets() returns [] until a tarball is
      staged, then discovers both.
  • pre-commit run --all-files clean (isort/black/flake8).
  • CI build on both arches produces 4 wheels + 3 sdists.
  • After trusted-publisher config, test release via kind=release
    workflow dispatch publishes all 3 projects.
  • Downstream relenv cutover: call ppbt.archive_for(triplet)
    from get_toolchain(); validates the cross-build path for #37.

Each cross toolchain is now its own PyPI project rather than being
bundled into the base ppbt wheel.  The base wheel stays lean (native
toolchain only, ~40 MiB); cross users opt in via extras:

    pip install ppbt[cross-aarch64-linux-gnu]
    pip install ppbt[cross-x86_64-linux-gnu]
    pip install ppbt[cross-all]

The base ppbt package exposes new API for picking a toolchain by
triplet -- archive_for(triplet), toolchain_for(triplet),
available_triplets() -- and extract() / environ() take a triplet=
kwarg.  Cross packages register themselves via a ppbt.toolchains
entry point so base ppbt discovers them at import time without
having to know their names.

Sibling packages:
- packages/cross-aarch64-linux-gnu/  (aarch64 target, x86_64 host)
- packages/cross-x86_64-linux-gnu/   (x86_64 target, aarch64 host)

Each ships its own crosstool-ng config + build backend, produces a
wheel tagged for its *host* arch (an aarch64 cross toolchain runs on
an x86_64 host, so the wheel is manylinux_2_17_x86_64), and has its
own RECORD-merging on extract.

CI matrix now has 4 cells (base x 2 host arches + 2 cross siblings
each on its one host), and both source + wheel upload patterns use
glob dispatch so new sibling packages fall out without wiring every
artifact name individually.  Editable installs across all three
packages skip the heavy crosstool-ng build via a PEP 660
build_editable hook, so dev installs take seconds rather than hours.
@dwoz dwoz mentioned this pull request Nov 21, 2026
2 of 4 tasks
dwoz added 8 commits November 20, 2026 20:48
- Pre-commit's ``Install System Deps`` step installed ``libxml2`` as a
  bare package, which ubuntu-26.04 ("resolute") dropped from main.
  ``libxml2-dev`` alone pulls the runtime transitively, which was the
  fix already used elsewhere.
- ``test_environ_defaults_to_host`` and ``test_environ_accepts_triplet``
  asserted ``env["CC"].endswith("bin/<triplet>-gcc")``, but on Windows
  ``pathlib`` builds ``bin\<triplet>-gcc`` (backslashes), so both
  failed on the Windows CI matrix.  Use ``pathlib.PurePath(cc).name``
  instead of a hard-coded separator substring.

Also picks up the black/isort reformats on the sibling build.py files
that had multi-line ``from ... import`` blocks collapsed by newer
black.
Black 22.6.0 calls asyncio.get_event_loop() which 3.12 removed; the
pyflakes bundled with flake8-mypy-fork references ast.Str, also
removed in 3.12.  ubuntu-26.04's default python is 3.12, so pin 3.11
with actions/setup-python before running pre-commit.

The copyright hook also wanted the 2024 headers bumped to 2024-2026
on the files touched in this PR.
GitHub retired macos-12 in late 2024 and macos-13-xlarge requires
paid Apple-Silicon runners that aren't enabled on this repo, so both
cells queued indefinitely on every PR run.  Use macos-13 (x86) and
macos-14 (Apple Silicon, generic label) instead — same coverage,
no paid tier required.
ppbt ships only Linux manylinux wheels (crosstool-ng gcc toolchain
targeting glibc 2.17); there's no macOS wheel to validate.  The macOS
cells had been queued-but-never-run for a while (macos-12 retired,
macos-13-xlarge needs paid Apple Silicon runners), and macos-13 /
macos-14 jobs get scheduler-cancelled on this org.  Removing them
rather than babysit a configuration that adds no coverage.
Self-hosted `src-build` runners weren't picking up these jobs
(queued indefinitely with no runner assignment).  Use ubuntu-latest
for x86_64 cells and ubuntu-24.04-arm for aarch64 cells; both are
free for public repos and compatible with the debian:11 container
the wheel build runs inside.
Debian 11 (bullseye) is no longer served from debian-security; the
pool returned 404 for every pinned security update so apt-get install
failed.  The target glibc (2.17) is produced by crosstool-ng inside
the container, not by the container itself, so moving the host image
up to bookworm doesn't change what ends up in the shipped toolchain.
Previously `src/ppbt/build.py` was both the PEP 517 build backend
and part of the installed wheel.  That meant anything consuming
`ppbt` at runtime (notably relenv) could trip over setuptools /
subprocess / tarfile machinery that only belongs at wheel-build
time.  Commit 09d32eb already moved setuptools imports out of
ppbt.common for the same reason; this finishes the job by relocating
the backend module outside `src/` entirely.

- Base ppbt: `_build.py` at repo root.
- Each cross sibling: `packages/cross-<triplet>/_build.py`.
- All three pyprojects now set `build-backend = "_build"` and
  `backend-path = ["."]`.
- `src/ppbt/build.py` deleted; backend duplicates the small subset
  of ppbt.common helpers it needs (build_arch, get_triplet,
  extract_archive) so it is standalone and not circular.
- tests/test_build.py now loads `_build.py` by path and asserts the
  PEP 517 hooks are exposed.
Isort 5.12 (pre-commit-pinned) splits `from X import Y as _Y` onto
its own line, which disagrees with my local isort's black profile
and ping-pongs the file.  Import the submodule once and dereference
each PEP 517 hook off it instead; no `as` imports, no disagreement.
@dwoz
dwoz merged commit f54cc65 into main Nov 21, 2026
16 checks passed
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