1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
//! Per-subcommand `clap::Subcommand` enums and value-enums referenced
//! from `Commands` in the parent module.
//!
//! Kept in a sibling file purely to keep `args/mod.rs` under the 1,000-LOC
//! cap. The public path (`cli::commands::args::<Name>`) is preserved via
//! re-exports in `args/mod.rs`.
use clap::{Subcommand, ValueEnum};
use std::path::PathBuf;
/// `zccache cache` subcommands (#695).
#[derive(Debug, Subcommand)]
pub(crate) enum CacheCommands {
/// Report the total on-disk size of the resolved cache root.
///
/// Walks the same root that `zccache cache-root` prints and sums the
/// bytes of every regular file under it. Hardlinks are counted once
/// (deduplicated by `(dev, inode)` on Unix; on Windows by inode-like
/// identity when available). Prints `<bytes>\t<human>\t<root>` on a
/// single line by default; use `--json` for a structured emit.
Size {
/// Emit `{"bytes": N, "human": "X GiB", "cache_root": "<abs>"}` instead of the
/// plain line.
#[arg(long)]
json: bool,
},
/// List per-version cache directories visible under the resolved cache
/// root, with last-active time, size, and status (current/warm/cold).
///
/// Today's single-root cache reports a single row (the resolved root
/// labeled `current`); when the multi-version `~/.zccache/v-<version>/`
/// layout from #694 lands, each per-version directory shows up as its
/// own row without any further CLI changes.
List {
/// Emit a JSON array of `{version, status, size_bytes, last_active_unix, path}`
/// instead of the plain tabular output.
#[arg(long)]
json: bool,
},
}
/// `zccache meson` subcommands.
#[derive(Debug, Subcommand)]
pub(crate) enum MesonCommands {
/// Cache-aware `meson setup`. On first invocation runs real meson and
/// captures the resulting build directory into the zccache cache; on
/// subsequent invocations with the same `meson.build` set, environment,
/// and meson version, restores the cached build directory and skips
/// invoking meson entirely.
///
/// **Same-build-dir restriction** — the build directory path is part of
/// the cache key. Build-dir-portable caching would require rewriting
/// the absolute paths meson scatters through `meson-info/` and
/// `meson-private/` on materialisation; for the common dev-loop case
/// (one developer, stable build dir) this is unnecessary. The
/// substantially larger fastled-style CI matrix that uses different
/// build dirs per platform still benefits because each (source, build,
/// host, env) tuple converges to a per-tuple cache entry on its second
/// invocation.
Configure {
/// Project source directory containing the root `meson.build`.
#[arg(long = "source-dir", value_name = "DIR")]
source_dir: PathBuf,
/// Build directory meson will populate.
#[arg(long = "build-dir", value_name = "DIR")]
build_dir: PathBuf,
/// Path to the meson executable. Defaults to `meson` on PATH.
#[arg(long = "meson-bin", value_name = "PATH")]
meson_bin: Option<PathBuf>,
/// Extra environment variable names whose values feed the cache
/// key. The current process env is queried at request time.
/// Repeatable. Common defaults (CC, CXX, CFLAGS, CXXFLAGS,
/// LDFLAGS, PKG_CONFIG_PATH) are always included.
#[arg(long = "input-env", value_name = "NAME")]
input_env: Vec<String>,
/// Extra file paths whose content feeds the cache key. Repeatable.
/// Each file is hashed by content; the path is recorded as it
/// appeared on the command line.
///
/// Use this when source-change detection lives outside the
/// meson.build set itself — e.g. a downstream caching layer that
/// hashes test/example/source globs and writes the digest to a
/// sidecar file. Pointing `--input-file` at that sidecar lets the
/// wrapper invalidate the cached configure tree when those globs
/// change, instead of forcing the caller to bypass the wrapper
/// entirely. See issue #654.
#[arg(long = "input-file", value_name = "PATH")]
input_file: Vec<String>,
/// Skip the implicit recursive walk of `--source-dir` for
/// `meson.build` / `meson.options` / `meson_options.txt`. The
/// caller takes full responsibility for naming every input file
/// via `--input-file` instead. Use this when you know your
/// project's input set exactly and the implicit walk is paying
/// for itself in directory-traversal cost on large monorepos
/// (e.g. trees with `.venv`, `.cached`, `.fbuild`, `.pio`, or
/// other large scratch dirs not on the default skip list). See
/// issue #659.
#[arg(long = "no-walk", default_value_t = false)]
no_walk: bool,
/// Extra `meson setup` arguments passed verbatim on a miss. They
/// also enter the cache key so different option sets produce
/// distinct cache entries.
#[arg(trailing_var_arg = true)]
meson_args: Vec<String>,
},
}
#[derive(Debug, Subcommand)]
pub(crate) enum SymbolsCommands {
/// Download the matching `-debug` archive from the GitHub release and
/// drop the per-binary sidecars next to the running zccache executable
/// so cdb/WinDbg (or perf/lldb) can resolve symbols.
Install {
/// Override the release version to fetch (defaults to the running
/// binary's compile-time `CARGO_PKG_VERSION`).
#[arg(long)]
version: Option<String>,
/// Override the Rust target triple (defaults to the running binary's
/// compile-time `ZCCACHE_BUILD_TARGET`).
#[arg(long)]
target: Option<String>,
/// Install into this directory instead of the directory containing
/// the running zccache executable.
#[arg(long)]
prefix: Option<PathBuf>,
/// Re-download even if matching sidecars are already present.
#[arg(long)]
force: bool,
},
/// Resolve symbols for one or more crash dumps. Reads the release
/// marker appended to the running zccache binary to determine which
/// version + target's symbol archive to fetch; the archive is cached
/// under `<cache>/symbols/<v>-<triple>/` (one copy per build) and a
/// `<dump>.symref` sidecar is written next to each crash dump
/// pointing at the cached symbol directory. If the running binary
/// is a dev build (no release marker), reports that and exits — use
/// the local `target/release/*.{pdb,dwp,dSYM}` manually.
Symbolicate {
/// One or more crash dump paths (`crash-*.txt` or `crash-*.dmp`).
#[arg(required = true)]
dumps: Vec<PathBuf>,
},
}
#[derive(Debug, Subcommand)]
pub(crate) enum DefenderExclusionsCommands {
/// Print whether the resolved cache root (and any sibling `runtime/`)
/// is on Defender's exclusion list. Non-destructive — no elevation
/// needed. Use `--json` for machine-readable output.
Check {
/// Emit a JSON document on stdout instead of human-readable text.
#[arg(long)]
json: bool,
},
/// Add the cache root (and any sibling `runtime/`) to Defender's
/// exclusion list. Requires administrator elevation; exits non-zero
/// with instructions when run from a non-elevated shell.
Add,
/// Remove the cache root (and any sibling `runtime/`) from Defender's
/// exclusion list. Requires administrator elevation.
Remove,
}
#[derive(Debug, Subcommand)]
pub(crate) enum CargoRegistryCommands {
/// Save cargo registry to a compressed archive.
Save {
/// Cache key (used as filename).
#[arg(long)]
key: String,
/// Cargo home directory (default: ~/.cargo or $CARGO_HOME).
#[arg(long)]
cargo_home: Option<String>,
},
/// Restore cargo registry from a compressed archive.
Restore {
/// Cache key to restore.
#[arg(long)]
key: String,
/// Cargo home directory (default: ~/.cargo or $CARGO_HOME).
#[arg(long)]
cargo_home: Option<String>,
},
/// Print hash of Cargo.lock for use as cache key.
Hash {
/// Path to Cargo.lock (default: ./Cargo.lock).
#[arg(long, default_value = "Cargo.lock")]
lockfile: String,
},
/// Remove cached registry archives.
Clean,
}
/// `zccache kv` subcommands.
#[derive(Debug, Subcommand)]
pub(crate) enum KvCommands {
/// Read a value to stdout. Exit 2 if missing.
Get {
/// Namespace (`[a-z0-9-]{1,64}`).
namespace: String,
/// 64-char hex key.
hex_key: String,
},
/// Write a value. Source is either `--value-from <file>` or stdin.
Put {
/// Namespace (`[a-z0-9-]{1,64}`).
namespace: String,
/// 64-char hex key.
hex_key: String,
/// Read value bytes from this file.
#[arg(long, conflicts_with = "value_from_stdin")]
value_from: Option<String>,
/// Read value bytes from stdin.
#[arg(long, conflicts_with = "value_from")]
value_from_stdin: bool,
},
/// Remove an entry. Idempotent — missing keys exit 0.
Rm {
/// Namespace.
namespace: String,
/// 64-char hex key.
hex_key: String,
},
/// List entries under a namespace, sorted by hex key. One row per entry:
/// `<hex> <bytes>`.
Ls {
/// Namespace.
namespace: String,
},
/// Drop every entry under a namespace.
Clear {
/// Namespace.
namespace: String,
},
/// Print total bytes and per-namespace bytes.
Stats,
}
/// Fingerprint subcommands.
#[derive(Debug, Subcommand)]
pub(crate) enum FpCommands {
/// Check if files have changed since last success.
///
/// Exit 0 = operation should run (files changed).
/// Exit 1 = skip (no changes detected).
Check {
/// Root directory to scan (default: current directory).
#[arg(long, default_value = ".")]
root: String,
/// File extensions to include (without dot, e.g., "rs", "cpp").
/// Cannot be used with --include.
#[arg(long, conflicts_with = "include")]
ext: Vec<String>,
/// Glob patterns for files to include (e.g., "**/*.rs").
/// Cannot be used with --ext.
#[arg(long, conflicts_with = "ext")]
include: Vec<String>,
/// Patterns or directory names to exclude.
#[arg(long)]
exclude: Vec<String>,
},
/// Mark the previous check as successful.
#[command(name = "mark-success")]
MarkSuccess,
/// Mark the previous check as failed.
#[command(name = "mark-failure")]
MarkFailure,
/// Invalidate the cache (delete all state).
Invalidate,
}
/// GitHub Actions cache subcommands.
#[derive(Debug, Subcommand)]
pub(crate) enum GhaCacheCommands {
/// Check if GHA cache API is available (env vars set).
Status,
/// Save a directory to the GHA cache (tar+gzip, then upload).
Save {
/// Cache key (must be unique per content).
#[arg(long)]
key: String,
/// Path to the directory to cache.
#[arg(long)]
path: String,
},
/// Restore a directory from the GHA cache.
Restore {
/// Cache key to look up.
#[arg(long)]
key: String,
/// Path to restore the directory into.
#[arg(long)]
path: String,
},
}
/// Rust artifact plan subcommands.
#[derive(Debug, Subcommand)]
pub(crate) enum RustPlanCommands {
/// Validate a soldr-generated Rust artifact plan.
Validate {
/// Path to the protobuf plan file, or a legacy JSON plan.
#[arg(long)]
plan: String,
/// Print a machine-readable JSON summary.
#[arg(long)]
json: bool,
/// Active zccache session ID whose compile-cache stats should be included.
#[arg(long = "session-id")]
session_id: Option<String>,
/// IPC endpoint for session stats lookup.
#[arg(long)]
endpoint: Option<String>,
/// Journal/log path to report in the summary, overriding the plan path.
#[arg(long)]
journal: Option<String>,
/// Local cache directory for bundle path/key reporting.
#[arg(long = "cache-dir")]
cache_dir: Option<String>,
},
/// Restore Rust target artifacts from a saved plan bundle.
Restore {
/// Path to the protobuf plan file, or a legacy JSON plan.
#[arg(long)]
plan: String,
/// Print a machine-readable JSON summary.
#[arg(long)]
json: bool,
/// Active zccache session ID whose compile-cache stats should be included.
#[arg(long = "session-id")]
session_id: Option<String>,
/// IPC endpoint for session stats lookup.
#[arg(long)]
endpoint: Option<String>,
/// Journal/log path to report in the summary, overriding the plan path.
#[arg(long)]
journal: Option<String>,
/// Cache backend to use.
#[arg(long, default_value = "auto")]
backend: RustPlanBackendArg,
/// Local cache directory used for bundle storage.
#[arg(long = "cache-dir")]
cache_dir: Option<String>,
},
/// Restore Rust target artifacts from base and delta plan bundles.
RestoreLayered {
/// Path to the protobuf plan file, or a legacy JSON plan.
#[arg(long)]
plan: String,
/// Print a machine-readable JSON summary.
#[arg(long)]
json: bool,
/// Active zccache session ID whose compile-cache stats should be included.
#[arg(long = "session-id")]
session_id: Option<String>,
/// IPC endpoint for session stats lookup.
#[arg(long)]
endpoint: Option<String>,
/// Journal/log path to report in the summary, overriding the plan path.
#[arg(long)]
journal: Option<String>,
/// Local cache directory containing the base bundle.
#[arg(long = "base-cache-dir")]
base_cache_dir: String,
/// Local cache directory containing the delta bundle.
#[arg(long = "delta-cache-dir")]
delta_cache_dir: String,
},
/// Save Rust target artifacts selected by a plan.
Save {
/// Path to the protobuf plan file, or a legacy JSON plan.
#[arg(long)]
plan: String,
/// Print a machine-readable JSON summary.
#[arg(long)]
json: bool,
/// Active zccache session ID whose compile-cache stats should be included.
#[arg(long = "session-id")]
session_id: Option<String>,
/// IPC endpoint for session stats lookup.
#[arg(long)]
endpoint: Option<String>,
/// Journal/log path to report in the summary, overriding the plan path.
#[arg(long)]
journal: Option<String>,
/// Cache backend to use.
#[arg(long, default_value = "auto")]
backend: RustPlanBackendArg,
/// Local cache directory used for bundle storage.
#[arg(long = "cache-dir")]
cache_dir: Option<String>,
},
/// Save only Rust target artifacts that differ from a base plan bundle.
SaveDelta {
/// Path to the protobuf plan file, or a legacy JSON plan.
#[arg(long)]
plan: String,
/// Print a machine-readable JSON summary.
#[arg(long)]
json: bool,
/// Active zccache session ID whose compile-cache stats should be included.
#[arg(long = "session-id")]
session_id: Option<String>,
/// IPC endpoint for session stats lookup.
#[arg(long)]
endpoint: Option<String>,
/// Journal/log path to report in the summary, overriding the plan path.
#[arg(long)]
journal: Option<String>,
/// Local cache directory containing the base bundle.
#[arg(long = "base-cache-dir")]
base_cache_dir: String,
/// Local cache directory that will receive the delta bundle.
#[arg(long = "delta-cache-dir")]
delta_cache_dir: String,
},
}
/// Rust artifact plan backend selection.
#[derive(Debug, Clone, Copy, ValueEnum, PartialEq, Eq)]
pub(crate) enum RustPlanBackendArg {
Auto,
Local,
Gha,
}