-
Notifications
You must be signed in to change notification settings - Fork 270
Expand file tree
/
Copy pathbuild.zig
More file actions
3265 lines (3160 loc) · 248 KB
/
Copy pathbuild.zig
File metadata and controls
3265 lines (3160 loc) · 248 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
const std = @import("std");
const web_engine_tool = @import("src/tooling/web_engine.zig");
const PlatformOption = enum {
auto,
null,
macos,
linux,
windows,
};
const TraceOption = enum {
off,
events,
runtime,
all,
};
const WebEngineOption = enum {
system,
chromium,
};
const PackageTarget = enum {
macos,
windows,
linux,
ios,
android,
};
const SigningMode = enum {
none,
adhoc,
identity,
};
pub const AppOptions = @import("build/app.zig").AppOptions;
pub const addApp = @import("build/app.zig").addApp;
pub const AppArtifacts = @import("build/app.zig").AppArtifacts;
pub const addAppArtifacts = @import("build/app.zig").addAppArtifacts;
pub const MobileLibOptions = @import("build/app.zig").MobileLibOptions;
pub const addMobileLib = @import("build/app.zig").addMobileLib;
const mobile_export_symbol_names = @import("build/app.zig").mobile_export_symbol_names;
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const host_target = b.graph.host;
const optimize = b.standardOptimizeOption(.{});
const platform_option = b.option(PlatformOption, "platform", "Desktop backend: auto, null, macos, linux, windows") orelse .auto;
const trace_option = b.option(TraceOption, "trace", "Trace output: off, events, runtime, all") orelse .events;
_ = b.option(bool, "debug-overlay", "Enable debug overlay output") orelse false;
_ = b.option(bool, "automation", "Enable Native SDK automation artifacts") orelse false;
_ = b.option(bool, "webview", "Deprecated compatibility flag; native surfaces are always enabled") orelse true;
const web_engine_override = b.option(WebEngineOption, "web-engine", "Override app.zon web engine: system, chromium");
const cef_dir_override = b.option([]const u8, "cef-dir", "Override CEF root directory for Chromium builds");
const cef_auto_install_override = b.option(bool, "cef-auto-install", "Override app.zon CEF auto-install setting");
_ = b.option(bool, "js-bridge", "Enable optional JavaScript bridge stubs") orelse false;
const package_target = b.option(PackageTarget, "package-target", "Package target: macos, windows, linux, ios, android") orelse .macos;
const signing_mode = b.option(SigningMode, "signing", "Signing mode: none, adhoc, identity") orelse .none;
const package_version = packageVersion(b);
const optimize_name = @tagName(optimize);
// Resolve against THIS build's root: as a dependency of a user app the
// build runner's cwd is the app project, and a cwd-relative "app.zon"
// would read (and panic on) the user's manifest instead of ours.
const app_web_engine = web_engine_tool.readManifestConfig(b.allocator, b.graph.io, b.pathFromRoot("app.zon")) catch |err| {
std.debug.panic("failed to read the framework's own app.zon web engine config: {s}", .{@errorName(err)});
};
const resolved_web_engine = web_engine_tool.resolve(app_web_engine, .{
.web_engine = if (web_engine_override) |value| webEngineFromBuildOption(value) else null,
.cef_dir = cef_dir_override,
.cef_auto_install = cef_auto_install_override,
}) catch |err| {
std.debug.panic("invalid app.zon web engine config: {s}", .{@errorName(err)});
};
const web_engine = buildWebEngineFromResolved(resolved_web_engine.engine);
const browser_web_engine: WebEngineOption = web_engine_override orelse .system;
const cef_auto_install = resolved_web_engine.cef_auto_install;
const selected_platform: PlatformOption = switch (platform_option) {
.auto => if (target.result.os.tag == .macos) .macos else if (target.result.os.tag == .linux) .linux else if (target.result.os.tag == .windows) .windows else .null,
else => platform_option,
};
const cef_dir = cef_dir_override orelse defaultCefDir(selected_platform, resolved_web_engine.cef_dir);
if (selected_platform == .macos and target.result.os.tag != .macos) {
@panic("-Dplatform=macos requires a macOS target");
}
if (selected_platform == .linux and target.result.os.tag != .linux) {
@panic("-Dplatform=linux requires a Linux target");
}
if (selected_platform == .windows and target.result.os.tag != .windows) {
@panic("-Dplatform=windows requires a Windows target");
}
if (web_engine == .chromium and selected_platform != .macos) {
@panic("-Dweb-engine=chromium currently requires -Dplatform=macos");
}
const geometry_mod = module(b, target, optimize, "src/primitives/geometry/root.zig");
const assets_mod = module(b, target, optimize, "src/primitives/assets/root.zig");
const app_dirs_mod = module(b, target, optimize, "src/primitives/app_dirs/root.zig");
const trace_mod = module(b, target, optimize, "src/primitives/trace/root.zig");
const app_manifest_mod = module(b, target, optimize, "src/primitives/app_manifest/root.zig");
const diagnostics_mod = module(b, target, optimize, "src/primitives/diagnostics/root.zig");
const platform_info_mod = module(b, target, optimize, "src/primitives/platform_info/root.zig");
const json_mod = module(b, target, optimize, "src/primitives/json/root.zig");
const canvas_mod = module(b, target, optimize, "src/primitives/canvas/root.zig");
canvas_mod.addImport("geometry", geometry_mod);
canvas_mod.addImport("json", json_mod);
if (target.result.os.tag == .macos) {
// The estimator-vs-CoreText agreement test (text_metrics_tests.zig)
// shapes the bundled face through CoreText; apps already link these
// transitively via AppKit.
canvas_mod.linkFramework("CoreFoundation", .{});
canvas_mod.linkFramework("CoreGraphics", .{});
canvas_mod.linkFramework("CoreText", .{});
canvas_mod.linkSystemLibrary("c", .{});
}
const debug_mod = module(b, target, optimize, "src/debug/root.zig");
debug_mod.addImport("app_dirs", app_dirs_mod);
debug_mod.addImport("trace", trace_mod);
const geometry_tests = testArtifact(b, geometry_mod);
const assets_tests = testArtifact(b, assets_mod);
const app_dirs_tests = testArtifact(b, app_dirs_mod);
const trace_tests = testArtifact(b, trace_mod);
const app_manifest_tests = testArtifact(b, app_manifest_mod);
const diagnostics_tests = testArtifact(b, diagnostics_mod);
const platform_info_tests = testArtifact(b, platform_info_mod);
const json_tests = testArtifact(b, json_mod);
const canvas_tests = testArtifact(b, canvas_mod);
const desktop_mod = module(b, target, optimize, "src/root.zig");
desktop_mod.addImport("geometry", geometry_mod);
desktop_mod.addImport("app_dirs", app_dirs_mod);
desktop_mod.addImport("assets", assets_mod);
desktop_mod.addImport("trace", trace_mod);
desktop_mod.addImport("app_manifest", app_manifest_mod);
desktop_mod.addImport("diagnostics", diagnostics_mod);
desktop_mod.addImport("platform_info", platform_info_mod);
desktop_mod.addImport("json", json_mod);
desktop_mod.addImport("canvas", canvas_mod);
const desktop_tests = testArtifact(b, desktop_mod);
const desktop_test_shards = desktopTestShardArtifacts(b, desktop_mod);
// The embeddable static library's root module carries only the C ABI
// exports (fixed WebView shell host); user-app canvas libraries are
// produced by `addMobileLib` from src/embed/app_exports.zig instead.
const embed_exports_mod = module(b, target, optimize, "src/embed/c_exports.zig");
embed_exports_mod.addImport("native_sdk", desktop_mod);
embed_exports_mod.export_symbol_names = &mobile_export_symbol_names;
const embed_lib = b.addLibrary(.{
.linkage = .static,
.name = "native-sdk",
.root_module = embed_exports_mod,
// The embed C ABI (`native_sdk_app_viewport`) is exactly the
// f32-heavy SysV signature Zig 0.16.0's self-hosted x86_64 backend
// miscompiles (see useLlvmWorkaround in build/app.zig): without
// this, Debug x86_64 libs (Android emulators, Intel simulators)
// hand clang hosts corrupted inset/keyboard floats. addMobileLib
// already forces LLVM there; the fixed-shell lib must match.
.use_llvm = @import("build/app.zig").useLlvmWorkaround(target),
});
b.installArtifact(embed_lib);
const automation_protocol_mod = module(b, target, optimize, "src/automation/protocol.zig");
const automation_protocol_tests = testArtifact(b, automation_protocol_mod);
// The app-icon pipeline as a standalone module: tooling needs only
// the vector core + PNG codec slice of canvas, not the full canvas
// module (which links platform frameworks on macOS and would weigh
// down the cross-compiled CLI).
const app_icon_mod = module(b, target, optimize, "src/primitives/canvas/app_icon.zig");
app_icon_mod.addImport("geometry", geometry_mod);
// The iOS and Android host sources as embedded bytes: the tooling
// module writes and compiles them for `native dev|package --target
// ios|android`.
const ios_host_mod = module(b, target, optimize, "src/platform/ios/files.zig");
const android_host_mod = module(b, target, optimize, "src/platform/android/files.zig");
const tooling_mod = module(b, target, optimize, "src/tooling/root.zig");
tooling_mod.addImport("assets", assets_mod);
tooling_mod.addImport("app_dirs", app_dirs_mod);
tooling_mod.addImport("app_manifest", app_manifest_mod);
tooling_mod.addImport("diagnostics", diagnostics_mod);
tooling_mod.addImport("debug", debug_mod);
tooling_mod.addImport("platform_info", platform_info_mod);
tooling_mod.addImport("trace", trace_mod);
tooling_mod.addImport("app_icon", app_icon_mod);
tooling_mod.addImport("ios_host", ios_host_mod);
tooling_mod.addImport("android_host", android_host_mod);
const tooling_tests = testArtifact(b, tooling_mod);
// Ejected-component identity proofs: a separate test module because
// the canonical component sources under src/tooling/components/
// import `native_sdk` exactly as they will inside an app after
// `native eject component <name>` copies them there.
const eject_components_mod = module(b, target, optimize, "src/tooling/components/identity_tests.zig");
eject_components_mod.addImport("native_sdk", desktop_mod);
const eject_components_tests = testArtifact(b, eject_components_mod);
// Transpiled-core end-to-end suite: tests/ts-core/fixture.ts is
// emitted by the repo's own transpiler AT BUILD TIME (never a
// committed Zig snapshot) and driven through the real runtime via
// `TsCoreHost`. Gated on node plus the transpiler package's
// installed dependency: absent either, the suite is skipped (the
// bridge itself stays covered by src/runtime/ts_core_host_tests.zig
// against a hand-written emitted-ABI core).
const ts_core_e2e_tests = tsCoreE2eArtifact(b, target, optimize, desktop_mod, tooling_mod);
const ui_markup_mod = module(b, target, optimize, "src/primitives/canvas/ui_markup.zig");
const markup_lsp_mod = module(b, target, optimize, "tools/native-sdk/markup_lsp.zig");
markup_lsp_mod.addImport("ui_markup", ui_markup_mod);
const markup_lsp_tests = testArtifact(b, markup_lsp_mod);
const automation_cli_mod = module(b, target, optimize, "tools/native-sdk/automation.zig");
automation_cli_mod.addImport("automation_protocol", automation_protocol_mod);
automation_cli_mod.addImport("ui_markup", ui_markup_mod);
const automation_cli_tests = testArtifact(b, automation_cli_mod);
const markup_cli_mod = module(b, target, optimize, "tools/native-sdk/markup.zig");
markup_cli_mod.addImport("ui_markup", ui_markup_mod);
markup_cli_mod.addImport("markup_lsp", markup_lsp_mod);
const markup_cli_tests = testArtifact(b, markup_cli_mod);
// The evals harness's Cmd wire-format decoder (copied next to every
// ts-track case harness at grading time). Its own tests run here —
// NOT at eval time — because a decoder that lags a
// cmd_format_version bump panics mid-eval inside case harnesses,
// where the failure reads as the graded app's, not the tooling's.
const evals_cmdview_mod = module(b, target, optimize, "evals/harness-lib/cmdview.zig");
const evals_cmdview_tests = testArtifact(b, evals_cmdview_mod);
// `native version` names the commit the binary was built from, so
// binary/framework skew ("your native binary may be stale") is a
// one-command check. Falls back to "unknown" outside a git checkout.
const cli_build_info = b.addOptions();
cli_build_info.addOption([]const u8, "build_commit", cliBuildCommit(b));
const cli_mod = module(b, target, optimize, "tools/native-sdk/main.zig");
cli_mod.addImport("tooling", tooling_mod);
cli_mod.addImport("automation_protocol", automation_protocol_mod);
cli_mod.addImport("ui_markup", ui_markup_mod);
cli_mod.addImport("markup_lsp", markup_lsp_mod);
cli_mod.addOptions("cli_build_info", cli_build_info);
const cli_exe = b.addExecutable(.{
.name = "native",
.root_module = cli_mod,
});
b.installArtifact(cli_exe);
// `zig build cli` builds and installs ONLY the CLI executable. The
// release pipeline cross-compiles it for every supported platform
// (packages/native-sdk/scripts/build-binaries.sh), and skipping the
// framework libraries, examples, and docs artifacts keeps that
// eight-target loop fast.
const cli_step = b.step("cli", "Build only the native CLI executable (cross-compile friendly)");
cli_step.dependOn(&b.addInstallArtifact(cli_exe, .{}).step);
const host_assets_mod = module(b, host_target, optimize, "src/primitives/assets/root.zig");
const host_app_dirs_mod = module(b, host_target, optimize, "src/primitives/app_dirs/root.zig");
const host_app_manifest_mod = module(b, host_target, optimize, "src/primitives/app_manifest/root.zig");
const host_diagnostics_mod = module(b, host_target, optimize, "src/primitives/diagnostics/root.zig");
const host_platform_info_mod = module(b, host_target, optimize, "src/primitives/platform_info/root.zig");
const host_trace_mod = module(b, host_target, optimize, "src/primitives/trace/root.zig");
const host_debug_mod = module(b, host_target, optimize, "src/debug/root.zig");
host_debug_mod.addImport("app_dirs", host_app_dirs_mod);
host_debug_mod.addImport("trace", host_trace_mod);
const host_automation_protocol_mod = module(b, host_target, optimize, "src/automation/protocol.zig");
const host_geometry_mod = module(b, host_target, optimize, "src/primitives/geometry/root.zig");
const host_app_icon_mod = module(b, host_target, optimize, "src/primitives/canvas/app_icon.zig");
host_app_icon_mod.addImport("geometry", host_geometry_mod);
const host_ios_host_mod = module(b, host_target, optimize, "src/platform/ios/files.zig");
const host_android_host_mod = module(b, host_target, optimize, "src/platform/android/files.zig");
const host_tooling_mod = module(b, host_target, optimize, "src/tooling/root.zig");
host_tooling_mod.addImport("assets", host_assets_mod);
host_tooling_mod.addImport("app_dirs", host_app_dirs_mod);
host_tooling_mod.addImport("app_manifest", host_app_manifest_mod);
host_tooling_mod.addImport("diagnostics", host_diagnostics_mod);
host_tooling_mod.addImport("debug", host_debug_mod);
host_tooling_mod.addImport("platform_info", host_platform_info_mod);
host_tooling_mod.addImport("trace", host_trace_mod);
host_tooling_mod.addImport("app_icon", host_app_icon_mod);
host_tooling_mod.addImport("ios_host", host_ios_host_mod);
host_tooling_mod.addImport("android_host", host_android_host_mod);
const host_ui_markup_mod = module(b, host_target, optimize, "src/primitives/canvas/ui_markup.zig");
const host_markup_lsp_mod = module(b, host_target, optimize, "tools/native-sdk/markup_lsp.zig");
host_markup_lsp_mod.addImport("ui_markup", host_ui_markup_mod);
const host_cli_mod = module(b, host_target, optimize, "tools/native-sdk/main.zig");
host_cli_mod.addImport("tooling", host_tooling_mod);
host_cli_mod.addImport("automation_protocol", host_automation_protocol_mod);
host_cli_mod.addImport("ui_markup", host_ui_markup_mod);
host_cli_mod.addImport("markup_lsp", host_markup_lsp_mod);
host_cli_mod.addOptions("cli_build_info", cli_build_info);
const host_cli_exe = b.addExecutable(.{
.name = "native",
.root_module = host_cli_mod,
});
// Docs component-preview generator: renders the built-in component
// catalog offscreen through the deterministic reference renderer and
// writes theme-aware webp pairs plus the markup vocabulary JSON into
// docs/. Regenerate with `zig build docs-component-previews`.
const docs_previews_mod = module(b, target, optimize, "tools/docs_component_previews.zig");
docs_previews_mod.addImport("native_sdk", desktop_mod);
// The eject registry as its own lean module (its imports stay inside
// src/tooling/), so the vocab JSON's `ejectable` table is written from
// the same rows `native eject component` dispatches on — the docs'
// <EjectSection> resolves from that JSON and can never drift.
docs_previews_mod.addImport("eject_components", module(b, target, optimize, "src/tooling/eject_components.zig"));
const docs_previews_exe = b.addExecutable(.{
.name = "docs-component-previews",
.root_module = docs_previews_mod,
});
const run_docs_previews = b.addRunArtifact(docs_previews_exe);
run_docs_previews.addArg(b.pathFromRoot("docs/public/components"));
run_docs_previews.addArg(b.pathFromRoot("docs/src/lib/component-vocab.json"));
run_docs_previews.has_side_effects = true;
const docs_previews_step = b.step("docs-component-previews", "Render built-in component previews and vocab JSON into docs/");
docs_previews_step.dependOn(&run_docs_previews.step);
// Render macro-benchmark: deterministic scenarios through the REAL
// engine pipeline (UiApp + Runtime + null-platform binary packet
// presents), reporting end-to-end and per-stage p50/p90 per
// interaction. Baselines should come from
// `zig build bench-render -Doptimize=ReleaseFast`.
const bench_render_mod = module(b, target, optimize, "tools/bench_render.zig");
bench_render_mod.addImport("native_sdk", desktop_mod);
const bench_render_exe = b.addExecutable(.{
.name = "bench-render",
.root_module = bench_render_mod,
});
const run_bench_render = b.addRunArtifact(bench_render_exe);
run_bench_render.has_side_effects = true;
// Repo root as cwd so the relative budgets path in the docs/gate
// invocation resolves regardless of where `zig build` ran from.
run_bench_render.setCwd(b.path("."));
// Ratchet mode: `zig build bench-render -Doptimize=ReleaseFast --
// --check tools/bench-render-budgets.txt` compares the median e2e
// p50 of three suite passes against the committed budgets (the
// benchmark refuses --check outside ReleaseFast).
if (b.args) |bench_args| run_bench_render.addArgs(bench_args);
const bench_render_step = b.step("bench-render", "Run the render macro-benchmark (deterministic scenarios; pass -Doptimize=ReleaseFast for baselines, `-- --check tools/bench-render-budgets.txt` for the budget ratchet)");
bench_render_step.dependOn(&run_bench_render.step);
// Live docs previews: the same scene catalog compiled to
// wasm32-freestanding (tools/docs_wasm_preview.zig) so the docs
// upgrade the static webp tiles to interactive engine instances.
// ReleaseSmall + strip keep the module small enough to lazy-load.
const wasm_target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding });
const wasm_optimize: std.builtin.OptimizeMode = .ReleaseSmall;
const wasm_geometry_mod = module(b, wasm_target, wasm_optimize, "src/primitives/geometry/root.zig");
const wasm_json_mod = module(b, wasm_target, wasm_optimize, "src/primitives/json/root.zig");
const wasm_canvas_mod = module(b, wasm_target, wasm_optimize, "src/primitives/canvas/root.zig");
wasm_canvas_mod.addImport("geometry", wasm_geometry_mod);
wasm_canvas_mod.addImport("json", wasm_json_mod);
const wasm_native_mod = module(b, wasm_target, wasm_optimize, "src/root.zig");
wasm_native_mod.addImport("geometry", wasm_geometry_mod);
wasm_native_mod.addImport("json", wasm_json_mod);
wasm_native_mod.addImport("canvas", wasm_canvas_mod);
wasm_native_mod.addImport("app_dirs", module(b, wasm_target, wasm_optimize, "src/primitives/app_dirs/root.zig"));
wasm_native_mod.addImport("assets", module(b, wasm_target, wasm_optimize, "src/primitives/assets/root.zig"));
wasm_native_mod.addImport("trace", module(b, wasm_target, wasm_optimize, "src/primitives/trace/root.zig"));
wasm_native_mod.addImport("app_manifest", module(b, wasm_target, wasm_optimize, "src/primitives/app_manifest/root.zig"));
wasm_native_mod.addImport("diagnostics", module(b, wasm_target, wasm_optimize, "src/primitives/diagnostics/root.zig"));
wasm_native_mod.addImport("platform_info", module(b, wasm_target, wasm_optimize, "src/primitives/platform_info/root.zig"));
const docs_wasm_preview_mod = module(b, wasm_target, wasm_optimize, "tools/docs_wasm_preview.zig");
docs_wasm_preview_mod.addImport("native_sdk", wasm_native_mod);
docs_wasm_preview_mod.strip = true;
const docs_wasm_preview_exe = b.addExecutable(.{
.name = "component-preview",
.root_module = docs_wasm_preview_mod,
});
docs_wasm_preview_exe.entry = .disabled;
docs_wasm_preview_exe.rdynamic = true;
// The engine trades heap for fixed capacity but still builds some
// sizable stack temporaries (NullPlatform alone is ~800 KB); the
// 1 MB wasm default overflows into linear memory silently.
docs_wasm_preview_exe.stack_size = 16 * 1024 * 1024;
const copy_docs_wasm_preview = b.addUpdateSourceFiles();
copy_docs_wasm_preview.addCopyFileToSource(docs_wasm_preview_exe.getEmittedBin(), "docs/public/wasm/component-preview.wasm");
const docs_wasm_preview_step = b.step("docs-wasm-preview", "Compile the live component-preview wasm module into docs/public/wasm/");
docs_wasm_preview_step.dependOn(©_docs_wasm_preview.step);
const file_contains_checker_mod = module(b, host_target, optimize, "tools/check_file_contains.zig");
const file_contains_checker = b.addExecutable(.{
.name = "check-file-contains",
.root_module = file_contains_checker_mod,
});
// Registry pin printer: emits the ui_schema table counts and
// fingerprints in the exact form ui_schema_tests.zig pins, plus the
// next free code per table for reserving codes ahead of parallel
// work. `zig build print-pins` after registry additions.
const print_pins_mod = module(b, host_target, optimize, "tools/print_pins.zig");
print_pins_mod.addImport("ui_schema", module(b, host_target, optimize, "src/primitives/canvas/ui_schema.zig"));
const print_pins_exe = b.addExecutable(.{
.name = "print-pins",
.root_module = print_pins_mod,
});
const run_print_pins = b.addRunArtifact(print_pins_exe);
run_print_pins.has_side_effects = true;
const print_pins_step = b.step("print-pins", "Print registry counts and fingerprints in pin-ready form");
print_pins_step.dependOn(&run_print_pins.step);
const platform_arg = switch (selected_platform) {
.auto => unreachable,
.null => "null",
.macos => "macos",
.linux => "linux",
.windows => "windows",
};
const test_step = b.step("test", "Run package and framework tests");
test_step.dependOn(&b.addRunArtifact(geometry_tests).step);
test_step.dependOn(&b.addRunArtifact(assets_tests).step);
test_step.dependOn(&b.addRunArtifact(app_dirs_tests).step);
test_step.dependOn(&b.addRunArtifact(trace_tests).step);
test_step.dependOn(&b.addRunArtifact(app_manifest_tests).step);
test_step.dependOn(&b.addRunArtifact(diagnostics_tests).step);
test_step.dependOn(&b.addRunArtifact(platform_info_tests).step);
test_step.dependOn(&b.addRunArtifact(json_tests).step);
test_step.dependOn(&b.addRunArtifact(canvas_tests).step);
for (desktop_test_shards) |shard_tests| {
test_step.dependOn(&b.addRunArtifact(shard_tests).step);
}
test_step.dependOn(&b.addRunArtifact(automation_protocol_tests).step);
test_step.dependOn(&b.addRunArtifact(tooling_tests).step);
test_step.dependOn(&b.addRunArtifact(eject_components_tests).step);
if (ts_core_e2e_tests) |ts_core_artifacts| {
const ts_core_e2e_step = b.step("test-ts-core-e2e", "Run the transpiled-core end-to-end suites (requires node)");
const host_e2e_run = b.addRunArtifact(ts_core_artifacts.host);
const soundboard_e2e_run = b.addRunArtifact(ts_core_artifacts.soundboard);
const monitor_e2e_run = b.addRunArtifact(ts_core_artifacts.system_monitor);
const scaffold_ide_e2e_run = b.addRunArtifact(ts_core_artifacts.scaffold_ide);
// The suite scaffolds and typechecks real trees under .zig-cache;
// no build inputs/outputs to hash, so always run it.
scaffold_ide_e2e_run.has_side_effects = true;
const ai_chat_e2e_run = b.addRunArtifact(ts_core_artifacts.ai_chat);
ts_core_e2e_step.dependOn(&host_e2e_run.step);
ts_core_e2e_step.dependOn(&soundboard_e2e_run.step);
ts_core_e2e_step.dependOn(&monitor_e2e_run.step);
ts_core_e2e_step.dependOn(&scaffold_ide_e2e_run.step);
ts_core_e2e_step.dependOn(&ai_chat_e2e_run.step);
test_step.dependOn(&host_e2e_run.step);
test_step.dependOn(&soundboard_e2e_run.step);
test_step.dependOn(&monitor_e2e_run.step);
test_step.dependOn(&scaffold_ide_e2e_run.step);
test_step.dependOn(&ai_chat_e2e_run.step);
}
test_step.dependOn(&b.addRunArtifact(markup_lsp_tests).step);
test_step.dependOn(&b.addRunArtifact(automation_cli_tests).step);
test_step.dependOn(&b.addRunArtifact(markup_cli_tests).step);
test_step.dependOn(&b.addRunArtifact(evals_cmdview_tests).step);
addFileContainsCheckStep(b, file_contains_checker, test_step, "test-package-types", "Verify package TypeScript platform feature names", &.{
.{ .path = "packages/native-sdk/native-sdk.d.ts", .pattern = "NativeSdkCommandInfo" },
.{ .path = "packages/native-sdk/native-sdk.d.ts", .pattern = "list(): Promise<NativeSdkCommandInfo[]>" },
.{ .path = "packages/native-sdk/native-sdk.d.ts", .pattern = "NativeSdkCreateWebViewViewOptions" },
.{ .path = "packages/native-sdk/native-sdk.d.ts", .pattern = "Stable runtime view id" },
.{ .path = "packages/native-sdk/native-sdk.d.ts", .pattern = "update(label: string" },
.{ .path = "packages/native-sdk/native-sdk.d.ts", .pattern = "focus(options: string | NativeSdkViewSelector)" },
.{ .path = "packages/native-sdk/native-sdk.d.ts", .pattern = "close(options: string | NativeSdkViewSelector)" },
.{ .path = "packages/native-sdk/native-sdk.d.ts", .pattern = "kind: \"webview\"" },
.{ .path = "packages/native-sdk/native-sdk.d.ts", .pattern = "url: string" },
.{ .path = "packages/native-sdk/native-sdk.d.ts", .pattern = "NativeSdkPlatformFeatureSelector" },
.{ .path = "packages/native-sdk/native-sdk.d.ts", .pattern = "supports(value: NativeSdkPlatformFeature | NativeSdkPlatformFeatureSelector)" },
.{ .path = "packages/native-sdk/native-sdk.d.ts", .pattern = "\"native_control_commands\"" },
.{ .path = "packages/native-sdk/native-sdk.d.ts", .pattern = "\"nativeControlCommands\"" },
.{ .path = "packages/native-sdk/native-sdk.d.ts", .pattern = "\"recent_documents\"" },
.{ .path = "packages/native-sdk/native-sdk.d.ts", .pattern = "\"recentDocuments\"" },
.{ .path = "packages/native-sdk/native-sdk.d.ts", .pattern = "\"file_drops\"" },
.{ .path = "packages/native-sdk/native-sdk.d.ts", .pattern = "\"fileDrops\"" },
.{ .path = "packages/native-sdk/native-sdk.d.ts", .pattern = "\"app_activation_events\"" },
.{ .path = "packages/native-sdk/native-sdk.d.ts", .pattern = "\"appActivationEvents\"" },
.{ .path = "packages/native-sdk/native-sdk.d.ts", .pattern = "\"gpu_surfaces\"" },
.{ .path = "packages/native-sdk/native-sdk.d.ts", .pattern = "\"gpuSurfaces\"" },
.{ .path = "packages/native-sdk/native-sdk.d.ts", .pattern = "gpuFirstFrameLatencyNs: number" },
});
addFileContainsCheckStep(b, file_contains_checker, test_step, "test-ts-toolchain-twins", "Verify the CLI's toolchain-resolution gate and its direct-`zig build` twin stay in lockstep (both resolve the aliased real compiler @typescript/old from packages/core — the same origin runtime imports it from — hold its resolved version against the manifest-read pin, never probe the unused @typescript/typescript6 wrapper, and teach instead of panicking)", &.{
// The resolution twins probe the aliased REAL compiler
// (@typescript/old — the package typed_ast.ts and ts_run.mjs
// actually load) — manifest AND entrypoint, in lockstep. The
// @typescript/typescript6 wrapper is never probed: nothing
// imports it at run time, and validating it false-rejects
// healthy conflict trees.
.{ .path = "src/tooling/ts_core.zig", .pattern = "\"node_modules\", \"@typescript\", \"old\", \"package.json\"" },
.{ .path = "src/tooling/ts_core.zig", .pattern = "\"node_modules\", \"@typescript\", \"old\", \"lib\", \"typescript.js\"" },
.{ .path = "build/app.zig", .pattern = "\"node_modules\", \"@typescript\", \"old\", \"package.json\"" },
.{ .path = "build/app.zig", .pattern = "\"node_modules\", \"@typescript\", \"old\", \"lib\", \"typescript.js\"" },
// The doctrine both twins document at their predicates: validate
// only what runtime loads, from runtime's own walk origin, and
// leave the declared-but-unimported wrapper out of the verdict.
.{ .path = "src/tooling/ts_core.zig", .pattern = "Validation tracks ONLY what runtime loads" },
.{ .path = "src/tooling/ts_core.zig", .pattern = "wrapper is deliberately NOT probed" },
.{ .path = "build/app.zig", .pattern = "Validation tracks ONLY what runtime loads" },
.{ .path = "build/app.zig", .pattern = "wrapper is deliberately NOT probed" },
// The reciprocal cross-references that keep the twins findable
// from each other.
.{ .path = "src/tooling/ts_core.zig", .pattern = "build/app.zig's tsToolchainResolution" },
.{ .path = "build/app.zig", .pattern = "transpilerResolution, this predicate's deliberate twin" },
// The version pin: both twins read the alias's RESOLVED
// package.json version and hold it against the exact
// `npm:typescript@X.Y.Z` pin read from the SDK's own
// packages/core/package.json (never hardcoded), and both carry
// the mismatch outcome plus its teaching naming the two versions.
.{ .path = "src/tooling/ts_core.zig", .pattern = "parseAliasedCompilerPin" },
.{ .path = "src/tooling/ts_core.zig", .pattern = "version_mismatch" },
.{ .path = "src/tooling/ts_core.zig", .pattern = "npm:typescript@{s}" },
.{ .path = "build/app.zig", .pattern = "tsPinnedCompilerVersion" },
.{ .path = "build/app.zig", .pattern = "version_mismatch" },
.{ .path = "build/app.zig", .pattern = "npm:typescript@{s}" },
// The teachings: the checkout's one production-config-safe npm ci
// command in both surfaces, the reinstall for npm layouts, and the
// build graph's clean configure-time failure (never a panic).
.{ .path = "src/tooling/ts_core.zig", .pattern = "pub const npm_ci_teaching_command = \"npm ci --include=dev\";" },
.{ .path = "src/tooling/ts_core.zig", .pattern = "reinstall @native-sdk/cli" },
.{ .path = "build/app.zig", .pattern = "npm ci --include=dev" },
.{ .path = "build/app.zig", .pattern = "cannot resolve its TypeScript toolchain" },
.{ .path = "build/app.zig", .pattern = "std.process.exit(1);" },
});
addFileContainsCheckStep(b, file_contains_checker, test_step, "test-app-test-entry-analysis", "Verify the managed app test step force-analyzes the entry point (UiApp.create's Model-defaults rule must teach at `native test`, not ambush at `native build`)", &.{
.{ .path = "build/app.zig", .pattern = "app_analysis.zig" },
.{ .path = "build/app.zig", .pattern = "if (@hasDecl(app, \"main\")) _ = &app.main;" },
.{ .path = "build/app.zig", .pattern = "test_step.dependOn(&analysis_obj.step);" },
.{ .path = "src/runtime/ui_app.zig", .pattern = "has no default value - give every Model field a default" },
});
addFileContainsCheckStep(b, file_contains_checker, test_step, "test-bridge-view-selector-helpers", "Verify injected view helpers accept string selectors", &.{
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "viewSelectorPayload(options)" },
.{ .path = "src/platform/macos/cef_host.mm", .pattern = "viewSelectorPayload(options)" },
.{ .path = "src/platform/linux/gtk_host.c", .pattern = "viewSelectorPayload(options)" },
.{ .path = "src/platform/windows/webview2_host.cpp", .pattern = "viewSelectorPayload(options)" },
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "focus:function(options){return invoke('native-sdk.view.focus',viewSelectorPayload(options))" },
.{ .path = "src/platform/macos/cef_host.mm", .pattern = "focus:function(options){return invoke('native-sdk.view.focus',viewSelectorPayload(options))" },
.{ .path = "src/platform/linux/gtk_host.c", .pattern = "focus:function(options){return invoke('native-sdk.view.focus',viewSelectorPayload(options))" },
.{ .path = "src/platform/windows/webview2_host.cpp", .pattern = "focus:function(options){return invoke('native-sdk.view.focus',viewSelectorPayload(options))" },
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "close:function(options){return invoke('native-sdk.view.close',viewSelectorPayload(options))" },
.{ .path = "src/platform/macos/cef_host.mm", .pattern = "close:function(options){return invoke('native-sdk.view.close',viewSelectorPayload(options))" },
.{ .path = "src/platform/linux/gtk_host.c", .pattern = "close:function(options){return invoke('native-sdk.view.close',viewSelectorPayload(options))" },
.{ .path = "src/platform/windows/webview2_host.cpp", .pattern = "close:function(options){return invoke('native-sdk.view.close',viewSelectorPayload(options))" },
});
addFileContainsCheckStep(b, file_contains_checker, test_step, "test-docs-command-contracts", "Verify command docs match native view update contracts", &.{
.{ .path = "docs/src/app/commands/page.mdx", .pattern = ".text = \"Refreshed\"" },
.{ .path = "docs/src/app/commands/page.mdx", .pattern = "const commands = await window.zero.commands.list();" },
});
addFileContainsCheckStep(b, file_contains_checker, test_step, "test-docs-native-view-contracts", "Verify native surface docs describe view identity", &.{
.{ .path = "docs/src/app/native-surfaces/page.mdx", .pattern = "ViewInfo.id" },
.{ .path = "docs/src/app/native-surfaces/page.mdx", .pattern = "window.zero.views.update(\"status\"" },
.{ .path = "docs/src/app/native-surfaces/page.mdx", .pattern = "first-frame latency budget" },
});
addFileContainsCheckStep(b, file_contains_checker, test_step, "test-docs-shell-manifest-contracts", "Verify app.zon docs describe shell compatibility window labels", &.{
.{ .path = "docs/src/app/app-zon/page.mdx", .pattern = "labels must stay unique across both lists" },
});
addFileContainsCheckStep(b, file_contains_checker, test_step, "test-docs-media-producer-contracts", "Verify the media producer docs' typed callback stays mirrored by the compile-shaped pin in media_surface_tests.zig", &.{
.{ .path = "docs/src/app/media-producers/page.mdx", .pattern = "producer: media.MediaSurfaceProducer" },
.{ .path = "src/runtime/media_surface_tests.zig", .pattern = "producer: media.MediaSurfaceProducer" },
});
addFileContainsCheckStep(b, file_contains_checker, test_step, "test-js-view-helper-contracts", "Verify injected view helpers support label-first updates", &.{
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "update:function(options,patch)" },
.{ .path = "src/platform/macos/cef_host.mm", .pattern = "update:function(options,patch)" },
.{ .path = "src/platform/linux/gtk_host.c", .pattern = "update:function(options,patch)" },
.{ .path = "src/platform/windows/webview2_host.cpp", .pattern = "update:function(options,patch)" },
});
addFileContainsCheckStep(b, file_contains_checker, test_step, "test-linux-gpu-frame-emission-below-paint", "Verify the Linux GPU frame emission is scheduled below layout and paint priorities", &.{
// A saturated demand-driven frame loop (cycle cost > frame
// interval => every present re-arms at delay 0) scheduled at
// G_PRIORITY_DEFAULT would be ready on every main-loop
// iteration and starve GTK's layout/paint sources: presents
// land and queue_draw keeps inviting a repaint, but the glass
// freezes on stale pixels for as long as the loop stays armed.
// The emission must stay below GDK_PRIORITY_REDRAW so every
// presented frame paints before the next frame event.
.{ .path = "src/platform/linux/gtk_host.c", .pattern = "view->gpu_emit_source = g_timeout_add_full(G_PRIORITY_DEFAULT_IDLE," },
.{ .path = "src/platform/linux/gtk_host.c", .pattern = "paint (GDK_PRIORITY_REDRAW," },
.{ .path = "src/platform/linux/gtk_host.c", .pattern = "static void native_sdk_gpu_surface_schedule_frame_emission" },
});
addFileContainsCheckStep(b, file_contains_checker, test_step, "test-linux-audio-buffering-clears-on-noop-resume", "Verify the Linux audio buffering flag drops when the 100% resume completes synchronously", &.{
// The buffering flag normally drops at the PLAYING
// state-changed message. When the refill's earlier PAUSED
// request never completed, the 100% resume is a no-op that
// posts no message; a non-ASYNC set_state result is the only
// signal, and the flag must drop on it or it rides every
// position tick for the rest of the track.
.{ .path = "src/platform/linux/gtk_host.c", .pattern = "const int change = gst->element_set_state(audio->playbin, NATIVE_SDK_GST_STATE_PLAYING);" },
.{ .path = "src/platform/linux/gtk_host.c", .pattern = "change != NATIVE_SDK_GST_STATE_CHANGE_ASYNC" },
.{ .path = "src/platform/linux/gtk_host.c", .pattern = "#define NATIVE_SDK_GST_STATE_CHANGE_ASYNC 2" },
});
addFileContainsCheckStep(b, file_contains_checker, test_step, "test-linux-init-close-policy-refusal", "Verify the Linux platform init refuses a .hide main window with the one shared teaching (the pre-created startup window never passes the runtime's create gate, so a silent drop here meant quit-on-close for direct-SDK users)", &.{
// The gate itself is unit-tested cross-host (it is extern-free);
// this pins its WIRING into initWithOptions, which only a Linux
// link can execute.
.{ .path = "src/platform/linux/root.zig", .pattern = "try refuseUnsupportedMainWindowClosePolicy(window_options);" },
// One message, all seams: the platform-init refusal and the
// generated runner's comptime refusal teach with the same text.
.{ .path = "src/platform/linux/root.zig", .pattern = "close_policy \\\"hide\\\" is not supported on linux: the GTK host has no status item (tray), so nothing could bring the hidden window back - declare \\\"quit\\\" (the default), or scope the .hide declaration to macos/windows builds" },
.{ .path = "src/app_runner/root.zig", .pattern = "close_policy \\\"hide\\\" is not supported on linux: the GTK host has no status item (tray), so nothing could bring the hidden window back - declare \\\"quit\\\" (the default), or scope the .hide declaration to macos/windows builds" },
.{ .path = "src/tooling/templates.zig", .pattern = "close_policy \\\\\\\"hide\\\\\\\" is not supported on linux" },
});
addFileContainsCheckStep(b, file_contains_checker, test_step, "test-macos-close-clears-policy-hidden", "Verify every macOS close exit leaves the policy-hidden set before its open=false emit (both hosts derive the frame event's hidden flag from set membership, and the Dock reopen re-shows every member — a close exit that skips the cleanup emits {open=false, hidden=true} and lets the reopen resurrect an app-closed window)", &.{
// AppKit: every close routes through NSWindow close/performClose,
// so the delegate's windowWillClose is the one cleanup site.
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "[self.host.policyHiddenWindows removeObject:@(self.windowId)];\n [self.host emitWindowFrameForWindowId:self.windowId open:NO];" },
// CEF: the delegate cleanup covers the [window close] fallback,
// and the app-driven close of a browser-bearing window exits
// through orderOut WITHOUT reaching windowWillClose — that
// branch must do the set cleanup itself, before its emit.
.{ .path = "src/platform/macos/cef_host.mm", .pattern = "[self.host.policyHiddenWindows removeObject:@(self.windowId)];\n [self.host emitWindowFrameForWindowId:self.windowId open:NO];" },
.{ .path = "src/platform/macos/cef_host.mm", .pattern = "[self.policyHiddenWindows removeObject:@(windowId)];\n [window orderOut:nil];\n [self emitWindowFrameForWindowId:windowId open:NO];" },
});
addFileContainsCheckStep(b, file_contains_checker, test_step, "test-macos-cef-window-verbs-synchronous", "Verify the CEF host's show and minimize verbs run synchronously on the main thread, the close verb's discipline (a dispatch_async show returns success while the window is still in policyHiddenWindows — the runtime's post-success focus flip then emits {focused:true, hidden:true} until the queued block lands — and a show-then-close in one dispatch re-orders: the queued show lands AFTER the synchronous close and puts a retained ordered-out closed window back on the glass)", &.{
// The show verb: direct on main, dispatch_sync hop otherwise,
// with the window lookup INSIDE the block so a window closed
// before an off-main hop lands is a no-op, not a resurrection.
.{ .path = "src/platform/macos/cef_host.mm", .pattern = "if ([NSThread isMainThread]) {\n showBlock();\n } else {\n dispatch_sync(dispatch_get_main_queue(), showBlock);\n }" },
// The minimize twin (a queued miniaturize captured past a
// synchronous close genies an app-closed window into the Dock).
.{ .path = "src/platform/macos/cef_host.mm", .pattern = "if ([NSThread isMainThread]) {\n miniaturizeBlock();\n } else {\n dispatch_sync(dispatch_get_main_queue(), miniaturizeBlock);\n }" },
// The C shims return success only after the synchronous verb —
// no dispatch_async between the lookup and the method call.
.{ .path = "src/platform/macos/cef_host.mm", .pattern = "if (!object.windows[@(window_id)]) return 0;\n [object miniaturizeWindowWithId:window_id];\n return 1;" },
.{ .path = "src/platform/macos/cef_host.mm", .pattern = "[object showWindowWithId:window_id];\n return 1;" },
// The AppKit host's twins are already synchronous direct calls
// (its runtime callbacks arrive on the main thread); these pins
// hold that symmetry.
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "[object showWindowWithId:window_id];\n return 1;" },
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "[object miniaturizeWindowWithId:window_id];\n return 1;" },
});
// The embedded-WebView layer must stay real AND declare-to-use: the
// standard build graph puts the vendored WebView2 SDK header on the
// include path exactly when app.zon declares web use (`if
// (web_layer)`), and only the native-only branch passes the stub
// define. In the guard the stub define is tested FIRST, before
// header visibility: on a machine where the WebView2 SDK headers are
// reachable through the system include paths, an
// include-path-decides guard would compile the full layer into a
// native-only build and reintroduce the WebView2Loader.dll reference
// its executable must not carry. Without the define the header is
// required — a web build that cannot see it fails at compile time
// instead of quietly shipping the stubbed host (whose WebView loads
// report WebViewNotFound at runtime).
addFileContainsCheckStep(b, file_contains_checker, test_step, "test-windows-webview2-vendor", "Verify the vendored WebView2 SDK stays wired into every web-declaring Windows build graph", &.{
.{ .path = "third_party/webview2/include/WebView2.h", .pattern = "CreateCoreWebView2EnvironmentWithOptions" },
.{ .path = "third_party/webview2/include/EventToken.h", .pattern = "EventRegistrationToken" },
.{ .path = "third_party/webview2/LICENSE.txt", .pattern = "Redistribution and use in source and binary forms" },
.{ .path = "src/platform/windows/webview2_host.cpp", .pattern = "#if defined(NATIVE_SDK_ALLOW_WEBVIEW2_STUB)" },
.{ .path = "src/platform/windows/webview2_host.cpp", .pattern = "#elif __has_include(<WebView2.h>) && __has_include(<wrl.h>)" },
.{ .path = "src/platform/windows/webview2_host.cpp", .pattern = "#error \"WebView2.h not found" },
.{ .path = "src/platform/windows/webview2_host.cpp", .pattern = "LoadLibraryW(L\"WebView2Loader.dll\")" },
.{ .path = "build/app.zig", .pattern = ".system => if (web_layer) {" },
.{ .path = "build/app.zig", .pattern = "app_mod.addIncludePath(dep.path(\"third_party/webview2/include\"));" },
.{ .path = "build/app.zig", .pattern = "third_party/webview2/x64/WebView2Loader.dll" },
.{ .path = "build/app.zig", .pattern = "\"-DNATIVE_SDK_ALLOW_WEBVIEW2_STUB\"" },
.{ .path = "src/tooling/templates.zig", .pattern = "third_party/webview2/include" },
.{ .path = "src/tooling/templates.zig", .pattern = "third_party/webview2/x64/WebView2Loader.dll" },
});
// The Linux mirror of the Windows seam: the stub define wins over
// header visibility (a native-only build never reintroduces the
// libwebkitgtk link even where the dev package is installed), the
// header is required for web builds, and both build graphs compile
// gtk_host.c with the stub and drop the webkitgtk-6.0 link when the
// web layer is excluded.
addFileContainsCheckStep(b, file_contains_checker, test_step, "test-linux-webkitgtk-seam", "Verify the WebKitGTK compile seam stays wired through the GTK host and both Linux build graphs", &.{
.{ .path = "src/platform/linux/gtk_host.c", .pattern = "#if defined(NATIVE_SDK_ALLOW_WEBKITGTK_STUB)" },
.{ .path = "src/platform/linux/gtk_host.c", .pattern = "#elif __has_include(<webkit/webkit.h>)" },
.{ .path = "src/platform/linux/gtk_host.c", .pattern = "#error \"webkit/webkit.h not found" },
.{ .path = "build/app.zig", .pattern = "\"-DNATIVE_SDK_ALLOW_WEBKITGTK_STUB\"" },
.{ .path = "src/tooling/templates.zig", .pattern = "\"-DNATIVE_SDK_ALLOW_WEBKITGTK_STUB\"" },
});
addLayoutCheckStep(b, test_step, "test-windows-webview2-loader-layout", "Verify the vendored WebView2 loader binaries are present", &.{
"third_party/webview2/x64/WebView2Loader.dll",
"third_party/webview2/arm64/WebView2Loader.dll",
});
addFileContainsCheckStep(b, file_contains_checker, test_step, "test-windows-packaged-assets-webview2", "Verify Windows packaged assets are served through WebView2 request interception", &.{
.{ .path = "src/platform/windows/webview2_host.cpp", .pattern = "constexpr const char *kAssetVirtualOrigin = \"https://native-sdk-app.localhost\";" },
.{ .path = "src/platform/windows/webview2_host.cpp", .pattern = "return virtualAssetEntryUrl(webview.asset_entry);" },
.{ .path = "src/platform/windows/webview2_host.cpp", .pattern = "AddWebResourceRequestedFilter(L\"https://native-sdk-app.localhost/*\"" },
.{ .path = "src/platform/windows/webview2_host.cpp", .pattern = "assetWebResourceResponse(environment_ref.Get(), found->second, uri)" },
.{ .path = "src/platform/windows/webview2_host.cpp", .pattern = "bridgeOriginForWebViewUrl(source_webview->second, source_url)" },
.{ .path = "src/platform/windows/webview2_host.cpp", .pattern = "webview.spa_fallback = spa_fallback != 0;" },
});
addFileContainsCheckStep(b, file_contains_checker, test_step, "test-macos-cef-packaged-assets-webviews", "Verify macOS CEF child WebViews resolve packaged asset URLs before loading", &.{
.{ .path = "src/platform/macos/cef_host.mm", .pattern = "self.assetRoots = [[NSMutableDictionary alloc] init];" },
.{ .path = "src/platform/macos/cef_host.mm", .pattern = "resolvedWebViewURLString:(NSString *)url windowId:(uint64_t)windowId" },
.{ .path = "src/platform/macos/cef_host.mm", .pattern = "CefBrowserHost::CreateBrowser(windowInfo, client.get(), std::string(resolvedURL.UTF8String)" },
.{ .path = "src/platform/macos/cef_host.mm", .pattern = "self.webviewPendingURLs[[self webViewKeyForWindow:windowId label:label]] = resolvedURL;" },
.{ .path = "src/platform/macos/cef_host.mm", .pattern = "bridgeOriginForWindowId:window_id_ webViewLabel:labelString sourceURL:sourceURLString" },
});
addFileContainsCheckStep(b, file_contains_checker, test_step, "test-appkit-native-accessibility-roles", "Verify AppKit native views publish accessibility roles", &.{
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "NativeSdkAccessibilityRoleForNativeViewKind" },
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "NSAccessibilityToolbarRole" },
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "NSAccessibilityProgressIndicatorRole" },
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "view.accessibilityRole = NativeSdkAccessibilityRoleForNativeViewKind(kind)" },
});
addFileContainsCheckStep(b, file_contains_checker, test_step, "test-appkit-gpu-input-repaints-retained-canvas", "Verify GPU input wakes retained canvas frames", &.{
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "- (void)requestRetainedCanvasFrame" },
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "[self requestRetainedCanvasFrame];" },
});
addFileContainsCheckStep(b, file_contains_checker, test_step, "test-appkit-pinch-terminal-delta", "Verify the macOS pinch stream forwards a terminal Ended/Cancelled magnification as a change before the end marker", &.{
// AppKit documents every magnifyWithEvent: as carrying the
// magnification since the previous event — the terminal one
// included. The Ended/Cancelled branch must forward a nonzero
// terminal magnification as PINCH_CHANGE before PINCH_END (zero
// magnification: end only), or the cumulative product of
// (1 + delta) diverges from what the OS delivered. Cancelled
// deliberately shares the path: pinch applies deltas
// incrementally with no rollback.
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "if (phase & (NSEventPhaseEnded | NSEventPhaseCancelled)) {" },
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "[self emitPinchChangeForEvent:event];\n [self emitPinchInputEventWithKind:NATIVE_SDK_APPKIT_GPU_INPUT_PINCH_END event:event magnification:0];" },
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "PINCH_END event:event magnification:0];" },
});
addFileContainsCheckStep(b, file_contains_checker, test_step, "test-appkit-pinch-magnification-doctrine", "Verify the macOS host forwards raw NSEvent.magnification as the multiplicative pinch delta (the engine convention), with the per-event floor", &.{
// The reading of NSEvent.magnification is SETTLED and this step
// exists to keep it settled: Apple's API-reference prose says
// "add", Apple's own Event Handling Guide example multiplies,
// and every browser engine (WebKit, Chromium) treats raw
// magnification as the multiplicative per-event delta. The
// doctrine comment at magnifyWithEvent: carries the receipts;
// these pins hold both the comment and the code to it. Any
// sum-based "additive normalization" of magnification must
// change emitPinchChangeForEvent:'s pinned body — and thereby
// fail this step, on purpose. Re-read the doctrine comment
// before touching either.
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "m_magnification += m_magnification * scaleWithResistance;" },
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "pinch_update.scale = event.magnification + 1.0;" },
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "Ruling: raw event.magnification IS the multiplicative per-event" },
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "Do NOT reintroduce a running-sum" },
// The raw forwarding, pinned as one body: the only transform
// between the OS and the wire is the per-event floor (a single
// magnification at or below -1 would emit a factor <= 0 — a
// zoom inverted through zero scale, physically impossible).
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "static const double NativeSdkPinchMagnificationFloor = -1.0 + 0x1p-10;" },
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "return magnification < NativeSdkPinchMagnificationFloor ? NativeSdkPinchMagnificationFloor : magnification;" },
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "- (void)emitPinchChangeForEvent:(NSEvent *)event {\n const double magnification = NativeSdkClampedPinchMagnification(event.magnification);\n if (magnification == 0) return;\n [self emitPinchInputEventWithKind:NATIVE_SDK_APPKIT_GPU_INPUT_PINCH_CHANGE event:event magnification:magnification];\n}" },
});
addFileContainsCheckStep(b, file_contains_checker, test_step, "test-appkit-gpu-input-paces-retained-canvas", "Verify GPU input frame requests are paced to the display interval", &.{
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "NativeSdkRetainedFrameIntervalNanoseconds" },
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "retainedFrameLastEmitNs" },
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "queuePointerMotionInputEvent:(NSEvent *)event" },
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "pendingPointerMotionKind = kind" },
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "emitQueuedPointerMotionInputEvent" },
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "queueScrollInputEvent:(NSEvent *)event" },
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "pendingScrollDeltaY += deltaY" },
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "emitQueuedScrollInputEvent" },
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "dispatch_after(dispatch_time(DISPATCH_TIME_NOW" },
// The single per-surface frame-event scheduler: every producer
// (requests, completions, occluded completions) coalesces into
// one paced emission per display interval.
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "- (void)scheduleFrameEventEmission" },
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "- (void)emitScheduledFrameEvent" },
});
addFileContainsCheckStep(b, file_contains_checker, test_step, "test-quit-stop-queued", "Verify the quit verb's stop is queued to the next loop turn on every synchronous-emit host (a synchronous emitShutdown nests the shutdown dispatch inside the requesting command's dispatch, seals the session journal before the command commits, and replay diverges)", &.{
// macOS (AppKit and CEF hosts): the main-queue hop, with the
// pre-run-loop inline fallback the failed-START precedent needs.
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "if (!NSApp.running) {" },
.{ .path = "src/platform/macos/cef_host.mm", .pattern = "if (!NSApp.running) {" },
// Linux: the idle hop — the same seam the wake and
// frame-request paths ride.
.{ .path = "src/platform/linux/gtk_host.c", .pattern = "static gboolean native_sdk_stop_idle(gpointer data)" },
.{ .path = "src/platform/linux/gtk_host.c", .pattern = "g_idle_add(native_sdk_stop_idle, host);" },
// Windows was queued from the start: stop posts, the loop
// exits, and the shutdown emits after the loop at top level.
.{ .path = "src/platform/windows/webview2_host.cpp", .pattern = "void native_sdk_windows_stop(Host *host) {" },
.{ .path = "src/platform/windows/webview2_host.cpp", .pattern = "PostQuitMessage(0);" },
// The runtime ordering the queue protects: the recorder seals
// on the shutdown dispatch's exit, and the modeled host's
// queued seam keeps the runtime suites honest about it.
.{ .path = "src/runtime/flow.zig", .pattern = "if (event_value == .app_shutdown) recorder.finish();" },
.{ .path = "src/platform/null_platform.zig", .pattern = "pub fn takeQueuedQuit" },
});
addFileContainsCheckStep(b, file_contains_checker, test_step, "test-quit-pre-run-pending", "Verify a PRE-RUN quit verb on the macOS hosts parks as a pending flag drained at top level, never the inline emit (an inline pre-run emit nests the shutdown inside the boot dispatch that requested it — the recorder seals the journal before that dispatch commits, the same bug the running-path queue fixes)", &.{
// The quit verb's own landing point: pre-run it PARKS — the
// inline emitShutdown+stop stays exclusive to
// native_sdk_appkit_stop, the host-side failure request the
// failed-START precedent rides (runWithCallback's didShutdown
// check).
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "void native_sdk_appkit_request_stop(native_sdk_appkit_host_t *host) {" },
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "object.pendingPreRunStop = YES;" },
.{ .path = "src/platform/macos/cef_host.mm", .pattern = "void native_sdk_appkit_request_stop(native_sdk_appkit_host_t *host) {" },
.{ .path = "src/platform/macos/cef_host.mm", .pattern = "object.pendingPreRunStop = YES;" },
// The drains: after the START dispatch (at the didShutdown
// decision point) and after the remaining pre-run dispatches
// (appearance/resize/window-frame, and AppKit's synchronous
// first canvas frame) — emitShutdown + stop at TOP LEVEL, once.
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "- (BOOL)drainPendingPreRunStop {\n if (!self.pendingPreRunStop) return NO;\n self.pendingPreRunStop = NO;\n if (self.didShutdown) return NO;\n [self emitShutdown];\n [self stop];\n return YES;\n}" },
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "[self drainPendingPreRunStop];\n // A failed START handler requests shutdown synchronously" },
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "if ([self drainPendingPreRunStop]) return;" },
.{ .path = "src/platform/macos/cef_host.mm", .pattern = "- (BOOL)drainPendingPreRunStop {\n if (!self.pendingPreRunStop) return NO;\n self.pendingPreRunStop = NO;\n if (self.didShutdown) return NO;\n [self emitShutdown];\n [self stop];\n return YES;\n}" },
.{ .path = "src/platform/macos/cef_host.mm", .pattern = "[self drainPendingPreRunStop];\n // A failed START handler requests shutdown synchronously" },
.{ .path = "src/platform/macos/cef_host.mm", .pattern = "if ([self drainPendingPreRunStop]) {\n shutdownCefIfNeeded();\n return;\n }" },
// The Zig split: the quit verb rides request_stop; the failed
// emit keeps the byte-for-byte host-side stop.
.{ .path = "src/platform/macos/root.zig", .pattern = "native_sdk_appkit_request_stop(self.host);" },
.{ .path = "src/platform/macos/root.zig", .pattern = "if (self.self) |mac| native_sdk_appkit_stop(mac.host);" },
});
addFileContainsCheckStep(b, file_contains_checker, test_step, "test-gtk-stop-idle-tracked", "Verify the GTK quit-stop idle source is tracked on the host, coalesced while pending, skipped after shutdown, and removed at destroy (an untracked second g_idle_add leaves a source holding a freed host after the loop quits)", &.{
.{ .path = "src/platform/linux/gtk_host.c", .pattern = "guint stop_idle_source;" },
// The idle retires its own tracking before it emits.
.{ .path = "src/platform/linux/gtk_host.c", .pattern = "host->stop_idle_source = 0;\n if (!host->did_shutdown) {" },
// Coalesce + post-shutdown skip, then the tracked add.
.{ .path = "src/platform/linux/gtk_host.c", .pattern = "if (host->did_shutdown || host->stop_idle_source) return;\n host->stop_idle_source = g_idle_add(native_sdk_stop_idle, host);" },
// Destroy removes a still-pending stop turn.
.{ .path = "src/platform/linux/gtk_host.c", .pattern = "if (host->stop_idle_source) {\n g_source_remove(host->stop_idle_source);\n host->stop_idle_source = 0;\n }" },
});
addFileContainsCheckStep(b, file_contains_checker, test_step, "test-gpu-occluded-frame-heartbeat", "Verify occluded windows throttle frame completions to a heartbeat and restore full cadence on reveal", &.{
// macOS: occluded surfaces pace logical completions on the ~1 Hz
// heartbeat (never stopping — on_frame-driven models stay gently
// current), de-occlusion supersedes the parked emission for an
// immediate return to the display grid, and heartbeat completions
// are flagged so the runtime never stamps input latency from them.
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "NativeSdkOccludedFrameHeartbeatNs = 1000000000ull" },
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "- (BOOL)occludedFramePacingActive" },
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "heartbeatPaced ? NativeSdkOccludedFrameHeartbeatNs" },
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "self.frameEventEmissionGeneration += 1" },
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "occluded:[self occludedFramePacingActive]" },
// Exempt producers (a real present's completion, an input's
// responding frame) fire at grid promptness — neither can
// sustain a spin.
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "scheduleFrameEventEmissionForPresentCompletion:YES" },
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "- (void)noteGpuSurfaceInputActivity" },
// Windows: the same throttle keyed on the two reliable
// occlusion facts — minimize (IsIconic) and the close_policy
// .hide hide (policy_hidden: a hidden menu-bar app must not
// spin its frame loop or its spectrum emissions full-rate for
// days). Restore re-arms the pending one-shot timer at the
// frame-grid delay through WM_SIZE, re-show through the show
// verb (SW_SHOW dispatches no WM_SIZE), and the input /
// first-present exemptions ride one prompt-frame flag.
.{ .path = "src/platform/windows/webview2_host.cpp", .pattern = "kGpuOccludedHeartbeatNs = 1000000000ull" },
.{ .path = "src/platform/windows/webview2_host.cpp", .pattern = "gpuSurfaceOccludedPacingActive" },
.{ .path = "src/platform/windows/webview2_host.cpp", .pattern = "owner->second.policy_hidden) return true;" },
.{ .path = "src/platform/windows/webview2_host.cpp", .pattern = "IsIconic(root)" },
.{ .path = "src/platform/windows/webview2_host.cpp", .pattern = "!IsIconic(entry.second.hwnd) && !entry.second.policy_hidden" },
.{ .path = "src/platform/windows/webview2_host.cpp", .pattern = "Re-show returns full frame cadence without dropping a beat" },
.{ .path = "src/platform/windows/webview2_host.cpp", .pattern = "gpu_prompt_frame_pending" },
.{ .path = "src/platform/windows/webview2_host.cpp", .pattern = "native_sdk_windows_note_gpu_surface_input" },
// The runtime side of the measurement honesty: occluded logical
// completions resolve pending inputs without a latency stamp,
// and every dispatched input notes the host for a prompt
// responding frame.
.{ .path = "src/runtime/gpu_surface_events.zig", .pattern = "resolveGpuSurfaceInputForOccludedFrame" },
.{ .path = "src/runtime/gpu_surface_events.zig", .pattern = "noteGpuSurfaceInput" },
// GTK: no reliable cross-backend occlusion signal — the decision
// to leave full cadence is documented at the scheduler, not
// implicit.
.{ .path = "src/platform/linux/gtk_host.c", .pattern = "No occluded/minimized throttle here, DELIBERATELY" },
});
addFileContainsCheckStep(b, file_contains_checker, test_step, "test-appkit-gpu-drawable-integral-pixels", "Verify AppKit GPU surfaces use integral drawable pixels", &.{
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "ceil(size.width * scale)" },
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "ceil(size.height * scale)" },
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "self.metalLayer.drawableSize = drawableSize" },
});
addFileContainsCheckStep(b, file_contains_checker, test_step, "test-appkit-gpu-resize-repaints-retained-canvas", "Verify AppKit GPU resize requests a correctly sized retained frame", &.{
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "_metalLayer.contentsGravity = kCAGravityTopLeft" },
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "if (changed) {" },
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "[self requestRetainedCanvasFrame];" },
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "canvasTextureMatchesDrawable" },
});
addFileContainsCheckStep(b, file_contains_checker, test_step, "test-appkit-gpu-packet-transforms", "Verify AppKit GPU packet presenter applies command transforms", &.{
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "NativeSdkPacketApplyTransform(command[@\"transform\"])" },
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "[affine setTransformStruct:transform]" },
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "[affine concat]" },
});
addFileContainsCheckStep(b, file_contains_checker, test_step, "test-appkit-gpu-packet-paths", "Verify AppKit GPU packet presenter draws path commands", &.{
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "[kind isEqualToString:@\"path\"]" },
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "[verb isEqualToString:@\"quad_to\"]" },
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "[kind isEqualToString:@\"fill_path\"]" },
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "[kind isEqualToString:@\"stroke_path\"]" },
});
addFileContainsCheckStep(b, file_contains_checker, test_step, "test-appkit-gpu-packet-corner-radii", "Verify AppKit GPU packet presenter honors per-corner radii", &.{
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "NativeSdkPacketRoundedRectPath" },
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "CGFloat topRight = NativeSdkPacketRadiusAt(radiusValue, 1, maxRadius)" },
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "CGFloat bottomLeft = NativeSdkPacketRadiusAt(radiusValue, 3, maxRadius)" },
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "return NativeSdkPacketRoundedRectPath(rect, shape[@\"radius\"])" },
});
addFileContainsCheckStep(b, file_contains_checker, test_step, "test-appkit-gpu-packet-load-frames", "Verify AppKit GPU packet presenter handles retained load frames", &.{
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "canvasPacketPixels" },
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "[loadAction isEqualToString:@\"load\"]" },
// Retained-backing discipline: dirty updates require the validity
// flag, and every present that mutates the backing clears it until
// the draw succeeds — a failed draw can never leak stale pixels
// around a later scissor.
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "!self.canvasPacketPixelsValid" },
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "self.canvasPacketPixelsValid = YES" },
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "hasDirtyRect:uploadDirtyRect" },
});
// Version prose is machine-checked: the wire-format v2/v3 drift (spec
// comments and changelog naming a version the constant had moved past)
// shipped once, so the constant and every prose site that names the
// version are pinned together. Bumping `binary_packet_version` fails
// this step until the encoder comment, the host decoder comment, and
// the patterns below move with it.
addFileContainsCheckStep(b, file_contains_checker, test_step, "test-wire-format-version-prose", "Verify wire-format version prose matches the packet version constant", &.{
.{ .path = "src/primitives/canvas/serialization.zig", .pattern = "pub const binary_packet_version: u8 = 4;" },
.{ .path = "src/primitives/canvas/serialization.zig", .pattern = "Compact binary gpu-surface packet encoding (wire format v4)." },
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "Compact binary gpu-surface packet decoding (wire format v4)." },
});
addFileContainsCheckStep(b, file_contains_checker, test_step, "test-appkit-gpu-packet-blur-effects", "Verify AppKit GPU packet presenter applies blur effects", &.{
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "NativeSdkPacketApplyBlur" },
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "CGBitmapContextGetData(context)" },
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "NSIntersectionRect(rect, clipRect)" },
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "NativeSdkPacketTransformRect(transformValue, NativeSdkPacketRect(effect[@\"rect\"]))" },
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "return NativeSdkPacketApplyBlur(effect, opacity, context, scale, transformValue, hasClip, clipRect)" },
});
addFileContainsCheckStep(b, file_contains_checker, test_step, "test-appkit-gpu-packet-text-layout", "Verify AppKit GPU packet presenter honors text layout metadata", &.{
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "NSMutableParagraphStyle" },
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "NativeSdkPacketTextLineBreakMode" },
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "NativeSdkPacketTextAlignment" },
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "NativeSdkPacketNumber(layout[@\"maxWidth\"], 0)" },
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "[value drawWithRect:NSMakeRect(origin.x, origin.y - size, textWidth, textHeight)" },
});
addFileContainsCheckStep(b, file_contains_checker, test_step, "test-appkit-gpu-packet-font-assets", "Verify AppKit GPU packet text registers bundled font assets", &.{
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "#import <CoreText/CoreText.h>" },
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "CTFontManagerRegisterFontsForURL" },
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "@[ @\"fonts\", @\"Fonts\", @\"assets/fonts\" ]" },
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "NativeSdkRegisterBundledFonts();" },
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "NativeSdkPacketPreferredFont(text, size)" },
.{ .path = "src/tooling/templates.zig", .pattern = "app_mod.linkFramework(\"CoreText\", .{});" },
});
addFileContainsCheckStep(b, file_contains_checker, test_step, "test-appkit-gpu-packet-span-fonts", "Verify AppKit packet text resolves reserved span font ids to real weighted and italic faces", &.{
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "static NSFont *NativeSdkItalicSansFont(NSFont *font)" },
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "static NSFont *NativeSdkWeightedSansFont(" },
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "NativeSdkWeightedSansFont(@[ @\"Geist-Medium\", @\"Geist Medium\" ], base, NSFontWeightMedium, NO, size)" },
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "NativeSdkWeightedSansFont(@[ @\"Geist-Bold\", @\"Geist Bold\" ], base, NSFontWeightBold, YES, size)" },
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "NativeSdkItalicSansFont(base)" },
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "NativeSdkItalicSansFont(NativeSdkWeightedSansFont(@[ @\"Geist-Bold\", @\"Geist Bold\" ], base, NSFontWeightBold, YES, size))" },
});
addFileContainsCheckStep(b, file_contains_checker, test_step, "test-appkit-registered-font-cache-eviction", "Verify the AppKit host invalidates BOTH per-process registered-font caches at registration (the caches are per-process while font-id permanence is per-runtime, so a new runtime re-registering an id must never resolve the previous runtime's face or its measured widths): the NSFont size cache by prefix eviction and the measured-width NSCache by a process-global registration token in its key", &.{
// No SDK test tier links appkit_host.m (only managed app builds
// compile it), so the eviction wiring is pinned textually like
// the other AppKit host contracts: the shared accessor both the
// resolve and registration paths use, the prefix eviction inside
// register_font, and the honest lifetime comment.
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "static NSMutableDictionary<NSString *, NSFont *> *NativeSdkRegisteredFontSizeCache(void)" },
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "NSString *stalePrefix = [NSString stringWithFormat:@\"%llu/\", (unsigned long long)font_id];" },
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "if ([cachedKey hasPrefix:stalePrefix]) [sizeCache removeObjectForKey:cachedKey];" },
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "an id is only permanent within" },
// The width-cache half: NSCache cannot enumerate keys, so the
// measured-width cache is invalidated by a registration token
// drawn from one process-global monotonic counter (tokens never
// repeat, which is what lets unregister DELETE an id's record
// instead of retaining a bumped one per retired id) — the token
// table, the fresh stamp inside register_font, and the
// token-carrying key inside measure_text.
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "static NSMutableDictionary<NSNumber *, NSNumber *> *NativeSdkRegisteredFontTokens(void)" },
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "unsigned long long token = ++NativeSdkRegisteredFontTokenCounter;" },
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "NativeSdkRegisteredFontTokens()[@(font_id)] = @(token);" },
// The stamp is also the registration's OWNERSHIP token: register
// reports it to the caller (`*out_token`), the runtime stores it
// beside the captured unregister owner, and unregister removes
// the id's state only while the id's current registration still
// carries it — an older runtime's deinit must never tear down a
// newer runtime's live face under a shared id (ids are
// per-runtime, host font state is per-process, last wins).
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "*out_token = token;" },
// The token and the registered face reach measure_text from ONE
// critical section (the snapshot helper): separate acquisitions
// let a registration land between the token read and the face
// resolution, pairing token 0 with the new registered face and
// caching registered widths under the reusable token-0 key —
// stale registered widths served after teardown. The snapshot
// signature and its measure_text call site are pinned so the
// two-acquisition shape cannot quietly return.
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "static NSFont *NativeSdkRegisteredFontSnapshot(unsigned long long value, CGFloat size, unsigned long long *out_token)" },
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "NSFont *registered = NativeSdkRegisteredFontSnapshot((unsigned long long)font_id, clamped, &token);" },
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "NSFont *font = registered ?: NativeSdkBuiltInFontForFontId(font_id, clamped);" },
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "[NSString stringWithFormat:@\"%llu/%llu/%.3f/%@\", (unsigned long long)font_id, token, (double)clamped, value]" },
// The width-cache WRITE is token-rechecked. Shaping runs outside
// the guard, so an unregister can land inside the shaping window:
// it clears the whole width cache (its only possible eviction),
// and an unconditional post-shape write would then repopulate the
// cleared cache with a retired-token entry — unreachable for
// serving (tokens never repeat) but resident until memory
// pressure, breaking the zero-retained-state teardown the clear
// exists to guarantee. measure_text therefore re-enters the
// descriptor guard after shaping and writes only while the id's
// current token still equals the snapshotted one; token 0
// (built-in resolution — never registered, so never cleared)
// caches without the recheck. Both branches are pinned so the
// unconditional-write shape cannot quietly return.
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "if (token == 0) {" },
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "NSNumber *currentToken = NativeSdkRegisteredFontTokens()[@(font_id)];" },
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "if (currentToken && currentToken.unsignedLongLongValue == token) {" },
// The teardown half: Runtime.deinit returns the host-side
// registration through the unregister owner each font entry
// captured at registration time (never live `options.platform`,
// which is publicly mutable), and the ObjC removal drops the
// descriptor, the size-cache entries, AND the token record —
// zero retained state per retired id. Pinned like the
// registration half (appkit_host.m has no SDK test tier); the
// capture and the deinit call site are pinned too so the seam
// can never silently lose its one caller or regress to the live
// read, and the embed cycle and platform-swap tests assert both
// behaviorally against null platform recorders.
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "int native_sdk_appkit_unregister_font(uint64_t font_id, uint64_t token) {" },
// The token-match guard itself: reverting removal to id-keyed
// (deleting whatever the id currently holds, whoever registered
// it) must fail here — the embed suite's survives-teardown test
// pins the same guard behaviorally against the null platform's
// host-font mirror.
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "if (!current || current.unsignedLongLongValue != token) return 1;" },
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "[NativeSdkRegisteredFontTokens() removeObjectForKey:@(font_id)];" },
.{ .path = "src/platform/macos/appkit_host.m", .pattern = "[table removeObjectForKey:@(font_id)];" },
// Teardown must also CLEAR the measured-width NSCache: a
// retiring token's entries can never be served again (tokens
// never repeat) but they stay resident until memory pressure,
// and NSCache cannot enumerate keys, so the whole-cache clear on