rsconstruct 0.9.18

Rust based fast build system
Documentation
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
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
use serde::{Deserialize, Serialize};
use std::collections::HashMap;

use super::{default_true, default_cc_compiler, default_cxx_compiler, default_output_suffix, KnownFields, ScanDefaultsData};

/// Universal processor config with all standard fields.
/// Checkers, generators, and simple processors all use this.
/// Fields not relevant to a given processor type are simply ignored.
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct StandardConfig {
    #[serde(default)]
    pub command: String,
    #[serde(default)]
    pub formats: Vec<String>,
    #[serde(default)]
    pub args: Vec<String>,
    #[serde(default)]
    pub dep_inputs: Vec<String>,
    #[serde(default)]
    pub dep_auto: Vec<String>,
    #[serde(default)]
    pub output_dir: String,
    #[serde(default = "default_true")]
    pub batch: bool,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub max_jobs: Option<usize>,
    /// Whether to cache this processor's outputs. Default true.
    /// Set to false to always rebuild and never store results.
    #[serde(default = "default_true")]
    pub cache: bool,
    /// Whether this processor is active. Set to false to disable without
    /// removing the stanza from rsconstruct.toml.
    #[serde(default = "default_true")]
    pub enabled: bool,
    // --- Scan fields (file discovery) ---
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub src_dirs: Option<Vec<String>>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub src_extensions: Option<Vec<String>>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub src_exclude_dirs: Option<Vec<String>>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub src_exclude_files: Option<Vec<String>>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub src_exclude_paths: Option<Vec<String>>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub src_files: Option<Vec<String>>,
}

impl Default for StandardConfig {
    fn default() -> Self {
        Self {
            command: String::new(),
            formats: Vec::new(),
            args: Vec::new(),
            dep_inputs: Vec::new(),
            dep_auto: Vec::new(),
            output_dir: String::new(),
            batch: true,
            max_jobs: None,
            cache: true,
            enabled: true,
            src_dirs: None,
            src_extensions: None,
            src_exclude_dirs: None,
            src_exclude_files: None,
            src_exclude_paths: None,
            src_files: None,
        }
    }
}

impl StandardConfig {
    /// Fill in None scan fields from scan defaults data.
    pub(crate) fn resolve_scan(&mut self, defaults: &ScanDefaultsData) {
        if self.src_dirs.is_none() {
            self.src_dirs = Some(defaults.src_dirs.iter().map(|s| s.to_string()).collect());
        }
        if self.src_extensions.is_none() {
            self.src_extensions = Some(defaults.src_extensions.iter().map(|s| s.to_string()).collect());
        }
        if self.src_exclude_dirs.is_none() {
            self.src_exclude_dirs = Some(defaults.src_exclude_dirs.iter().map(|s| s.to_string()).collect());
        }
        if self.src_exclude_files.is_none() {
            self.src_exclude_files = Some(Vec::new());
        }
        if self.src_exclude_paths.is_none() {
            self.src_exclude_paths = Some(Vec::new());
        }
        if self.src_files.is_none() {
            self.src_files = Some(Vec::new());
        }
    }

    pub(crate) fn src_dirs(&self) -> &[String] {
        self.src_dirs.as_deref().expect(crate::errors::SCAN_CONFIG_NOT_RESOLVED)
    }
    pub(crate) fn src_extensions(&self) -> &[String] {
        self.src_extensions.as_deref().expect(crate::errors::SCAN_CONFIG_NOT_RESOLVED)
    }
    pub(crate) fn src_exclude_dirs(&self) -> &[String] {
        self.src_exclude_dirs.as_deref().expect(crate::errors::SCAN_CONFIG_NOT_RESOLVED)
    }
    pub(crate) fn src_exclude_files(&self) -> &[String] {
        self.src_exclude_files.as_deref().expect(crate::errors::SCAN_CONFIG_NOT_RESOLVED)
    }
    pub(crate) fn src_exclude_paths(&self) -> &[String] {
        self.src_exclude_paths.as_deref().expect(crate::errors::SCAN_CONFIG_NOT_RESOLVED)
    }
    pub(crate) fn src_files(&self) -> &[String] {
        self.src_files.as_deref().expect(crate::errors::SCAN_CONFIG_NOT_RESOLVED)
    }

    /// Return the command string, or error with context if it was never set.
    pub(crate) fn require_command(&self, context: &str) -> anyhow::Result<&str> {
        if self.command.is_empty() {
            anyhow::bail!("'command' is not set for processor '{}'", context);
        }
        Ok(&self.command)
    }
}

impl KnownFields for StandardConfig {
    fn known_fields() -> &'static [&'static str] {
        // Note: "enabled" and "cache" are universal — declared once in
        // STANDARD_EXTRA_FIELDS and merged in by the validator, not repeated here.
        &["command", "formats", "args", "dep_inputs", "dep_auto", "output_dir", "batch", "max_jobs"]
    }
    fn checksum_fields() -> &'static [&'static str] {
        // formats and output_dir are excluded: format is encoded as a per-product
        // variant in the cache key, and output_dir is encoded in the product's
        // declared outputs path — both would double-count if hashed here.
        &["command", "args"]
    }
    fn field_descriptions() -> &'static [(&'static str, &'static str)] {
        // "enabled" and "cache" descriptions live in SHARED_FIELD_DESCRIPTIONS.
        &[
            ("command",    "Path to the tool executable"),
            ("formats",    "Output formats to generate"),
            ("args",       "Extra arguments passed to the tool"),
            ("output_dir", "Directory where generated output files are written"),
        ]
    }
}

/// Simple checker config. No custom fields.
/// Unused StandardConfig fields: formats, output_dir.
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct CheckerConfig {
    #[serde(flatten)]
    pub standard: StandardConfig,
}
impl Default for CheckerConfig {
    fn default() -> Self { Self { standard: StandardConfig::default() } }
}
impl KnownFields for CheckerConfig {
    fn known_fields() -> &'static [&'static str] { StandardConfig::known_fields() }
    fn checksum_fields() -> &'static [&'static str] { StandardConfig::checksum_fields() }
    fn must_fields() -> &'static [&'static str] { StandardConfig::must_fields() }
    fn field_descriptions() -> &'static [(&'static str, &'static str)] { StandardConfig::field_descriptions() }
}

/// Alias for CheckerConfig (used by SimpleChecker).
pub type CheckerConfigWithCommand = CheckerConfig;

/// Config for Creator processors — run a command and cache declared outputs.
#[derive(Debug, Deserialize, Serialize, Clone)]
/// Creator processor config.
/// Custom fields: output_dirs, output_files.
/// Unused StandardConfig fields: formats, output_dir.
pub struct CreatorConfig {
    /// Directories to cache after the command runs.
    #[serde(default)]
    pub output_dirs: Vec<String>,
    /// Individual files to cache after the command runs.
    #[serde(default)]
    pub output_files: Vec<String>,
    #[serde(flatten)]
    pub standard: StandardConfig,
}

impl Default for CreatorConfig {
    fn default() -> Self {
        Self {
            output_dirs: Vec::new(),
            output_files: Vec::new(),
            standard: StandardConfig::default(),
        }
    }
}

