zlayer_types/toolchain_lock.rs
1//! Wire types for the toolchain lockfile (`zlayer-toolchains.lock`).
2//!
3//! These are **pure serde** shapes. The file's load/save/lookup/upsert I/O (TOML
4//! on disk, deterministic ordering, sha256 recomputation) lives in
5//! `zlayer-toolchain`'s `lockfile` module — this crate only defines the shapes so
6//! both `zlayer-toolchain` (which *consumes* a lock during provisioning) and
7//! `zlayer-builder` (which will *pass* one through in a later commit) can name
8//! them without pulling in `tokio`/`reqwest`.
9//!
10//! A lock pins one resolved `(tool, platform, arch)` to an exact `version`,
11//! download `url`, and `sha256`, so a later provision is reproducible and
12//! integrity-checked rather than resolving "latest" afresh.
13
14use serde::{Deserialize, Serialize};
15
16/// Current on-disk schema version for [`ToolchainLockfile`].
17pub const TOOLCHAIN_LOCK_SCHEMA: u32 = 1;
18
19/// The parsed toolchain lockfile: a schema tag, a generation timestamp, and the
20/// set of pinned tools (serialized as a TOML `[[tool]]` array of tables).
21#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
22pub struct ToolchainLockfile {
23 /// On-disk schema version (see [`TOOLCHAIN_LOCK_SCHEMA`]).
24 pub schema: u32,
25 /// RFC 3339 timestamp of when the lock was last written.
26 pub generated_at: String,
27 /// The pinned tools. Serialized/deserialized as `[[tool]]` tables.
28 #[serde(default, rename = "tool")]
29 pub tools: Vec<LockedTool>,
30}
31
32/// One pinned toolchain entry: an exact, integrity-checked resolution.
33///
34/// `Ord` is derived field-by-field (tool, then platform, then arch, ...), so the
35/// natural sort orders entries by `(tool, platform, arch)` first — the ordering
36/// the lockfile writer uses for a stable, diff-friendly file.
37#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
38pub struct LockedTool {
39 /// The tool request token as provisioned (e.g. `git`, `node@lts`).
40 pub tool: String,
41 /// Target platform (`macos` / `windows`).
42 pub platform: String,
43 /// Host architecture token (`arm64` / `x86_64`).
44 pub arch: String,
45 /// The exact resolved version (e.g. `2.55.0`).
46 pub version: String,
47 /// The exact download URL the artifact was fetched from.
48 pub url: String,
49 /// The artifact's sha256 (bare lowercase hex).
50 pub sha256: String,
51 /// RFC 3339 timestamp of when this entry was resolved.
52 pub resolved_at: String,
53}