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
//! Bake a **working** `rustc` path into the crate that runs rustc.
//!
//! Plan 01 (`docs/05 - 01 - Vertical Slice.md`) leaf 7 wrote this, for
//! `voltaic-cli`. Plan 50 (`docs/44 - 50 - MCP Server.md`) leaf 1 **moved it
//! here**, because `cargo::rustc-env` bakes a value into whichever crate
//! carries the build script and three crates now need the value:
//! `voltaic-cli`'s `check`, `voltaic-bench`'s IR comparison, and `voltaic-mcp`'s
//! `voltaic_check` tool. Before the move there were two copies of this file
//! differing **only in their doc comments** — `voltaic-cli`'s and
//! `voltaic-bench`'s — and a third was about to be written.
//!
//! Neither obvious source for a rustc path is reliable here, and each one
//! looks like the other's fix:
//!
//! - Resolving `rustc` from `PATH` **at run time** finds NixOS's `stub-ld`
//! shim under `blaze test`, which cannot execute at all.
//! - Trusting `RUSTC` **at build time** finds blaze's own shim under
//! `blaze build`, which refuses general rustc work with
//! `BLAZE_SCRIPT_RUSTC does not name blaze's rustc`.
//!
//! So a candidate is not trusted, it is **verified**: each is run with
//! `--version` and the first that answers like a real rustc wins. See
//! `AGENTS.md`'s known tooling gotchas.
//!
//! A build script also sees something a test binary does not — the real
//! toolchain on `PATH` — which is why run-time probing alone is not enough.
//! `voltaic-bench` learned that the hard way: all four of its tests failed under
//! `blaze test` with *"no rustc answered `--version` like rustc"* while passing
//! under `cargo nextest`, because every candidate visible at run time was a
//! shim.
use PathBuf;
use Command;
/// The first candidate that behaves like a real rustc.
/// Whether `candidate` answers `--version` like rustc itself.
///
/// A shim that proxies for a build graph fails here — either by exiting
/// non-zero or by printing something that is not a rustc version banner.