impl KnownFields for CreatorConfig {
    fn known_fields() -> &'static [&'static str] {
        &["command", "args", "dep_inputs", "dep_auto", "output_dirs", "output_files", "batch", "max_jobs"]
    }
    fn checksum_fields() -> &'static [&'static str] {
        // output_dirs/output_files are excluded: the output paths themselves are
        // already part of the product's identity, not its config-change checksum.
        &["command", "args"]
    }
    fn field_descriptions() -> &'static [(&'static str, &'static str)] {
        &[
            ("command",      "Command to run"),
            ("args",         "Extra arguments passed to the command"),
            ("output_dirs",  "Directories to cache after the command runs"),
            ("output_files", "Individual files to cache after the command runs"),
        ]
    }
}
/// Tera template processor config. No custom fields.
/// Unused StandardConfig fields: command, formats, output_dir.
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct TeraConfig {
    #[serde(flatten)]
    pub standard: StandardConfig,
}
impl Default for TeraConfig {
    fn default() -> Self { Self { standard: StandardConfig::default() } }
}
impl KnownFields for TeraConfig {
    fn known_fields() -> &'static [&'static str] { StandardConfig::known_fields() }
    fn checksum_fields() -> &'static [&'static str] { StandardConfig::checksum_fields() }
    fn must_fields() -> &'static [&'static str] { StandardConfig::must_fields() }
    fn field_descriptions() -> &'static [(&'static str, &'static str)] { StandardConfig::field_descriptions() }
}

/// Mako template processor config. No custom fields.
/// Unused StandardConfig fields: command, formats, output_dir.
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct MakoConfig {
    #[serde(flatten)]
    pub standard: StandardConfig,
}
impl Default for MakoConfig {
    fn default() -> Self { Self { standard: StandardConfig::default() } }
}
impl KnownFields for MakoConfig {
    fn known_fields() -> &'static [&'static str] { StandardConfig::known_fields() }
    fn checksum_fields() -> &'static [&'static str] { StandardConfig::checksum_fields() }
    fn must_fields() -> &'static [&'static str] { StandardConfig::must_fields() }
    fn field_descriptions() -> &'static [(&'static str, &'static str)] { StandardConfig::field_descriptions() }
}

/// Jinja2 template processor config. No custom fields.
/// Unused StandardConfig fields: command, formats, output_dir.
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct Jinja2Config {
    #[serde(flatten)]
    pub standard: StandardConfig,
}
impl Default for Jinja2Config {
    fn default() -> Self { Self { standard: StandardConfig::default() } }
}
impl KnownFields for Jinja2Config {
    fn known_fields() -> &'static [&'static str] { StandardConfig::known_fields() }
    fn checksum_fields() -> &'static [&'static str] { StandardConfig::checksum_fields() }
    fn must_fields() -> &'static [&'static str] { StandardConfig::must_fields() }
    fn field_descriptions() -> &'static [(&'static str, &'static str)] { StandardConfig::field_descriptions() }
}

/// Engines accepted for `pandoc.pdf_engine`. Empty string means "use pandoc's default".
pub const PANDOC_PDF_ENGINES: &[&str] = &["pdflatex", "xelatex", "lualatex", "tectonic", "wkhtmltopdf", "weasyprint", "prince", "context"];

/// Pandoc processor config. Custom field: pdf_engine (forwarded to --pdf-engine
/// when format == pdf). Empty string keeps pandoc's default engine.
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct PandocConfig {
    #[serde(default)]
    pub pdf_engine: String,
    #[serde(flatten)]
    pub standard: StandardConfig,
}
impl Default for PandocConfig {
    fn default() -> Self {
        Self {
            pdf_engine: String::new(),
            standard: StandardConfig {
                command: "pandoc".into(),
                output_dir: "out/pandoc".into(),
                formats: vec!["pdf".into(), "html".into(), "docx".into()],
                ..StandardConfig::default()
            },
        }
    }
}
impl KnownFields for PandocConfig {
    fn known_fields() -> &'static [&'static str] {
        &[
            "command", "args", "dep_inputs", "dep_auto", "formats", "output_dir",
            "batch", "max_jobs", "src_dirs", "src_extensions",
            "src_exclude_dirs", "src_exclude_files", "src_exclude_paths", "src_files",
            "pdf_engine",
        ]
    }
    fn checksum_fields() -> &'static [&'static str] {
        &["command", "args", "formats", "output_dir", "pdf_engine"]
    }
    fn must_fields() -> &'static [&'static str] { StandardConfig::must_fields() }
    fn field_descriptions() -> &'static [(&'static str, &'static str)] {
        &[
            ("command",    "Path to the pandoc executable"),
            ("args",       "Extra arguments passed to pandoc"),
            ("formats",    "Output formats to generate (pdf, html, docx, …)"),
            ("output_dir", "Directory where converted files are written"),
            ("pdf_engine", "PDF engine for --pdf-engine (e.g. xelatex, lualatex). Empty = pandoc default (pdflatex)."),
        ]
    }
}






pub type MarpImagesConfig = CheckerConfig;

/// ClangTidy config. Custom fields: compiler_args.
/// Unused StandardConfig fields: command, formats, output_dir.
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct ClangTidyConfig {
    #[serde(default)]
    pub compiler_args: Vec<String>,
    #[serde(flatten)]
    pub standard: StandardConfig,
}

impl Default for ClangTidyConfig {
    fn default() -> Self {
        Self {
            compiler_args: Vec::new(),
            standard: StandardConfig::default(),
        }
    }
}

impl KnownFields for ClangTidyConfig {
    fn known_fields() -> &'static [&'static str] {
        &[
            "args", "compiler_args", "dep_inputs", "dep_auto", "batch", "max_jobs",
        ]
    }
    fn checksum_fields() -> &'static [&'static str] {
        &["args", "compiler_args"]
    }
    fn field_descriptions() -> &'static [(&'static str, &'static str)] {
        &[
            ("args",          "Extra arguments passed to clang-tidy"),
            ("compiler_args", "Compiler flags forwarded to clang-tidy for parsing"),
        ]
    }
}

/// Method for scanning C/C++ header dependencies
#[derive(Debug, Deserialize, Serialize, Clone, Default, PartialEq)]
#[serde(rename_all = "lowercase")]
pub enum IncludeScanner {
    /// Native regex-based scanner (fast, no external process)
    #[default]
    Native,
    /// Use gcc/g++ -MM (accurate but slower, spawns external process)
    Compiler,
}

/// Configuration for a single compiler profile
#[derive(Debug, Deserialize, Serialize, Clone)]
#[serde(deny_unknown_fields)]
pub struct CompilerProfile {
    /// Profile name (used in output paths, e.g., "gcc", "clang")
    pub name: String,
    /// Whether this profile is enabled (default: true)
    #[serde(default = "default_true")]
    pub enabled: bool,
    #[serde(default = "default_cc_compiler")]
    pub cc: String,
    #[serde(default = "default_cxx_compiler")]
    pub cxx: String,
    #[serde(default)]
    pub cflags: Vec<String>,
    #[serde(default)]
    pub cxxflags: Vec<String>,
    #[serde(default)]
    pub ldflags: Vec<String>,
    #[serde(default = "default_output_suffix")]
    pub output_suffix: String,
}

/// CcSingleFile config. Custom fields: cc, cxx, cflags, cxxflags, ldflags, output_suffix, compilers, include_paths, include_scanner.
/// Unused StandardConfig fields: command, formats.
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct CcSingleFileConfig {
    /// Legacy single-compiler fields (used when `compilers` is empty)
    #[serde(default = "default_cc_compiler")]
    pub cc: String,
    #[serde(default = "default_cxx_compiler")]
    pub cxx: String,
    #[serde(default)]
    pub cflags: Vec<String>,
    #[serde(default)]
    pub cxxflags: Vec<String>,
    #[serde(default)]
    pub ldflags: Vec<String>,
    #[serde(default = "default_output_suffix")]
    pub output_suffix: String,
    /// Multiple compiler profiles (if set, overrides legacy fields)
    #[serde(default)]
    pub compilers: Vec<CompilerProfile>,
    /// Shared settings across all compilers
    #[serde(default)]
    pub include_paths: Vec<String>,
    /// Method for scanning header dependencies (native or compiler)
    #[serde(default)]
    pub include_scanner: IncludeScanner,
    #[serde(flatten)]
    pub standard: StandardConfig,
}

