How astral-sh/cargo-dist works
1. cargo-dist is a Rust workspace centered on a release-distribution toolchain for binaries. The top-level crate is a CLI/library that inspects a repo, plans releases, generates CI, and emits packaging/install artifacts.
2. The architecture is split into three main crates:
- cargo-dist: the core product logic and CLI.
- cargo-dist-schema: a schema/serialization crate for the machine-readable manifest format.
- axoproject: a helper crate for repository/project introspection, especially Rust and JS project metadata and changelog/repo utilities.
3. The primary runtime flow is: user runs dist init or dist commands → the tool reads workspace config and project layout → it computes a release/build plan → it generates CI/workflow files, manifests, installers, and release metadata. The README’s “Plan, Build, Host, Publish, Announce” split is the clearest boundary in the system.
4. Configuration is versioned and centralized under cargo-dist/src/config. There are v0 and v1 formats, plus migration code from v0 to v1. Within v1, config is decomposed by concern: builds, artifacts, CI, hosts, installers, and publishers. This strongly suggests the tool treats configuration as the source of truth for the generated pipeline.
5. Build planning is implemented in cargo-dist/src/build, with separate paths for Cargo-based builds and generic builds. That boundary matters: Cargo workspaces are first-class, but the tool also supports non-Rust or manually built projects by switching to generic build definitions.
6. CI generation is a backend concern under cargo-dist/src/backend/ci, with GitHub Actions being the concrete provider. The backend layer is also responsible for composing templates for release workflows and publish jobs, so CI generation is not hand-authored but synthesized from the computed plan.
7. Installer generation is another backend boundary under cargo-dist/src/backend/installer and corresponding templates. The repo supports multiple installer types, including Homebrew, MSI, npm, PowerShell, shell scripts, and macpkg. These installers are generated artifacts rather than separate maintained projects.
8. The tool also models hosting, publishing, signing, and announcement as distinct subsystems:
- host.rs and config/v1/hosts for release hosting destinations.
- publishers/* for package-manager publication.
- sign/* for signing workflows on macOS and Windows/SSL.com.
- announce.rs for release-note and release-announcement generation.
9. manifest.rs, cargo-dist-schema, and tests/snapshots indicate a strong machine-readable contract. The generated manifest is a key integration point: it captures release inputs/outputs so other tools and the generated CI jobs can consume the same plan consistently.
10. cargo-dist/src/platform and cargo-dist/src/linkage.rs show that platform targeting and binary compatibility are treated explicitly. This suggests the build planner reasons about target triples, runners, and platform-specific packaging, not just “build once, ship everywhere.”
11. cargo-dist/src/init.rs and the templates/ directory are the bootstrap path. They generate repo-local files such as workflow YAML, installer assets, and npm wrapper files, which means the tool is both an analyzer and a scaffold generator.
12. The book/ directory is a substantial documentation subsystem, not just ancillary docs. It documents architecture-relevant concepts such as artifacts, installers, CI, workspaces, and supply-chain security, reinforcing that the repo’s outputs are meant to be understood as a generated release system.
13. Testing is heavily fixture- and snapshot-driven. The cargo-dist/tests/gallery and cargo-dist/tests/snapshots directories validate rendered outputs against many example projects: Rust crates, Cargo workspaces, generic C projects, npm apps, and workspace variants. This indicates the core risk area is output correctness, not long-running services.
14. The sample projects under axoproject/tests/projects and cargo-dist/tests/gallery/dist form the architecture’s integration boundary with real repositories. They exercise discovery of workspace structure, changelogs, licenses, package metadata, and build layouts across multiple ecosystems.
15. Operationally, the repo is self-hosting and CI-driven. GitHub Actions workflows in .github/workflows handle CI, publishing crates, and releases, while the README notes releases are produced by tagging and pushing, with cargo-release helping maintain versioning and changelog hygiene.
16. For an architecture diagram, the most important nodes are: user/CLI input, repo introspection/config parsing, release planning, schema/manifest emission, build artifact generation, CI template generation, installer/publisher/signing backends, and the test/docs surfaces that validate and explain those outputs.
Main entry points: backend/mod.rs Backend · lib.rs Repo introspection · build/mod.rs Planner · config/mod.rs Config
Components 20
cargo-dist
Main release-distribution CLI and orchestration crate.
- CLI · User-facing dist commands and startup flow.
cargo-dist/src/cli.rs - Init · Scaffolds repo-local dist files and templates.
cargo-dist/src/init.rs - Config · Central config model and v0/v1 migration boundary.
cargo-dist/src/config/mod.rs - Planner · Computes build and release plans from repo layout and config.
cargo-dist/src/build/mod.rs - Manifest · Emits the machine-readable release manifest consumed by CI and tools.
cargo-dist/src/manifest.rs - Backend · Synthesizes workflows, installers, and publish jobs from the plan.
cargo-dist/src/backend/mod.rs - CI · Generates GitHub Actions release and publish workflows.
cargo-dist/src/backend/ci/mod.rs - Installers · Generates installer artifacts and wrapper assets.
cargo-dist/src/backend/installer/mod.rs - Publishers · Models package-manager publication targets and steps.
cargo-dist/src/config/v1/publishers/mod.rs - Signing · Handles macOS and Windows/SSL.com signing workflows.
cargo-dist/src/sign/mod.rs - Hosts · Represents release hosting destinations and upload targets.
cargo-dist/src/host.rs - Platform · Encodes target triples, runners, and platform-specific packaging.
cargo-dist/src/platform - Announce · Builds release-note and announcement payloads.
cargo-dist/src/announce.rs
Schema
Machine-readable manifest contract.
- Schema crate · Shared serialization schema for generated manifest data.
cargo-dist-schema/src/lib.rs
axoproject
Repository and project introspection helpers.
- Repo introspection · Detects repo structure, metadata, and changelog information.
axoproject/src/lib.rs - Rust · Inspects Cargo workspaces and crate metadata.
axoproject/src/rust.rs - JavaScript · Inspects npm and JS project metadata.
axoproject/src/javascript.rs - Repo utils · Local repository, generic project, and changelog utilities.
axoproject/src/repo.rs
Connections 28
- CLI → Config: loads · Reads versioned config and command settings.
- CLI → Repo introspection: inspects · Discovers repository shape and metadata.
- CLI → Init: boots · Initializes dist files and templates.
- CLI → Planner: plans · Produces the release/build plan.
- Init → Backend: scaffolds · Writes generated workflow and installer files.
- Config → Planner: drives · Config is the source of truth for planning.
- Config → Backend: parameterizes · Backend generation follows config-derived plan data.
- Planner → Manifest: emits · Serializes the planned release graph.
- Planner → Backend: feeds · Provides inputs for workflow and artifact generation.
- Planner → Platform: targets · Resolves platform and runner-specific decisions.
- Backend → CI: generates · Synthesizes CI workflows and publish jobs.
- Backend → Installers: generates · Synthesizes installer outputs and wrapper assets.
- Backend → Publishers: coordinates · Composes publish steps for package registries.
- Backend → Signing: coordinates · Adds signing steps where required.
- Backend → Hosts: uploads to · Uses hosting destinations for release assets.
- Backend → Announce: produces · Creates release announcement content.
- Schema crate → Manifest: defines · Shared schema underpins the emitted manifest.
- Repo introspection → Rust: detects · Rust workspace and crate discovery.
- Repo introspection → JavaScript: detects · JavaScript package discovery.
- Repo introspection → Repo utils: supports · Generic repo and changelog helpers.
- Repo introspection → Config: supplies inputs · Feeds project metadata into config and planning.
- Book → CI: documents · Explains CI generation concepts and customization.
- Book → Installers: documents · Explains installer families and usage.
- Book → Config: documents · Documents config and concepts.
- Snapshots → Planner: validates · Checks release planning against fixtures and snapshots.
- Snapshots → Backend: validates · Checks rendered workflows and installers.
- Snapshots → Repo introspection: exercises · Runs against sample projects across ecosystems.
- Snapshots → Manifest: validates · Ensures manifest output stays stable.