Repository navigation
Expand file tree
/
Copy pathpipeline.cppm
More file actions
2053 lines (1990 loc) · 108 KB
/
Copy pathpipeline.cppm
File metadata and controls
2053 lines (1990 loc) · 108 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.pack.pipeline — pack orchestration: the plan of each configuration group
// of the members being packed (re-preparing for musl static when needed), what is
// refused before anything is compiled, one build per group, then for each member
// its program, its plan and the bundler, and one dispatch pass per group. The
// package of one directory is a group of one member, and runs the same steps.
export module mcpp.pack.pipeline;
import std;
import mcpp.build.runtime_placement;
import mcpp.build.prepare;
import mcpp.build.backend;
import mcpp.build.distribution;
import mcpp.build.flags;
import mcpp.build.ninja;
import mcpp.build.plan;
import mcpp.build.progress;
import mcpp.config;
import mcpp.fetcher.progress;
import mcpp.manifest;
import mcpp.pack;
import mcpp.pack.stage_tree;
import mcpp.pack.strip;
import mcpp.pack.compress;
import mcpp.runtime.launch_env;
import mcpp.toolchain.model;
import mcpp.toolchain.probe;
import mcpp.toolchain.registry;
import mcpp.toolchain.triple;
import mcpp.log;
import mcpp.ui;
import mcpp.diag;
import mcpp.provider;
import mcpp.provider.select;
import mcpp.toolchain.platform; // host_arch: the static row
import mcpp.pack.distribution; // the package's metadata, for a dispatched format
import mcpp.platform; // serves: a leg the platform states
namespace mcpp::pack {
// #622 A10: the CLI exit code, plus the artifact(s) this pass reported as
// "Packed" -- the staged tree or archive for a built-in format, or the
// distributable(s) a DISPATCHED format's provider submitted for THIS
// request. `mcpp run --format <name>` takes `artifacts.front()` as its run
// operand rather than re-deriving it: the reported path IS the thing rule 3
// ("declare unconditionally, submit conditionally") makes unambiguous, and a
// second derivation is a second place for it to disagree. Empty whenever
// `rc != 0`.
export struct PackOutcome {
int rc = 0;
std::vector<std::filesystem::path> artifacts;
// #649 E9: what `mcpp pack --message-format json` reports beside the
// artifacts. All of it was already answered by the pass that produced
// them; nothing here is derived for the report.
//
// `format` is the `--format` value as requested (`tar` when omitted);
// `targets` the canonical triple of every leg, the primary first. The
// stage fields are empty when no tree was staged; `closure` is the stage
// manifest's own word, `walked` or `not-walked`.
std::string format;
std::vector<std::string> targets;
std::filesystem::path stageDir;
std::filesystem::path stageManifest;
std::string closure;
// The axes the package was made with (SPEC-014 §9): `linkage`, `mode`,
// and the systems whose loaders it carries.
std::string linkage;
std::string mode;
std::vector<std::string> systems;
// Every container written, in the order `--pkg-format` named them (`format`
// is the first), and where the package runs (design 2026-10-29 §3.5, §4.4):
// its `runs_on`, or a single file's own pairs.
std::vector<std::string> formats;
std::vector<std::string> runsOnSelf;
std::map<std::string, std::vector<std::string>> runsOnWith;
// A pack of a package per leg (design 2026-10-29 §4.2): each artifact's
// legs, beside `artifacts`; empty when every artifact holds `targets`.
std::vector<std::vector<std::string>> artifactTargets;
// Whether a build program ran in this pack, for the envelope's `effects`.
bool ranBuildPrograms = false;
// What one packed member answered (member selection design 2026-09-30,
// K1). A pack of several members reports each in member order, and the
// fields above then describe the pack as a whole: `artifacts` holds every
// member's, and the stage fields, which name one tree, are the first
// member's. A pack of one member holds that member here as well.
struct Member {
std::string name; // qualified package name
int rc = 0;
std::vector<std::filesystem::path> artifacts;
std::string format;
std::vector<std::string> targets;
std::filesystem::path stageDir;
std::filesystem::path stageManifest;
std::string closure;
std::string linkage;
std::string mode;
std::vector<std::string> systems;
std::vector<std::string> formats;
std::vector<std::string> runsOnSelf;
std::map<std::string, std::vector<std::string>> runsOnWith;
// What the summary says after `Packed` (design 2026-10-29 §4.4,
// §4.8): the pairs a requested system or architecture is not covered
// on, each with its reason, and the hint of a one-leg tree.
std::vector<std::string> notCovered;
std::string hint;
};
std::vector<Member> members;
};
// #634 A3: the two directory lists an Android row's closure is read against,
// asked of the row's own driver rather than derived from the NDK's layout:
// where the link searches for a library (`-print-search-dirs`), and the
// directory the driver finds bionic's `libc.so` in, which is the API level's
// stub directory -- the set of names the device itself provides.
//
// A driver that answers neither leaves both lists empty; `pack::run` then
// reports that it cannot tell the device's libraries from the program's rather
// than staging stubs.
struct DriverLibraryDirs {
std::vector<std::filesystem::path> search;
std::vector<std::filesystem::path> platform;
};
DriverLibraryDirs driver_library_dirs(const mcpp::toolchain::Toolchain& tc)
{
DriverLibraryDirs out;
auto query = [&](std::string_view flag) {
std::vector<std::string> argv{ tc.binaryPath.string() };
if (!tc.crossTargetFlag.empty()) argv.push_back(tc.crossTargetFlag);
argv.emplace_back(flag);
return mcpp::toolchain::run_capture(argv, mcpp::toolchain::compiler_env(tc));
};
if (auto r = query("-print-search-dirs")) {
std::istringstream is{*r};
std::string line;
const std::string_view key = "libraries: =";
const auto sep = mcpp::runtime::launch_env::path_list_separator();
while (std::getline(is, line)) {
if (!line.starts_with(key)) continue;
std::string rest = mcpp::toolchain::trim_line(line.substr(key.size()));
std::size_t at = 0;
while (at <= rest.size()) {
auto next = rest.find(sep, at);
if (next == std::string::npos) next = rest.size();
if (next > at)
out.search.push_back(
std::filesystem::path(rest.substr(at, next - at)).lexically_normal());
at = next + sep.size();
}
}
}
if (auto r = query("-print-file-name=libc.so")) {
// A driver that cannot place the library echoes the bare name back.
std::filesystem::path lib(mcpp::toolchain::trim_line(*r));
std::error_code ec;
if (lib.has_parent_path() && std::filesystem::is_regular_file(lib, ec))
out.platform.push_back(lib.parent_path().lexically_normal());
}
return out;
}
// #630 A9: build every triple but the PRIMARY one for a `kind = "app"`
// target whose form is a shared object on every requested row (Android).
// Each leg is its own `prepare_build` + `ninja` build, the same shape
// `build_and_pack_library`'s leg loop uses and for the same reason: the
// artifact a leg contributes is the one THIS run made, never a glob over
// `target/` that could silently pick up a stale binary from an earlier
// build. The primary triple is not built here — it takes the ordinary
// single-triple `build_and_pack` path, which is what stages the tree,
// deploys the declared files once and runs the one dispatch pass; this
// function only produces the OTHER legs' bytes and where they belong.
//
// Returns `nullopt` on the first leg that fails, having already printed the
// error — the same contract `build_and_pack_library` and `build_and_pack`
// use, so `cmd_pack` only has to check the outcome and return.
export std::optional<std::vector<SharedLeg>>
build_extra_android_legs(const std::string& targetName,
std::span<const std::string> triples,
const std::string& profile,
const std::string& features)
{
std::vector<SharedLeg> out;
// Planned one after another, then built at once (mcpp.build.legs).
std::vector<mcpp::build::legs::Spec> specs;
for (auto const& triple : triples) {
mcpp::build::legs::Spec spec;
auto& ov = spec.overrides;
ov.target_triple = triple;
// A packaged artifact leaves this machine — same fallback as every
// other pack leg (`build_and_pack_library`, and the primary leg
// below).
ov.profile = profile;
ov.profile_fallback = "release";
ov.features = features;
specs.push_back(std::move(spec));
}
auto planned = mcpp::build::legs::plan(std::move(specs));
if (!planned) { mcpp::ui::error(planned.error()); return std::nullopt; }
std::vector<mcpp::build::BuildContext*> contexts;
for (auto& l : planned->legs) contexts.push_back(&l.ctx);
mcpp::build::progress::programs_done();
auto built = mcpp::build::legs::build(contexts, [](mcpp::build::BuildContext& c) {
auto be = mcpp::build::make_ninja_backend();
mcpp::build::BuildOptions bo;
if (auto br = be->build(c.plan, bo); !br) {
mcpp::build::report_failed_drive(br.error());
return 1;
}
mcpp::build::populate_dependency_cache(c);
return 0;
});
if (mcpp::build::legs::first_failure(built) != 0) return std::nullopt;
for (auto& planned_leg : planned->legs) {
const auto& triple = planned_leg.triple;
auto* ctx = &planned_leg.ctx;
// FROM THE PLAN, never a glob — see the function comment. A
// dependency's own `shared` target also contributes a `SharedLibrary`
// link unit to this plan, and `dependencyOwned` is what excludes it
// (the same exclusion `pipeline.cppm`'s `is_program_link_unit` makes
// for the primary leg).
const mcpp::build::LinkUnit* lu = nullptr;
for (auto const& u : ctx->plan.linkUnits)
if (u.targetName == targetName
&& u.kind == mcpp::build::LinkUnit::SharedLibrary
&& !u.dependencyOwned) { lu = &u; break; }
if (!lu) {
mcpp::ui::error(std::format(
"target '{}' produced no shared-object artifact for {}.\n"
" Every leg of a several-`--target` app pack must resolve to "
"the same shared-object\n"
" form the primary `--target` does; this row did not.",
targetName, triple));
return std::nullopt;
}
auto t = mcpp::toolchain::triple::parse(triple);
auto canonical = t ? t->str() : triple;
auto abi = t ? mcpp::toolchain::triple::android_abi(*t) : triple;
mcpp::ui::status("Packed leg", std::format("{} [{}]", canonical, abi));
// #634 A3: where THIS triple's closure is read from -- the same
// channels the primary leg's plan names (`build_and_pack` below), from
// this leg's own plan and driver.
SharedLeg leg;
leg.abi = std::move(abi);
leg.triple = canonical;
leg.artifact = ctx->outputDir / lu->output;
// #649 E5: what THIS leg's graph built, which pack strips as it strips
// the program; see `Plan::graphSharedLibraries`.
for (auto const& u : ctx->plan.linkUnits)
if (u.kind == mcpp::build::LinkUnit::SharedLibrary)
leg.graphSharedLibraries.push_back(ctx->outputDir / u.output);
leg.searchDirs.push_back(leg.artifact.parent_path());
for (auto const& d : ctx->plan.runtimeLibraryDirs) leg.searchDirs.push_back(d);
for (auto const& d : ctx->plan.linkIntent.runtimeSearchDirs)
leg.searchDirs.push_back(d);
for (auto const& d : ctx->plan.linkIntent.linkLibraryDirs)
leg.searchDirs.push_back(d);
for (auto const& d : ctx->plan.linkIntent.transitiveNeededDirs)
leg.searchDirs.push_back(d);
auto dirs = driver_library_dirs(ctx->tc);
for (auto const& d : dirs.search) leg.searchDirs.push_back(d);
leg.platformDirs = std::move(dirs.platform);
out.push_back(std::move(leg));
}
return out;
}
// The human report of what a dispatched format produced. A format may submit
// one output per file of a distribution tree (1,309 for one program of the
// validation project), and a line per file then buries the rest of the pass.
// Up to `kListedOutputs` outputs are named one per line; more are named by the
// entry each lies in below their common parent, with a count, and --verbose
// names every one. `--message-format json` lists every output in either case.
constexpr std::size_t kListedOutputs = 8;
void report_packed(const std::vector<std::filesystem::path>& outputs,
const mcpp::ui::PathContext& pathCtx) {
if (outputs.size() <= kListedOutputs || mcpp::log::is_verbose()) {
for (auto const& o : outputs)
mcpp::ui::status("Packed", mcpp::ui::shorten_path(o, pathCtx));
return;
}
auto parent = outputs.front().parent_path();
for (auto const& o : outputs) {
auto a = parent.begin(), b = o.begin();
std::filesystem::path common;
for (; a != parent.end() && b != o.end() && *a == *b; ++a, ++b) common /= *a;
parent = common;
}
// Each entry, in the order first reached, with the outputs below it and
// whether it is itself an output (then named alone).
struct Entry { std::filesystem::path path; std::size_t outputs = 0; bool isOutput = false; };
std::vector<Entry> entries;
for (auto const& o : outputs) {
// Outputs with no common parent (two drives) are named one by one.
const auto rel = parent.empty() ? std::filesystem::path{} : o.lexically_relative(parent);
const auto path = rel.empty() || rel == "." ? o : parent / *rel.begin();
auto it = std::ranges::find(entries, path, &Entry::path);
if (it == entries.end()) it = entries.insert(entries.end(), Entry{path});
++it->outputs;
it->isOutput = it->isOutput || path == o;
}
for (auto const& e : entries)
mcpp::ui::status("Packed", e.outputs == 1 && e.isOutput
? mcpp::ui::shorten_path(e.path, pathCtx)
: std::format("{} ({} {})", mcpp::ui::shorten_path(e.path, pathCtx), e.outputs,
e.outputs == 1 ? "file" : "files"));
}
// What `mcpp pack` over several workspace members packs (member selection
// design 2026-09-30, K1), as the command selected it.
//
// The members are planned as the selection `mcpp build` plans: once per
// configuration group, one graph and one build for the members of a group, so
// a package that several members reach is compiled once and its build program
// runs once. Packing each member alone would plan the graph, run the build
// programs and start the build again for each (#749).
export struct MemberPack {
// The workspace's root.
std::filesystem::path root;
// The packed members, each as `[workspace] members` spells it, by
// configuration group: members whose root-position values are equal are
// planned together. Every member has a program target to pack.
std::vector<std::vector<std::string>> groups;
// `--output` when several members are packed: the directory each member's
// archive or tree is written below, under the name it would have by
// default. Empty: each member's own `target/dist`.
std::filesystem::path outputDir;
// Every packed member, as `[workspace] members` spells it, in that order:
// the order the members are reported in, whichever group each is in.
std::vector<std::string> order;
};
// One member of a pack, and what each step learned of it. A project that is not
// a workspace member has one, which is the plan's own package.
struct MemberJob {
// The member's qualified package name.
std::string name;
// The member as `[workspace] members` spells it; empty outside a workspace.
std::string path;
// Whether the plan holds workspace members, and the member is read through
// `with_member`. False for a plain project, whose plan is its own view.
bool inWorkspace = false;
// This member's request: the command's, with the mode the member's manifest
// and the command line resolved to.
Options request;
bool modeFromUser = false;
// The request with what the plan answered added to it (`member_plan`).
Options opts;
// The program the member packs, from the member's link units.
std::filesystem::path mainBinary;
bool programIsSharedObject = false;
std::optional<Plan> plan;
// Set only when NO tree exists at all; see `stage_member`.
std::string stageFailure;
ClosureStatus closure;
mcpp::ui::PathContext pathCtx;
bool ranBuildPrograms = false;
// What the member's pack answered: its status, artifacts and stage.
PackOutcome::Member result;
};
// One configuration group: the plan of its members, what produced the plan,
// and the members. A plan of one package, or of the member a command runs in,
// is a group of one member.
struct GroupJob {
// The members as `[workspace] members` spells them; empty for the package
// of the directory the command runs in.
std::vector<std::string> paths;
// What produced `ctx`. It stays the record of it, because the dispatch pass
// prepares again with the same overrides plus the packaging pass's values.
mcpp::build::BuildOverrides ov;
std::optional<mcpp::build::BuildContext> ctx;
std::vector<MemberJob> members;
// The group failed as a whole: its plan, or its build.
int rc = 0;
};
// What the command asked for, and what every group of it shares.
struct PackRun {
Options opts;
bool modeFromUser = false;
std::string wantTarget;
std::vector<SharedLeg> extraLegs;
const MemberPack* selection = nullptr;
// More than one member is packed, so a line about one names it.
bool several = false;
// The value of a dispatched `--format` is not known to be one until prepare
// has run; see `prepare_group`.
bool quietUntilValidated = false;
// The command reports its build (`mcpp pack` in human output): the drives
// are stated as `mcpp build` states one (#753).
bool reporting = false;
std::optional<mcpp::config::GlobalConfig> cfg;
};
// A refusal: what the command exits with, and the message. The message is
// reported where the refusal is made.
struct Refusal {
int rc = 0;
std::string message;
};
// A line about a member names it when several are packed, and stays as it has
// always been for one.
std::string about(const PackRun& run, const MemberJob& m, std::string_view text) {
return run.several ? std::format("member '{}': {}", m.name, text) : std::string(text);
}
// Does the member's closure carry this program shipped through `artifacts`? In a
// plan of several members each program a member ships is placed in that member's
// product directory (`BuildPlan::LinkGroup::placements`), and the member's own
// files are the ones that directory holds.
bool member_carries(const mcpp::build::BuildContext& ctx, const MemberJob& m,
const mcpp::build::LinkUnit& u) {
if (!m.inWorkspace || ctx.workspaceMembers.size() < 2) return true;
for (auto const& g : ctx.plan.linkGroups) {
if (g.linkOnly || g.member != m.name) continue;
if (u.output.parent_path() == g.productDir) return true;
return std::ranges::any_of(g.placements,
[&](auto const& pl) { return pl.source == u.output; });
}
return false;
}
// The program a member packs, and everything the member's pack reads from the
// plan: its request resolved against the flags, and the pack plan. It reads the
// plan and no built file but the program's format (`make_plan`), so it is asked
// before the build of a pack of several members, for what it refuses and for
// where it writes, and again after it, for the plan `pack::run` executes.
//
// Called inside the member's view (`with_member`): `ctx.manifest`,
// `ctx.projectRoot` and the plan's link group are the member's.
// Whether a pack of `ctx`'s target stages the tree of a platform with a runner
// (design 2026-10-29 §4.2, §4.3): an image of a platform that states a
// runner, in a format other than a single file, whatever the number of legs.
bool packs_tree(const mcpp::build::BuildContext& ctx, const Options& opts) {
auto t = mcpp::toolchain::triple::parse(ctx.tc.targetTriple);
auto const& P = ctx.plan.platform;
return t && t->loader_supplies_os() && P.active && P.fields.runner.set && !P.fields.runner.cmd.empty()
&& opts.format != mcpp::pack::Format::SingleFile;
}
// The combinations of a member's pack refused before anything is built
// (SPEC-014 §1.5, design 2026-10-29 §4.7): what its options and the plan's
// platform already decide.
std::optional<std::string> refused_combination(const mcpp::build::BuildContext& ctx, const Options& opts) {
// A single file carries what it runs, whichever source stated the mode.
if (opts.format == mcpp::pack::Format::SingleFile && opts.mode == mcpp::pack::Mode::None)
return std::string("--pkg-format single-file carries what the program runs, and the mode is "
"system ([pack] default_mode).\n use: --mode vendored | self-contained");
// A single file is an executable of one system (the engine's launcher, or
// the platform's carrier); a WebAssembly module is no program of a system,
// and no launcher of `wasm32-linux-musl` (the row this would have tried)
// exists. The web is reached through a provider's page.
auto t = mcpp::toolchain::triple::parse(ctx.tc.targetTriple);
if (opts.format == mcpp::pack::Format::SingleFile && t && t->is_wasm())
return std::format("--pkg-format single-file makes an executable of one system, and {} "
"builds a WebAssembly module a JavaScript engine runs.\n"
" use: --pkg-format tar | zip | dir, or a provider's format "
"(dist-web of mcpp-plugins writes a page)", t->str());
auto const& P = ctx.plan.platform;
// Several images are one package's legs where the platform's runner
// starts them (the tree's launchers), or as single files.
if (opts.legTargets.size() > 1 && !packs_tree(ctx, opts) && opts.format != mcpp::pack::Format::SingleFile)
return std::format("several images are one package's legs where the platform starts them through "
"its runner, and {} states none.\n use: one pack per target, or "
"--pkg-format single-file", P.active ? P.display() : std::string("the target"));
for (auto const& target : opts.legTargets) {
auto lt = mcpp::toolchain::triple::parse(target);
if (lt && t && lt->str() != t->str() && !mcpp::platform::serves(P.fields, P.package, *lt))
return std::format("--target {} is not a target of {}", lt->str(), P.display());
}
// okb holds the images alone (okb v1): a self-contained tree's runner
// would be dropped (design 2026-10-29 §4.6).
const bool selfContained = opts.mode == mcpp::pack::Mode::BundleAll || opts.mode == mcpp::pack::Mode::Static;
const auto& named = opts.formats.empty() ? std::vector<std::string>{ opts.formatName } : opts.formats;
if (packs_tree(ctx, opts) && selfContained
&& std::ranges::all_of(named, [](std::string const& f) { return f == "okb"; }))
return std::string("--mode self-contained carries the runner under libexec/, and okb holds the "
"images alone; the runner would be dropped.\n use: --pkg-format tar,okb");
return std::nullopt;
}
std::optional<Refusal> member_plan(PackRun& run, GroupJob& g, MemberJob& m) {
auto& ctx = *g.ctx;
const bool sharedPlan = ctx.workspaceMembers.size() > 1;
Options opts = m.request;
// ─── Pick the main binary target ─────────────────────────────────
//
// An explicitly named target wins over the package-name convention: the
// user said which one, and guessing past that is how `mcpp pack app2`
// would produce app1's bundle under app2's name.
//
// #622 A3/A10: an `app` whose form on THIS row is a shared object still
// links as `LinkUnit::SharedLibrary` (`mcpp.build.plan`), so "is this
// link unit the program" cannot ask for `Binary` alone any more without
// reintroducing the refusal `Target::is_program()` exists to remove
// everywhere else this record sweeps (§2.3). `dependencyOwned` is
// excluded: a dependency's own `shared` target contributes a link unit to
// this plan too, and it is never the package being packed.
//
// In a plan of several members the link units are every member's, and a
// member packs the ones `memberOf` names it for.
auto is_program_link_unit = [&](const mcpp::build::LinkUnit& lu) {
if (sharedPlan && lu.memberOf != m.name) return false;
// A dependency's program shipped beside this one (mcpp#711) is staged
// as a file, never packed as the program.
if (lu.kind == mcpp::build::LinkUnit::Binary) return lu.artifactOf.empty();
if (lu.kind != mcpp::build::LinkUnit::SharedLibrary || lu.dependencyOwned)
return false;
for (auto const& t : ctx.manifest.targets)
if (t.name == lu.targetName)
return t.kind == mcpp::manifest::Target::Application;
return false;
};
// THE PROGRAM A FORMAT'S PROVIDER ASSEMBLES FROM (design 2026-11-15 N30).
// A provider that states `mcpp::pack_program` is followed when no program
// is named: the convention below knows nothing of the provider's own
// choice (a web directory configured for `app`), and packing another
// program left the provider nothing to wrap. A named program outranks it.
std::string want = run.wantTarget;
std::string wantFrom;
if (want.empty()) {
std::vector<std::pair<std::string, std::string>> stated; // provider, program
const auto& asked = run.opts.formats.empty() ? std::vector<std::string>{ run.opts.formatName }
: run.opts.formats;
for (auto const& format : asked) {
auto it = ctx.packFormatProviders.find(format);
if (format.empty() || mcpp::pack::is_builtin_pack_format(format)
|| it == ctx.packFormatProviders.end()) continue;
for (auto const& p : it->second) {
if (sharedPlan) {
auto reach = ctx.packReach.find(p);
if (reach == ctx.packReach.end() || mcpp::build::pack_owner(p, reach->second) != m.name)
continue;
}
auto pp = ctx.packPrograms.find(p);
if (pp == ctx.packPrograms.end()) continue;
for (auto const& name : pp->second)
if (std::ranges::none_of(stated, [&](auto const& e) { return e.second == name; }))
stated.emplace_back(p, name);
}
}
if (stated.size() > 1) {
std::string list;
for (auto const& [p, name] : stated) list += std::format("\n {} (stated by {})", name, p);
return Refusal{2, about(run, m, std::format(
"the providers of the requested formats state different programs:{}\n"
" name one: mcpp pack <program> --pkg-format <format>", list))};
}
if (!stated.empty()) { want = stated.front().second; wantFrom = stated.front().first; }
}
std::filesystem::path mainBinary;
const mcpp::build::LinkUnit* chosenLu = nullptr;
if (!want.empty()) {
for (auto& lu : ctx.plan.linkUnits) {
if (is_program_link_unit(lu) && lu.targetName == want) {
mainBinary = ctx.outputDir / lu.output;
chosenLu = &lu;
break;
}
}
if (mainBinary.empty())
return Refusal{2, about(run, m, wantFrom.empty()
? std::format("target '{}' is not a program in this build", want)
: std::format("{} states the program '{}' (mcpp::pack_program), which is not a program "
"in this build", wantFrom, want))};
}
for (auto& lu : ctx.plan.linkUnits) {
if (!mainBinary.empty()) break;
if (is_program_link_unit(lu) && lu.targetName == ctx.manifest.package.name) {
mainBinary = ctx.outputDir / lu.output;
chosenLu = &lu;
break;
}
}
// SEVERAL PROGRAMS ARE NOT PACKED WITHOUT A WORD (mcpp#911 B3): the
// program named after the package is the package's; with none so named,
// the first by name, as before. Either way the others are said, with the
// two ways to choose otherwise.
std::vector<const mcpp::build::LinkUnit*> programs;
for (auto const& lu : ctx.plan.linkUnits)
if (is_program_link_unit(lu)) programs.push_back(&lu);
const bool named = !mainBinary.empty();
if (mainBinary.empty() && !programs.empty()) {
mainBinary = ctx.outputDir / programs.front()->output;
chosenLu = programs.front();
}
if (mainBinary.empty())
return Refusal{1, about(run, m, "no binary target to pack")};
if (programs.size() > 1 && !opts.allPrograms && !wantFrom.empty())
mcpp::diag::note("pack", std::format("packing {}, the program {} states for its format", want, wantFrom));
if (programs.size() > 1 && !opts.allPrograms && want.empty()) {
std::string others;
for (auto const* lu : programs)
if (lu != chosenLu) others += (others.empty() ? "" : ", ") + lu->targetName;
mcpp::diag::note("pack", std::format(
"packing {}, {}; its other programs are not packed ({}): `mcpp pack <program>` names "
"another, `mcpp pack --all-programs` ships them beside it", chosenLu->targetName,
named ? "the program named after the package" : "the first by name, as none is named after the package",
others));
}
// Passed to `make_plan` rather than re-derived from the file: `make_plan`
// has only `mainBinary` and would otherwise have to ask the triple and
// the manifest the same question a second time.
const bool programIsSharedObject =
chosenLu && chosenLu->kind == mcpp::build::LinkUnit::SharedLibrary;
if (!run.cfg) {
auto cfg = mcpp::config::load_or_init(/*quiet=*/false,
mcpp::fetcher::make_bootstrap_progress_callback());
if (!cfg) return Refusal{4, cfg.error().message};
run.cfg = std::move(*cfg);
}
// ─── What the build promised, and where its runtime lives ────────
//
// The C++ runtime contract has been resolved since the flags were
// computed; `pack` simply had no way to see it (design §4.3), so on PE
// nothing enforced it and on ELF the `ldd` closure agreed with it by
// luck. Reading the RESOLVED value rather than the manifest string is the
// point: a request that was downgraded (a per-role self-contained on
// /MD, say) must not make the package behave as though it had been
// honoured.
{
const auto flags = mcpp::build::compute_flags(ctx.plan);
opts.carryToolchainRuntime =
flags.contractByRole[static_cast<std::size_t>(
mcpp::build::dist::Role::Distributable)]
== mcpp::build::dist::Contract::ToolchainCoupled;
// AN EXPLICIT `--mode system` OUTRANKS A DEFAULTED CONTRACT (#718,
// §7.3): the MSVC-ABI default is toolchain-coupled, and asking for
// `--mode system` on a project that never wrote `cxx_runtime` down is
// an explicit choice for host-coupled, not a contradiction — the
// contradiction is reserved for a manifest that SAID
// toolchain-coupled and a mode that bundles nothing (checked below,
// unchanged).
if (opts.mode == mcpp::pack::Mode::None
&& opts.carryToolchainRuntime
&& !flags.programCxxRuntimeStated) {
opts.carryToolchainRuntime = false;
}
opts.toolchainRuntimeDirs = ctx.plan.toolchain.linkRuntimeDirs;
if (!ctx.plan.toolchain.base.msvc.redistDir.empty())
opts.toolchainRuntimeDirs.push_back(ctx.plan.toolchain.base.msvc.redistDir);
// Where a third-party dependency's shared library may be found. Both
// channels, because they answer for different things: the runtime
// library dirs are what `mcpp run` puts on the loader's path, and the
// link intent's search dirs are what a dependency package declared.
opts.depSearchDirs = ctx.plan.runtimeLibraryDirs;
for (auto const& d : ctx.plan.linkIntent.runtimeSearchDirs)
opts.depSearchDirs.push_back(d);
// What the build placed relative to the executable (#615): the
// runtime placement resolver's answer (`CompileFlags::runtimeDeploy`),
// not the plan's candidates, so the package carries the files the
// build placed and no other. The destinations are `bin/<to>/<file>`,
// and the executable is in `bin/`.
//
// The MSVC C++ runtime's names are left to the closure below: in a
// mode that carries the toolchain's runtime it resolves them beside
// the program, where the build placed the chosen set; otherwise they
// are the host's (`hostProvidedLibs`), whichever directory offers a
// copy. A copy found in a dependency's directory never enters a
// package that the contract says the host serves.
namespace rp = mcpp::build::runtime_placement;
const bool msvcAbi = mcpp::toolchain::is_msvc_target(ctx.plan.toolchain);
// Relative to the program's directory: `bin`, or a workspace member's
// product directory (§15 of the 2026-09-29 workspace design).
const auto& productDir = ctx.plan.productDir;
for (auto const& d : flags.runtimeDeploy) {
if (msvcAbi && d.dest.parent_path() == productDir
&& rp::is_msvc_crt_name(d.dest.filename().string()))
continue;
opts.runtimeFiles.push_back(d.dest.lexically_relative(productDir));
}
if (msvcAbi && !opts.carryToolchainRuntime && flags.runtimeCrtPolicy != "static")
for (auto n : rp::kMsvcCrtNames) opts.hostProvidedLibs.emplace_back(n);
// A dependency's program the manifest ships with this one (mcpp#711,
// `artifacts = [...]`) is linked into `bin/` beside the executable, so
// it is staged the way a deployed file is.
// In a workspace member's product directory it is the placed copy.
for (auto const& u : ctx.plan.linkUnits)
if (!u.artifactOf.empty() && member_carries(ctx, m, u))
opts.runtimeFiles.push_back(productDir == "bin"
? u.output.lexically_relative("bin")
: std::filesystem::path(u.output.filename()));
// `--all-programs`: the package's other programs, beside the chosen one.
if (opts.allPrograms)
for (auto const* u : programs)
if (u != chosenLu && u->kind == mcpp::build::LinkUnit::Binary) {
opts.runtimeFiles.push_back(productDir == "bin"
? u->output.lexically_relative("bin")
: std::filesystem::path(u->output.filename()));
opts.otherPrograms.push_back(u->output.filename().string());
}
// #634 A3: the Android row reads its closure against the directories
// its link declared -- a prebuilt library named through `[runtime]
// link_library_dirs` is a file the link used and the device does not
// have -- and against its driver's; see `driver_library_dirs`.
if (programIsSharedObject) {
for (auto const& d : ctx.plan.linkIntent.linkLibraryDirs)
opts.depSearchDirs.push_back(d);
for (auto const& d : ctx.plan.linkIntent.transitiveNeededDirs)
opts.depSearchDirs.push_back(d);
auto dirs = driver_library_dirs(ctx.tc);
opts.toolchainLibraryDirs = std::move(dirs.search);
opts.platformLibraryDirs = std::move(dirs.platform);
}
}
// ─── A loaded artifact: the static row, the tree and its legs ─────
//
// `--mode static` of an image is `--linkage static --mode self-contained`
// (SPEC-014 §1.2). An image of a platform that states a runner is packed
// as its tree whatever the number of legs (design 2026-10-29 §4.3); the
// legs are the targets the command named, a set expanded (§4.2), and a
// tree of several is named after the platform. A single file is made per
// leg and system.
std::vector<mcpp::pack::LoadedLeg> loadedLegs;
{
auto t = mcpp::toolchain::triple::parse(ctx.tc.targetTriple);
const bool loaded = t && t->loader_supplies_os();
if (loaded && opts.mode == mcpp::pack::Mode::Static) opts.mode = mcpp::pack::Mode::BundleAll;
auto const& P = ctx.plan.platform;
if (auto why = refused_combination(ctx, opts)) return Refusal{2, about(run, m, *why)};
// COMPAT(platform-universal): `[platform] universal` decides nothing.
static bool saidUniversal = false;
if (loaded && P.active && P.fields.universal.set && !std::exchange(saidUniversal, true)) {
mcpp::pm::compat::record_use("platform-universal", P.package, "[platform] universal", true);
mcpp::diag::note("pack", std::format(
"{} states `universal`, which no longer decides what a pack holds: the legs are the "
"targets the command names ({}); `--target {}` packs every architecture",
P.display(), mcpp::pm::compat::deprecation_clause(
*mcpp::pm::compat::find_deprecation("platform-universal")),
mcpp::manifest::platform::platform_name(P.package.substr(P.package.find('.') + 1))));
}
opts.tree = packs_tree(ctx, opts);
if (opts.tree && opts.legTargets.size() > 1)
opts.universalName = mcpp::manifest::platform::platform_name(
P.package.substr(P.package.find('.') + 1));
if (loaded && opts.legTargets.size() > 1) {
// The other legs are planned one after another and built at once
// (mcpp.build.legs); this leg is the pack's own.
std::vector<mcpp::build::legs::Spec> specs;
for (auto const& target : opts.legTargets) {
auto lt = mcpp::toolchain::triple::parse(target);
if (!lt || lt->str() == t->str()) continue;
mcpp::build::legs::Spec spec{g.ov};
auto& ov = spec.overrides;
ov.target_triple = lt->str();
// The member's own plan, in a workspace; the project's otherwise.
ov.workspace_members.clear();
ov.workspace_request.clear();
if (m.inWorkspace && !m.path.empty()) {
ov.workspace_members = { m.path };
ov.workspace_request = { m.path };
}
specs.push_back(std::move(spec));
}
auto planned = mcpp::build::legs::plan(std::move(specs));
if (!planned) return Refusal{1, about(run, m, planned.error())};
std::vector<mcpp::build::BuildContext*> contexts;
for (auto& l : planned->legs) contexts.push_back(&l.ctx);
auto built = mcpp::build::legs::build(contexts, [](mcpp::build::BuildContext& c) {
auto be = mcpp::build::make_ninja_backend();
mcpp::build::BuildOptions bo;
if (auto br = be->build(c.plan, bo); !br) {
mcpp::build::report_failed_drive(br.error());
return 1;
}
mcpp::build::populate_dependency_cache(c);
return 0;
});
for (std::size_t i = 0; i < planned->legs.size(); ++i) {
auto const& leg = planned->legs[i];
if (built[i] != 0)
return Refusal{1, about(run, m, std::format("the {} leg did not build", leg.triple))};
std::filesystem::path artifact;
for (auto const& lu : leg.ctx.plan.linkUnits)
if (lu.targetName == chosenLu->targetName && lu.kind == chosenLu->kind
&& !lu.dependencyOwned
&& (leg.ctx.workspaceMembers.size() < 2 || lu.memberOf == m.name)) {
artifact = leg.ctx.outputDir / lu.output;
break;
}
if (artifact.empty()) return Refusal{1, about(run, m, std::format(
"the {} leg built no '{}'", leg.triple, chosenLu->targetName))};
auto lt = mcpp::toolchain::triple::parse(leg.triple);
mcpp::ui::status("Packed leg", leg.triple);
loadedLegs.push_back({ leg.triple, lt ? lt->arch : std::string{}, artifact });
}
}
}
// ─── Build the plan ──────────────────────────────────────────────
opts.baseStated = ctx.tc.base.stated();
auto plan = mcpp::pack::make_plan(ctx.manifest, *run.cfg, opts,
mainBinary, ctx.projectRoot, ctx.tc.targetTriple,
// From the RESOLVED graph. `mcpp why runtime` on a real imgui project
// lists `capability:opengl.glx.driver <- compat.glfw@3.4` — none of
// which appears in the project's own manifest.
ctx.plan.runtimeRequirements, programIsSharedObject);
if (!plan) return Refusal{1, about(run, m, plan.error().message)};
plan->platform = ctx.plan.platform;
plan->loadedLegs = std::move(loadedLegs);
plan->programStatic = ctx.plan.manifest.buildConfig.linkage == "static";
plan->linkageName = opts.linkage == mcpp::pack::Linkage::Static ? "static"
: opts.linkage == mcpp::pack::Linkage::Shared ? "shared"
: opts.mode == mcpp::pack::Mode::Static ? "static"
: ctx.plan.manifest.buildConfig.dependencyLinkage.empty()
? "declared" : ctx.plan.manifest.buildConfig.dependencyLinkage;
// `--output <dir>` with several members: each member's archive, or its tree
// for `--format dir`, is written below the directory under the name it would
// have by default. The staging tree of an archive, and of a dispatched
// format, stays in the member's `target/dist`, as it does for `-o <file>`.
if (run.selection && !run.selection->outputDir.empty()) {
plan->archivePath = run.selection->outputDir / plan->archivePath.filename();
if (opts.format == mcpp::pack::Format::Dir)
plan->stagingRoot = run.selection->outputDir / plan->stagingRoot.filename();
}
m.opts = std::move(opts);
m.mainBinary = std::move(mainBinary);
m.programIsSharedObject = programIsSharedObject;
m.plan = std::move(*plan);
return std::nullopt;
}
// Prepares one group of the pack: the plan of its members, and what is decided
// from it alone.
std::optional<Refusal> prepare_group(PackRun& run, GroupJob& g) {
// QUIET FOR A DISPATCHED FORMAT, AND ONLY UNTIL THE VALUE IS VALIDATED.
//
// `mcpp pack --format bogus` must write NOTHING to stdout and exit 2 --
// the machine-output contract, asserted by
// tests/e2e/202_machine_output_contract.sh, because this is the path a
// client hits when it probes an mcpp for a capability. The set of valid
// values is a property of the resolved graph, so the refusal cannot be
// decided until prepare has run, and prepare narrates what it resolves.
//
// Nothing is lost when the value IS valid: the dispatch pass prepares a
// second time and prints the same lines, so a successful
// `pack --format <name>` narrates once rather than twice.
auto prepare = [&]() {
if (run.quietUntilValidated) mcpp::ui::set_quiet(true);
auto ctx = mcpp::build::prepare_build(/*print_fp=*/false, /*includeDevDeps=*/false,
/*extraTargets=*/{}, g.ov);
if (run.quietUntilValidated) mcpp::ui::set_quiet(false);
return ctx;
};
auto ctx = prepare();
if (!ctx) return Refusal{2, ctx.error()};
g.ctx = std::move(*ctx);
// The members of the group: the workspace members of its plan, in
// selection order, or the plan's own package.
if (g.ctx->workspaceMembers.empty()) {
MemberJob m;
m.name = mcpp::build::qualified_package_name(g.ctx->manifest);
g.members.push_back(std::move(m));
} else {
for (auto const& wm : g.ctx->workspaceMembers) {
MemberJob m;
m.name = wm.name;
m.path = wm.memberPath;
m.inWorkspace = true;
g.members.push_back(std::move(m));
}
}
auto manifest_of = [&](const MemberJob& m) -> const mcpp::manifest::Manifest& {
if (!m.inWorkspace) return g.ctx->manifest;
for (auto const& wm : g.ctx->workspaceMembers)
if (wm.name == m.name) return wm.manifest;
return g.ctx->manifest;
};
// Manifest may override mode only when neither --mode nor an
// equivalent flag (--target *-musl → static) was given.
// A workspace plan's subject is its selected member (§15).
for (auto& m : g.members) {
m.request = run.opts;
m.modeFromUser = run.modeFromUser;
const auto& mf = manifest_of(m);
if (!m.modeFromUser && !mf.packConfig.defaultMode.empty()) {
if (auto mode = mcpp::pack::parse_mode(mf.packConfig.defaultMode))
m.request.mode = *mode;
}
}
// Re-derive target triple: if mode is Static we force the musl
// triple even when the manifest's [pack].default_mode bumped us
// here after `prepare_build` ran with the host toolchain.
//
// ...but NOT over a target the user asked for. `--mode static` on its own
// has always meant "the musl-static ELF", and that stays; `--mode static
// --target x86_64-windows-gnu` used to silently become a Linux build,
// which was invisible while PE packaging did not exist and is a wrong
// answer now that it does. An explicit `--target` is an instruction.
//
// One group is one target, so the members of a group that want the static
// row must all want it.
const bool anyStatic = std::ranges::any_of(g.members, [](const MemberJob& m) {
return m.request.mode == mcpp::pack::Mode::Static; });
if (anyStatic
&& run.opts.targetTriple.empty()
&& g.ctx->tc.targetTriple.find("-musl") == std::string::npos) {
if (auto other = std::ranges::find_if(g.members, [](const MemberJob& m) {
return m.request.mode != mcpp::pack::Mode::Static; });
other != g.members.end()) {
auto first = std::ranges::find_if(g.members, [](const MemberJob& m) {
return m.request.mode == mcpp::pack::Mode::Static; });
return Refusal{2, std::format(
"member '{}' packs as --mode static, which links for the musl target, and "
"member '{}' does not, and the two share one build.\n"
" use: --mode <mode> for both, or pack them separately",
first->name, other->name)};
}
// Need to re-prepare the build with the musl target.
//
// `ov` IS MUTATED RATHER THAN SHADOWED. It has to stay the record of
// what produced `ctx`, because the dispatch pass below re-enters
// prepare with the same overrides plus two fields -- and a second
// overrides object left behind here would make that pass differ from
// this build in a way nothing states.
g.ov.target_triple = std::format("{}-linux-musl", mcpp::toolchain::platform::host_arch);
// Quiet on the same grounds as the first prepare: this one also runs
// before `--format` has been validated.
auto ctx2 = prepare();
if (!ctx2) return Refusal{2, ctx2.error()};
g.ctx = std::move(*ctx2);
}
return std::nullopt;
}
// Is the requested format one the group provides, and for which members? The
// refusals of a dispatched `--format`, before the build.
std::optional<Refusal> check_format(PackRun& run, GroupJob& g) {
auto const& ctx = *g.ctx;
// What each member's options and the platform decide.
for (auto const& m : g.members) {
std::optional<std::string> why;
mcpp::build::with_member(*g.ctx, m.inWorkspace ? m.name : std::string_view{}, [&] {
why = refused_combination(ctx, m.request);
});
if (why) return Refusal{2, about(run, m, *why)};
}
// ─── `--systems` names the runners a package carries ─────────────
//
// A self-contained tree carries a runner per system and architecture of
// its legs, and a single file of an image is made per leg and system;
// nothing else is made per system. Refused here, before the build
// (SPEC-014 §1.5, design 2026-10-29 §4.7); `[pack] systems` that does not
// fit the pack is said and left aside, as `[pack] compress` is.
if (!run.opts.systems.empty()) {
auto t = mcpp::toolchain::triple::parse(ctx.tc.targetTriple);
const bool loaded = t && t->loader_supplies_os();
// A polyglot file holds an image's single files of several systems; a
// program of one system has one (SPEC-014 §5.3).
if (run.opts.polyglot && !loaded)
return Refusal{2, std::format(
"--pkg-format polyglot holds the single files of an ok image for several systems, and "
"{} is a program of one system.\n use: --pkg-format single-file, or --target openkal",
t ? t->str() : ctx.tc.targetTriple)};
const bool tree = packs_tree(ctx, run.opts);
const bool selfContained = run.opts.mode == mcpp::pack::Mode::BundleAll
|| run.opts.mode == mcpp::pack::Mode::Static;
const bool singleFile = loaded && run.opts.format == mcpp::pack::Format::SingleFile;
if (!(tree && selfContained) && !singleFile) {
if (run.opts.systemsFromManifest) {
mcpp::diag::note("pack", std::format(
"[pack] systems names the runners a self-contained tree carries, or the systems "
"single files of an image are made for; this pack is neither (--mode {}), so it "
"is left aside", mcpp::pack::mode_cli_name(run.opts.mode)));
for (auto& m : g.members) m.request.systems.clear();
run.opts.systems.clear();
} else {
return Refusal{2, tree
? std::format("--systems names the runners a self-contained package carries, and "
"--mode {} carries none.\n use: --mode self-contained",
mcpp::pack::mode_cli_name(run.opts.mode))
: std::string("--systems names the runners a self-contained package of images "
"carries, or the systems single files of an image are made for; this "
"pack is neither.\n use: --mode self-contained over a platform that "
"states a runner, or --pkg-format single-file")};
}
}
}
if (!run.opts.systems.empty()) {
auto t = mcpp::toolchain::triple::parse(ctx.tc.targetTriple);
const bool loaded = t && t->loader_supplies_os();
std::vector<std::string> archs;
for (auto const& l : run.opts.legTargets)
if (auto lt = mcpp::toolchain::triple::parse(l)) archs.push_back(lt->arch);
if (archs.empty() && t) archs.push_back(t->arch);
// An `<os>-<arch>` of no leg's architecture names nothing the pack makes.
for (auto const& e : run.opts.systems) {
const auto dash = e.find('-');
if (dash == std::string::npos) continue;
if (std::ranges::find(archs, e.substr(dash + 1)) == archs.end())