impl CcSingleFileConfig {
    /// Get the list of enabled compiler profiles to use.
    /// If `compilers` is set, returns enabled profiles from that list.
    /// Otherwise, creates a single profile from the legacy fields.
    pub(crate) fn get_compiler_profiles(&self) -> Vec<CompilerProfile> {
        if !self.compilers.is_empty() {
            self.compilers.iter().filter(|p| p.enabled).cloned().collect()
        } else {
            // Legacy mode: create single profile from top-level fields
            vec![CompilerProfile {
                name: String::new(), // Empty name = no subdirectory
                enabled: true,
                cc: self.cc.clone(),
                cxx: self.cxx.clone(),
                cflags: self.cflags.clone(),
                cxxflags: self.cxxflags.clone(),
                ldflags: self.ldflags.clone(),
                output_suffix: self.output_suffix.clone(),
            }]
        }
    }
}

impl Default for CcSingleFileConfig {
    fn default() -> Self {
        Self {
            cc: "gcc".into(),
            cxx: "g++".into(),
            cflags: Vec::new(),
            cxxflags: Vec::new(),
            ldflags: Vec::new(),
            output_suffix: ".elf".into(),
            compilers: Vec::new(),
            include_paths: Vec::new(),
            include_scanner: IncludeScanner::default(),
            standard: StandardConfig {
                output_dir: "out/cc_single_file".into(),
                ..StandardConfig::default()
            },
        }
    }
}

impl KnownFields for CcSingleFileConfig {
    fn known_fields() -> &'static [&'static str] {
        &[
            "cc", "cxx", "cflags", "cxxflags", "ldflags", "output_suffix",
            "compilers", "include_paths", "dep_inputs", "dep_auto", "output_dir",
            "include_scanner", "batch", "max_jobs",
        ]
    }
    fn checksum_fields() -> &'static [&'static str] {
        &[
            "cc", "cxx", "cflags", "cxxflags", "ldflags", "output_suffix",
            "compilers", "include_paths", "output_dir", "include_scanner",
        ]
    }
    fn field_descriptions() -> &'static [(&'static str, &'static str)] {
        &[
            ("cc",              "C compiler executable"),
            ("cxx",             "C++ compiler executable"),
            ("output_suffix",   "Suffix appended to output binary names"),
            ("compilers",       "Named compiler profiles (overrides cc/cxx when set)"),
            ("include_paths",   "Additional header search directories"),
            ("output_dir",      "Directory where compiled binaries are written"),
            ("include_scanner", "Header dependency scanner: native (fast) or compiler (accurate)"),
        ]
    }
}

// --- cc (full C/C++ project builds) ---

#[derive(Debug, Deserialize, Serialize, Clone)]
#[serde(deny_unknown_fields)]
pub struct CcLibraryDef {
    pub name: String,
    #[serde(default = "default_cc_lib_type")]
    pub lib_type: String,
    pub sources: Vec<String>,
    #[serde(default)]
    pub include_dirs: Vec<String>,
    #[serde(default)]
    pub cflags: Vec<String>,
    #[serde(default)]
    pub cxxflags: Vec<String>,
    #[serde(default)]
    pub ldflags: Vec<String>,
}

fn default_cc_lib_type() -> String {
    "shared".into()
}

#[derive(Debug, Deserialize, Serialize, Clone)]
#[serde(deny_unknown_fields)]
pub struct CcProgramDef {
    pub name: String,
    pub sources: Vec<String>,
    #[serde(default)]
    pub link: Vec<String>,
    #[serde(default)]
    pub include_dirs: Vec<String>,
    #[serde(default)]
    pub cflags: Vec<String>,
    #[serde(default)]
    pub cxxflags: Vec<String>,
    #[serde(default)]
    pub ldflags: Vec<String>,
}

/// Parsed contents of a cc.yaml file.
#[derive(Debug, Deserialize, Serialize, Clone)]
#[serde(deny_unknown_fields)]
pub struct CcManifest {
    #[serde(default = "default_cc_compiler")]
    pub cc: String,
    #[serde(default = "default_cxx_compiler")]
    pub cxx: String,
    #[serde(default)]
    pub cflags: Vec<String>,
    #[serde(default)]
    pub cxxflags: Vec<String>,
    #[serde(default)]
    pub ldflags: Vec<String>,
    #[serde(default)]
    pub include_dirs: Vec<String>,
    #[serde(default)]
    pub libraries: Vec<CcLibraryDef>,
    #[serde(default)]
    pub programs: Vec<CcProgramDef>,
}

/// CC (full C/C++ project) config. Custom: cc, cxx, cflags, cxxflags, ldflags, include_dirs, single_invocation, cache_output_dir.
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct CcConfig {
    #[serde(default = "default_cc_compiler")]
    pub cc: String,
    #[serde(default = "default_cxx_compiler")]
    pub cxx: String,
    #[serde(default)]
    pub cflags: Vec<String>,
    #[serde(default)]
    pub cxxflags: Vec<String>,
    #[serde(default)]
    pub ldflags: Vec<String>,
    #[serde(default)]
    pub include_dirs: Vec<String>,
    #[serde(default)]
    pub single_invocation: bool,
    #[serde(default = "default_true")]
    pub cache_output_dir: bool,
    #[serde(flatten)]
    pub standard: StandardConfig,
}

impl Default for CcConfig {
    fn default() -> Self {
        Self {
            cc: "gcc".into(),
            cxx: "g++".into(),
            cflags: Vec::new(),
            cxxflags: Vec::new(),
            ldflags: Vec::new(),
            include_dirs: Vec::new(),
            single_invocation: false,
            cache_output_dir: true,
            standard: StandardConfig::default(),
        }
    }
}

impl KnownFields for CcConfig {
    fn known_fields() -> &'static [&'static str] {
        &[
            "cc", "cxx", "cflags", "cxxflags", "ldflags",
            "include_dirs", "single_invocation",
            "dep_inputs", "cache_output_dir", "batch", "max_jobs",
        ]
    }
    fn checksum_fields() -> &'static [&'static str] {
        &[
            "cc", "cxx", "cflags", "cxxflags", "ldflags",
            "include_dirs", "single_invocation",
        ]
    }
    fn field_descriptions() -> &'static [(&'static str, &'static str)] {
        &[
            ("cc",                "C compiler executable"),
            ("cxx",               "C++ compiler executable"),
            ("cflags",            "Flags passed to the C compiler"),
            ("cxxflags",          "Flags passed to the C++ compiler"),
            ("ldflags",           "Flags passed to the linker"),
            ("include_dirs",      "Additional header search directories"),
            ("single_invocation", "Compile all sources in one compiler call"),
            ("cache_output_dir",  "Cache the entire output directory as a unit"),
        ]
    }
}

// --- linux_module (Linux kernel module builds) ---

/// A single kernel module definition inside linux-module.yaml.
#[derive(Debug, Deserialize, Serialize, Clone)]
#[serde(deny_unknown_fields)]
pub struct LinuxModuleModuleDef {
    pub name: String,
    pub sources: Vec<String>,
    #[serde(default)]
    pub extra_cflags: Vec<String>,
}

