Repository navigation
Expand file tree
/
Copy pathplan.cppm
More file actions
5454 lines (5256 loc) · 298 KB
/
Copy pathplan.cppm
File metadata and controls
5454 lines (5256 loc) · 298 KB
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
// mcpp.build.plan — backend-agnostic representation of "what to build".
//
// The pipeline is:
// manifest + modgraph + toolchain + fingerprint → BuildPlan → Backend.build()
export module mcpp.build.plan;
import std;
import mcpp.pm.patch; // a variant's name (design 2026-11-02 §14.1)
import mcpp.build.graph_shape;
import mcpp.build.refusal;
import mcpp.targetside;
import mcpp.build.loader_contract;
import mcpp.manifest;
import mcpp.source_kind;
import mcpp.modgraph.graph;
import mcpp.modgraph.scanner;
import mcpp.modgraph.glob; // a deploy glob's fixed directory (design 2026-11-16 §4.1)
import mcpp.toolchain.cppfly;
import mcpp.toolchain.detect;
import mcpp.toolchain.dialect;
import mcpp.toolchain.fingerprint;
import mcpp.toolchain.linkmodel;
import mcpp.toolchain.triple;
import mcpp.toolchain.target_rows; // a row's fixed executable suffix (N48)
import mcpp.pack.prebuilt; // is_distribution_package — a shipped shared lib is not rebuilt
import mcpplibs.os.platform;
import mcpp.toolchain.platform;
import mcpp.runtime.search;
import mcpp.runtime.env_contract;
import mcpp.runtime.binding;
import mcpp.provider;
import mcpp.provider.select;
import mcpp.home;
import mcpp.platform;
export namespace mcpp::build {
struct CompileUnit {
std::filesystem::path source;
// The unit's ROLE. Copied from the SourceUnit the scanner classified, and
// read by the object namer, the link-object collectors, the ninja rule
// picker, the CDB emitter and the assembly dialect check — none of which
// look at the extension any more. See mcpp.source_kind.
//
// Declared second so a hand-built unit reads `.source` then `.kind`. There
// is no safe default: a unit whose kind was never set would route to the
// generic C++ rule, which is a silent misroute rather than an error. Any
// producer other than make_plan (i.e. a test) must state it.
mcpp::SourceKind kind = mcpp::SourceKind::Other;
std::filesystem::path object; // relative to plan.outputDir
std::string packageName;
std::vector<std::filesystem::path> localIncludeDirs;
// #249: emitted as -idirafter (searched after the toolchain's system
// dirs) — a dep source root on this list can't shadow standard headers.
std::vector<std::filesystem::path> localIncludeDirsAfter;
std::vector<std::string> packageCflags;
std::vector<std::string> packageCxxflags;
std::vector<std::string> packageAsmflags; // per-glob asmflags (G4)
// The logical module name, when this unit is a module interface; empty
// otherwise (a module name is never empty). A plain string and not an
// `std::optional<std::string>`: that member type does not copy under
// clang with the MSVC STL once the module interface around it changes
// (`_SMF_control` has no matching constructor), and the error names this
// struct from whichever unit copies a CompileUnit first.
std::string providesModule;
// The unit's BMI, relative to the toolchain's BMI directory: the module's
// name (`common.gcm`) when the root package provides it, and below the
// provider's directory (`gpp.updater/common.gcm`) for every other package
// (pack drive and selection design 2026-10-01, B1). Empty on a unit that
// provides nothing, and on a unit built by hand, which then takes the name.
std::string bmiFile;
std::vector<std::string> imports; // logical names imported
// A file of a test program (its `main` file, or another of its directory):
// the one kind of unit `trim_paths` leaves its paths, since a test finds
// its fixtures through `__FILE__` and runs where it was built.
bool testUnit = false;
// A target's entry `main`, synthesized for the image that links it (a test
// program's `mtest/main`). It provides no module, so it compiles where the
// image is built, beside the package's other units: the global cache
// serves and fills those and passes this one by, and the instance digest
// does not count it, as it does not count the root's units (design
// 2026-11-20 §5.4: an entry without a cache address took the whole of
// mcpplibs.mtest out of the cache in every project).
bool entryUnit = false;
// The key of this unit's module map in `BuildPlan::moduleScopes`: the BMI
// of every module the unit imports, directly or through another module,
// and of the module it provides. Empty when every such BMI lies at its
// name in the BMI directory, which is where the compilers look unaided.
std::string moduleScope;
// Unit came from a scan_overrides declaration — plan-vs-ddi
// verification is mandatory for it (ninja_backend emits --expect-*).
bool scanOverridden = false;
// The source file as written, when `source` is a unit built for it
// (mcpp.modgraph SourceUnit::writtenAs); empty otherwise.
std::filesystem::path writtenAs;
// The module declaration form the scanner read (mcpp.modgraph.graph).
// Stated as the unit's role by the build database.
mcpp::modgraph::ModuleDeclaration declaration = mcpp::modgraph::ModuleDeclaration::None;
// THE EXTENSION SAYS WHICH LANGUAGE; THE MODULE DECLARATION SAYS WHICH
// ROLE (D8, #790). A C++ unit that provides a module -- an interface, or
// either kind of partition -- writes a BMI and takes the module rule,
// whatever its extension; a module-extension file takes it as well, for
// its depfile handling, even when it holds an implementation unit. Read
// by every place that chooses a rule or a BMI edge, so the rule, the BMI
// the edge declares and the flags the edge passes cannot disagree.
// Before this the choice was the extension's: a `.cpp` holding
// `module m:part;` declared a BMI its `cxx_object` edge never wrote, and
// was rebuilt by every build (R4); `export module m;` in a `.cpp` was not
// found by its importers under Clang (R5).
bool is_implementation_partition() const {
return declaration == mcpp::modgraph::ModuleDeclaration::ImplementationPartition;
}
// A build program's `.mcpp` source takes the module rule too: that rule
// states the unit's language per edge (`module_lang`), which a `.mcpp`
// file needs whether or not it imports anything (mcpp#797).
bool uses_module_rule() const {
return kind == mcpp::SourceKind::ModuleInterface
|| (kind == mcpp::SourceKind::Cxx && !providesModule.empty())
|| mcpp::needs_explicit_cxx_language(source);
}
// This unit's outputs are already in the global cache: the backend emits
// `stage_file` edges from the cache instead of a compile edge (and skips
// the P1689 scan for it entirely). The unit itself stays in the plan so
// compile_commands.json keeps an entry for it and clangd does not lose the
// dependency's sources.
bool servedFromCache = false;
std::filesystem::path cachedObject; // absolute, inside the cache
std::filesystem::path cachedBmi; // absolute; empty if no module
// This unit's outputs fill a global-cache entry after the build: the
// entry holds its package's every BMI and object, so the backend builds
// the unit even where nothing in this build imports or links it (the
// engine package's `mcpp.core' in a build plugin's configuration, where
// the plugin imports `mcpp' alone).
bool fillsCache = false;
// mcpp#344: this object's address INSIDE a global-cache entry — relative to
// `<entry>/obj/`, and a pure function of the owning package (its source's
// path relative to its own package root). Distinct from `object`, which is
// a build-dir path and therefore depends on which other packages this
// particular build contains.
//
// Empty means "no admissible cache address": the root package (never
// cached), or a dependency source that could not be anchored to anything
// machine-independent. prepare.cppm drops the WHOLE package out of the
// cache when any of its units has an empty address — a half-staged package
// mixes cached and freshly built BMIs, which is the mismatch GCC reports as
// a CRC error three edges later.
std::filesystem::path packageObjectRel;
};
struct LinkUnit {
std::string targetName;
// The package the unit belongs to (qualified name): the root's, a
// member's, or the dependency's whose library or program it is. The build
// report attributes the link step to it (build progress design
// 2026-09-29, §6.3).
std::string package;
enum Kind { Binary, StaticLibrary, SharedLibrary, TestBinary } kind = Binary;
// Does this image belong to a DEPENDENCY rather than to the package being
// built? A `kind = "shared"` dependency contributes a link unit to the
// consumer's plan, and that unit is not one of the consumer's targets.
//
// It decides where a `role = "object"` action's outputs go. "Every linked
// image" is the right default for a build program's objects -- a test
// binary and a static library both need them -- but it was reading as
// "every link unit in the plan", so a device island was linked into a
// dependency's shared library as well. Measured: `compat:opencl`'s ICD
// loader, a C library, came out carrying `saxpy_device` and thirty-seven
// `sycl::` instantiations, and the process then had two copies of the
// island. Latent until a SYCL project first had a shared dependency.
bool dependencyOwned = false;
// mcpp#711: the dependency whose program this is, when a consumer's edge
// asked for it with `artifacts = [...]` (qualified package name). Empty for
// every other unit. A dependency-owned `Binary` is always one of these; the
// name is what `${mcpp.artifact:<package>/<target>}` is resolved against.
std::string artifactOf;
// A workspace plan's link unit of a selected member (workspace design
// 2026-09-29 §15): the member's qualified package name, and the index of
// its link group in `BuildPlan::linkGroups`, which holds the link flags
// and the runtime files of the member's closure. Empty and -1 on every
// other unit.
std::string memberOf;
int linkGroup = -1;
// Normally relative to plan.outputDir. A `role = "object"` action's outputs
// land here ABSOLUTE, on purpose: ninja identifies a file by the string an
// edge declares, and the action edge declares whatever prepare_actions
// produced — respelling it here would create a second node and "missing and
// no known rule to make it". Do not normalise this vector.
std::vector<std::filesystem::path> objects;
std::vector<std::filesystem::path> implicitInputs; // relative to plan.outputDir
std::vector<std::string> linkFlags; // per-link edge flags
// The loader-tag flag for THIS unit's form (mcpp.build.loader_contract).
// Separate from linkFlags because its correctness is positional: gcc specs
// and clang config files hand ld `--enable-new-dtags`, last occurrence
// wins, so the emitter puts this after every other linker argument.
// Deciding it stays here; placing it is the emitter's business.
std::string loaderTagFlag;
// The symbol patterns this unit publishes, empty when it publishes all.
// Carried as the neutral list rather than a rendered flag: the file to
// write and the flag that names it are both platform-shaped, and the
// backend is where the target OS is known.
std::vector<std::string> exportPatterns;
std::filesystem::path output; // relative to plan.outputDir
// The import library a PE shared library also produces — empty on ELF and
// Mach-O, and empty for every non-shared unit. It is a SECOND output of the
// link edge, declared implicitly so the consumer that links it has a
// producer; without that, ninja reports "no known rule to make it" naming a
// file the link command does in fact write.
std::filesystem::path importLibrary; // relative to plan.outputDir
// The generated module-definition file, on the MSVC ABI only.
//
// MSVC exports nothing from a DLL without `__declspec(dllexport)` or a
// `.def`, so without this the import library is empty and every consumer
// fails with unresolved externals for symbols that are visibly in the
// objects. MinGW's linker auto-exports and needs none of this.
std::filesystem::path defFile; // relative to plan.outputDir
// The target states `windows_auto_export` (either value); see
// `Target::windowsAutoExport`.
bool autoExportStated = false;
std::string soname; // ABI name for shared libraries
std::vector<std::filesystem::path> runtimeAliases; // relative aliases, e.g. bin/libfoo.so.1
std::optional<std::filesystem::path> entryMain; // src path of main.cpp for bin
// Of a test: the files that are its own (its `main` file and, under
// `[test] programs = "directory"`, its directory's others).
std::vector<std::filesystem::path> ownSources;
// `windows_subsystem` / `windows_entry` of the target this unit links
// (#618), carried as the declared words. Rendering them needs the linker
// the emitter addresses, which the plan does not know, so the backend does
// it; see `windows_executable_link_flags`. Empty on every non-Binary unit.
std::string windowsSubsystem;
std::string windowsEntry;
// Design 2026-10-26 §24: where the program's beginning comes from, as
// `<package>/<entry>` when a dependency's entry target supplies it (empty
// for the target's own `main`), and the symbol the image is entered at
// with the statement that put it there (empty = the linker script's
// `ENTRY()` or the linker's default). The backend renders `start`.
std::string entryFrom;
std::string start;
std::string startFrom;
// `main = false` (mcpp#981): the image has no program start, and its starter
// enters it only through the names it exports. Such a unit is no program
// `mcpp run` starts.
bool noProgramStart = false;
// The test protocol the selected entry states it implements
// (`test-protocol`, docs/08); 0 when none does. `mcpp test` also reads a
// program's marker for it (mtest spec/protocol.md P2.3).
int testProtocol = 0;
// The package whose entry begins this test, when one does: the framework
// whose guide `mcpp test --guide` names (BuildPlan::testFrameworks).
std::string testFramework;
};
// One Windows resource script compiled into one linkable resource artifact
// (mcpp#365).
//
// Deliberately NOT a CompileUnit. A `.rc` has no module semantics, so putting it
// there would drag it into the module graph, the topological order, the cache
// key and compile_commands.json — where clangd would be handed a file no C++
// frontend can parse. It is its own edge whose output joins `LinkUnit::objects`,
// which is the one thing `[build].ldflags` could never do: ldflags is a flat
// string in the link command, so a `.res` named there is invisible to ninja and
// changing it produced "no work to do".
struct ResourceUnit {
// The package whose `[resources]` declared the script (qualified name).
std::string package;
std::filesystem::path source; // absolute; synthesised ones live under outputDir
std::filesystem::path output; // relative to plan.outputDir
// The `.rc`'s own inputs: quoted #includes and the data files named by its
// resource statements. Neither windres nor llvm-rc can emit a depfile
// (verified against llvm-rc 22.1.8: /I, /D, no dependency output), so these
// come from a text scan plus `[resources].extra-inputs`.
std::vector<std::filesystem::path> implicitInputs;
// The directories the script's `#include`s are searched in: its package's
// directory and include_dirs. A workspace plan compiles the resources of
// several members, each against its own package.
std::vector<std::filesystem::path> includeDirs;
// The resource compiler's flags for this script. `BuildPlan::rcFlags` are
// the first unit's; a unit whose flags differ states its own.
std::vector<std::string> flags;
};
struct RuntimeCapabilityProvider {
std::string capability;
mcpp::manifest::PackageId provider;
};
// A library a package requires at run time and loads with `dlopen`, and the
// directories of that package's own shared objects, from which the loader
// looks it up (design 2026-11-21, offline and toolchain defaults §3.10). A
// named struct, not a pair, for the module hazard `RuntimeCapabilityProvider`
// records.
struct DlopenRequirement {
std::string soname;
std::string requester; // the package, canonical
std::vector<std::filesystem::path> originDirs;
};
struct ResolvedRuntimeContract {
std::vector<mcpp::manifest::RuntimeRequirement> requirements;
std::vector<mcpp::manifest::RuntimeArtifact> artifacts;
mcpp::manifest::LinkIntent linkIntent;
std::vector<RuntimeCapabilityProvider> providers;
std::vector<DlopenRequirement> dlopen;
// A deploy glob that matched no file, or a `name` whose `from` did not
// match exactly one: each a sentence naming the package and the entry.
std::vector<std::string> errors;
};
// The files a deploy entry of `root`'s package places (design 2026-11-16
// §4.1): each match of `from` under `to`, at its path relative to the glob's
// fixed directory, renamed by `name`. A literal `from` (no wildcard) is
// returned as written, existing or not: a build may generate it. Exported as a
// pure seam for the tests.
std::expected<std::vector<mcpp::manifest::DeployEntry>, std::string>
expand_deploy_entry(const std::filesystem::path& root, const mcpp::manifest::DeployEntry& entry);
// Normalize structured and legacy runtime metadata and stamp every fact with
// the exact package identity that supplied it. Exported as a pure seam for
// contract tests and machine-readable tooling; it performs no host probing.
ResolvedRuntimeContract resolve_runtime_contract(
const std::vector<mcpp::modgraph::PackageRoot>& packages);
// A static package this build could not link into exactly one image (#646 F1).
//
// `images` names the shared libraries of the plan whose static closure
// reaches the package (by target name); `program` says whether the root's own
// images reach it as well. `make_plan` leaves such a package where it always
// was, in the root's images, and records it here: whether that is refused or
// reported depends on the target format, which prepare decides.
struct StaticPlacementConflict {
std::string package; // qualified package name
std::vector<std::string> images; // shared library target names
bool program = false;
};
// Where each static package of a graph is linked.
//
// A shared image's STATIC CLOSURE is the set of static packages reachable from
// its package without crossing another shared package. A static package in
// exactly one closure, which the root does not reach itself, belongs in that
// image; one in several closures, or in one and the root's, has no single
// image to live in (`conflicts`). Packages in no closure stay with the root.
//
// Indices are package indices; 0 is the root. `sharedImages` maps each shared
// package to the number of images it produces; `boundaries` are packages that
// are neither placed nor traversed (a distribution package's library is
// already built).
struct StaticPlacement {
std::map<std::size_t, std::size_t> intoImage; // static package -> shared package
struct Conflict {
std::size_t package = 0;
std::vector<std::size_t> images; // shared packages reaching it
bool root = false;
};
std::vector<Conflict> conflicts;
};
StaticPlacement place_static_packages(
const std::map<std::size_t, std::vector<std::size_t>>& edges,
const std::map<std::size_t, std::size_t>& sharedImages,
const std::set<std::size_t>& boundaries);
// The standard-library units this configuration's build compiles, when it
// imports `std` (design 2026-09-26 §3.5, D5a/D5b). Populated once, in
// prepare.cppm, by recovering the invocation from the command mcpp actually
// ran to build the module into the shared std cache
// (mcpp.toolchain.stdmod::StdModuleDescription) — recovered here, on the
// plan, rather than separately by each renderer, so compile_commands.json,
// `emit --spec compile-commands` and the S1 document cannot list different
// arguments for the same unit (P1, mcpp.build.compile_commands's header).
// Zero, one (`std`) or two (`std`, `std.compat`) entries.
struct StdModuleUnit {
std::filesystem::path source;
std::filesystem::path workDirectory; // the shared std cache, not outputDir
std::vector<std::string> arguments; // driver first, as recovered
std::filesystem::path object;
std::filesystem::path bmi; // the BMI the build writes (S1 `provides`)
std::string module; // "std" | "std.compat"
std::vector<std::string> requiresModules; // {} for std, {"std"} for std.compat
};
// Splits a command string mcpp rendered for the host shell into words,
// undoing its quoting: POSIX `sh` rules, or the Microsoft C runtime's rules
// on Windows. The reader is mcpp::manifest::host_command_words; this name is
// kept for the standard-library units' recovery below.
std::vector<std::string> split_command_words(std::string_view command, bool windows);
// The working directory and argument vector of the command in `commands`
// whose words name `source`, recovered from the rendering: a leading `cd`, an
// `env` word and environment assignments, and redirections are removed. A
// driver path that the rendering left unquoted despite a space is rejoined.
// Empty when no command names the source. Used to populate
// StdModuleUnit::workDirectory/arguments (prepare.cppm) from
// mcpp.toolchain.stdmod::StdModuleDescription's recorded commands.
struct RecoveredInvocation {
std::filesystem::path workDirectory;
std::vector<std::string> arguments;
};
std::optional<RecoveredInvocation> recover_invocation(
const std::vector<std::string>& commands,
const std::filesystem::path& source,
const std::filesystem::path& driver,
const std::filesystem::path& defaultDirectory,
bool windows);
// How the build's report names a package of the plan (build progress design
// 2026-09-29, §4.2, §6.3): the qualified name the plan's units carry, whether
// the command asked for it (the root, or a selected member), the subject of
// its line, and the units the global cache supplied.
struct PlanPackage {
std::string name;
bool requested = false;
// As a package line names it (build output design revision 3, §5.10): the
// short name for a package inside the project, the full identity for any
// other; `detail` is its version and origin; `source` is where it comes
// from: project, official, index, git or path.
std::string subject;
std::size_t cachedUnits = 0;
std::string detail;
std::string source;
};
// The module map of a set of compile units (pack drive and selection design
// 2026-10-01, B1): which BMI each module name means to them. A unit is given
// one when a module it imports, or the module it provides, lies below its
// provider's directory, which is every module of a package other than the
// root. GCC reads `mapFile` through `-fmodule-mapper=`, because its mapper
// does not fall back for a name it does not list; clang and MSVC read
// `argsFile` as an argument file of `-fmodule-file=` or `/reference` lines.
// The dyndep step reads `mapFile` on every compiler.
//
// The map lists what the UNIT reaches through its imports, and nothing that
// the rest of the graph holds. A map derived from the graph, or from the
// package's whole closure, would name other members' modules under
// `--workspace` and not under `-p`, and the dev-dependencies' modules under
// `mcpp test` and not under `mcpp build`, and a unit compiled in one build
// directory by both would be compiled again at every switch (#751).
struct ModuleScope {
// Relative to the build directory, with a hash of `content` in its name,
// so a changed resolution changes the flag that names it.
std::filesystem::path mapFile;
// `<module name> <BMI path relative to the build directory>` lines, one
// per name, sorted by name.
std::string content;
// clang and MSVC: relative to the build directory, named after `mapFile`
// with the `.modmap` suffix that CMake's module maps carry and that
// compilation-database readers recognise as module mechanics. Empty for
// GCC.
std::filesystem::path argsFile;
// The arguments `argsFile` holds, unquoted, each BMI path absolute. The
// backend writes them one per line in the host's response-file syntax,
// with the byte order mark an MSVC tool needs to read a non-ASCII path.
std::vector<std::string> arguments;
};
// A package of the graph whose entry states how its tests are written or run
// (`test-guide`, `test-protocol`, `test-main`): a test framework.
struct TestFramework {
std::string package; // qualified name
std::string version;
std::string entry; // `<package>/<entry>`
int protocol = 0;
std::string guide; // absolute path of its guide, or empty
std::string repo;
// What it states of the mcpp test spec (docs/specs/test.md, B6): the
// optional capabilities it implements, and its session's command (O9).
std::vector<std::string> capabilities;
std::vector<std::string> session;
};
// A package's license files, as a pack stages them (design 2026-11-16 §4.3):
// the package as its directory under `share/licenses/` names it, its root, and
// its `license_files` or the engine's default.
struct LicenseSource {
std::string package;
std::filesystem::path root;
std::vector<std::string> patterns;
bool declared = false;
};
struct BuildPlan {
mcpp::manifest::Manifest manifest;
// Every package of the graph, as the report names it; the backend writes
// the step record from it and from the statements it emits.
std::vector<PlanPackage> packages;
// Packages whose declared `[build] c_standard` the compiler does not apply,
// spelt `<package> (<standard>)`, in the order their first C unit appears.
// Filled only for cl.exe (W3b of the #693-#696 record) and reported once by
// the backend, so a declared value is never dropped without a word.
std::vector<std::string> cStandardsNotApplied;
// Every package root of the graph, the root's first. The hermetic check
// reads it on an isolated graph link: a package may add a package-relative
// `-L` (openkal-musl's empty archives), and a path dependency's root can
// be anywhere on the machine, not only under the store.
std::vector<std::filesystem::path> packageRoots;
// Every package of the graph with its license files (§4.3), the root's
// first: the program's link and run closure, whatever its linkage.
std::vector<LicenseSource> licenseSources;
// THE PATHS AN ARTIFACT CARRIES, MAPPED (`trim_paths`; design 2026-10-23
// §15.3, mcpp#832): each package's root to `<name>@<version>`, and the
// store, the home, the build directory, the toolchain and the target base
// to fixed placeholders. Ordered by prefix length, shortest first, so that
// a driver that tries the last-given mapping first takes the longest
// match. Empty unless the profile trims.
std::vector<std::pair<std::filesystem::path, std::string>> trimMap;
// THE SAME MAP, PER PACKAGE (mcpp#844, design 2026-10-26 part 2 §10.4),
// by `CompileUnit::packageName`: the fixed roots and the roots of the
// package and its dependency closure -- every prefix the package's units
// can write -- in the order of `trimMap`. A unit's command carries its
// package's map and no other, so a package's command line does not
// depend on which members the plan builds. Filled by prepare, which owns
// the dependency edges.
std::map<std::string, std::vector<std::pair<std::filesystem::path, std::string>>,
std::less<>> packageTrimMaps;
mcpp::toolchain::Toolchain toolchain;
mcpp::toolchain::Fingerprint fingerprint;
// Where the target's platform interface, C library and C++ runtime come
// from, resolved once in prepare after the dependency graph is known.
//
// It is a field of the plan rather than of the toolchain because it is not
// a property of the compiler: the same clang serves a build whose system
// comes from its own payload and one whose system is built from source by
// that same clang. Attaching it to the toolchain is what produced the
// `openkal-llvm` family name, which had to be invented to carry a fact
// about the dependency graph on an object that describes a compiler.
mcpp::targetside::TargetSide targetSide;
// What every unit of this build receives from beneath it -- the target
// side's include directories and flags, the engine's predefines, the
// realised C environment -- as the build's contract states it for a
// foreign build compiling for the target (`write_build_contract`).
mcpp::modgraph::UsageRequirements contractTargetSide;
// THE C++ ISLAND OF THIS BUILD, when it has one (design 2026-10-26 §6.3):
// a C++ runtime other than the build's own reaches the link -- declared by
// packages' private `mcpp:c++-abi` requirements, named on the link line,
// or needed by a library the line names. The runtime table then embeds
// the build's own runtime hidden with one unwinder, the named words follow
// it on the line, and every C++ image is verified after the link
// (mcpp.build.cxx_runtime). Absent: one runtime, nothing to verify.
struct CxxIsland {
std::string own; // "libc++" / "libstdc++"
std::string foreign;
std::vector<std::string> packages; // the packages that declared it
std::vector<std::string> namedWords; // link words naming the foreign runtime
std::vector<std::string> neededBy; // libraries on the line that NEED it
};
std::optional<CxxIsland> cxxIsland;
// Which graph this plan will write into build.ninja. The fingerprint does
// NOT cover dev-deps or test targets, so `mcpp build` and `mcpp test`
// share an output directory and overwrite each other's graph; this is what
// lets a fast path tell them apart (mcpp#407, mcpp.build.graph_shape).
GraphShape graphShape = GraphShape::Normal;
// The file the graph is written to, in the output directory. `mcpp test`
// writes `test.ninja` (design 2026-11-10 supplement, T5): the build's own
// graph stays where its fast path replays it, and the two share the
// directory's objects, `.ninja_log` and `.ninja_deps`, so an output both
// graphs name is rebuilt when one names another command for it.
std::string graphFile = "build.ninja";
// The module-edge schedule this plan will emit, resolved ONCE (see
// mcpp.build.schedule.policy). The backend writes the graph in this shape,
// the graph records the tag, and the fast path compares against it — three
// readers, one derivation. Deriving it separately in the backend and in the
// executor is how the BMI-equivalence check and the job count drifted into
// disagreeing about what a module edge is.
// Does this build need position-independent code?
//
// ONE DERIVATION, THREE READERS — the flag assembly, the whole-project
// fingerprint, and the per-package cache key. It used to be derived by
// `flags.cppm` alone, by scanning the link units, and the other two did
// not know about it at all. That was survivable only while a package's
// form was fixed by its author: once a consumer can ask for the shared
// form (`[build] dependency_linkage`), the same cache entry can serve
// non-PIC objects to a link that puts them inside a shared object, and
// the failure is `relocation R_X86_64_32S ... can not be used when making
// a shared object` on a file nobody edited.
bool needsPic = false;
// Static packages that no single image could take (#646 F1); see
// `StaticPlacementConflict`. Empty for every graph without a shared
// library over a static package that something else reaches too.
std::vector<StaticPlacementConflict> staticPlacementConflicts;
std::string scheduleTag = "none";
// What this graph was planned FOR, beyond what names its directory: the
// workspace members of the plan and the requested features, as one tag
// (`request_tag`). Neither moves the build directory (workspace design
// 2026-09-29 §3), so build.ninja records the tag and the fast paths
// compare it before replaying the file.
std::string requestTag;
// Whether `--accel` / `--no-accel` selected this graph's device variant
// over `[build] accel`. The variant is in the fingerprint, so the two
// builds land in different directories -- and the fast path, which runs
// before any plan exists, replays whichever directory was built LAST. A
// plain `mcpp build` after `mcpp build --no-accel` therefore reported
// "Finished in 0.00s" and handed back the CPU variant. The graph records
// the selection so the fast path can decline a graph an override chose.
bool accelOverridden = false;
// What to hand ninja. Under detach-codegen a compiler stops holding a slot
// when it publishes, so this must exceed the real compiler cap or the ready
// frontier starves — see the hazard note in schedule/detach_codegen.
int scheduleNinjaJobs = 0;
int scheduleCompilerCap = 0;
// The memory a compiler may start below (design 2026-11-20 §5.5), in bytes:
// the compiler executor waits below it (MCPP_MEMORY_THRESHOLD in its env).
std::uint64_t memoryThreshold = 0;
// The unit cache (design 2026-11-20 §5.3): its directory, empty when the
// build uses no global cache, and the roots whose files never change in
// place, which the compiler executor reads a path of as its identity.
std::filesystem::path unitCacheDir;
std::vector<std::filesystem::path> immutableRoots;
// One immutable snapshot selected before workspace member substitution.
// Build/run/test and cache fast paths consume this value; none may re-read
// xlings active/current state.
mcpp::runtime::RuntimeBinding runtimeBinding;
std::string cppStandard = "c++23";
std::string cppStandardFlag = "-std=c++23";
// Module-graph-global dialect flags (issue #210), pre-joined with a
// leading space per flag (e.g. " -freflection"). Rides -std='s channels:
// global $cxxflags (all TUs incl. deps), std BMI prebuild, scans.
std::string dialectFlags;
std::filesystem::path projectRoot; // where mcpp.toml lives
std::filesystem::path outputDir; // target/<triple>/<lineage>/
// The engine the graph's commands run: the directory's link to this
// engine (mcpp.build.graph_engine); empty, this engine's own path.
std::filesystem::path engine;
// Where compile_commands.json goes. Carried rather than derived from
// projectRoot: under BuildOverrides::work_dir the package root is a shared
// (possibly read-only) registry directory, and deriving the path would put
// an IDE database there. Empty → projectRoot, the historical default.
std::filesystem::path compileDbPath;
// Whether writing this plan's compile database also publishes the root
// copy. False for each plan of a command that planned several
// configurations, which publishes the root file itself, once, from all of
// them (`publish_root_compile_commands` over a list).
bool publishRootCompileDb = true;
// `[build] compile_commands` as resolved (resolve_compile_commands):
// relative to the project root, empty when no copy is published. Recorded
// with the build so a fast path publishes to the same place.
std::string rootCompileDb;
// See StdModuleUnit above. Empty when the build does not import `std`.
std::vector<StdModuleUnit> stdModuleUnits;
// GCC only: a specs file that replaces the pristine `*link:`, so the
// payload's own (patched by every home that ever installed against it)
// cannot inject rpath entries into this build's artifacts. Empty for
// clang, which bypasses its cfg with --no-default-config instead.
std::filesystem::path gccCleanSpecs;
std::filesystem::path stdBmiPath; // absolute path to prebuilt std.gcm
std::filesystem::path stdObjectPath; // absolute path to prebuilt std.o
std::filesystem::path stdCompatBmiPath; // absolute path to prebuilt std.compat.pcm
// By `CompileUnit::moduleScope`. Empty when every module of the plan is
// the root package's, and then the BMI directory is flat and no command
// names a map.
std::map<std::string, ModuleScope, std::less<>> moduleScopes;
// The package instances this plan compiles, as `<package>/<digest>` below
// `obj/` and the BMI directory (design 2026-11-19 §11.1). Recorded with the
// time a plan last used each (`instances.tsv`), which `mcpp clean --stale`
// reads to remove an instance no build has used within its window.
// Keyed by the package's qualified name; the value is `<slug>/<digest>`.
// A GCC BMI records its imports at their instance paths, so the build
// cache keys a package's entry by its instance too (`bmiPathConvention`).
std::map<std::string, std::string> instanceDirs;
std::filesystem::path stdCompatObjectPath; // absolute path to prebuilt std.compat.o
std::filesystem::path scanDepsPath; // clang-scan-deps binary (Clang only)
// THE TARGET'S PLATFORM (SPEC-013): the merged statement, its flags for
// this target and the programs its link and seal run. `active` is false
// for a target that uses none; the runner fields are filled either way,
// because a build program and the project state them for any target.
mcpp::platform::Resolved platform;
// NASM assembly (.asm sources). Both resolved in prepare AFTER the plan
// exists — only when the plan actually contains .asm units (lazy, hard
// failure when unavailable; never a silent skip).
std::filesystem::path nasmPath; // nasm binary (empty → no .asm units)
std::string nasmFormat; // -f value derived from the target triple
// Windows resources (mcpp#365). Resolved in prepare AFTER the plan exists
// and only when the plan actually has resource units — same lazy, hard-fail
// shape as nasm above: a resource that silently vanished would show up as
// "my icon is gone" with nothing to attribute it to.
std::vector<ResourceUnit> resourceUnits;
std::filesystem::path rcPath; // windres / llvm-rc / rc.exe
// "gnu" → windres, emits a COFF object (ld cannot consume a .res)
// "msvc" → rc.exe / llvm-rc, emits a .res (link.exe and lld-link take it)
std::string rcStyle;
std::vector<std::string> rcFlags; // -I / -D, target-shaped
std::vector<CompileUnit> compileUnits; // topologically sorted
std::vector<LinkUnit> linkUnits;
// The test frameworks of the graph (docs/08 "Writing a test").
std::vector<TestFramework> testFrameworks;
// Build-graph nodes declared by build programs (`mcpp:action=`). Paths are
// absolute and engine variables already substituted by the time they get
// here, so the backend only has to spell edges.
std::vector<mcpp::manifest::BuildAction> actions;
// The distribution formats the RESOLVED GRAPH provides, sorted and unique
// (`mcpp:pack-format=`). This is what `mcpp pack --format <name>` resolves
// against and what an unknown value's refusal names.
//
// Collected on EVERY prepare, including the pass that asked for no format
// at all -- which is the pass that has to answer "what is available". See
// `mcpp::provides_pack_format` for the author-facing rule that makes this
// possible: declare unconditionally, submit conditionally.
std::vector<std::string> providedPackFormats;
// Non-empty when this prepare is the second pass of `mcpp pack --format
// <name>`: the staged closure `${mcpp.stage_dir}` expanded to. Recorded on
// the plan so the graph header line can say which format wrote this graph,
// and the fast paths can decline to replay it for a plain build.
std::string packFormat;
std::vector<std::filesystem::path> runtimeLibraryDirs;
// ONLY the dependency packages' [runtime] library_dirs (not toolchain/
// payload dirs). These are the dirs that must be baked into the produced
// binary's RUNPATH (e.g. compat.glx-runtime). Kept separate so static/musl
// links don't pull the glibc payload dir.
std::vector<std::filesystem::path> depRuntimeLibraryDirs;
std::vector<mcpp::manifest::RuntimeRequirement> runtimeRequirements;
std::vector<mcpp::manifest::RuntimeArtifact> runtimeArtifacts;
mcpp::manifest::LinkIntent linkIntent;
// The complete run-time search closure of the artifacts this plan will
// produce, in loader order and tagged with where each directory came from
// (`mcpp.runtime.search`).
//
// This is the RECORD — what resolution.json publishes and `mcpp why
// runtime` explains. Emission is still owned by each origin's existing
// producer (payloads by the toolchain link model, package dirs by
// LinkIntent), with one exception: SubosFarm entries have no other
// producer, so `flags.cppm` renders them from here, appended last.
//
// The farm deliberately does NOT enter `runtimeLibraryDirs`. That
// vector becomes LD_LIBRARY_PATH for `mcpp run`, which is inherited by
// every child process including host binaries — measured to kill
// `xdg-open`/`notify-send` outright when a private libc is on it. The farm
// is reachable PER OBJECT (DT_RPATH) and must stay that way.
std::vector<mcpp::runtime::search::Dir> runtimeSearch;
// The project states its environment (`[xlings] subos`): the union view of
// that environment is its own (design 2026-11-27 §4.1). False: the view is
// the machine's default environment, which the project reaches through
// COMPAT(implicit-default-environment) until the row's floor.
bool statedEnvironment = false;
// Windows runtime-DLL deployment. On PE (`supports_rpath` is false) a
// directly-launched .exe cannot RUNPATH-locate a dependency's DLL, so each
// *.dll found in a dependency's [runtime] library_dir is copied beside the
// produced executable (into bin/). The filter is the *.dll extension, not a
// platform `if constexpr`: a real Linux/macOS dependency ships .so/.dylib
// (never .dll), so this list is empty there and non-Windows builds are
// byte-for-byte unchanged; only a Windows prebuilt-DLL package (or a test
// that ships a .dll) populates it. dest is relative to outputDir.
struct DeployFile {
// Absolute source paths. Usually one; more than one means two or more
// packages of this graph each generate a file for this destination
// (SPEC-007 R4.2) — an `artifacts` dependency and its consumer asking
// one plugin for the same translation catalog is the case #723 was
// filed for. Planning no longer refuses this: at planning time a
// generated source may not exist yet, so its content cannot be
// compared. `mcpp stage` (mcpp.build.stage) is where the sources are
// actually checked, at build time, against each other's bytes.
std::vector<std::filesystem::path> sources;
std::filesystem::path dest; // relative to outputDir, e.g. bin/libopenblas.dll
// Where the entry comes from: a declaration, the toolset's C++
// runtime, or a DLL found in a runtime search directory. The plan
// lists declared and derived candidates; which file sits beside the
// program is decided once, by mcpp.build.runtime_placement (read
// through `CompileFlags::runtimeDeploy`), never by a reader of this
// list.
enum class Origin : std::uint8_t { Declared, Toolchain, Derived };
Origin origin = Origin::Declared;
// Whether `other` names this destination. On a PE target the
// comparison folds case: the file systems a Windows program runs from
// and its loader both do, so `Foo.DLL` and `foo.dll` are one file
// there, whatever the build host's file system does.
bool is_destination(const std::filesystem::path& other, bool peTarget) const {
if (!peTarget) return dest == other;
auto fold = [](std::string s) {
std::ranges::transform(s, s.begin(),
[](unsigned char c) { return static_cast<char>(std::tolower(c)); });
return s;
};
return fold(dest.generic_string()) == fold(other.generic_string());
}
};
std::vector<DeployFile> runtimeDeployFiles;
// Aggregated host-runtime requirements from dependency packages'
// [runtime] metadata. Capability/provider-driven — no platform special-casing
// in mcpp: providers (e.g. compat.glx-runtime) declare these per platform.
std::vector<DlopenRequirement> runtimeDlopenLibs; // deps' required dlopen sonames, by requester
std::vector<std::string> runtimeCapabilities; // union of host capabilities
// (capability, provider package). A named aggregate instead of std::pair:
// musl-gcc 15.1 modules failed to emit vector<pair<string,string>>'s
// move-ctor instantiation across the module boundary (release link error).
std::vector<RuntimeCapabilityProvider> runtimeProviders;
// Where the files the runtime needs are placed beside the programs,
// relative to outputDir: `bin`, or a workspace member's product directory
// while its link group is swapped in (§15).
std::filesystem::path productDir = "bin";
// A workspace plan's per-member link data (workspace design 2026-09-29
// §15). A selected member's link units link the member's closure -- the
// member and what it reaches without an `artifacts` or member edge -- with
// that closure's own link flags, and the files its runtime needs are
// placed in its product directory. The fields repeat the plan's own, so a
// group is read by swapping it into a copy of the plan
// (`swap_link_group`). Empty outside a workspace plan, where the plan's
// own fields serve the root's units.
struct Placement {
std::filesystem::path source; // relative to outputDir
std::filesystem::path dest; // relative to outputDir
};
struct LinkGroup {
std::string member; // qualified package name
std::filesystem::path productDir; // relative to outputDir
std::vector<std::string> ldflags; // the plan's, then the closure's
std::vector<std::filesystem::path> runtimeLibraryDirs;
std::vector<std::filesystem::path> depRuntimeLibraryDirs;
std::vector<mcpp::manifest::RuntimeRequirement> runtimeRequirements;
std::vector<mcpp::manifest::RuntimeArtifact> runtimeArtifacts;
mcpp::manifest::LinkIntent linkIntent;
std::vector<DeployFile> runtimeDeployFiles;
std::vector<DlopenRequirement> runtimeDlopenLibs;
std::vector<std::string> runtimeCapabilities;
std::vector<RuntimeCapabilityProvider> runtimeProviders;
// The graph-built shared libraries the member's units load, placed
// beside them (a hard link where the file system allows, §5.3).
std::vector<Placement> placements;
// The group of a program shipped through `artifacts`: it holds the
// link line and the runtime contract of the program's own closure,
// and places nothing, since the members that ship the program place
// it and its runtime files. `member` is empty.
bool linkOnly = false;
};
std::vector<LinkGroup> linkGroups;
};
// Exchange a link group's fields with the plan's own. Called twice, it
// restores both; between the calls, the plan describes the group's units to
// every reader of those fields (`compute_flags` in particular).
void swap_link_group(BuildPlan& plan, BuildPlan::LinkGroup& g) {
std::swap(plan.manifest.buildConfig.ldflags, g.ldflags);
std::swap(plan.runtimeLibraryDirs, g.runtimeLibraryDirs);
std::swap(plan.depRuntimeLibraryDirs, g.depRuntimeLibraryDirs);
std::swap(plan.runtimeRequirements, g.runtimeRequirements);
std::swap(plan.runtimeArtifacts, g.runtimeArtifacts);
std::swap(plan.linkIntent, g.linkIntent);
std::swap(plan.runtimeDeployFiles, g.runtimeDeployFiles);
std::swap(plan.runtimeDlopenLibs, g.runtimeDlopenLibs);
std::swap(plan.runtimeCapabilities, g.runtimeCapabilities);
std::swap(plan.runtimeProviders, g.runtimeProviders);
std::swap(plan.productDir, g.productDir);
}
// Merge the generic facts exported by the already-selected xlings
// RuntimeBinding. This is data ingestion only: xlings has already selected
// providers and materialized artifacts before mcpp sees this snapshot.
void merge_runtime_binding_contract(
BuildPlan& plan,
const mcpp::runtime::RuntimeBinding& binding);
// The run-time search closure for this plan, in loader order and tagged with
// provenance. Exported so a test can exercise the guards (cross target, non-ELF
// format, undeclared SubOS) without linking a binary for each.
std::vector<mcpp::runtime::search::Dir> runtime_search_closure(
const BuildPlan& plan,
const mcpp::runtime::RuntimeBinding& binding);
// Is `p` inside one of `roots`, judged LEXICALLY?
//
// Lexical is the whole point (mcpp#344). std::filesystem::relative() runs
// weakly_canonical on both sides and therefore RESOLVES SYMLINKS, and a payload
// store whose entries are symlinks into another store is ordinary — e2e's
// _inherit_toolchain.sh builds one, and so does any CI cache that links a warm
// payload tree into a fresh MCPP_HOME. Under canonicalization those packages
// stop looking like store packages and silently drop out of the build cache.
// Both the cacheability gate and the cache-address anchor ask "where was this
// installed", which is a question about the path, not about the inode — and
// they must answer it the same way, so there is one function.
bool path_is_under_any(const std::filesystem::path& p,
const std::vector<std::filesystem::path>& roots);
// THE TEST FRAMEWORKS A PACKAGE STATES (docs/08): each entry of `m` that
// states its guide, its protocol, its session or capabilities, or that it
// begins a test, appended to `out`. `dir` is the package's root, which a
// guide's path is relative to. Read by the plan and by `mcpp test --guide`,
// which reads a resolved graph and plans nothing (#932).
void collect_test_frameworks(const mcpp::manifest::Manifest& m, const std::filesystem::path& dir,
std::vector<TestFramework>& out);
// True if a source file defines a top-level `int main(`/`auto main(` entry,
// ignoring comments and string/raw-string literals. Drives the archive-vs-inline
// choice for kind="lib" dependencies (see plan.cppm).
bool source_defines_main(const std::filesystem::path& src);
// Build a BuildPlan from already-validated inputs. Fails (mcpp#233) only
// when the object-path uniqueness assertion below finds a residual
// collision after the relPath-mirroring scheme — a would-be ninja
// "multiple rules generate X" turned into a diagnosable mcpp error.
std::expected<BuildPlan, std::string>
make_plan(const mcpp::manifest::Manifest& manifest,
const mcpp::toolchain::Toolchain& tc,
const mcpp::toolchain::Fingerprint& fp,
const mcpp::modgraph::Graph& graph,
const std::vector<std::size_t>& topoOrder,
const std::vector<mcpp::modgraph::PackageRoot>& packages,
const std::filesystem::path& projectRoot,
const std::filesystem::path& outputDir,
const std::filesystem::path& stdBmiPath,
const std::filesystem::path& stdObjectPath,
// Roots of the immutable xpkgs payload stores (there is more than
// one: the global registry, plus the project-local `.mcpp/**/data`
// roots a custom git index installs into). Used ONLY to anchor the
// cache address of a dependency source that lives outside its own
// package root (a build.mcpp OUT_DIR product). Empty is legal and
// simply makes those units uncacheable.
const std::vector<std::filesystem::path>& storeRoots = {},
// The target's platform (SPEC-013): its artifact names, when it
// states them, replace the target row's.
const mcpp::platform::Resolved* platform = nullptr);
// Expand one manifest `include_dirs` entry against the project root — the
// #249 consistency join + the expand_dir_glob the dep path uses. Exported
// (like modgraph's glob_literal_prefix) so unit tests can assert its
// native-separator contract directly; see the definition below.
std::vector<std::filesystem::path>
expand_manifest_include_entry(const std::filesystem::path& root,
const std::filesystem::path& inc);
// How a package is named when one part of the plan has to be matched against
// another. `CompileUnit::packageName` and `BuildAction::packageName` are both
// this, and mcpp#534's ordering edge joins them — so it is exported rather
// than re-derived at the second call site, which is how the same decision
// ends up spelled two ways.
std::string qualified_package_name(const mcpp::manifest::Manifest& manifest);
// What `${mcpp.target_file:<name>}` names in `plan`: the build-dir-relative
// output of the link unit of that target name. A plan of several members may
// hold a target of one name in each of them; the name then means the unit of
// `actingMember`, the member the referring package acts for. `output` is empty
// when no unit has the name. `members` is non-empty when the name is ambiguous:
// several members define it and none of them is `actingMember`.
struct TargetFileAnswer {
std::string output;
std::vector<std::string> members;
};
TargetFileAnswer resolve_target_file(const BuildPlan& plan, std::string_view name,
std::string_view actingMember);
// Where the backend writes the object list of the link unit whose
// build-dir-relative output is `output` (design 2026-11-19 §8.2):
// `<out>/objects/<output><suffix>`, `.list` one absolute path per line and
// `.rsp` in response-file quoting. Absolute and generic, as every path token is.
std::filesystem::path objects_list_path(const BuildPlan& plan, std::string_view output,
std::string_view suffix);
// The record of a configuration's package instances (design 2026-11-19 §11.1):
// `<outputDir>/instances.tsv`, one `<package>/<digest>\t<seconds>\t<last>`
// line per instance: the time a build last used it, and whether the plan that
// wrote the build graph uses it. `record_instances` marks a plan's set as the
// last one and stamps it; `touch_last_instances` restamps that set for a build
// that runs the graph without planning (the fast path), writing only when a
// stamp is an hour old. `mcpp clean` keeps the last set whatever the window.
struct InstanceUse {
std::int64_t when = 0;
bool last = false;
};
std::map<std::string, InstanceUse> read_instances(const std::filesystem::path& outputDir);
void write_instances(const std::filesystem::path& outputDir,
const std::map<std::string, InstanceUse>& instances);
void record_instances(const std::filesystem::path& outputDir, const std::vector<std::string>& used);
void touch_last_instances(const std::filesystem::path& outputDir);
// Replaces `${mcpp.objects:<name>}` and `${mcpp.objects_rsp:<name>}` in `s`
// with `objects_list_path` of the unit `resolve_target_file` names, records the
// unit in `units` once, and a name no unit has, or several members define, in
// the two sets the refusal reads. True when `s` held either token.
bool substitute_objects_tokens(const BuildPlan& plan, std::string& s, std::string_view actingMember,
std::vector<std::string>& units,
std::set<std::string>& unresolved,
std::map<std::string, std::vector<std::string>>& ambiguous);
// The references an action's arguments made that the plan cannot answer, as
// the refusal a user reads: names no link unit has (`unresolvedTargets`), names
// several members define for a package that acts for none of them
// (`ambiguousTargets`, from `resolve_target_file`), and `${mcpp.artifact:}`
// references no requested artifact matches (`unresolvedArtifacts`).
std::expected<void, std::string> refuse_unresolved_references(
const BuildPlan& plan, const std::set<std::string>& unresolvedTargets,
const std::map<std::string, std::vector<std::string>>& ambiguousTargets,
const std::set<std::string>& unresolvedArtifacts);
// The references an action's arguments made that its role or this run cannot
// answer: `${mcpp.stage_dir}` where no tree is staged (`stageDirNoPass`; the
// package several packed members reach is `stageDirShared`, the stage's own
// reason `stageDirWhy`), and `${mcpp.stage_dir}` or `${mcpp.objects:<name>}`
// used by a role that runs before what it names. Each set holds action ids.
struct ActionRoleReferences {
std::set<std::string> stageDirNoPass, stageDirWrongRole, objectsWrongRole;
std::string stageDirWhy, stageDirShared;
};
std::expected<void, std::string> refuse_action_roles(const ActionRoleReferences& r);
// The objects a package contributes to an image that links it whole: its
// module units, which link unconditionally, then its implementation units, in
// plan order. A shared library that carries a private copy of a graph C++
// runtime takes the runtime package's objects through this (#641).
std::vector<std::filesystem::path>