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
//! Build script: detect the zero-feature build so the crate's unit-test target
//! can refuse to report a vacuous green (#4901).
//!
//! Why: `trusty-common` declares `default = []` and gates 25+ modules behind
//! opt-in features, so `cargo test -p trusty-common` — the command CLAUDE.md
//! prescribed as the per-crate check — compiles none of them. It runs 328 of
//! the crate's ~2062 tests and exits 0, including when a file in `memory_core`
//! does not compile at all; PR #4899 shipped a green run on exactly that basis
//! before the correct code existed. Cargo hands the resolved feature set to a
//! build script but never to `cfg`, so "no features at all" has to be detected
//! here. The alternative — a `#[cfg(not(any(feature = …)))]` list in `lib.rs` —
//! would silently stop covering every feature added after it was written.
//! What: emits `trusty_common_build_script_ran` unconditionally (so the guard's
//! delivery mechanism is itself testable), `trusty_common_no_features` when
//! Cargo activated no feature at all, and `trusty_common_default_not_empty`
//! when the manifest's `default` set stops being `[]` — the precondition that
//! makes discounting `CARGO_FEATURE_DEFAULT` correct. `lib.rs` turns the latter
//! two into `compile_error!`s for the `cfg(test)` build only, so a plain
//! `cargo build` / `cargo check` and all 20 consumer crates are unaffected.
//! Test: `src/lib.rs` refuses to compile at all when
//! `trusty_common_build_script_ran` is absent, so this script ceasing to run is
//! a build failure rather than a silent one. The guard's own behaviour is
//! demonstrated in the PR for #4901 by breaking a `memory_core` file and
//! re-running both command forms.
/// Why (#4901): reads the one manifest fact the zero-feature guard depends on.
/// What: scans `Cargo.toml` for the `default` key inside `[features]` and
/// reports whether its value is the empty array. Fails CLOSED — an unreadable
/// manifest, a missing `[features]` table, or a `default` spelled in a shape
/// this scan does not recognise all report "not empty", which turns into a
/// `cfg(test)`-scoped `compile_error!` rather than a silently inert guard.
/// Text-scanned rather than parsed because a build script that pulled in a TOML
/// parser would put a build-dependency on every consumer of this crate;
/// `tests/feature_coverage.rs` does the real parse, where `toml` is already a
/// dev-dependency.
/// Test: `default_feature_set_is_empty` (`tests/feature_coverage.rs`) asserts
/// the same fact through a real TOML parse, so the two disagree loudly if this
/// scan ever reads the manifest wrong.