/// Parsed contents of a linux-module.yaml file.
#[derive(Debug, Deserialize, Serialize, Clone)]
#[serde(deny_unknown_fields)]
pub struct LinuxModuleManifest {
    #[serde(default = "default_make_tool")]
    pub make: String,
    #[serde(default)]
    pub kdir: Option<String>,
    #[serde(default)]
    pub arch: Option<String>,
    #[serde(default)]
    pub cross_compile: Option<String>,
    #[serde(default = "default_linux_module_v")]
    pub v: u32,
    #[serde(default = "default_linux_module_w")]
    pub w: u32,
    pub modules: Vec<LinuxModuleModuleDef>,
}

fn default_make_tool() -> String {
    "make".into()
}

fn default_linux_module_v() -> u32 {
    0
}

fn default_linux_module_w() -> u32 {
    1
}

/// Linux module config. No custom fields.
/// Unused StandardConfig fields: command, formats, output_dir, args.
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct LinuxModuleConfig {
    #[serde(flatten)]
    pub standard: StandardConfig,
}
impl Default for LinuxModuleConfig {
    fn default() -> Self { Self { standard: StandardConfig::default() } }
}
impl KnownFields for LinuxModuleConfig {
    fn known_fields() -> &'static [&'static str] { StandardConfig::known_fields() }
    fn checksum_fields() -> &'static [&'static str] { StandardConfig::checksum_fields() }
    fn must_fields() -> &'static [&'static str] { StandardConfig::must_fields() }
    fn field_descriptions() -> &'static [(&'static str, &'static str)] { StandardConfig::field_descriptions() }
}

fn default_zspell_language() -> String {
    "en_US".into()
}

fn default_zspell_words_file() -> String {
    ".zspell-words".into()
}

/// Zspell config. Custom fields: language, words_file, auto_add_words.
/// Unused StandardConfig fields: command, formats, output_dir.
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct ZspellConfig {
    #[serde(default = "default_zspell_language")]
    pub language: String,
    #[serde(default = "default_zspell_words_file")]
    pub words_file: String,
    /// When true, automatically add misspelled words to words_file instead of failing
    #[serde(default)]
    pub auto_add_words: bool,
    #[serde(flatten)]
    pub standard: StandardConfig,
}

impl Default for ZspellConfig {
    fn default() -> Self {
        Self {
            language: "en_US".into(),
            words_file: ".zspell-words".into(),
            auto_add_words: false,
            standard: StandardConfig::default(),
        }
    }
}

impl KnownFields for ZspellConfig {
    fn known_fields() -> &'static [&'static str] {
        &[
            "language", "words_file", "auto_add_words", "dep_inputs", "dep_auto", "batch", "max_jobs",
        ]
    }
    fn checksum_fields() -> &'static [&'static str] {
        &["language", "auto_add_words"]
    }
    fn field_descriptions() -> &'static [(&'static str, &'static str)] {
        &[
            ("language",       "Language/locale for spell checking"),
            ("words_file",     "Path to a personal dictionary file"),
            ("auto_add_words", "When true, automatically add misspelled words to words_file instead of failing"),
        ]
    }
}

fn default_cargo() -> String {
    "cargo".into()
}

fn default_cargo_profiles() -> Vec<String> {
    vec!["dev".into(), "release".into()]
}

/// Cargo config. Custom: cargo, profiles, cache_output_dir.
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct CargoConfig {
    #[serde(default = "default_cargo")]
    pub cargo: String,
    #[serde(default = "default_cargo_profiles")]
    pub profiles: Vec<String>,
    #[serde(default = "default_true")]
    pub cache_output_dir: bool,
    #[serde(flatten)]
    pub standard: StandardConfig,
}

impl Default for CargoConfig {
    fn default() -> Self {
        Self {
            cargo: "cargo".into(),
            profiles: default_cargo_profiles(),
            cache_output_dir: true,
            standard: StandardConfig {
                command: "build".into(),
                ..StandardConfig::default()
            },
        }
    }
}

impl KnownFields for CargoConfig {
    fn known_fields() -> &'static [&'static str] {
        &[
            "cargo", "command", "args", "dep_inputs", "profiles",
            "cache_output_dir", "batch", "max_jobs", "src_extensions", "src_exclude_dirs", "src_exclude_files",
            "src_exclude_paths",
        ]
    }
    fn checksum_fields() -> &'static [&'static str] {
        &["cargo", "command", "args", "profiles"]
    }
    fn field_descriptions() -> &'static [(&'static str, &'static str)] {
        &[
            ("cargo",   "Path to the cargo executable"),
            ("command", "Cargo subcommand to run (e.g. build, test)"),
            ("args",    "Extra arguments passed to cargo"),
            ("profiles", "Build profiles to run (e.g. dev, release)"),
        ]
    }
}


#[derive(Debug, Deserialize, Serialize, Clone)]
/// Clippy config. Custom: cargo.
pub struct ClippyConfig {
    #[serde(default = "default_cargo")]
    pub cargo: String,
    #[serde(flatten)]
    pub standard: StandardConfig,
}

impl Default for ClippyConfig {
    fn default() -> Self {
        Self {
            cargo: "cargo".into(),
            standard: StandardConfig { command: "clippy".into(), ..StandardConfig::default() },
        }
    }
}

impl KnownFields for ClippyConfig {
    fn known_fields() -> &'static [&'static str] {
        &[
            "cargo", "command", "args", "dep_inputs", "dep_auto", "batch", "max_jobs",
        ]
    }
    fn checksum_fields() -> &'static [&'static str] {
        &["cargo", "command", "args"]
    }
    fn field_descriptions() -> &'static [(&'static str, &'static str)] {
        &[
            ("cargo",   "Path to the cargo executable"),
            ("command", "Cargo subcommand to run (defaults to clippy)"),
            ("args",    "Extra arguments passed to cargo clippy"),
        ]
    }
}

/// Make config. Custom: target.
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct MakeConfig {
    #[serde(default)]
    pub target: String,
    #[serde(flatten)]
    pub standard: StandardConfig,
}

impl Default for MakeConfig {
    fn default() -> Self {
        Self {
            target: String::new(),
            standard: StandardConfig { command: "make".into(), ..StandardConfig::default() },
        }
    }
}

impl KnownFields for MakeConfig {
    fn known_fields() -> &'static [&'static str] {
        &[
            "command", "args", "target", "dep_inputs", "dep_auto", "batch", "max_jobs",
        ]
    }
    fn checksum_fields() -> &'static [&'static str] {
        &["command", "args", "target"]
    }
    fn field_descriptions() -> &'static [(&'static str, &'static str)] {
        &[
            ("command", "Path to the make executable"),
            ("args",   "Extra arguments passed to make"),
            ("target", "Make target to build"),
        ]
    }
}








pub type JsonSchemaConfig = CheckerConfig;

fn default_tags_output() -> String {
    "out/tags/tags.db".into()
}

fn default_tags_dir() -> String {
    "tags".into()
}

#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct TagsConfig {
    #[serde(default = "default_tags_output")]
    pub output: String,
    /// Directory containing tag list files.
    /// Each `<name>.txt` file defines allowed tags as `<name>:<line>` pairs.
    #[serde(default = "default_tags_dir")]
    pub tags_dir: String,
    /// Frontmatter fields that every markdown file must have.
    #[serde(default)]
    pub required_fields: Vec<String>,
    /// Scalar fields whose values must exist in the corresponding tag_lists file.
    #[serde(default)]
    pub required_values: Vec<String>,
    /// Fields whose values must be unique across all files.
    #[serde(default)]
    pub unique_fields: Vec<String>,
    /// Expected types for fields: "scalar", "list", or "number".
    #[serde(default)]
    pub field_types: HashMap<String, String>,
    /// Groups of fields where at least one group must be fully present.
    /// Each inner Vec is a group; a file passes if all fields in any one group are present.
    #[serde(default)]
    pub required_field_groups: Vec<Vec<String>>,
    /// Require list-type fields to have items in sorted order.
    #[serde(default)]
    pub sorted_tags: bool,
    /// Fail the build when tags in the allowlist are not used by any file.
    #[serde(default)]
    pub check_unused: bool,
    #[serde(flatten)]
    pub standard: StandardConfig,
}

