Repository navigation
Expand file tree
/
Copy pathbuild.zig
More file actions
6295 lines (6109 loc) · 486 KB
/
Copy pathbuild.zig
File metadata and controls
6295 lines (6109 loc) · 486 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 test_shards = @import("build/test_shards.zig");
test "complete root test sharding" {
std.testing.refAllDecls(test_shards);
}
// Installing the archive extractor opts this checkout into compiler tests.
// The build drivers then require a complete checksum-pinned release cache;
// disabling npm install scripts must not silently skip compiler qualification.
fn repositoryScriptcInstallMarker(b: *std.Build) []const u8 {
return b.pathFromRoot("packages/core/node_modules/tar/package.json");
}
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;
test "service archive support matches ScriptC localized object formats" {
const app_build = @import("build/app.zig");
const host = @import("builtin").target;
const resolved = struct {
fn target(os: std.Target.Os.Tag, arch: std.Target.Cpu.Arch, abi: std.Target.Abi) std.Build.ResolvedTarget {
var result = host;
result.os.tag = os;
result.cpu.arch = arch;
result.abi = abi;
return .{
.query = .{ .os_tag = os, .cpu_arch = arch, .abi = abi },
.result = result,
};
}
}.target;
var macos_host = host;
macos_host.os.tag = .macos;
macos_host.cpu.arch = .aarch64;
macos_host.abi = .none;
try std.testing.expect(app_build.serviceArchiveSupported(macos_host, resolved(.windows, .x86_64, .gnu)));
try std.testing.expect(!app_build.serviceArchiveSupported(macos_host, resolved(.windows, .x86_64, .msvc)));
try std.testing.expect(!app_build.serviceArchiveSupported(macos_host, resolved(.windows, .aarch64, .gnu)));
try std.testing.expect(app_build.serviceArchiveSupported(macos_host, resolved(.linux, .x86_64, .musl)));
try std.testing.expect(app_build.serviceArchiveSupported(macos_host, resolved(.linux, .aarch64, .musl)));
try std.testing.expect(!app_build.serviceArchiveSupported(macos_host, resolved(.linux, .riscv64, .musl)));
try std.testing.expect(app_build.serviceArchiveSupported(macos_host, resolved(.macos, .x86_64, .none)));
var linux_host = host;
linux_host.os.tag = .linux;
linux_host.cpu.arch = .riscv64;
linux_host.abi = .musl;
try std.testing.expect(app_build.serviceArchiveSupported(linux_host, .{ .query = .{}, .result = linux_host }));
try std.testing.expect(!app_build.serviceArchiveSupported(linux_host, resolved(.macos, .aarch64, .none)));
var gnu_linux_host = host;
gnu_linux_host.os.tag = .linux;
gnu_linux_host.cpu.arch = .x86_64;
gnu_linux_host.abi = .gnu;
const explicit_same_triple_gnu = resolved(.linux, .x86_64, .gnu);
try std.testing.expect(!app_build.scriptcTargetIsCross(gnu_linux_host, explicit_same_triple_gnu));
try std.testing.expect(app_build.linuxGlibcSpellingHitsDefaultFloor(explicit_same_triple_gnu));
try std.testing.expect(!app_build.linuxGlibcSpellingHitsDefaultFloor(.{ .query = .{}, .result = gnu_linux_host }));
var windows_host = host;
windows_host.os.tag = .windows;
windows_host.cpu.arch = .x86_64;
windows_host.abi = .gnu;
const native_windows_msvc = resolved(.windows, .x86_64, .msvc);
try std.testing.expect(!app_build.scriptcTargetIsCross(windows_host, native_windows_msvc));
try std.testing.expect(app_build.scriptcCompileSupported(windows_host, native_windows_msvc));
try std.testing.expect(app_build.serviceArchiveSupported(windows_host, native_windows_msvc));
}
test "root TypeScript markup discovery classification and resolver budgets" {
const app_build = @import("build/app.zig");
try std.testing.expect(app_build.isRootMarkupSourcePath("components/card.native"));
try std.testing.expect(app_build.isRootMarkupSourcePath("feature/nested/panel.native"));
try std.testing.expect(!app_build.isRootMarkupSourcePath("app.native"));
try std.testing.expect(!app_build.isRootMarkupSourcePath("windows/settings.native"));
try std.testing.expect(!app_build.isRootMarkupSourcePath("components/card.ts"));
// The authored paths are relative to src/, while native check and the
// desktop hot-reload resolver see the leading `src/` too. Pin the exact
// source-relative boundaries that keep those full paths within 24
// segments and 200 bytes.
const max_segments_path = "a/" ** 22 ++ "a";
try std.testing.expect(app_build.markupSourcePathWithinBudget(max_segments_path));
try std.testing.expect(!app_build.markupSourcePathWithinBudget(max_segments_path ++ "/a"));
try std.testing.expect(app_build.markupSourcePathWithinBudget("a" ** 196));
try std.testing.expect(!app_build.markupSourcePathWithinBudget("a" ** 197));
}
test "generated TypeScript runners install the compiled root markup view" {
const desktop = @embedFile("src/app_runner/ts_core_main.zig");
try std.testing.expect(std.mem.indexOf(u8, desktop, "TsUiAppWithFeatures(core, .{ .runtime_markup = dev and !ts_view.enabled, .compiled_model = ts_view.enabled })") != null);
try std.testing.expect(std.mem.indexOf(u8, desktop, "if (dev) void else @import(\"app_markup_root\")") != null);
try std.testing.expect(std.mem.indexOf(u8, desktop, "CompiledMarkupImports(core.Model, core.Msg, \"app.native\", &app_markup_sources)") != null);
try std.testing.expect(std.mem.indexOf(u8, desktop, ".view = CompiledAppView.build") != null);
try std.testing.expect(std.mem.indexOf(u8, desktop, "if (comptime ts_view.enabled) options.view = ts_view.buildRuntime") != null);
try std.testing.expect(std.mem.indexOf(u8, desktop, ".markup = if (dev and !ts_view.enabled)") != null);
const mobile = @embedFile("src/app_runner/ts_core_mobile.zig");
try std.testing.expect(std.mem.indexOf(u8, mobile, "pub const features: native_sdk.UiAppFeatures = .{ .runtime_markup = false, .compiled_model = ts_view.enabled }") != null);
try std.testing.expect(std.mem.indexOf(u8, mobile, "TsUiAppWithFeatures(core, features)") != null);
try std.testing.expect(std.mem.indexOf(u8, mobile, "const app_markup_root = @import(\"app_markup_root\")") != null);
try std.testing.expect(std.mem.indexOf(u8, mobile, "CompiledMarkupImports(core.Model, core.Msg, \"app.native\", &app_markup_sources)") != null);
try std.testing.expect(std.mem.indexOf(u8, mobile, ".view = if (ts_view.enabled) ts_view.buildRuntime else CompiledAppView.build") != null);
try std.testing.expect(std.mem.indexOf(u8, mobile, "pub const SourceModel = core.Model") != null);
try std.testing.expect(std.mem.indexOf(u8, mobile, ".markup =") == null);
}
test "Debug TypeScript root markup stays outside the staged app module" {
const source = @embedFile("build/app.zig");
try std.testing.expect(std.mem.indexOf(
u8,
source,
"_ = staged.addCopyFile(b.path(appPath(b, app_root, \"src/app.native\")), \"app.native\");",
) == null);
try std.testing.expect(std.mem.indexOf(
u8,
source,
"_ = release_markup.addCopyFile(b.path(appPath(b, app_root, \"src/app.native\")), \"app.native\");",
) != null);
try std.testing.expect(std.mem.indexOf(u8, source, "if (optimize != .Debug)") != null);
}
test "native check preserves the app markup root for component files" {
const source = @embedFile("tools/native-sdk/main.zig");
try std.testing.expect(std.mem.indexOf(
u8,
source,
"checkFiles(allocator, io, markup_files.items, .{\n .import_root_for_file = markup_cli.importRootForFile,\n",
) != null);
}
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;
const webview_inspection = b.option(bool, "webview-inspect", "Enable macOS system WebView inspection (default: Debug builds only)");
_ = 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 signing_identity = b.option([]const u8, "identity", "Code signing identity for distribution packages");
const signing_entitlements = b.option([]const u8, "entitlements", "Entitlements plist for identity signing");
const notary_profile = b.option([]const u8, "notary-profile", "notarytool Keychain profile for notarization");
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 app_runner_assets_mod = module(b, target, optimize, "src/app_runner/app_assets.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 app_runner_assets_tests = testArtifact(b, app_runner_assets_mod);
const canvas_tests = testArtifact(b, canvas_mod);
// Keep the GTK software-present damage math in a C-only executable: it
// exercises the production helper without requiring GTK headers, a
// display server, or the native host to be linked into unit tests.
const gtk_pixels_test_run = b.addSystemCommand(&.{ b.graph.zig_exe, "run", "-lc", "-cflags", "-std=c11", "-Wall", "-Wextra", "-Werror", "--" });
gtk_pixels_test_run.addFileArg(b.path("src/platform/linux/gtk_pixels_test.c"));
gtk_pixels_test_run.addFileInput(b.path("src/platform/linux/gtk_pixels.h"));
gtk_pixels_test_run.expectExitCode(0);
const gtk_pixels_test_step = b.step("test-gtk-pixels", "Run GTK software pixel conversion tests");
gtk_pixels_test_step.dependOn(>k_pixels_test_run.step);
const spectrum_bins_test_run = b.addSystemCommand(&.{ b.graph.zig_exe, "run", "-lc", "-cflags", "-std=c11", "-Wall", "-Wextra", "-Werror", "--" });
spectrum_bins_test_run.addFileArg(b.path("src/platform/macos/spectrum_bins_test.c"));
spectrum_bins_test_run.addFileInput(b.path("src/platform/macos/spectrum_bins.h"));
spectrum_bins_test_run.expectExitCode(0);
const spectrum_bins_test_step = b.step("test-spectrum-bins", "Run audio spectrum bin range tests");
spectrum_bins_test_step.dependOn(&spectrum_bins_test_run.step);
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);
desktop_mod.addImport("terminal_vt", terminalVtModule(b, target, optimize));
desktop_mod.addIncludePath(b.path("third_party/sqlite"));
desktop_mod.addCSourceFile(.{
.file = b.path("third_party/sqlite/sqlite3.c"),
// Mobile -Dtargets (the mobile e2e battery) compile the
// amalgamation against the platform SDK/NDK sysroot; desktop
// targets keep Zig's ordinary libc discovery.
.flags = if (target.result.os.tag == .ios or target.result.abi.isAndroid())
@import("build/app.zig").sqliteCFlags(b, target)
else
sqliteCompileFlags(),
});
const app_runner_window_placement_mod = module(b, target, optimize, "src/app_runner/window_placement.zig");
app_runner_window_placement_mod.addImport("native_sdk", desktop_mod);
const app_runner_window_placement_tests = testArtifact(b, app_runner_window_placement_mod);
const app_runner_options = b.addOptions();
app_runner_options.addOption([]const u8, "platform", "null");
app_runner_options.addOption([]const u8, "trace", "off");
app_runner_options.addOption([]const u8, "web_engine", "system");
app_runner_options.addOption(bool, "debug_overlay", false);
app_runner_options.addOption(bool, "automation", false);
app_runner_options.addOption(bool, "web_layer", false);
// Omit an unspecified setting to also exercise older custom build options.
if (webview_inspection) |enabled| {
app_runner_options.addOption(?bool, "webview_inspection", enabled);
}
app_runner_options.addOption(bool, "webview_inspection_expected", webview_inspection orelse (optimize == .Debug));
const app_runner_mod = module(b, target, optimize, "src/app_runner/root.zig");
app_runner_mod.addImport("native_sdk", desktop_mod);
app_runner_mod.addImport("build_options", app_runner_options.createModule());
app_runner_mod.addImport("app_manifest_zon", b.createModule(.{ .root_source_file = b.path("tests/app-runner/menu_commands_fixture.zon") }));
const app_runner_migrations_mod = module(b, target, optimize, "src/app_runner/no_migrations.zig");
app_runner_migrations_mod.addImport("native_sdk", desktop_mod);
app_runner_mod.addImport("relational_migrations", app_runner_migrations_mod);
const app_runner_tests = testArtifact(b, app_runner_mod);
const app_runner_test_run = b.addRunArtifact(app_runner_tests);
const app_runner_test_step = b.step("test-app-runner", "Run framework app-runner manifest fallback tests");
app_runner_test_step.dependOn(&app_runner_test_run.step);
desktop_mod.link_libc = true;
if (target.result.os.tag == .macos) {
const flags: []const []const u8 = if (b.sysroot) |sysroot|
&.{ "-fobjc-arc", "-fno-sanitize=builtin", "-ObjC", "-mmacosx-version-min=11.0", "-isysroot", sysroot, b.fmt("-I{s}/usr/include", .{sysroot}) }
else
&.{ "-fobjc-arc", "-fno-sanitize=builtin", "-ObjC", "-mmacosx-version-min=11.0" };
desktop_mod.addCSourceFile(.{ .file = b.path("src/platform/macos/image_fit_test.m"), .flags = flags });
desktop_mod.linkFramework("Foundation", .{});
desktop_mod.linkFramework("ImageIO", .{});
desktop_mod.linkSystemLibrary("objc", .{});
}
const desktop_tests = testArtifact(b, desktop_mod);
const desktop_test_shards = desktopTestShardArtifacts(b, desktop_mod);
// Tier-5 crash battery: a child uses the public streamed sink, signals
// after a chunk is durable only in the atomic temporary, then the parent
// kills it and verifies the destination still names the old generation.
const file_crash_helper_mod = module(b, target, optimize, "src/runtime/file_effect_crash_helper.zig");
file_crash_helper_mod.addImport("native_sdk", desktop_mod);
const file_crash_helper = b.addExecutable(.{ .name = "file-effect-crash-helper", .root_module = file_crash_helper_mod });
const file_crash_tests_mod = module(b, target, optimize, "src/runtime/file_effect_crash_tests.zig");
file_crash_tests_mod.addImport("native_sdk", desktop_mod);
const file_crash_options = b.addOptions();
file_crash_options.addOptionPath("helper_executable", file_crash_helper.getEmittedBin());
file_crash_tests_mod.addOptions("file_crash_options", file_crash_options);
const file_crash_tests = testArtifact(b, file_crash_tests_mod);
const file_crash_run = b.addRunArtifact(file_crash_tests);
const file_crash_step = b.step("test-file-effect-crash", "Kill a streamed writer before close and verify atomic destination visibility");
file_crash_step.dependOn(&file_crash_run.step);
const tier5_tests = filteredTestArtifact(b, desktop_mod, "storage-tier-5-tests", &.{
"runtime.effects_file_tests.test",
"runtime.file_access.test",
"runtime.session_record.test.recorder moves streamed file chunks",
"runtime.session_tests.test.a multi-megabyte file stream",
});
const tier5_run = b.addRunArtifact(tier5_tests);
const tier5_step = b.step("test-storage-tier-5", "Run file streaming, bounds, replay/blob, gating, and crash-atomicity batteries");
tier5_step.dependOn(&tier5_run.step);
tier5_step.dependOn(&file_crash_run.step);
// SQLite is capability-shed from ordinary app artifacts. Its focused
// engine/store suite gets a dedicated module that explicitly compiles the
// vendored amalgamation, so framework tests cover it without making every
// unrelated example carry the database object.
const record_store_mod = module(b, target, optimize, "src/runtime/record_store.zig");
record_store_mod.addIncludePath(b.path("third_party/sqlite"));
record_store_mod.addCSourceFile(.{
.file = b.path("third_party/sqlite/sqlite3.c"),
.flags = sqliteCompileFlags(),
});
record_store_mod.link_libc = true;
const record_store_tests = testArtifact(b, record_store_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");
const update_feed_mod = module(b, target, optimize, "src/updater/feed.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);
tooling_mod.addImport("sqlite_engine", module(b, target, optimize, "src/runtime/sqlite_engine.zig"));
tooling_mod.addImport("update_feed", update_feed_mod);
tooling_mod.addIncludePath(b.path("third_party/sqlite"));
tooling_mod.addCSourceFile(.{
.file = b.path("third_party/sqlite/sqlite3.c"),
.flags = sqliteCompileFlags(),
});
tooling_mod.link_libc = true;
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);
// The mirror's byte runtime stays a native unit root. Core admission
// and projection tests use the compiled host archive in the TypeScript
// tooling block below, alongside frontend-sidecar conformance.
const corewire_shim_rt_tests = testArtifact(b, module(b, target, optimize, "tools/corewire/shim_rt.zig"));
// TypeScript-core end-to-end suite: each fixture core is compiled
// through the external core compiler AT BUILD TIME (never a
// committed archive) and its e2e battery drives the linked archive
// through the real runtime via `TsCoreHost` over the generated
// mirror. Gated on node plus the package's installed dependencies
// (`npm ci` in packages/core — the compiler and the frontend
// toolchain arrive together): absent either, the suite is skipped
// (the bridge itself stays covered by
// src/runtime/ts_core_host_tests.zig against a hand-written
// core-ABI module).
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);
const skills_cli_mod = module(b, target, optimize, "tools/native-sdk/skills.zig");
const skills_cli_tests = testArtifact(b, skills_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);
const build_graph_tests = testArtifact(b, module(b, host_target, optimize, "build.zig"));
const invalid_import_compile_mod = module(b, target, optimize, "tests/ts-core/invalid_import_compile.zig");
invalid_import_compile_mod.addImport("canvas", canvas_mod);
const invalid_import_compile = b.addObject(.{
.name = "ts-invalid-import-compile",
.root_module = invalid_import_compile_mod,
});
invalid_import_compile.expect_errors = .{ .contains = "imported files define templates only - this file has a view root element; move the view to its own file and import just the templates" };
// `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");
const host_update_feed_mod = module(b, host_target, optimize, "src/updater/feed.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);
host_tooling_mod.addImport("sqlite_engine", module(b, host_target, optimize, "src/runtime/sqlite_engine.zig"));
host_tooling_mod.addImport("update_feed", host_update_feed_mod);
host_tooling_mod.addIncludePath(b.path("third_party/sqlite"));
host_tooling_mod.addCSourceFile(.{
.file = b.path("third_party/sqlite/sqlite3.c"),
.flags = sqliteCompileFlags(),
});
host_tooling_mod.link_libc = true;
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"));
// The docs preview never runs an emulator: the stub keeps the wasm
// module free of the ghostty graph (and of pty transports it could
// not use anyway).
wasm_native_mod.addImport("terminal_vt", module(b, wasm_target, wasm_optimize, "src/runtime/terminal_vt_stub.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, plus this build's layout fingerprints (session journal
// format, automation protocol). `zig build print-pins` after
// registry additions. The journal fingerprint lives in the full
// framework module, and the tool runs on the build HOST by
// construction (addRunArtifact), so it builds against a host clone
// of the framework module — cross-compiled `-Dtarget` builds keep a
// runnable print-pins, and the fingerprints are layout identities
// (type shapes, never target-sized values), identical either way.
const pins_json_mod = module(b, host_target, optimize, "src/primitives/json/root.zig");
const pins_canvas_mod = module(b, host_target, optimize, "src/primitives/canvas/root.zig");
pins_canvas_mod.addImport("geometry", host_geometry_mod);
pins_canvas_mod.addImport("json", pins_json_mod);
if (host_target.result.os.tag == .macos) {
// Same CoreText linkage the target canvas module carries (see
// canvas_mod above): the shaping path calls it on macOS hosts.
pins_canvas_mod.linkFramework("CoreFoundation", .{});
pins_canvas_mod.linkFramework("CoreGraphics", .{});
pins_canvas_mod.linkFramework("CoreText", .{});
pins_canvas_mod.linkSystemLibrary("c", .{});
}
const pins_native_mod = module(b, host_target, optimize, "src/root.zig");
pins_native_mod.addImport("geometry", host_geometry_mod);
pins_native_mod.addImport("app_dirs", host_app_dirs_mod);
pins_native_mod.addImport("assets", host_assets_mod);
pins_native_mod.addImport("trace", host_trace_mod);
pins_native_mod.addImport("app_manifest", host_app_manifest_mod);
pins_native_mod.addImport("diagnostics", host_diagnostics_mod);
pins_native_mod.addImport("platform_info", host_platform_info_mod);
pins_native_mod.addImport("json", pins_json_mod);
pins_native_mod.addImport("canvas", pins_canvas_mod);
// The pin printer reflects registry tables and layout fingerprints —
// type shapes, never emulator state — so the stub keeps it light.
pins_native_mod.addImport("terminal_vt", module(b, host_target, optimize, "src/runtime/terminal_vt_stub.zig"));
const print_pins_mod = module(b, host_target, optimize, "tools/print_pins.zig");
print_pins_mod.addImport("native_sdk", pins_native_mod);
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");
b.step("test-ts-canvas-hooks", "Verify canvas declaration validation, ownership, and model accessibility themes").dependOn(&b.addRunArtifact(filteredTestArtifact(b, desktop_mod, "ts-canvas-hook-tests", &.{ "TypeScript canvas", "model accessibility theme" })).step);
test_step.dependOn(&invalid_import_compile.step);
test_step.dependOn(&b.addRunArtifact(build_graph_tests).step);
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(app_runner_assets_tests).step);
test_step.dependOn(&b.addRunArtifact(app_runner_window_placement_tests).step);
test_step.dependOn(&app_runner_test_run.step);
test_step.dependOn(&b.addRunArtifact(canvas_tests).step);
test_step.dependOn(>k_pixels_test_run.step);
test_step.dependOn(&spectrum_bins_test_run.step);
if (b.graph.host.result.os.tag == .macos) {
for ([_]struct { file: []const u8, step: []const u8, description: []const u8 }{
.{ .file = "widget_focus_test.m", .step = "test-macos-widget-focus", .description = "Verify native accessibility publication preserves keyboard focus without assistive feedback" },
.{ .file = "scroll_driver_test.m", .step = "test-macos-scroll-drivers", .description = "Verify native scroll resize reports settle after driver reconciliation" },
.{ .file = "pointer_motion_test.m", .step = "test-macos-pointer-motion", .description = "Verify coalesced native pointer drags preserve geometry deltas" },
.{ .file = "webview_inspection_test.m", .step = "test-macos-webview-inspection", .description = "Verify inspection capability for primary, lazy, secondary and child WebViews" },
.{ .file = "text_keyboard_test.m", .step = "test-macos-text-keyboard", .description = "Verify native Enter modifiers survive AppKit text interpretation" },
}) |probe| {
const probe_run = b.addSystemCommand(&.{ b.graph.zig_exe, "run", "-lc" });
for ([_][]const u8{ "AppKit", "AVFoundation", "ScreenCaptureKit", "MediaToolbox", "CoreMedia", "Accelerate", "Metal", "QuartzCore", "WebKit", "CoreFoundation", "CoreText", "ImageIO", "Security", "UniformTypeIdentifiers" }) |framework| {
probe_run.addArgs(&.{ "-framework", framework });
}
probe_run.addArgs(&.{ "-cflags", "-fobjc-arc", "-fno-sanitize=builtin", "-mmacosx-version-min=11.0" });
if (b.sysroot) |sysroot| probe_run.addArgs(&.{ "-isysroot", sysroot });
probe_run.addArg("--");
probe_run.addFileArg(b.path(b.fmt("src/platform/macos/{s}", .{probe.file})));
probe_run.addFileInput(b.path("src/platform/macos/appkit_host.m"));
probe_run.addFileInput(b.path("src/platform/macos/appkit_host.h"));
probe_run.expectExitCode(0);
b.step(probe.step, probe.description).dependOn(&probe_run.step);
test_step.dependOn(&probe_run.step);
}
}
test_step.dependOn(&b.addRunArtifact(record_store_tests).step);
test_step.dependOn(&file_crash_run.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);
test_step.dependOn(&b.addRunArtifact(corewire_shim_rt_tests).step);
const ts_services_e2e_step = b.step("test-ts-services-e2e", "Run both TypeScript service carriers end to end: the out-of-process child (crash recovery, timeout, replay) and the in-process pool (parallel keys, FIFO, trap isolation, replay)");
if (ts_core_e2e_tests) |ts_core_artifacts| {
const ts_core_e2e_step = b.step("test-ts-core-e2e", "Run the TypeScript-core end-to-end suites over externally compiled fixture cores (requires node and `npm ci` in packages/core)");
// Keep stderr inherited for timed app reference/replay commands: Zig's
// I/O lock then serializes their nested builds, whose CPU pools would
// otherwise compete with one another. Capture stdout for quiet runs.
// Independent compilation and ordinary example suites remain parallel.
const native_driver_run = managedExampleRun(b, host_cli_exe, &.{ "test", "-Dplatform=null" });
native_driver_run.setCwd(b.path("tests/native-driver"));
native_driver_run.has_side_effects = true;
_ = native_driver_run.captureStdOut(.{});
native_driver_run.setName("TypeScript native test driver");
native_driver_run.setEnvironmentVariable("NATIVE_SDK_TEST_VIEW_BACKEND", "typescript");
const legacy_driver_run = managedExampleRun(b, host_cli_exe, &.{ "test", "-Dplatform=null", "-Dtypescript-view=false" });
legacy_driver_run.setCwd(b.path("tests/native-driver"));
legacy_driver_run.has_side_effects = true;
legacy_driver_run.setEnvironmentVariable("NATIVE_SDK_TEST_VIEW_BACKEND", "zig");
_ = legacy_driver_run.captureStdOut(.{});
legacy_driver_run.setName("Native test driver reference view");
// Both builds share the app scratch graph. Run the reference first,
// then exercise the compiled default in the same test battery.
native_driver_run.step.dependOn(&legacy_driver_run.step);
const native_driver_step = b.step("test-ts-native-driver", "Drive a compiled app from authored TypeScript tests");
native_driver_step.dependOn(&native_driver_run.step);
const kanban_driver_run = managedExampleRun(b, host_cli_exe, &.{ "test", "-Dplatform=null" });
kanban_driver_run.setCwd(b.path("examples/kanban"));
kanban_driver_run.has_side_effects = true;
kanban_driver_run.setEnvironmentVariable("NATIVE_SDK_TEST_VIEW_BACKEND", "typescript");
kanban_driver_run.setEnvironmentVariable("NATIVE_SDK_TEST_VIEW_REFERENCE", b.pathFromRoot(".zig-cache/kanban-view-reference"));
_ = kanban_driver_run.captureStdOut(.{});
kanban_driver_run.setName("TypeScript Kanban native test driver");
const kanban_reference_run = managedExampleRun(b, host_cli_exe, &.{ "test", "-Dplatform=null", "-Dtypescript-view=false" });
kanban_reference_run.setCwd(b.path("examples/kanban"));
kanban_reference_run.has_side_effects = true;
kanban_reference_run.setEnvironmentVariable("NATIVE_SDK_TEST_VIEW_BACKEND", "zig");
kanban_reference_run.setEnvironmentVariable("NATIVE_SDK_TEST_VIEW_REFERENCE", b.pathFromRoot(".zig-cache/kanban-view-reference"));
_ = kanban_reference_run.captureStdOut(.{});
kanban_reference_run.setName("Kanban native test driver reference view");
kanban_driver_run.step.dependOn(&kanban_reference_run.step);
native_driver_step.dependOn(&kanban_driver_run.step);
ts_core_e2e_step.dependOn(&kanban_driver_run.step);
test_step.dependOn(&kanban_driver_run.step);
const feed_reference_run = managedExampleRun(b, host_cli_exe, &.{ "test", "-Dplatform=null", "-Dtypescript-view=false" });
feed_reference_run.setCwd(b.path("examples/service-feed-reader"));
feed_reference_run.has_side_effects = true;
feed_reference_run.setEnvironmentVariable("NATIVE_SDK_TEST_VIEW_BACKEND", "zig");
feed_reference_run.setEnvironmentVariable("NATIVE_SDK_TEST_VIEW_REFERENCE", b.pathFromRoot(".zig-cache/feed-view-reference"));
_ = feed_reference_run.captureStdOut(.{});
const feed_driver_run = managedExampleRun(b, host_cli_exe, &.{ "test", "-Dplatform=null" });
feed_driver_run.setCwd(b.path("examples/service-feed-reader"));
feed_driver_run.has_side_effects = true;
feed_driver_run.setEnvironmentVariable("NATIVE_SDK_TEST_VIEW_BACKEND", "typescript");
feed_driver_run.setEnvironmentVariable("NATIVE_SDK_TEST_VIEW_REFERENCE", b.pathFromRoot(".zig-cache/feed-view-reference"));
_ = feed_driver_run.captureStdOut(.{});
feed_driver_run.step.dependOn(&feed_reference_run.step);
native_driver_step.dependOn(&feed_driver_run.step);
ts_core_e2e_step.dependOn(&feed_driver_run.step);
ts_services_e2e_step.dependOn(&feed_driver_run.step);
test_step.dependOn(&feed_driver_run.step);
const subscription_reference_run = managedExampleRun(b, host_cli_exe, &.{ "test", "-Dplatform=null", "-Dtypescript-view=false" });
subscription_reference_run.setCwd(b.path("examples/subscription-policy"));
subscription_reference_run.has_side_effects = true;
subscription_reference_run.setEnvironmentVariable("NATIVE_SDK_TEST_VIEW_BACKEND", "zig");
subscription_reference_run.setEnvironmentVariable("NATIVE_SDK_TEST_VIEW_REFERENCE", b.pathFromRoot(".zig-cache/subscription-policy-reference"));
_ = subscription_reference_run.captureStdOut(.{});
const subscription_driver_run = managedExampleRun(b, host_cli_exe, &.{ "test", "-Dplatform=null" });
subscription_driver_run.setCwd(b.path("examples/subscription-policy"));
subscription_driver_run.has_side_effects = true;
subscription_driver_run.setEnvironmentVariable("NATIVE_SDK_TEST_VIEW_BACKEND", "typescript");
subscription_driver_run.setEnvironmentVariable("NATIVE_SDK_TEST_VIEW_REFERENCE", b.pathFromRoot(".zig-cache/subscription-policy-reference"));
_ = subscription_driver_run.captureStdOut(.{});
subscription_driver_run.step.dependOn(&subscription_reference_run.step);
native_driver_step.dependOn(&subscription_driver_run.step);
ts_core_e2e_step.dependOn(&subscription_driver_run.step);
test_step.dependOn(&subscription_driver_run.step);
const effect_reference_run = managedExampleRun(b, host_cli_exe, &.{ "test", "-Dplatform=null", "-Dtypescript-view=false" });
effect_reference_run.setCwd(b.path("examples/effect-policy"));
effect_reference_run.has_side_effects = true;
effect_reference_run.setEnvironmentVariable("NATIVE_SDK_TEST_VIEW_BACKEND", "zig");
effect_reference_run.setEnvironmentVariable("NATIVE_SDK_TEST_VIEW_REFERENCE", b.pathFromRoot(".zig-cache/effect-policy-reference"));
_ = effect_reference_run.captureStdOut(.{});
const effect_driver_run = managedExampleRun(b, host_cli_exe, &.{ "test", "-Dplatform=null" });
effect_driver_run.setCwd(b.path("examples/effect-policy"));
effect_driver_run.has_side_effects = true;
effect_driver_run.setEnvironmentVariable("NATIVE_SDK_TEST_VIEW_BACKEND", "typescript");
effect_driver_run.setEnvironmentVariable("NATIVE_SDK_TEST_VIEW_REFERENCE", b.pathFromRoot(".zig-cache/effect-policy-reference"));
_ = effect_driver_run.captureStdOut(.{});
effect_driver_run.step.dependOn(&effect_reference_run.step);
native_driver_step.dependOn(&effect_driver_run.step);
ts_core_e2e_step.dependOn(&effect_driver_run.step);
test_step.dependOn(&effect_driver_run.step);
const stream_reference_run = managedExampleRun(b, host_cli_exe, &.{ "test", "-Dplatform=null", "-Dtypescript-view=false" });
stream_reference_run.setCwd(b.path("examples/stream-policy"));
stream_reference_run.has_side_effects = true;
stream_reference_run.setEnvironmentVariable("NATIVE_SDK_TEST_VIEW_BACKEND", "zig");
stream_reference_run.setEnvironmentVariable("NATIVE_SDK_TEST_VIEW_REFERENCE", b.pathFromRoot(".zig-cache/stream-policy-reference"));
_ = stream_reference_run.captureStdOut(.{});
const stream_driver_run = managedExampleRun(b, host_cli_exe, &.{ "test", "-Dplatform=null" });
stream_driver_run.setCwd(b.path("examples/stream-policy"));
stream_driver_run.has_side_effects = true;
stream_driver_run.setEnvironmentVariable("NATIVE_SDK_TEST_VIEW_BACKEND", "typescript");
stream_driver_run.setEnvironmentVariable("NATIVE_SDK_TEST_VIEW_REFERENCE", b.pathFromRoot(".zig-cache/stream-policy-reference"));
_ = stream_driver_run.captureStdOut(.{});
stream_driver_run.step.dependOn(&stream_reference_run.step);
native_driver_step.dependOn(&stream_driver_run.step);
ts_core_e2e_step.dependOn(&stream_driver_run.step);
test_step.dependOn(&stream_driver_run.step);
const pipeline_reference_run = managedExampleRun(b, host_cli_exe, &.{ "test", "-Dplatform=null", "-Dtypescript-view=false" });
pipeline_reference_run.setCwd(b.path("examples/pipeline"));
pipeline_reference_run.has_side_effects = true;
pipeline_reference_run.setEnvironmentVariable("NATIVE_SDK_TEST_VIEW_BACKEND", "zig");
pipeline_reference_run.setEnvironmentVariable("NATIVE_SDK_TEST_VIEW_REFERENCE", b.pathFromRoot(".zig-cache/pipeline-view-reference"));
_ = pipeline_reference_run.captureStdOut(.{});
const pipeline_driver_run = managedExampleRun(b, host_cli_exe, &.{ "test", "-Dplatform=null" });
pipeline_driver_run.setCwd(b.path("examples/pipeline"));
pipeline_driver_run.has_side_effects = true;
pipeline_driver_run.setEnvironmentVariable("NATIVE_SDK_TEST_VIEW_BACKEND", "typescript");
pipeline_driver_run.setEnvironmentVariable("NATIVE_SDK_TEST_VIEW_REFERENCE", b.pathFromRoot(".zig-cache/pipeline-view-reference"));
_ = pipeline_driver_run.captureStdOut(.{});
pipeline_driver_run.step.dependOn(&pipeline_reference_run.step);
native_driver_step.dependOn(&pipeline_driver_run.step);
ts_core_e2e_step.dependOn(&pipeline_driver_run.step);
test_step.dependOn(&pipeline_driver_run.step);
const radio_policy_reference_run = managedExampleRun(b, host_cli_exe, &.{ "test", "-Dplatform=null", "-Dtypescript-view=false" });
radio_policy_reference_run.setCwd(b.path("examples/radio-policy"));
radio_policy_reference_run.has_side_effects = true;
radio_policy_reference_run.setEnvironmentVariable("NATIVE_SDK_TEST_VIEW_BACKEND", "zig");
radio_policy_reference_run.setEnvironmentVariable("NATIVE_SDK_TEST_VIEW_REFERENCE", b.pathFromRoot(".zig-cache/radio-policy-view-reference"));
_ = radio_policy_reference_run.captureStdOut(.{});
const radio_policy_driver_run = managedExampleRun(b, host_cli_exe, &.{ "test", "-Dplatform=null" });
radio_policy_driver_run.setCwd(b.path("examples/radio-policy"));
radio_policy_driver_run.has_side_effects = true;
radio_policy_driver_run.setEnvironmentVariable("NATIVE_SDK_TEST_VIEW_BACKEND", "typescript");
radio_policy_driver_run.setEnvironmentVariable("NATIVE_SDK_TEST_VIEW_REFERENCE", b.pathFromRoot(".zig-cache/radio-policy-view-reference"));
_ = radio_policy_driver_run.captureStdOut(.{});
radio_policy_driver_run.step.dependOn(&radio_policy_reference_run.step);
native_driver_step.dependOn(&radio_policy_driver_run.step);
ts_core_e2e_step.dependOn(&radio_policy_driver_run.step);
test_step.dependOn(&radio_policy_driver_run.step);
const tabs_policy_reference_run = managedExampleRun(b, host_cli_exe, &.{ "test", "-Dplatform=null", "-Dtypescript-view=false" });
tabs_policy_reference_run.setCwd(b.path("examples/tabs-policy"));
tabs_policy_reference_run.has_side_effects = true;
tabs_policy_reference_run.setEnvironmentVariable("NATIVE_SDK_TEST_VIEW_BACKEND", "zig");
tabs_policy_reference_run.setEnvironmentVariable("NATIVE_SDK_TEST_VIEW_REFERENCE", b.pathFromRoot(".zig-cache/tabs-policy-view-reference"));
_ = tabs_policy_reference_run.captureStdOut(.{});
const tabs_policy_driver_run = managedExampleRun(b, host_cli_exe, &.{ "test", "-Dplatform=null" });
tabs_policy_driver_run.setCwd(b.path("examples/tabs-policy"));
tabs_policy_driver_run.has_side_effects = true;
tabs_policy_driver_run.setEnvironmentVariable("NATIVE_SDK_TEST_VIEW_BACKEND", "typescript");
tabs_policy_driver_run.setEnvironmentVariable("NATIVE_SDK_TEST_VIEW_REFERENCE", b.pathFromRoot(".zig-cache/tabs-policy-view-reference"));
_ = tabs_policy_driver_run.captureStdOut(.{});
tabs_policy_driver_run.step.dependOn(&tabs_policy_reference_run.step);
native_driver_step.dependOn(&tabs_policy_driver_run.step);
ts_core_e2e_step.dependOn(&tabs_policy_driver_run.step);
test_step.dependOn(&tabs_policy_driver_run.step);
const tree_policy_reference_run = managedExampleRun(b, host_cli_exe, &.{ "test", "-Dplatform=null", "-Dtypescript-view=false" });
tree_policy_reference_run.setCwd(b.path("examples/tree-policy"));
tree_policy_reference_run.has_side_effects = true;
tree_policy_reference_run.setEnvironmentVariable("NATIVE_SDK_TEST_VIEW_BACKEND", "zig");
tree_policy_reference_run.setEnvironmentVariable("NATIVE_SDK_TEST_VIEW_REFERENCE", b.pathFromRoot(".zig-cache/tree-policy-view-reference"));
_ = tree_policy_reference_run.captureStdOut(.{});
const tree_policy_driver_run = managedExampleRun(b, host_cli_exe, &.{ "test", "-Dplatform=null" });
tree_policy_driver_run.setCwd(b.path("examples/tree-policy"));
tree_policy_driver_run.has_side_effects = true;
tree_policy_driver_run.setEnvironmentVariable("NATIVE_SDK_TEST_VIEW_BACKEND", "typescript");
tree_policy_driver_run.setEnvironmentVariable("NATIVE_SDK_TEST_VIEW_REFERENCE", b.pathFromRoot(".zig-cache/tree-policy-view-reference"));
_ = tree_policy_driver_run.captureStdOut(.{});
tree_policy_driver_run.step.dependOn(&tree_policy_reference_run.step);
native_driver_step.dependOn(&tree_policy_driver_run.step);
ts_core_e2e_step.dependOn(&tree_policy_driver_run.step);
test_step.dependOn(&tree_policy_driver_run.step);
const list_policy_reference_run = managedExampleRun(b, host_cli_exe, &.{ "test", "-Dplatform=null", "-Dtypescript-view=false" });
list_policy_reference_run.setCwd(b.path("examples/list-policy"));
list_policy_reference_run.has_side_effects = true;
list_policy_reference_run.setEnvironmentVariable("NATIVE_SDK_TEST_VIEW_BACKEND", "zig");
list_policy_reference_run.setEnvironmentVariable("NATIVE_SDK_TEST_VIEW_REFERENCE", b.pathFromRoot(".zig-cache/list-policy-view-reference"));
_ = list_policy_reference_run.captureStdOut(.{});
const list_policy_driver_run = managedExampleRun(b, host_cli_exe, &.{ "test", "-Dplatform=null" });
list_policy_driver_run.setCwd(b.path("examples/list-policy"));
list_policy_driver_run.has_side_effects = true;
list_policy_driver_run.setEnvironmentVariable("NATIVE_SDK_TEST_VIEW_BACKEND", "typescript");
list_policy_driver_run.setEnvironmentVariable("NATIVE_SDK_TEST_VIEW_REFERENCE", b.pathFromRoot(".zig-cache/list-policy-view-reference"));
_ = list_policy_driver_run.captureStdOut(.{});
list_policy_driver_run.step.dependOn(&list_policy_reference_run.step);
native_driver_step.dependOn(&list_policy_driver_run.step);
ts_core_e2e_step.dependOn(&list_policy_driver_run.step);
test_step.dependOn(&list_policy_driver_run.step);
const menu_policy_reference_run = managedExampleRun(b, host_cli_exe, &.{ "test", "-Dplatform=null", "-Dtypescript-view=false" });
menu_policy_reference_run.setCwd(b.path("examples/menu-policy"));
menu_policy_reference_run.has_side_effects = true;
menu_policy_reference_run.setEnvironmentVariable("NATIVE_SDK_TEST_VIEW_BACKEND", "zig");
menu_policy_reference_run.setEnvironmentVariable("NATIVE_SDK_TEST_VIEW_REFERENCE", b.pathFromRoot(".zig-cache/menu-policy-view-reference"));
_ = menu_policy_reference_run.captureStdOut(.{});
const menu_policy_driver_run = managedExampleRun(b, host_cli_exe, &.{ "test", "-Dplatform=null" });
menu_policy_driver_run.setCwd(b.path("examples/menu-policy"));
menu_policy_driver_run.has_side_effects = true;
menu_policy_driver_run.setEnvironmentVariable("NATIVE_SDK_TEST_VIEW_BACKEND", "typescript");
menu_policy_driver_run.setEnvironmentVariable("NATIVE_SDK_TEST_VIEW_REFERENCE", b.pathFromRoot(".zig-cache/menu-policy-view-reference"));
_ = menu_policy_driver_run.captureStdOut(.{});
menu_policy_driver_run.step.dependOn(&menu_policy_reference_run.step);
native_driver_step.dependOn(&menu_policy_driver_run.step);
ts_core_e2e_step.dependOn(&menu_policy_driver_run.step);
test_step.dependOn(&menu_policy_driver_run.step);
const toggle_policy_reference_run = managedExampleRun(b, host_cli_exe, &.{ "test", "-Dplatform=null", "-Dtypescript-view=false" });
toggle_policy_reference_run.setCwd(b.path("examples/toggle-policy"));
toggle_policy_reference_run.has_side_effects = true;
toggle_policy_reference_run.setEnvironmentVariable("NATIVE_SDK_TEST_VIEW_BACKEND", "zig");
toggle_policy_reference_run.setEnvironmentVariable("NATIVE_SDK_TEST_VIEW_REFERENCE", b.pathFromRoot(".zig-cache/toggle-policy-view-reference"));
_ = toggle_policy_reference_run.captureStdOut(.{});
const toggle_policy_driver_run = managedExampleRun(b, host_cli_exe, &.{ "test", "-Dplatform=null" });
toggle_policy_driver_run.setCwd(b.path("examples/toggle-policy"));
toggle_policy_driver_run.has_side_effects = true;
toggle_policy_driver_run.setEnvironmentVariable("NATIVE_SDK_TEST_VIEW_BACKEND", "typescript");
toggle_policy_driver_run.setEnvironmentVariable("NATIVE_SDK_TEST_VIEW_REFERENCE", b.pathFromRoot(".zig-cache/toggle-policy-view-reference"));
_ = toggle_policy_driver_run.captureStdOut(.{});
toggle_policy_driver_run.step.dependOn(&toggle_policy_reference_run.step);
native_driver_step.dependOn(&toggle_policy_driver_run.step);
ts_core_e2e_step.dependOn(&toggle_policy_driver_run.step);
test_step.dependOn(&toggle_policy_driver_run.step);
const accordion_policy_reference_run = managedExampleRun(b, host_cli_exe, &.{ "test", "-Dplatform=null", "-Dtypescript-view=false" });
accordion_policy_reference_run.setCwd(b.path("examples/accordion-policy"));
accordion_policy_reference_run.has_side_effects = true;
accordion_policy_reference_run.setEnvironmentVariable("NATIVE_SDK_TEST_VIEW_BACKEND", "zig");
accordion_policy_reference_run.setEnvironmentVariable("NATIVE_SDK_TEST_VIEW_REFERENCE", b.pathFromRoot(".zig-cache/accordion-policy-view-reference"));
_ = accordion_policy_reference_run.captureStdOut(.{});
const accordion_policy_driver_run = managedExampleRun(b, host_cli_exe, &.{ "test", "-Dplatform=null" });
accordion_policy_driver_run.setCwd(b.path("examples/accordion-policy"));
accordion_policy_driver_run.has_side_effects = true;
accordion_policy_driver_run.setEnvironmentVariable("NATIVE_SDK_TEST_VIEW_BACKEND", "typescript");
accordion_policy_driver_run.setEnvironmentVariable("NATIVE_SDK_TEST_VIEW_REFERENCE", b.pathFromRoot(".zig-cache/accordion-policy-view-reference"));
_ = accordion_policy_driver_run.captureStdOut(.{});
accordion_policy_driver_run.step.dependOn(&accordion_policy_reference_run.step);
native_driver_step.dependOn(&accordion_policy_driver_run.step);