impl Default for TagsConfig {
    fn default() -> Self {
        Self {
            output: "out/tags/tags.db".into(),
            tags_dir: "tags".into(),
            required_fields: Vec::new(),
            required_values: Vec::new(),
            unique_fields: Vec::new(),
            field_types: HashMap::new(),
            required_field_groups: Vec::new(),
            sorted_tags: false,
            check_unused: false,
            standard: StandardConfig::default(),
        }
    }
}

impl KnownFields for TagsConfig {
    fn known_fields() -> &'static [&'static str] {
        &[
            "output", "tags_dir", "required_fields", "required_values",
            "unique_fields", "field_types", "required_field_groups", "sorted_tags",
            "check_unused", "dep_inputs", "dep_auto", "batch", "max_jobs",
        ]
    }
    fn checksum_fields() -> &'static [&'static str] {
        // The validation-rule fields (required_fields, required_values, etc.)
        // are excluded: they affect whether the build passes, not the bytes of
        // the produced tags database. A change in those triggers a re-validation
        // pass via dep_inputs, not a re-hash of the output.
        &["output", "tags_dir", "check_unused"]
    }
    fn field_descriptions() -> &'static [(&'static str, &'static str)] {
        &[
            ("output",                "Output tags database file path"),
            ("tags_dir",              "Directory containing tag list files"),
            ("required_fields",       "Frontmatter fields that every markdown file must have"),
            ("required_values",       "Scalar fields whose values must exist in the tag lists file"),
            ("unique_fields",         "Fields whose values must be unique across all files"),
            ("field_types",           "Expected types for fields: scalar, list, or number"),
            ("required_field_groups", "Groups of fields where at least one group must be fully present"),
            ("sorted_tags",           "Require list-type fields to have items in sorted order"),
            ("check_unused",          "Fail the build when tags in the allowlist are not used by any file"),
        ]
    }
}


/// Script processor config. No custom fields.
/// Unused StandardConfig fields: formats, output_dir.
/// Note: empty command means "no command configured".
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct ScriptConfig {
    #[serde(flatten)]
    pub standard: StandardConfig,
    /// Command to run in fix mode (`rsconstruct fix`). Empty means no fix capability.
    #[serde(default)]
    pub fix_command: String,
    /// Arguments for the fix command (prepended before file paths).
    #[serde(default)]
    pub fix_args: Vec<String>,
    /// Whether fix mode supports batch execution (multiple files per invocation).
    /// Defaults to the same value as `batch`.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub fix_batch: Option<bool>,
}
impl Default for ScriptConfig {
    fn default() -> Self {
        Self {
            standard: StandardConfig::default(),
            fix_command: String::new(),
            fix_args: Vec::new(),
            fix_batch: None,
        }
    }
}
impl KnownFields for ScriptConfig {
    fn known_fields() -> &'static [&'static str] {
        &["command", "formats", "args", "dep_inputs", "dep_auto", "output_dir", "batch", "max_jobs",
          "fix_command", "fix_args", "fix_batch"]
    }
    fn checksum_fields() -> &'static [&'static str] { StandardConfig::checksum_fields() }
    fn must_fields() -> &'static [&'static str] { StandardConfig::must_fields() }
    fn field_descriptions() -> &'static [(&'static str, &'static str)] {
        &[
            ("command",     "Path to the checker tool executable"),
            ("args",        "Extra arguments passed to the checker tool"),
            ("fix_command", "Path to the fixer tool executable (empty = no fix capability)"),
            ("fix_args",    "Arguments for the fixer (prepended before file paths)"),
            ("fix_batch",   "Whether fix mode supports batch execution (default: same as batch)"),
        ]
    }
}

fn default_generator_output_extension() -> String {
    "out".into()
}

/// Generator config. Custom: output_extension.
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct GeneratorConfig {
    #[serde(default = "default_generator_output_extension")]
    pub output_extension: String,
    #[serde(flatten)]
    pub standard: StandardConfig,
}

impl Default for GeneratorConfig {
    fn default() -> Self {
        Self {
            output_extension: "out".into(),
            standard: StandardConfig { output_dir: "out/generator".into(), ..StandardConfig::default() },
        }
    }
}

impl KnownFields for GeneratorConfig {
    fn known_fields() -> &'static [&'static str] {
        &[
            "command", "output_dir", "output_extension", "args",
            "dep_inputs", "dep_auto", "batch", "max_jobs",
        ]
    }
    fn checksum_fields() -> &'static [&'static str] {
        &["command", "output_dir", "output_extension", "args"]
    }
    fn field_descriptions() -> &'static [(&'static str, &'static str)] {
        &[
            ("command",          "Script or executable to run as a generator (required)"),
            ("args",             "Extra arguments passed to the command before file paths"),
            ("output_dir",       "Directory where generated output files are written"),
            ("output_extension", "File extension for generated output files"),
        ]
    }
}

// --- explicit processor (many inputs → few outputs, fully declared) ---

/// Explicit config. Custom: inputs, input_globs, output_files, output_dirs.
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct ExplicitConfig {
    #[serde(default)]
    pub inputs: Vec<String>,
    #[serde(default)]
    pub input_globs: Vec<String>,
    #[serde(default)]
    pub output_files: Vec<String>,
    #[serde(default)]
    pub output_dirs: Vec<String>,
    #[serde(flatten)]
    pub standard: StandardConfig,
}

impl Default for ExplicitConfig {
    fn default() -> Self {
        Self {
            inputs: Vec::new(),
            input_globs: Vec::new(),
            output_files: Vec::new(),
            output_dirs: Vec::new(),
            standard: StandardConfig { command: "true".into(), ..StandardConfig::default() },
        }
    }
}

impl KnownFields for ExplicitConfig {
    fn known_fields() -> &'static [&'static str] {
        &["command", "args", "inputs", "input_globs", "output_files", "output_dirs"]
    }
    fn checksum_fields() -> &'static [&'static str] {
        // inputs/input_globs are excluded: input changes are detected by content
        // hashing of the resolved input file set, not by hashing the pattern list.
        &["command", "args", "output_files", "output_dirs"]
    }
    fn must_fields() -> &'static [&'static str] {
        &["command"]
    }
    fn field_descriptions() -> &'static [(&'static str, &'static str)] {
        &[
            ("command",      "Command to run to produce the outputs"),
            ("args",         "Extra arguments passed before input/output paths"),
            ("inputs",       "Explicit list of input files"),
            ("input_globs",  "Glob patterns for input files"),
            ("output_files", "Output files produced by the command"),
            ("output_dirs",  "Output directories produced by the command"),
        ]
    }
}

#[derive(Debug, Deserialize, Serialize, Clone)]
/// Pip config. Custom: none (uses standard.command as the pip executable).
pub struct PipConfig {
    #[serde(flatten)]
    pub standard: StandardConfig,
}

impl Default for PipConfig {
    fn default() -> Self {
        Self { standard: StandardConfig { command: "pip".into(), ..StandardConfig::default() } }
    }
}

impl KnownFields for PipConfig {
    fn known_fields() -> &'static [&'static str] {
        &[
            "command", "args", "dep_inputs", "batch", "max_jobs",
        ]
    }
    fn checksum_fields() -> &'static [&'static str] {
        &["command", "args"]
    }
    fn field_descriptions() -> &'static [(&'static str, &'static str)] {
        &[
            ("command", "Path to the pip executable"),
            ("args",    "Extra arguments passed to pip install"),
        ]
    }
}

#[derive(Debug, Deserialize, Serialize, Clone)]
/// Requirements generator config. Produces a requirements.txt from Python imports.
pub struct RequirementsConfig {
    /// Output file path.
    #[serde(default = "default_requirements_output")]
    pub output: String,
    /// Import names to never emit (e.g. internal vendored modules).
    #[serde(default)]
    pub exclude: Vec<String>,
    /// Sort entries alphabetically. When false, entries appear in first-seen order.
    #[serde(default = "default_true")]
    pub sorted: bool,
    /// Include a "# Generated by rsconstruct" comment header.
    #[serde(default = "default_true")]
    pub header: bool,
    /// User-supplied import→distribution mapping overrides. Wins over the built-in table.
    #[serde(default)]
    pub mapping: HashMap<String, String>,
    /// Distribution names to always include in the output, even when no
    /// `import` statement references them. Use this for transitive runtime
    /// dependencies that an upstream package needs at import time but fails
    /// to declare in its own metadata (e.g. `setuptools` for packages that
    /// `import pkg_resources`).
    #[serde(default)]
    pub extra: Vec<String>,
    #[serde(flatten)]
    pub standard: StandardConfig,
}

fn default_requirements_output() -> String {
    "requirements.txt".into()
}

impl Default for RequirementsConfig {
    fn default() -> Self {
        Self {
            output: default_requirements_output(),
            exclude: Vec::new(),
            sorted: true,
            header: true,
            mapping: HashMap::new(),
            extra: Vec::new(),
            standard: StandardConfig::default(),
        }
    }
}

impl KnownFields for RequirementsConfig {
    fn known_fields() -> &'static [&'static str] {
        &[
            "output", "exclude", "sorted", "header", "mapping", "extra",
            "dep_inputs", "dep_auto", "batch", "max_jobs",
        ]
    }
    fn checksum_fields() -> &'static [&'static str] {
        &["output", "exclude", "sorted", "header", "mapping", "extra"]
    }
    fn field_descriptions() -> &'static [(&'static str, &'static str)] {
        &[
            ("output",  "Path of the generated requirements.txt file"),
            ("exclude", "Import names to never emit (e.g. internal vendored modules)"),
            ("sorted",  "Sort entries alphabetically (false preserves first-seen order)"),
            ("header",  "Include a comment header line in the generated file"),
            ("mapping", "Per-project import→distribution overrides (win over built-in table)"),
            ("extra",   "Distribution names to always include, e.g. transitive deps undeclared by upstream"),
        ]
    }
}

#[derive(Debug, Deserialize, Serialize, Clone)]
/// Sphinx config. Custom: working_dir, cache_output_dir.
pub struct SphinxConfig {
    #[serde(default)]
    pub working_dir: Option<String>,
    #[serde(default = "default_true")]
    pub cache_output_dir: bool,
    #[serde(flatten)]
    pub standard: StandardConfig,
}

impl Default for SphinxConfig {
    fn default() -> Self {
        Self {
            working_dir: None,
            cache_output_dir: true,
            standard: StandardConfig {
                command: "sphinx-build".into(),
                output_dir: "docs".into(),
                ..StandardConfig::default()
            },
        }
    }
}

impl KnownFields for SphinxConfig {
    fn known_fields() -> &'static [&'static str] {
        &[
            "command", "output_dir", "working_dir", "args", "dep_inputs", "cache_output_dir", "batch", "max_jobs",
        ]
    }
    fn checksum_fields() -> &'static [&'static str] {
        &["command", "output_dir", "working_dir", "args"]
    }
    fn field_descriptions() -> &'static [(&'static str, &'static str)] {
        &[
            ("command",     "Path to the sphinx-build executable"),
            ("output_dir",  "Directory where built docs are written"),
            ("working_dir", "Working directory for sphinx-build (defaults to conf.py location)"),
            ("args",        "Extra arguments passed to sphinx-build"),
        ]
    }
}

#[derive(Debug, Deserialize, Serialize, Clone)]
/// Mdbook config. Custom: cache_output_dir.
pub struct MdbookConfig {
    #[serde(default = "default_true")]
    pub cache_output_dir: bool,
    #[serde(flatten)]
    pub standard: StandardConfig,
}

impl Default for MdbookConfig {
    fn default() -> Self {
        Self {
            cache_output_dir: true,
            standard: StandardConfig {
                command: "mdbook".into(),
                output_dir: "book".into(),
                ..StandardConfig::default()
            },
        }
    }
}

impl KnownFields for MdbookConfig {
    fn known_fields() -> &'static [&'static str] {
        &[
            "command", "output_dir", "args", "dep_inputs", "cache_output_dir", "batch", "max_jobs",
        ]
    }
    fn checksum_fields() -> &'static [&'static str] {
        &["command", "output_dir", "args"]
    }
    fn field_descriptions() -> &'static [(&'static str, &'static str)] {
        &[
            ("command",    "Path to the mdbook executable"),
            ("output_dir", "Directory where the built book is written"),
            ("args",       "Extra arguments passed to mdbook build"),
        ]
    }
}

#[derive(Debug, Deserialize, Serialize, Clone)]
/// Npm config. Custom: cache_output_dir.
pub struct NpmConfig {
    #[serde(default = "default_true")]
    pub cache_output_dir: bool,
    #[serde(flatten)]
    pub standard: StandardConfig,
}

impl Default for NpmConfig {
    fn default() -> Self {
        Self {
            cache_output_dir: true,
            standard: StandardConfig { command: "npm".into(), ..StandardConfig::default() },
        }
    }
}

impl KnownFields for NpmConfig {
    fn known_fields() -> &'static [&'static str] {
        &[
            "command", "args", "dep_inputs", "cache_output_dir", "batch", "max_jobs",
        ]
    }
    fn checksum_fields() -> &'static [&'static str] {
        &["command", "args"]
    }
    fn field_descriptions() -> &'static [(&'static str, &'static str)] {
        &[
            ("command", "Path to the npm executable"),
            ("args",    "Arguments passed to npm install"),
        ]
    }
}

fn default_gem_home() -> String {
    "gems".into()
}

fn default_gem_stamp() -> String {
    "out/gem/root.stamp".into()
}

#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct MdlConfig {
    #[serde(default)]
    pub local_repo: bool,
    #[serde(default = "default_gem_home")]
    pub gem_home: String,
    #[serde(default = "default_gem_stamp")]
    pub gem_stamp: String,
    #[serde(flatten)]
    pub standard: StandardConfig,
}

impl Default for MdlConfig {
    fn default() -> Self {
        Self {
            local_repo: false,
            gem_home: "gems".into(),
            gem_stamp: "out/gem/root.stamp".into(),
            standard: StandardConfig { command: "mdl".into(), ..StandardConfig::default() },
        }
    }
}

impl KnownFields for MdlConfig {
    fn known_fields() -> &'static [&'static str] {
        &[
            "local_repo", "gem_home", "command", "args", "dep_inputs", "dep_auto", "gem_stamp", "batch", "max_jobs",
        ]
    }
    fn checksum_fields() -> &'static [&'static str] {
        &["local_repo", "gem_home", "command", "args", "gem_stamp"]
    }
    fn field_descriptions() -> &'static [(&'static str, &'static str)] {
        &[
            ("local_repo", "Use a local gem repository instead of system install"),
            ("gem_home",   "Path to the local gem repository"),
            ("command",    "Path to the mdl executable"),
            ("args",       "Extra arguments passed to mdl"),
            ("gem_stamp",  "Stamp file tracking the local gem installation"),
        ]
    }
}



#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct MarkdownlintConfig {
    #[serde(flatten)]
    pub standard: StandardConfig,
}

impl Default for MarkdownlintConfig {
    fn default() -> Self {
        Self {
            standard: StandardConfig {
                command: "markdownlint".into(),
                ..StandardConfig::default()
            },
        }
    }
}

impl KnownFields for MarkdownlintConfig {
    fn known_fields() -> &'static [&'static str] {
        &[
            "command", "args", "dep_inputs", "dep_auto", "batch", "max_jobs",
        ]
    }
    fn checksum_fields() -> &'static [&'static str] {
        &["command", "args"]
    }
    fn field_descriptions() -> &'static [(&'static str, &'static str)] {
        &[
            ("command", "Path to the markdownlint executable"),
            ("args",    "Extra arguments passed to markdownlint"),
        ]
    }
}


fn default_aspell_conf() -> String {
    ".aspell.conf".into()
}

fn default_aspell_words_file() -> String {
    ".aspell.en.pws".into()
}

#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct AspellConfig {
    #[serde(default = "default_aspell_conf")]
    pub conf: String,
    #[serde(default)]
    pub auto_add_words: bool,
    #[serde(default = "default_aspell_words_file")]
    pub words_file: String,
    #[serde(flatten)]
    pub standard: StandardConfig,
}

impl Default for AspellConfig {
    fn default() -> Self {
        Self {
            conf: ".aspell.conf".into(),
            auto_add_words: false,
            words_file: ".aspell.en.pws".into(),
            standard: StandardConfig { command: "aspell".into(), ..StandardConfig::default() },
        }
    }
}

impl KnownFields for AspellConfig {
    fn known_fields() -> &'static [&'static str] {
        &[
            "command", "args", "conf", "auto_add_words", "words_file", "dep_inputs", "dep_auto", "batch", "max_jobs",
        ]
    }
    fn checksum_fields() -> &'static [&'static str] {
        &["command", "args", "conf", "auto_add_words"]
    }
    fn field_descriptions() -> &'static [(&'static str, &'static str)] {
        &[
            ("command",        "Path to the aspell executable"),
            ("args",           "Extra arguments passed to aspell"),
            ("conf",           "Path to the aspell configuration file"),
            ("auto_add_words", "When true, automatically add misspelled words to words_file instead of failing"),
            ("words_file",     "Path to the personal word list file"),
        ]
    }
}


pub type AsciiConfig = CheckerConfig;

fn default_dir_terms_unambiguous() -> String {
    "terms/unambiguous".into()
}

fn default_dir_terms_ambiguous() -> String {
    "terms/ambiguous".into()
}

#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct TermsConfig {
    #[serde(default = "default_dir_terms_unambiguous")]
    pub dir_terms_unambiguous: String,
    #[serde(default = "default_dir_terms_ambiguous")]
    pub dir_terms_ambiguous: String,
    /// When true (default), backticking an ambiguous term is a build error
    /// and `terms fix` strips those backticks. When false, ambiguous terms
    /// are loaded only to validate the disjoint invariant; their use in
    /// backticks is neither flagged nor changed.
    #[serde(default = "default_true")]
    pub forbid_backticked_ambiguous: bool,
    #[serde(flatten)]
    pub standard: StandardConfig,
}

impl Default for TermsConfig {
    fn default() -> Self {
        Self {
            dir_terms_unambiguous: "terms/unambiguous".into(),
            dir_terms_ambiguous: "terms/ambiguous".into(),
            forbid_backticked_ambiguous: true,
            standard: StandardConfig::default(),
        }
    }
}

impl KnownFields for TermsConfig {
    fn known_fields() -> &'static [&'static str] {
        &["dir_terms_unambiguous", "dir_terms_ambiguous", "forbid_backticked_ambiguous", "dep_inputs", "dep_auto", "batch", "max_jobs"]
    }
    fn checksum_fields() -> &'static [&'static str] {
        &["dir_terms_unambiguous", "dir_terms_ambiguous", "forbid_backticked_ambiguous"]
    }
    fn field_descriptions() -> &'static [(&'static str, &'static str)] {
        &[
            ("dir_terms_unambiguous", "Directory containing unambiguous term definition files (must be backticked in prose)"),
            ("dir_terms_ambiguous", "Optional directory of ambiguous terms; build fails if any term overlaps with dir_terms_unambiguous"),
            ("forbid_backticked_ambiguous", "If true (default), backticking an ambiguous term is a build error and `terms fix` strips those backticks"),
        ]
    }
}




fn default_pdflatex_runs() -> usize {
    2
}

#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct PdflatexConfig {
    #[serde(default = "default_pdflatex_runs")]
    pub runs: usize,
    #[serde(default = "default_true")]
    pub qpdf: bool,
    #[serde(flatten)]
    pub standard: StandardConfig,
}

impl Default for PdflatexConfig {
    fn default() -> Self {
        Self {
            runs: 2,
            qpdf: true,
            standard: StandardConfig {
                command: "pdflatex".into(),
                output_dir: "out/pdflatex".into(),
                ..StandardConfig::default()
            },
        }
    }
}

impl KnownFields for PdflatexConfig {
    fn known_fields() -> &'static [&'static str] {
        &[
            "command", "args", "dep_inputs", "dep_auto", "runs", "qpdf", "output_dir", "batch", "max_jobs",
        ]
    }
    fn checksum_fields() -> &'static [&'static str] {
        &["command", "args", "runs", "qpdf", "output_dir"]
    }
    fn field_descriptions() -> &'static [(&'static str, &'static str)] {
        &[
            ("command",   "Path to the pdflatex executable"),
            ("args",      "Extra arguments passed to pdflatex"),
            ("runs",      "Number of pdflatex compilation passes"),
            ("qpdf",      "Run qpdf to optimize the output PDF"),
            ("output_dir","Directory where compiled PDFs are written"),
        ]
    }
}




#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct GemConfig {
    #[serde(default = "default_gem_home")]
    pub gem_home: String,
    #[serde(default = "default_true")]
    pub cache_output_dir: bool,
    #[serde(flatten)]
    pub standard: StandardConfig,
}

impl Default for GemConfig {
    fn default() -> Self {
        Self {
            gem_home: "gems".into(),
            cache_output_dir: true,
            standard: StandardConfig { command: "bundle".into(), ..StandardConfig::default() },
        }
    }
}

impl KnownFields for GemConfig {
    fn known_fields() -> &'static [&'static str] {
        &[
            "command", "gem_home", "args", "dep_inputs", "cache_output_dir", "batch", "max_jobs",
        ]
    }
    fn checksum_fields() -> &'static [&'static str] {
        &["command", "gem_home", "args"]
    }
    fn field_descriptions() -> &'static [(&'static str, &'static str)] {
        &[
            ("command",  "Path to the bundler executable"),
            ("gem_home", "Directory where gems are installed"),
            ("args",     "Extra arguments passed to bundler install"),
        ]
    }
}







pub type IjqConfig = CheckerConfig;

pub type IjsonlintConfig = CheckerConfig;

pub type IyamllintConfig = CheckerConfig;

#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct IyamlschemaConfig {
    #[serde(default = "default_true")]
    pub check_ordering: bool,
    #[serde(flatten)]
    pub standard: StandardConfig,
}

impl Default for IyamlschemaConfig {
    fn default() -> Self {
        Self {
            check_ordering: true,
            standard: StandardConfig::default(),
        }
    }
}

impl KnownFields for IyamlschemaConfig {
    fn known_fields() -> &'static [&'static str] {
        &["check_ordering", "dep_inputs", "dep_auto", "batch", "max_jobs"]
    }
    fn checksum_fields() -> &'static [&'static str] {
        &["check_ordering"]
    }
    fn field_descriptions() -> &'static [(&'static str, &'static str)] {
        &[
            ("check_ordering", "Require YAML keys to appear in the order defined by the schema"),
        ]
    }
}


pub type ItaploConfig = CheckerConfig;

fn default_rust_single_file_output_suffix() -> String { ".elf".into() }
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct RustSingleFileConfig {
    #[serde(default)]
    pub flags: Vec<String>,
    #[serde(default = "default_rust_single_file_output_suffix")]
    pub output_suffix: String,
    #[serde(flatten)]
    pub standard: StandardConfig,
}

impl Default for RustSingleFileConfig {
    fn default() -> Self {
        Self {
            flags: Vec::new(),
            output_suffix: ".elf".into(),
            standard: StandardConfig {
                command: "rustc".into(),
                output_dir: "out/rust_single_file".into(),
                ..StandardConfig::default()
            },
        }
    }
}

impl KnownFields for RustSingleFileConfig {
    fn known_fields() -> &'static [&'static str] {
        &["command", "flags", "output_suffix", "dep_inputs", "dep_auto", "output_dir", "batch", "max_jobs"]
    }
    fn checksum_fields() -> &'static [&'static str] {
        &["command", "flags", "output_suffix", "output_dir"]
    }
    fn field_descriptions() -> &'static [(&'static str, &'static str)] {
        &[
            ("command",       "Path to the rustc executable"),
            ("flags",         "Extra flags passed to rustc"),
            ("output_suffix", "Suffix appended to output binary names"),
            ("output_dir",    "Directory where compiled binaries are written"),
        ]
    }
}


fn default_pdfunite_source_dir() -> String {
    "marp/courses".into()
}

fn default_pdfunite_source_ext() -> String {
    ".md".into()
}

fn default_pdfunite_source_output_dir() -> String {
    "out/marp".into()
}

#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct PdfuniteConfig {
    #[serde(default = "default_pdfunite_source_dir")]
    pub source_dir: String,
    #[serde(default = "default_pdfunite_source_ext")]
    pub source_ext: String,
    #[serde(default = "default_pdfunite_source_output_dir")]
    pub source_output_dir: String,
    #[serde(flatten)]
    pub standard: StandardConfig,
}

impl Default for PdfuniteConfig {
    fn default() -> Self {
        Self {
            source_dir: "marp/courses".into(),
            source_ext: ".md".into(),
            source_output_dir: "out/marp".into(),
            standard: StandardConfig {
                command: "pdfunite".into(),
                output_dir: "out/pdfunite".into(),
                ..StandardConfig::default()
            },
        }
    }
}

impl KnownFields for PdfuniteConfig {
    fn known_fields() -> &'static [&'static str] {
        &[
            "command", "source_dir", "source_ext", "source_output_dir",
            "args", "dep_inputs", "dep_auto", "output_dir", "batch", "max_jobs",
        ]
    }
    fn checksum_fields() -> &'static [&'static str] {
        &[
            "command", "source_dir", "source_ext", "source_output_dir",
            "args", "output_dir",
        ]
    }
    fn field_descriptions() -> &'static [(&'static str, &'static str)] {
        &[
            ("command",           "Path to the pdfunite executable"),
            ("source_dir",        "Directory containing course YAML files listing PDFs to merge"),
            ("source_ext",        "Extension of source files used to find PDFs"),
            ("source_output_dir", "Directory where source PDFs (to be merged) are located"),
            ("args",              "Extra arguments passed to pdfunite"),
            ("output_dir",        "Directory where merged PDFs are written"),
        ]
    }
}


// --- ipdfunite (internal PDF merge, no external binary) ---

fn default_ipdfunite_source_dir() -> String {
    "marp/courses".into()
}

fn default_ipdfunite_source_ext() -> String {
    ".md".into()
}

fn default_ipdfunite_source_output_dir() -> String {
    "out/marp".into()
}

#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct IpdfuniteConfig {
    #[serde(default = "default_ipdfunite_source_dir")]
    pub source_dir: String,
    #[serde(default = "default_ipdfunite_source_ext")]
    pub source_ext: String,
    #[serde(default = "default_ipdfunite_source_output_dir")]
    pub source_output_dir: String,
    #[serde(flatten)]
    pub standard: StandardConfig,
}

impl Default for IpdfuniteConfig {
    fn default() -> Self {
        Self {
            source_dir: "marp/courses".into(),
            source_ext: ".md".into(),
            source_output_dir: "out/marp".into(),
            standard: StandardConfig { output_dir: "out/ipdfunite".into(), ..StandardConfig::default() },
        }
    }
}

impl KnownFields for IpdfuniteConfig {
    fn known_fields() -> &'static [&'static str] {
        &[
            "source_dir", "source_ext", "source_output_dir",
            "dep_inputs", "dep_auto", "output_dir", "batch", "max_jobs",
        ]
    }
    fn checksum_fields() -> &'static [&'static str] {
        &[
            "source_dir", "source_ext", "source_output_dir", "output_dir",
        ]
    }
    fn field_descriptions() -> &'static [(&'static str, &'static str)] {
        &[
            ("source_dir",        "Directory containing course YAML files listing PDFs to merge"),
            ("source_ext",        "Extension of source files used to find PDFs"),
            ("source_output_dir", "Directory where source PDFs (to be merged) are located"),
            ("output_dir",        "Directory where merged PDFs are written"),
        ]
    }
}




// --- tidy (HTML validator) ---

// --- stylelint (CSS linter) ---

// --- jslint (JavaScript linter) ---

// --- standard (JavaScript style checker) ---

// --- htmllint (HTML linter) ---

// --- php_lint (PHP syntax checker) ---

// --- perlcritic (Perl code analyzer) ---

// --- xmllint (XML validator) ---

// --- svglint (SVG linter) ---

// --- svgo (SVG validator via svgo; stdout discarded, non-zero exit = malformed) ---

// --- checkstyle (Java style checker) ---

// --- yq (YAML processor/validator) ---

// --- cmake (CMake build system) ---

// --- docker (Docker image build) ---

// --- jekyll (Static site generator) ---
pub type JekyllConfig = CheckerConfig;

// --- slidev (Slidev presentations) ---

// --- encoding (UTF-8 validation) ---
pub type EncodingConfig = CheckerConfig;

// --- duplicate_files (duplicate detection by SHA-256) ---
pub type DuplicateFilesConfig = CheckerConfig;

// --- marp_images (validate image references in Marp presentations) ---

// --- license_header (verify license headers in source files) ---
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct LicenseHeaderConfig {
    #[serde(default)]
    pub header_lines: Vec<String>,
    #[serde(flatten)]
    pub standard: StandardConfig,
}

impl Default for LicenseHeaderConfig {
    fn default() -> Self {
        Self {
            header_lines: Vec::new(),
            standard: StandardConfig::default(),
        }
    }
}

impl KnownFields for LicenseHeaderConfig {
    fn known_fields() -> &'static [&'static str] {
        &["args", "dep_inputs", "dep_auto", "batch", "max_jobs", "header_lines"]
    }
    fn checksum_fields() -> &'static [&'static str] {
        &["args", "header_lines"]
    }
    fn field_descriptions() -> &'static [(&'static str, &'static str)] {
        &[
            ("args",         "Extra arguments passed to the license header checker"),
            ("header_lines", "Lines of the license header that must appear at the top of each file"),
        ]
    }
}