@native-sdk/cli 0.9.3 → 0.9.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/README.md +3 -3
  2. package/build/app.zig +323 -76
  3. package/build/ts_run.mjs +15 -18
  4. package/build.zig +83 -8
  5. package/package.json +14 -10
  6. package/packages/core/compile-surface/core.ts +1 -0
  7. package/packages/core/package-lock.json +16 -13
  8. package/packages/core/package.json +5 -2
  9. package/packages/core/scripts/compiler_command.mjs +71 -0
  10. package/packages/core/scripts/compiler_typecheck.mjs +4 -4
  11. package/packages/core/scripts/embed_markup_c.mjs +25 -0
  12. package/packages/core/scripts/npm_static_spike.mjs +3 -3
  13. package/packages/core/scripts/run_external_core_compiler.mjs +21 -10
  14. package/packages/core/scripts/run_external_service_compiler.mjs +17 -7
  15. package/packages/core/scripts/vendor_service_packages.mjs +121 -8
  16. package/packages/core/sdk/core.ts +1 -0
  17. package/packages/core/sdk/events.d.ts +36 -4
  18. package/packages/core/sdk/events.ts +49 -6
  19. package/packages/core/src/checker.ts +106 -10
  20. package/packages/core/src/modules.ts +6 -2
  21. package/packages/core/src/sqlite_cli.ts +22 -2
  22. package/packages/core/src/typed_ast.ts +4 -2
  23. package/packages/core/src/types.ts +8 -8
  24. package/schemas/app.schema.json +435 -0
  25. package/skill-data/core/SKILL.md +53 -15
  26. package/skill-data/core/references/project-anatomy.md +6 -6
  27. package/skill-data/native-ui/SKILL.md +28 -6
  28. package/skill-data/ts-core/SKILL.md +9 -6
  29. package/skill-data/ts-services/references/service-surface.md +1 -1
  30. package/skills/native-sdk/SKILL.md +2 -2
  31. package/src/app_runner/ts_core_main.zig +12 -4
  32. package/src/app_runner/ts_core_mobile.zig +6 -2
  33. package/src/automation/snapshot.zig +91 -3
  34. package/src/platform/macos/appkit_host.h +41 -2
  35. package/src/platform/macos/appkit_host.m +198 -9
  36. package/src/platform/macos/cef_host.mm +191 -9
  37. package/src/platform/macos/root.zig +110 -3
  38. package/src/platform/null_platform.zig +50 -1
  39. package/src/platform/null_platform_tests.zig +53 -0
  40. package/src/platform/root.zig +9 -0
  41. package/src/platform/types.zig +58 -0
  42. package/src/platform/windows/root.zig +88 -15
  43. package/src/primitives/canvas/reference.zig +37 -15
  44. package/src/primitives/canvas/reference_tests.zig +63 -0
  45. package/src/primitives/canvas/ui.zig +9 -0
  46. package/src/primitives/canvas/ui_markup.zig +29 -0
  47. package/src/primitives/canvas/ui_markup_compiled.zig +32 -0
  48. package/src/primitives/canvas/ui_markup_compiled_tests.zig +4 -2
  49. package/src/primitives/canvas/ui_markup_contract.zig +7 -0
  50. package/src/primitives/canvas/ui_markup_contract_tests.zig +21 -0
  51. package/src/primitives/canvas/ui_markup_tests.zig +6 -0
  52. package/src/primitives/canvas/ui_markup_view.zig +28 -0
  53. package/src/primitives/canvas/ui_markup_view_tests.zig +32 -3
  54. package/src/primitives/canvas/ui_schema.zig +9 -0
  55. package/src/primitives/canvas/ui_schema_tests.zig +5 -3
  56. package/src/primitives/canvas/ui_tests.zig +4 -2
  57. package/src/primitives/canvas/widget_render.zig +7 -2
  58. package/src/primitives/canvas/widget_semantics_tests.zig +3 -1
  59. package/src/root.zig +4 -0
  60. package/src/runtime/automation_snapshot.zig +3 -0
  61. package/src/runtime/flow.zig +1 -1
  62. package/src/runtime/state.zig +14 -0
  63. package/src/runtime/system_services.zig +62 -0
  64. package/src/runtime/ts_ui_app.zig +181 -39
  65. package/src/runtime/ui_app.zig +40 -1
  66. package/src/runtime/ui_app_tests.zig +63 -0
  67. package/src/runtime/ui_app_window_tests.zig +23 -0
  68. package/src/runtime/validation.zig +87 -1
  69. package/src/tooling/android.zig +5 -4
  70. package/src/tooling/buildgraph.zig +24 -8
  71. package/src/tooling/db.zig +1 -1
  72. package/src/tooling/doctor.zig +1 -1
  73. package/src/tooling/ios.zig +5 -4
  74. package/src/tooling/json_to_zon.zig +136 -0
  75. package/src/tooling/manifest.zig +120 -33
  76. package/src/tooling/raw_manifest.zig +4 -0
  77. package/src/tooling/root.zig +1 -0
  78. package/src/tooling/templates.zig +171 -118
  79. package/src/tooling/ts_core.zig +12 -8
  80. package/src/tooling/verbs.zig +233 -5
  81. package/src/tooling/web_engine.zig +17 -1
  82. package/tools/corewire/emit_profile.zig +20 -7
  83. package/tools/corewire/emit_service.zig +49 -24
  84. package/tools/corewire/main.zig +21 -2
package/build/app.zig CHANGED
@@ -5,6 +5,95 @@
5
5
 
6
6
  const std = @import("std");
7
7
  const builtin = @import("builtin");
8
+ const json_to_zon = @import("../src/tooling/json_to_zon.zig");
9
+
10
+ /// Canonicalize a generated file by its CONTENT before another build step
11
+ /// consumes it. `std.Build.Step.Run` normally places outputs under a cache
12
+ /// directory keyed by every declared input. That is correct for the producer,
13
+ /// but it means an unrelated input can change the output PATH even when the
14
+ /// file's bytes are identical; downstream Run steps hash that path and miss
15
+ /// their own caches. TypeScript's combined frontend is exactly that shape:
16
+ /// service implementation edits re-run the checker while often leaving the
17
+ /// core ABI contract byte-identical.
18
+ ///
19
+ /// This narrow adapter gives equal bytes one immutable cache path. Consumers
20
+ /// still invalidate whenever the bytes change, while producer-only churn
21
+ /// stops here. It is public so the repository's fixture graph can exercise
22
+ /// the same boundary as app builds.
23
+ pub fn stabilizeGeneratedFile(b: *std.Build, source: std.Build.LazyPath, basename: []const u8, trace: bool) std.Build.LazyPath {
24
+ return StableGeneratedFile.create(b, source, basename, trace).lazyPath();
25
+ }
26
+
27
+ const StableGeneratedFile = struct {
28
+ step: std.Build.Step,
29
+ source: std.Build.LazyPath,
30
+ basename: []const u8,
31
+ trace: bool,
32
+ generated: std.Build.GeneratedFile,
33
+
34
+ fn create(b: *std.Build, source: std.Build.LazyPath, basename: []const u8, trace: bool) *StableGeneratedFile {
35
+ const stable = b.allocator.create(StableGeneratedFile) catch @panic("OOM");
36
+ stable.* = .{
37
+ .step = std.Build.Step.init(.{
38
+ .id = .custom,
39
+ .name = b.fmt("stabilize generated {s}", .{basename}),
40
+ .owner = b,
41
+ .makeFn = make,
42
+ }),
43
+ .source = source.dupe(b),
44
+ .basename = b.dupePath(basename),
45
+ .trace = trace,
46
+ .generated = undefined,
47
+ };
48
+ stable.generated = .{ .step = &stable.step };
49
+ source.addStepDependencies(&stable.step);
50
+ return stable;
51
+ }
52
+
53
+ fn lazyPath(self: *StableGeneratedFile) std.Build.LazyPath {
54
+ return .{ .generated = .{ .file = &self.generated } };
55
+ }
56
+
57
+ fn make(step: *std.Build.Step, options: std.Build.Step.MakeOptions) !void {
58
+ _ = options;
59
+ const self: *StableGeneratedFile = @fieldParentPtr("step", step);
60
+ const b = step.owner;
61
+ const io = b.graph.io;
62
+ const arena = b.allocator;
63
+ const source_path = self.source.getPath3(b, step);
64
+ const bytes = source_path.root_dir.handle.readFileAlloc(io, source_path.sub_path, arena, .limited(64 * 1024 * 1024)) catch |err|
65
+ return step.fail("cannot stabilize generated {s}: {t}", .{ self.basename, err });
66
+
67
+ var digest: [std.crypto.hash.sha2.Sha256.digest_length]u8 = undefined;
68
+ std.crypto.hash.sha2.Sha256.hash(bytes, &digest, .{});
69
+ const hex = std.fmt.bytesToHex(digest, .lower);
70
+ const output_dir = b.pathJoin(&.{ "o", "native-stable", &hex });
71
+ const output_path = b.pathJoin(&.{ output_dir, self.basename });
72
+ self.generated.path = try b.cache_root.join(arena, &.{output_path});
73
+
74
+ var reused = false;
75
+ if (b.cache_root.handle.readFileAlloc(io, output_path, arena, .limited(64 * 1024 * 1024))) |existing| {
76
+ reused = std.mem.eql(u8, existing, bytes);
77
+ } else |_| {}
78
+ if (!reused) {
79
+ b.cache_root.handle.createDirPath(io, output_dir) catch |err|
80
+ return step.fail("cannot create the stable generated-output directory for {s}: {t}", .{ self.basename, err });
81
+ var atomic = b.cache_root.handle.createFileAtomic(io, output_path, .{ .replace = true }) catch |err|
82
+ return step.fail("cannot stage stable generated {s}: {t}", .{ self.basename, err });
83
+ defer atomic.deinit(io);
84
+ atomic.file.writeStreamingAll(io, bytes) catch |err|
85
+ return step.fail("cannot write stable generated {s}: {t}", .{ self.basename, err });
86
+ atomic.replace(io) catch |err|
87
+ return step.fail("cannot publish stable generated {s}: {t}", .{ self.basename, err });
88
+ }
89
+ step.result_cached = reused;
90
+ if (self.trace) std.debug.print("native build trace: {s} content {s} {s}\n", .{
91
+ self.basename,
92
+ &hex,
93
+ if (reused) "reused" else "changed",
94
+ });
95
+ }
96
+ };
8
97
 
9
98
  /// The shared web-layer inference contract: this build graph is one thin
10
99
  /// adapter over it (the CLI's manifest tooling and the app runner are the
@@ -33,6 +122,9 @@ const WebLayerOption = web_layer_contract.WebViewLayer;
33
122
 
34
123
  pub const AppOptions = struct {
35
124
  name: []const u8,
125
+ /// Explicit manifest path. Null auto-detects app.json first, then app.zon,
126
+ /// so older owned build.zig files can adopt JSON without a build edit.
127
+ manifest: ?[]const u8 = null,
36
128
  /// App entry point; defaults to src/main.zig (relative to `app_root`).
37
129
  main: []const u8 = "src/main.zig",
38
130
  /// Root of the app source tree, relative to the build root. "." for a
@@ -75,6 +167,34 @@ fn appFileExists(b: *std.Build, app_root: []const u8, sub_path: []const u8) bool
75
167
  return true;
76
168
  }
77
169
 
170
+ fn appManifestName(b: *std.Build, app_root: []const u8, requested: ?[]const u8) []const u8 {
171
+ if (requested) |name| return name;
172
+ if (appFileExists(b, app_root, "app.json")) return "app.json";
173
+ return "app.zon";
174
+ }
175
+
176
+ fn appManifestPath(b: *std.Build, app_root: []const u8, manifest_name: []const u8) []const u8 {
177
+ return appPath(b, app_root, manifest_name);
178
+ }
179
+
180
+ /// Produce the Zig module consumed by the existing comptime manifest wiring.
181
+ /// ZON manifests are already modules; JSON manifests are converted losslessly
182
+ /// into a generated module, keeping one runtime feature path for both formats.
183
+ fn appManifestModule(b: *std.Build, app_root: []const u8, manifest_name: []const u8) *std.Build.Module {
184
+ const path = appManifestPath(b, app_root, manifest_name);
185
+ if (!json_to_zon.isJsonPath(path)) {
186
+ return b.createModule(.{ .root_source_file = b.path(path) });
187
+ }
188
+ const source = b.build_root.handle.readFileAlloc(b.graph.io, path, b.allocator, .limited(1024 * 1024)) catch
189
+ @panic("cannot read app.json");
190
+ const zon = json_to_zon.convertAlloc(b.allocator, source) catch |err| switch (err) {
191
+ error.NullNotAllowed => @panic("app.json cannot contain null values; omit optional fields instead"),
192
+ else => @panic("cannot convert app.json into the build-time manifest module; run `native check` for a precise diagnostic"),
193
+ };
194
+ const generated = b.addWriteFiles().add("app_manifest.zon", zon);
195
+ return b.createModule(.{ .root_source_file = generated });
196
+ }
197
+
78
198
  const TsWindowView = struct {
79
199
  label: []const u8,
80
200
  source_path: []const u8,
@@ -239,15 +359,14 @@ const core_compiler_teaching =
239
359
  " that is the default.\nDelete the setting (or spell it \"external\").\n";
240
360
 
241
361
  /// The staged TypeScript-core wiring: one generated directory holding the
242
- /// core module (the generated mirror with its staged shim runtime), the
243
- /// app's markup, and the SDK's generated-wiring entry (ts_core_main.zig
244
- /// as main.zig) — plus the compiled-core archive the app module links
245
- /// behind the mirror. Built once per app build and shared by the exe
246
- /// and test modules.
362
+ /// core module (the generated mirror with its staged shim runtime) and the
363
+ /// SDK's generated-wiring entry (ts_core_main.zig as main.zig) — plus the
364
+ /// compiled-core archive and isolated markup data object the app module
365
+ /// links. Built once per app build and shared by the exe and test modules.
247
366
  const TsCoreStage = struct {
248
367
  main_root: std.Build.LazyPath,
249
368
  /// The staged mobile wiring (ts_core_mobile.zig beside the same
250
- /// mirror/markup/registry files): the embed static library's `app`
369
+ /// mirror/registry files): the embed static library's `app`
251
370
  /// module roots here on iOS/Android targets.
252
371
  mobile_root: std.Build.LazyPath,
253
372
  /// The compiled-core archive: the app module links it (with libc,
@@ -262,6 +381,9 @@ const TsCoreStage = struct {
262
381
  /// carrier is selected. The app module links it beside the core's
263
382
  /// archive.
264
383
  service_archive: ?std.Build.LazyPath = null,
384
+ /// C source containing the primary markup bytes under stable external
385
+ /// symbols. Compiled as a tiny data object by the final app artifact.
386
+ markup_c: std.Build.LazyPath,
265
387
  migrations: std.Build.LazyPath,
266
388
  };
267
389
 
@@ -586,48 +708,27 @@ fn tsParseQuotedManifestValue(manifest_json: []const u8, comptime key: []const u
586
708
  return suffix;
587
709
  }
588
710
 
589
- /// The external core compiler's entry module (scriptc's dist/main.js),
590
- /// resolved by node's ancestor node_modules walk from the SDK's
591
- /// packages/core — the same origin the frontend toolchain resolves from
592
- /// (tsAliasedCompilerVersion's walk, kept in lockstep). Repo checkouts
593
- /// install it there with `npm ci`; the npm-installed CLI carries the
594
- /// compiler as a regular dependency, nested under the package on global
595
- /// prefixes and hoisted to the project root on local ones.
596
- fn tsExternalCompilerJs(b: *std.Build, dep: *std.Build.Dependency) ?[]const u8 {
597
- const io = b.graph.io;
598
- const sdk_root = tsSdkRoot(b.allocator, io, dep);
711
+ /// PR 166 adds both the published compile-cache bootstrap and the optional
712
+ /// library-profile optimization field. The installed bootstrap is therefore
713
+ /// the capability marker: keep older exact pins byte-for-byte compatible;
714
+ /// once that release is installed, Debug/native-dev gets `dev` and
715
+ /// release/package artifacts get `release` automatically.
716
+ fn scriptcProfileOptimization(b: *std.Build, dep: *std.Build.Dependency, optimize: std.builtin.OptimizeMode) ?[]const u8 {
717
+ const sdk_root = tsSdkRoot(b.allocator, b.graph.io, dep);
599
718
  var dir: []const u8 = b.pathJoin(&.{ sdk_root, "packages", "core" });
600
719
  while (true) {
601
720
  if (!std.mem.eql(u8, std.fs.path.basename(dir), "node_modules")) {
602
- const candidate = b.pathJoin(&.{ dir, "node_modules", "scriptc", "dist", "main.js" });
603
- found: {
604
- std.Io.Dir.cwd().access(io, candidate, .{}) catch break :found;
605
- return candidate;
606
- }
721
+ const marker = b.pathJoin(&.{ dir, "node_modules", "scriptc", "dist", "bootstrap.js" });
722
+ std.Io.Dir.cwd().access(b.graph.io, marker, .{}) catch {
723
+ dir = std.fs.path.dirname(dir) orelse return null;
724
+ continue;
725
+ };
726
+ return if (optimize == .Debug) "dev" else "release";
607
727
  }
608
728
  dir = std.fs.path.dirname(dir) orelse return null;
609
729
  }
610
730
  }
611
731
 
612
- fn requireTsExternalCompilerJs(b: *std.Build, dep: *std.Build.Dependency) []const u8 {
613
- return tsExternalCompilerJs(b, dep) orelse {
614
- const sdk_root = tsSdkRoot(dep.builder.allocator, dep.builder.graph.io, dep);
615
- std.debug.print(
616
- \\
617
- \\error: the external TypeScript compiler is not installed (cores and services
618
- \\compile through it). It ships as an exact-pinned dependency of the SDK's
619
- \\packages/core — install it once with:
620
- \\ cd {s}/packages/core && npm ci
621
- \\(or point NATIVE_SDK_CORE_COMPILER at the pinned release's command; an
622
- \\npm-installed @native-sdk/cli carries the compiler automatically — if it is
623
- \\missing there, the install is broken: reinstall @native-sdk/cli).
624
- \\
625
- \\
626
- , .{sdk_root});
627
- std.process.exit(1);
628
- };
629
- }
630
-
631
732
  /// The SDK dependency's real root, resolved the way both the toolchain
632
733
  /// check and its teaching name it.
633
734
  fn tsSdkRoot(allocator: std.mem.Allocator, io: std.Io, dep: *std.Build.Dependency) []const u8 {
@@ -643,11 +744,11 @@ const TsToolingConsumer = enum { app_core, sqlite_schema };
643
744
  fn tsToolingPreflight(b: *std.Build, dep: *std.Build.Dependency, consumer: TsToolingConsumer) []const u8 {
644
745
  const node = b.findProgram(&.{"node"}, &.{}) catch switch (consumer) {
645
746
  .app_core => @panic("\nbuilding a TypeScript app core needs node on PATH (the @native-sdk/core frontend checks the" ++
646
- " core at build time; the binary you ship carries no JS runtime).\nInstall Node.js 22.15+ (on the 23" ++
647
- " line: 23.5+) — https://nodejs.org or `brew install node` — and re-run.\n"),
747
+ " core at build time; the binary you ship carries no JS runtime).\nInstall Node.js 24+" ++
748
+ " — https://nodejs.org or `brew install node` — and re-run.\n"),
648
749
  .sqlite_schema => @panic("\nbuilding relational SQLite migrations needs node on PATH (the schema checker and" ++
649
750
  " migration generator run at build time; the binary you ship carries no JS runtime).\nInstall Node.js" ++
650
- " 22.15+ (on the 23 line: 23.5+) — https://nodejs.org or `brew install node` — and re-run.\n"),
751
+ " 24+ — https://nodejs.org or `brew install node` — and re-run.\n"),
651
752
  };
652
753
  switch (tsToolchainResolution(b, dep)) {
653
754
  .resolved => {},
@@ -737,7 +838,7 @@ fn tsCorePreflight(b: *std.Build, dep: *std.Build.Dependency, app_root: []const
737
838
  /// contract sidecar, and corewire generates the mirror module from THAT
738
839
  /// document — so the boot identity fence always pairs the mirror with
739
840
  /// its own compile. The staged module directory carries core.zig (the
740
- /// mirror) + its staged runtime + app.native + main.zig, so the
841
+ /// mirror) + its staged runtime + main.zig, so the
741
842
  /// generated wiring imports one fixed shape.
742
843
  fn tsCoreStage(
743
844
  b: *std.Build,
@@ -754,6 +855,8 @@ fn tsCoreStage(
754
855
  service_packages: []const ServicePackageConfig,
755
856
  service_carrier_choice: ServiceCarrierOption,
756
857
  service_pool_workers: ?u8,
858
+ build_trace: bool,
859
+ scriptc_optimization: ?[]const u8,
757
860
  ) TsCoreStage {
758
861
  const node = tsCorePreflight(b, dep, app_root);
759
862
  const window_views = collectTsWindowViews(b, app_root);
@@ -789,6 +892,16 @@ fn tsCoreStage(
789
892
  sqlite_check.addFileArg(dep.path("packages/core/compile-surface/core.ts"));
790
893
  sqlite_check.addArg("--sdk-out");
791
894
  checked_sdk_core = sqlite_check.addOutputFileArg("core.ts");
895
+ sqlite_check.addArg("--sdk-events-out");
896
+ _ = sqlite_check.addOutputFileArg("events.ts");
897
+ sqlite_check.addArg("--sdk-text-out");
898
+ _ = sqlite_check.addOutputFileArg("text.ts");
899
+ sqlite_check.addArg("--sdk-bytes-text-methods-out");
900
+ _ = sqlite_check.addOutputFileArg("bytes_text_methods.d.ts");
901
+ sqlite_check.addArg("--sdk-events-dts-out");
902
+ _ = sqlite_check.addOutputFileArg("events.d.ts");
903
+ sqlite_check.addArg("--sdk-text-dts-out");
904
+ _ = sqlite_check.addOutputFileArg("text.d.ts");
792
905
  sqlite_check.addArg("--static-out");
793
906
  checked_static_core = sqlite_check.addOutputFileArg("core_static.ts");
794
907
  sqlite_check.addArg("--zig-out");
@@ -801,6 +914,9 @@ fn tsCoreStage(
801
914
  }
802
915
  sqlite_check.addFileInput(dep.path("packages/core/src/sqlite_codegen.ts"));
803
916
  sqlite_check.addFileInput(dep.path("packages/core/src/sqlite_runtime_policy.ts"));
917
+ for ([_][]const u8{ "events.ts", "text.ts", "bytes_text_methods.d.ts", "events.d.ts", "text.d.ts" }) |source| {
918
+ sqlite_check.addFileInput(dep.path(b.fmt("packages/core/sdk/{s}", .{source})));
919
+ }
804
920
  addAppSqlDirInputs(b, sqlite_check, appPath(b, app_root, "src"));
805
921
  }
806
922
 
@@ -819,17 +935,20 @@ fn tsCoreStage(
819
935
  // of the reachable imports: over-approximation only re-runs the
820
936
  // check, never misses a stale input).
821
937
  const check = b.addSystemCommand(&.{node});
938
+ check.setName("native ts frontend (core + service contracts)");
822
939
  check.addFileArg(dep.path("build/ts_run.mjs"));
823
940
  check.addFileArg(dep.path("packages/core/src/cli.ts"));
824
941
  check.addFileArg(b.path(appPath(b, app_root, "src/core.ts")));
825
942
  check.addArg("--contract");
826
- const contract = check.addOutputFileArg("core.contract.json");
943
+ const contract_raw = check.addOutputFileArg("core.contract.json");
944
+ const contract = stabilizeGeneratedFile(b, contract_raw, "core.contract.json", build_trace);
827
945
  // The document's entry spelling is app-relative (the sidecar/facade
828
946
  // contract carries no machine paths).
829
947
  check.addArgs(&.{ "--contract-entry", "src/core.ts" });
830
948
  const services_contract: ?std.Build.LazyPath = if (has_services) services_contract: {
831
949
  check.addArg("--services-contract");
832
- break :services_contract check.addOutputFileArg("services.contract.json");
950
+ const raw = check.addOutputFileArg("services.contract.json");
951
+ break :services_contract stabilizeGeneratedFile(b, raw, "services.contract.json", build_trace);
833
952
  } else null;
834
953
  if (persist_capability) check.addArgs(&.{ "--capability", "persist" });
835
954
  for (service_packages) |package_entry| {
@@ -869,12 +988,14 @@ fn tsCoreStage(
869
988
  // so the profile's entry spelling and the facade file can never skew.
870
989
  const corewire_exe = corewireExe(b, dep);
871
990
  const project = b.addRunArtifact(corewire_exe);
991
+ project.setName("native corewire (core facade + profile)");
872
992
  project.addArg("--sidecar");
873
993
  project.addFileArg(contract);
874
994
  project.addArg("--facade");
875
995
  const facade = project.addOutputFileArg("core_facade.ts");
876
996
  project.addArg("--profile");
877
997
  const profile = project.addOutputFileArg("core_profile.json");
998
+ if (scriptc_optimization) |value| project.addArgs(&.{ "--optimization", value });
878
999
 
879
1000
  // The fourth corewire projection is intentionally driven only by the
880
1001
  // service sidecar: the generated TypeScript dispatch loop and Zig
@@ -885,14 +1006,17 @@ fn tsCoreStage(
885
1006
  var service_client: ?std.Build.LazyPath = null;
886
1007
  if (services_contract) |service_contract| {
887
1008
  const service_project = b.addRunArtifact(corewire_exe);
1009
+ service_project.setName("native corewire (service host + ABI projections)");
888
1010
  service_project.addArg("--services-sidecar");
889
1011
  service_project.addFileArg(service_contract);
890
1012
  service_project.addArg("--service-host-main");
891
1013
  const service_host_main = service_project.addOutputFileArg("service_host_main.ts");
892
1014
  service_project.addArg("--service-registry");
893
- service_registry = service_project.addOutputFileArg("services.zig");
1015
+ const service_registry_raw = service_project.addOutputFileArg("services.zig");
1016
+ service_registry = stabilizeGeneratedFile(b, service_registry_raw, "services.zig", build_trace);
894
1017
  service_project.addArg("--service-client");
895
- service_client = service_project.addOutputFileArg("services.gen.ts");
1018
+ const service_client_raw = service_project.addOutputFileArg("services.gen.ts");
1019
+ service_client = stabilizeGeneratedFile(b, service_client_raw, "services.gen.ts", build_trace);
896
1020
  const service_inproc_main: ?std.Build.LazyPath = if (service_carrier == .in_process) inproc: {
897
1021
  service_project.addArg("--service-inproc-main");
898
1022
  break :inproc service_project.addOutputFileArg("service_inproc_main.ts");
@@ -907,6 +1031,7 @@ fn tsCoreStage(
907
1031
  // throw into the tagged Error shape the pinned compiler can catch from an
908
1032
  // imported op; no deterministic profile fences participate here.
909
1033
  const service_stage_run = b.addSystemCommand(&.{node});
1034
+ service_stage_run.setName("native stage TypeScript services");
910
1035
  service_stage_run.addFileArg(dep.path("packages/core/scripts/stage_external_services.mjs"));
911
1036
  service_stage_run.addArg("--src");
912
1037
  service_stage_run.addDirectoryArg(b.path(appPath(b, app_root, "src")));
@@ -920,6 +1045,7 @@ fn tsCoreStage(
920
1045
  service_stage_run.addArg("--inproc-profile");
921
1046
  service_stage_run.addFileArg(inproc_profile);
922
1047
  }
1048
+ if (scriptc_optimization) |value| service_project.addArgs(&.{ "--optimization", value });
923
1049
  service_stage_run.addArg("--contract");
924
1050
  service_stage_run.addFileArg(service_contract);
925
1051
  service_stage_run.addArg("--out");
@@ -929,7 +1055,10 @@ fn tsCoreStage(
929
1055
  service_stage_run.has_side_effects = true;
930
1056
 
931
1057
  const service_compile = b.addSystemCommand(&.{node});
1058
+ service_compile.setName("native scriptc service compile");
1059
+ if (build_trace) service_compile.setEnvironmentVariable("SCRIPTC_TIMING", "1");
932
1060
  service_compile.addFileArg(dep.path("packages/core/scripts/run_external_service_compiler.mjs"));
1061
+ service_compile.addFileInput(dep.path("packages/core/scripts/compiler_command.mjs"));
933
1062
  service_compile.addArg("--stage");
934
1063
  service_compile.addDirectoryArg(service_stage_dir);
935
1064
  service_compile.addArg("--manifest");
@@ -961,15 +1090,18 @@ fn tsCoreStage(
961
1090
  if (b.graph.environ_map.get("NATIVE_SDK_CORE_COMPILER")) |override| {
962
1091
  service_compile.addArgs(&.{ "--compiler", override });
963
1092
  } else {
964
- const compiler_js = requireTsExternalCompilerJs(b, dep);
965
- service_compile.addArg("--compiler-js");
966
- service_compile.addFileArg(.{ .cwd_relative = compiler_js });
1093
+ // Let Node resolve the dependency from the SDK package origin:
1094
+ // this is npm's own nested/hoisted/global-sibling walk, and the
1095
+ // driver follows scriptc's published `bin` declaration.
1096
+ service_compile.addArg("--compiler-package-origin");
1097
+ service_compile.addFileArg(dep.path("packages/core/package.json"));
967
1098
  }
968
1099
  }
969
1100
 
970
1101
  // The compile stage: author sources + staged SDK + static surface +
971
1102
  // generated entry/profile, one scratch tree.
972
1103
  const stage_run = b.addSystemCommand(&.{node});
1104
+ stage_run.setName("native stage TypeScript core");
973
1105
  stage_run.addFileArg(dep.path("packages/core/scripts/stage_external_core.mjs"));
974
1106
  stage_run.addArg("--src");
975
1107
  stage_run.addDirectoryArg(b.path(appPath(b, app_root, "src")));
@@ -985,6 +1117,15 @@ fn tsCoreStage(
985
1117
  stage_run.addArg("--services-client");
986
1118
  stage_run.addFileArg(client);
987
1119
  }
1120
+ // `addDirectoryArg` orders the stager after a generated directory but
1121
+ // does not hash a source directory's discovered contents. The old graph
1122
+ // accidentally got core-source invalidation from changing producer cache
1123
+ // paths. Now that generated ABI files are stabilized by content, state
1124
+ // every source the stager copies explicitly: authored core files plus the
1125
+ // two SDK implementation modules. Services are excluded because they have
1126
+ // their own compile lane.
1127
+ addAppCoreTsDirInputs(b, stage_run, appPath(b, app_root, "src"));
1128
+ addStagedCoreSdkInputs(b, dep.builder, stage_run);
988
1129
  stage_run.addArg("--out");
989
1130
  const stage_dir = stage_run.addOutputDirectoryArg("stage");
990
1131
 
@@ -992,7 +1133,10 @@ fn tsCoreStage(
992
1133
  // exact pin, archive normalized, the co-emitted sidecar captured.
993
1134
  const symbol_name = externalCoreSymbolName(b, app_name);
994
1135
  const compile = b.addSystemCommand(&.{node});
1136
+ compile.setName("native scriptc core compile");
1137
+ if (build_trace) compile.setEnvironmentVariable("SCRIPTC_TIMING", "1");
995
1138
  compile.addFileArg(dep.path("packages/core/scripts/run_external_core_compiler.mjs"));
1139
+ compile.addFileInput(dep.path("packages/core/scripts/compiler_command.mjs"));
996
1140
  compile.addArg("--stage");
997
1141
  compile.addDirectoryArg(stage_dir);
998
1142
  compile.addArgs(&.{ "--name", symbol_name });
@@ -1020,13 +1164,13 @@ fn tsCoreStage(
1020
1164
  // driver still refuses a release other than the SDK's pin.
1021
1165
  compile.addArgs(&.{ "--compiler", override });
1022
1166
  } else {
1023
- const compiler_js = requireTsExternalCompilerJs(b, dep);
1024
- compile.addArg("--compiler-js");
1025
- compile.addFileArg(.{ .cwd_relative = compiler_js });
1167
+ compile.addArg("--compiler-package-origin");
1168
+ compile.addFileArg(dep.path("packages/core/package.json"));
1026
1169
  }
1027
1170
 
1028
1171
  // The mirror, generated from the archive's OWN co-emitted contract.
1029
1172
  const mirror = b.addRunArtifact(corewire_exe);
1173
+ mirror.setName("native corewire (compiled-core mirror)");
1030
1174
  mirror.addArg("--sidecar");
1031
1175
  mirror.addFileArg(compiled_sidecar);
1032
1176
  mirror.addArg("--out");
@@ -1051,7 +1195,14 @@ fn tsCoreStage(
1051
1195
  \\
1052
1196
  , .{ service_carrier, service_pool_workers }));
1053
1197
  _ = staged.addCopyFile(migrations_zig, "migrations.zig");
1054
- _ = staged.addCopyFile(b.path(appPath(b, app_root, "src/app.native")), "app.native");
1198
+ // Primary markup bytes live in their own tiny C translation unit. They
1199
+ // no longer participate in Zig source analysis, so a markup edit reuses
1200
+ // the compiled app/SDK graph and performs only C data compile + relink.
1201
+ const markup_embed = b.addSystemCommand(&.{node});
1202
+ markup_embed.setName("native embed primary markup data");
1203
+ markup_embed.addFileArg(dep.path("packages/core/scripts/embed_markup_c.mjs"));
1204
+ markup_embed.addFileArg(b.path(appPath(b, app_root, "src/app.native")));
1205
+ const markup_c = markup_embed.addOutputFileArg("app_markup.c");
1055
1206
  for (window_views.sources) |source| {
1056
1207
  _ = staged.addCopyFile(b.path(appPath(b, app_root, source.source_path)), source.staged_path);
1057
1208
  }
@@ -1067,6 +1218,7 @@ fn tsCoreStage(
1067
1218
  .archive = archive,
1068
1219
  .service_exe = service_exe,
1069
1220
  .service_archive = service_archive,
1221
+ .markup_c = markup_c,
1070
1222
  .migrations = migrations_zig,
1071
1223
  };
1072
1224
  }
@@ -1156,6 +1308,37 @@ fn addAppTsDirInputs(b: *std.Build, transpile: *std.Build.Step.Run, src_path: []
1156
1308
  }
1157
1309
  }
1158
1310
 
1311
+ /// Declare exactly the author TypeScript files copied into the core compiler's
1312
+ /// scratch tree. `src/services/` is a separate compiler class and `.d.ts`
1313
+ /// files are declarations for editor/provider use, not scriptc source inputs.
1314
+ fn addAppCoreTsDirInputs(b: *std.Build, stage: *std.Build.Step.Run, src_path: []const u8) void {
1315
+ var dir = b.build_root.handle.openDir(b.graph.io, src_path, .{ .iterate = true }) catch return;
1316
+ defer dir.close(b.graph.io);
1317
+ var walker = dir.walk(b.allocator) catch return;
1318
+ defer walker.deinit();
1319
+ while (walker.next(b.graph.io) catch null) |entry| {
1320
+ if (entry.kind != .file or !std.mem.endsWith(u8, entry.basename, ".ts") or std.mem.endsWith(u8, entry.basename, ".d.ts")) continue;
1321
+ const normalized = b.dupe(entry.path);
1322
+ for (normalized) |*char| if (char.* == '\\') {
1323
+ char.* = '/';
1324
+ };
1325
+ if (std.mem.startsWith(u8, normalized, "services/")) continue;
1326
+ stage.addFileInput(b.path(b.fmt("{s}/{s}", .{ src_path, entry.path })));
1327
+ }
1328
+ }
1329
+
1330
+ /// Declare the SDK implementation modules copied by
1331
+ /// stage_external_core.mjs. A directory LazyPath supplies ordering only for
1332
+ /// this source tree; these file inputs make implementation-only SDK edits
1333
+ /// invalidate the staged tree and compiled core archive even when the public
1334
+ /// contract remains byte-identical. Public for the repository fixture graph,
1335
+ /// which exercises the same compiler boundary as app builds.
1336
+ pub fn addStagedCoreSdkInputs(b: *std.Build, sdk_builder: *std.Build, stage: *std.Build.Step.Run) void {
1337
+ for ([_][]const u8{ "text.ts", "events.ts" }) |source| {
1338
+ stage.addFileInput(sdk_builder.path(b.fmt("packages/core/sdk/{s}", .{source})));
1339
+ }
1340
+ }
1341
+
1159
1342
  fn appHasServiceFiles(b: *std.Build, app_root: []const u8) bool {
1160
1343
  const services_path = appPath(b, app_root, "src/services");
1161
1344
  var dir = b.build_root.handle.openDir(b.graph.io, services_path, .{ .iterate = true }) catch return false;
@@ -1274,6 +1457,7 @@ pub const MobileTsCore = struct {
1274
1457
  archive: std.Build.LazyPath,
1275
1458
  /// The in-process service archive, when src/services exists.
1276
1459
  service_archive: ?std.Build.LazyPath,
1460
+ markup_c: std.Build.LazyPath,
1277
1461
  /// The app.zon module the mobile wiring reads scene chrome, identity,
1278
1462
  /// and theme from (`app_manifest_zon`).
1279
1463
  manifest_mod: *std.Build.Module,
@@ -1352,6 +1536,7 @@ fn addMobileLibWithTarget(b: *std.Build, dep: *std.Build.Dependency, target: std
1352
1536
  // host link already passes).
1353
1537
  exports_mod.link_libc = true;
1354
1538
  exports_mod.addObjectFile(ts.archive);
1539
+ exports_mod.addObjectFile(markupDataObject(b, target, optimize, ts.markup_c).getEmittedBin());
1355
1540
  if (ts.service_archive) |service_archive| exports_mod.addObjectFile(service_archive);
1356
1541
  }
1357
1542
  if (options.store_capability or options.relational_capability) {
@@ -1432,6 +1617,8 @@ pub fn addAppArtifacts(b: *std.Build, dep: *std.Build.Dependency, app_options: A
1432
1617
  const optimize_request = b.option(std.builtin.OptimizeMode, "optimize", "Prioritize performance, safety, or binary size");
1433
1618
  const optimize = exampleOptimizeMode(b, optimize_request, .Debug);
1434
1619
  const app_optimize = exampleOptimizeMode(b, optimize_request, .ReleaseFast);
1620
+ const build_trace = b.option(bool, "build-trace", "Trace generated TypeScript ABI artifacts and cache reuse") orelse false;
1621
+ const scriptc_optimization = scriptcProfileOptimization(b, dep, app_optimize);
1435
1622
 
1436
1623
  // The core role is detected from the tree (never a flag or config):
1437
1624
  // builds with a custom `main` entry declared their core explicitly and
@@ -1446,7 +1633,8 @@ pub fn addAppArtifacts(b: *std.Build, dep: *std.Build.Dependency, app_options: A
1446
1633
  " src/main.zig,\nor keep src/main.zig and delete src/core.ts. (Other Zig files under" ++
1447
1634
  " src/ are fine either way.)\n");
1448
1635
  }
1449
- const app_config = appManifestBuildConfig(b, app_options.app_root);
1636
+ const manifest_name = appManifestName(b, app_options.app_root, app_options.manifest);
1637
+ const app_config = appManifestBuildConfig(b, app_options.app_root, manifest_name);
1450
1638
  // The core-compiler setting names the one lane there is; the flag
1451
1639
  // overrides app.zon's `.core_compiler` and both exist so a stated
1452
1640
  // choice stays stateable (and so the removed lane's spelling teaches
@@ -1491,6 +1679,8 @@ pub fn addAppArtifacts(b: *std.Build, dep: *std.Build.Dependency, app_options: A
1491
1679
  app_config.service_packages,
1492
1680
  service_carrier_choice,
1493
1681
  service_pool_workers,
1682
+ build_trace,
1683
+ scriptc_optimization,
1494
1684
  )
1495
1685
  else
1496
1686
  null;
@@ -1524,7 +1714,8 @@ pub fn addAppArtifacts(b: *std.Build, dep: *std.Build.Dependency, app_options: A
1524
1714
  .main_root = stage.mobile_root,
1525
1715
  .archive = stage.archive,
1526
1716
  .service_archive = stage.service_archive,
1527
- .manifest_mod = b.createModule(.{ .root_source_file = b.path(appPath(b, app_options.app_root, "app.zon")) }),
1717
+ .markup_c = stage.markup_c,
1718
+ .manifest_mod = appManifestModule(b, app_options.app_root, manifest_name),
1528
1719
  } else null,
1529
1720
  });
1530
1721
  }
@@ -1574,10 +1765,32 @@ pub fn addAppArtifacts(b: *std.Build, dep: *std.Build.Dependency, app_options: A
1574
1765
  options.addOption(bool, "web_layer", web_layer);
1575
1766
  const options_mod = options.createModule();
1576
1767
 
1577
- const app_mod = appModule(b, dep, target, app_optimize, app_options, options_mod, ts_stage, relational_migrations, app_config);
1768
+ const app_mod = appModule(b, dep, target, app_optimize, app_options, manifest_name, options_mod, ts_stage, relational_migrations, app_config);
1769
+ // TypeScript app code and platform hosts are expensive Zig/Clang semantic
1770
+ // work but do not depend on primary markup bytes. Compile them once into
1771
+ // an object, then make the executable a link-only artifact over that
1772
+ // cached object plus the tiny generated markup-data object. A markup edit
1773
+ // therefore avoids re-analyzing the SDK and app runner entirely.
1774
+ const exe_root = if (ts_stage) |stage| root: {
1775
+ const app_code = b.addObject(.{
1776
+ .name = b.fmt("{s}-app-code", .{app_options.name}),
1777
+ .root_module = app_mod,
1778
+ .use_llvm = useLlvmWorkaround(target),
1779
+ });
1780
+ const link_mod = b.createModule(.{ .target = target, .optimize = app_optimize });
1781
+ link_mod.addObject(app_code);
1782
+ link_mod.addObject(markupDataObject(b, target, app_optimize, stage.markup_c));
1783
+ // Object dependencies propagate framework/system-library NAMES, but
1784
+ // Zig does not propagate the search paths or rpaths recorded on the
1785
+ // module that produced an object. Restate those path-only facts on
1786
+ // the final link module so the cached app-code split remains link-
1787
+ // equivalent to compiling the app module directly.
1788
+ addPlatformLinkSearchPaths(b, selected_platform, web_engine, cef_dir, link_mod);
1789
+ break :root link_mod;
1790
+ } else app_mod;
1578
1791
  const exe = b.addExecutable(.{
1579
1792
  .name = app_options.name,
1580
- .root_module = app_mod,
1793
+ .root_module = exe_root,
1581
1794
  // The app executable crosses the platform C seam on every host
1582
1795
  // call (the GTK host's `native_sdk_gtk_create_view` is a
1583
1796
  // 22-parameter mix of pointers, sizes, ints, and doubles), and
@@ -1629,7 +1842,14 @@ pub fn addAppArtifacts(b: *std.Build, dep: *std.Build.Dependency, app_options: A
1629
1842
  const run_step = b.step("run", "Run the app");
1630
1843
  run_step.dependOn(&run.step);
1631
1844
 
1632
- const test_app_mod = if (app_optimize == optimize) app_mod else appModule(b, dep, target, optimize, app_options, options_mod, ts_stage, relational_migrations, app_config);
1845
+ // TypeScript tests need their own module even when optimize modes match:
1846
+ // the production app module feeds the cached app-code object and must not
1847
+ // absorb the separately linked markup data object.
1848
+ const test_app_mod = if (ts_stage != null or app_optimize != optimize)
1849
+ appModule(b, dep, target, optimize, app_options, manifest_name, options_mod, ts_stage, relational_migrations, app_config)
1850
+ else
1851
+ app_mod;
1852
+ if (ts_stage) |stage| test_app_mod.addObject(markupDataObject(b, target, optimize, stage.markup_c));
1633
1853
  const tests = b.addTest(.{ .root_module = test_app_mod, .use_llvm = useLlvmWorkaround(target) });
1634
1854
  const test_step = b.step("test", "Run tests");
1635
1855
  test_step.dependOn(&b.addRunArtifact(tests).step);
@@ -1725,7 +1945,7 @@ pub fn addAppArtifacts(b: *std.Build, dep: *std.Build.Dependency, app_options: A
1725
1945
  // WebView2 loader) from the framework root; the cached artifact's
1726
1946
  // own location cannot derive it, so hand it over explicitly.
1727
1947
  package_run.setEnvironmentVariable("NATIVE_SDK_PATH", dep.builder.pathFromRoot("."));
1728
- package_run.addArgs(&.{ "package", "--target", package_target_name, "--manifest", "app.zon", "--output" });
1948
+ package_run.addArgs(&.{ "package", "--target", package_target_name, "--manifest", manifest_name, "--output" });
1729
1949
  package_run.addArg(if (host_os == .macos)
1730
1950
  b.fmt("zig-out/package/{s}.app", .{app_options.name})
1731
1951
  else
@@ -1802,14 +2022,14 @@ fn exampleOptimizeMode(b: *std.Build, requested: ?std.builtin.OptimizeMode, defa
1802
2022
  };
1803
2023
  }
1804
2024
 
1805
- fn appModule(b: *std.Build, dep: *std.Build.Dependency, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode, app_options: AppOptions, options_mod: *std.Build.Module, ts_stage: ?TsCoreStage, relational_migrations: std.Build.LazyPath, app_config: AppManifestBuildConfig) *std.Build.Module {
2025
+ fn appModule(b: *std.Build, dep: *std.Build.Dependency, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode, app_options: AppOptions, manifest_name: []const u8, options_mod: *std.Build.Module, ts_stage: ?TsCoreStage, relational_migrations: std.Build.LazyPath, app_config: AppManifestBuildConfig) *std.Build.Module {
1806
2026
  const native_sdk_mod = nativeSdkModuleWithTerminal(b, dep, target, optimize, app_options.terminal_sessions);
1807
2027
  const runner_mod = b.createModule(.{
1808
2028
  .root_source_file = dep.path("src/app_runner/root.zig"),
1809
2029
  .target = target,
1810
2030
  .optimize = optimize,
1811
2031
  });
1812
- const manifest_mod = b.createModule(.{ .root_source_file = b.path(appPath(b, app_options.app_root, "app.zon")) });
2032
+ const manifest_mod = appManifestModule(b, app_options.app_root, manifest_name);
1813
2033
  runner_mod.addImport("native_sdk", native_sdk_mod);
1814
2034
  runner_mod.addImport("build_options", options_mod);
1815
2035
  runner_mod.addImport("app_manifest_zon", manifest_mod);
@@ -1820,7 +2040,7 @@ fn appModule(b: *std.Build, dep: *std.Build.Dependency, target: std.Build.Resolv
1820
2040
  const app_mod = if (ts_stage) |stage|
1821
2041
  // TypeScript core: the app module roots at the staged generated
1822
2042
  // wiring (ts_core_main.zig beside the mirror core.zig, its shim
1823
- // runtime, and the app's markup).
2043
+ // runtime; primary markup bytes link as a separate data object).
1824
2044
  b.createModule(.{
1825
2045
  .root_source_file = stage.main_root,
1826
2046
  .target = target,
@@ -1859,6 +2079,15 @@ fn appModule(b: *std.Build, dep: *std.Build.Dependency, target: std.Build.Resolv
1859
2079
  return app_mod;
1860
2080
  }
1861
2081
 
2082
+ /// Compile primary markup bytes independently from the Zig app graph. The
2083
+ /// final artifact sees this as an object-file input, so a markup edit dirties
2084
+ /// only this tiny C compile and the final link.
2085
+ fn markupDataObject(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode, source: std.Build.LazyPath) *std.Build.Step.Compile {
2086
+ const mod = b.createModule(.{ .target = target, .optimize = optimize });
2087
+ mod.addCSourceFile(.{ .file = source, .flags = &.{} });
2088
+ return b.addObject(.{ .name = "native-app-markup-data", .root_module = mod });
2089
+ }
2090
+
1862
2091
  /// Bare Mach-O executables launched by the dev loop do not have an app
1863
2092
  /// bundle's external Info.plist. Embed launch policy plus capture usage
1864
2093
  /// strings in the conventional section so LaunchServices starts accessory
@@ -2216,6 +2445,7 @@ fn externalModule(b: *std.Build, dep: *std.Build.Dependency, target: std.Build.R
2216
2445
  // 26.0 SDKs. Release builds never hit it (no UBSan), which is why only
2217
2446
  // Debug-built examples (standardOptimizeOption default) crashed.
2218
2447
  fn linkPlatform(b: *std.Build, dep: *std.Build.Dependency, target: std.Build.ResolvedTarget, app_mod: *std.Build.Module, exe: *std.Build.Step.Compile, platform: PlatformOption, web_engine: WebEngineOption, web_layer: bool, cef_dir: []const u8, cef_auto_install: bool) void {
2448
+ addPlatformLinkSearchPaths(b, platform, web_engine, cef_dir, app_mod);
2219
2449
  if (platform == .macos) {
2220
2450
  switch (web_engine) {
2221
2451
  .system => {
@@ -2240,14 +2470,9 @@ fn linkPlatform(b: *std.Build, dep: *std.Build.Dependency, target: std.Build.Res
2240
2470
  const flags: []const []const u8 = if (b.sysroot) |sysroot| &.{ "-fobjc-arc", "-fno-sanitize=builtin", "-ObjC++", "-std=c++17", "-stdlib=libc++", "-mmacosx-version-min=11.0", "-isysroot", sysroot, sdk_include, include_arg, define_arg } else &.{ "-fobjc-arc", "-fno-sanitize=builtin", "-ObjC++", "-std=c++17", "-stdlib=libc++", "-mmacosx-version-min=11.0", include_arg, define_arg };
2241
2471
  app_mod.addCSourceFile(.{ .file = dep.path("src/platform/macos/cef_host.mm"), .flags = flags });
2242
2472
  app_mod.addObjectFile(b.path(b.fmt("{s}/libcef_dll_wrapper/libcef_dll_wrapper.a", .{cef_dir})));
2243
- app_mod.addFrameworkPath(b.path(b.fmt("{s}/Release", .{cef_dir})));
2244
2473
  app_mod.linkFramework("Chromium Embedded Framework", .{});
2245
- app_mod.addRPath(.{ .cwd_relative = "@executable_path/Frameworks" });
2246
2474
  },
2247
2475
  }
2248
- if (b.sysroot) |sysroot| {
2249
- app_mod.addFrameworkPath(.{ .cwd_relative = b.pathJoin(&.{ sysroot, "System/Library/Frameworks" }) });
2250
- }
2251
2476
  app_mod.linkFramework("AppKit", .{});
2252
2477
  // The audio playback service (the AppKit host's single AVPlayer).
2253
2478
  app_mod.linkFramework("AVFoundation", .{});
@@ -2308,9 +2533,7 @@ fn linkPlatform(b: *std.Build, dep: *std.Build.Dependency, target: std.Build.Res
2308
2533
  const define_arg = b.fmt("-DNATIVE_SDK_CEF_DIR=\"{s}\"", .{cef_dir});
2309
2534
  app_mod.addCSourceFile(.{ .file = dep.path("src/platform/linux/cef_host.cpp"), .flags = &.{ "-std=c++17", include_arg, define_arg } });
2310
2535
  app_mod.addObjectFile(b.path(b.fmt("{s}/libcef_dll_wrapper/libcef_dll_wrapper.a", .{cef_dir})));
2311
- app_mod.addLibraryPath(b.path(b.fmt("{s}/Release", .{cef_dir})));
2312
2536
  app_mod.linkSystemLibrary("cef", .{});
2313
- app_mod.addRPath(.{ .cwd_relative = "$ORIGIN" });
2314
2537
  },
2315
2538
  }
2316
2539
  app_mod.linkSystemLibrary("c", .{});
@@ -2369,7 +2592,6 @@ fn linkPlatform(b: *std.Build, dep: *std.Build.Dependency, target: std.Build.Res
2369
2592
  app_mod.addCSourceFile(.{ .file = dep.path("src/platform/windows/cef_host.cpp"), .flags = &.{ "-std=c++17", include_arg, define_arg } });
2370
2593
  app_mod.addCSourceFile(.{ .file = dep.path("src/platform/windows/gpu_surface_renderer.cpp"), .flags = &.{"-std=c++17"} });
2371
2594
  app_mod.addObjectFile(b.path(b.fmt("{s}/libcef_dll_wrapper/libcef_dll_wrapper.lib", .{cef_dir})));
2372
- app_mod.addLibraryPath(b.path(b.fmt("{s}/Release", .{cef_dir})));
2373
2595
  },
2374
2596
  }
2375
2597
  app_mod.linkSystemLibrary("c", .{});
@@ -2402,6 +2624,27 @@ fn linkPlatform(b: *std.Build, dep: *std.Build.Dependency, target: std.Build.Res
2402
2624
  }
2403
2625
  }
2404
2626
 
2627
+ /// Link-search metadata is not inherited through a compiled object in Zig's
2628
+ /// build graph. Keep every path-only platform setting in this one helper so a
2629
+ /// TypeScript app's cached app-code object and its final link receive the same
2630
+ /// framework/library lookup and runtime-search policy.
2631
+ fn addPlatformLinkSearchPaths(b: *std.Build, platform: PlatformOption, web_engine: WebEngineOption, cef_dir: []const u8, mod: *std.Build.Module) void {
2632
+ if (platform == .macos) {
2633
+ if (b.sysroot) |sysroot| {
2634
+ mod.addFrameworkPath(.{ .cwd_relative = b.pathJoin(&.{ sysroot, "System/Library/Frameworks" }) });
2635
+ }
2636
+ if (web_engine == .chromium) {
2637
+ mod.addFrameworkPath(b.path(b.fmt("{s}/Release", .{cef_dir})));
2638
+ mod.addRPath(.{ .cwd_relative = "@executable_path/Frameworks" });
2639
+ }
2640
+ } else if (platform == .linux and web_engine == .chromium) {
2641
+ mod.addLibraryPath(b.path(b.fmt("{s}/Release", .{cef_dir})));
2642
+ mod.addRPath(.{ .cwd_relative = "$ORIGIN" });
2643
+ } else if (platform == .windows and web_engine == .chromium) {
2644
+ mod.addLibraryPath(b.path(b.fmt("{s}/Release", .{cef_dir})));
2645
+ }
2646
+ }
2647
+
2405
2648
  /// The vendored WebView2Loader.dll for the target architecture, relative
2406
2649
  /// to the framework root.
2407
2650
  fn webView2LoaderSubPath(target: std.Build.ResolvedTarget) []const u8 {
@@ -2569,15 +2812,19 @@ fn appPath(b: *std.Build, app_root: []const u8, sub_path: []const u8) []const u8
2569
2812
  return b.pathJoin(&.{ app_root, sub_path });
2570
2813
  }
2571
2814
 
2572
- fn appManifestBuildConfig(b: *std.Build, app_root: []const u8) AppManifestBuildConfig {
2815
+ fn appManifestBuildConfig(b: *std.Build, app_root: []const u8, manifest_name: []const u8) AppManifestBuildConfig {
2573
2816
  // The fallback for a manifest this lenient parse cannot read keeps
2574
2817
  // the web layer (see AppManifestBuildConfig): a shape mismatch here
2575
2818
  // is not proof the app declares no web use.
2576
2819
  const fallback: AppManifestBuildConfig = .{ .web_declaration = .unreadable_manifest };
2577
- const source = b.build_root.handle.readFileAlloc(b.graph.io, appPath(b, app_root, "app.zon"), b.allocator, .limited(1024 * 1024)) catch return fallback;
2578
- const source_z = b.allocator.dupeZ(u8, source) catch return fallback;
2820
+ const source = b.build_root.handle.readFileAlloc(b.graph.io, appPath(b, app_root, manifest_name), b.allocator, .limited(1024 * 1024)) catch return fallback;
2579
2821
  @setEvalBranchQuota(2000);
2580
- const raw = std.zon.parse.fromSliceAlloc(InferenceManifest, b.allocator, source_z, null, .{ .ignore_unknown_fields = true }) catch return fallback;
2822
+ const raw = if (std.ascii.eqlIgnoreCase(std.fs.path.extension(manifest_name), ".json"))
2823
+ std.json.parseFromSliceLeaky(InferenceManifest, b.allocator, source, .{ .ignore_unknown_fields = true }) catch return fallback
2824
+ else zon: {
2825
+ const source_z = b.allocator.dupeZ(u8, source) catch return fallback;
2826
+ break :zon std.zon.parse.fromSliceAlloc(InferenceManifest, b.allocator, source_z, null, .{ .ignore_unknown_fields = true }) catch return fallback;
2827
+ };
2581
2828
  // `.core_compiler` names the one lane there is; validated here so
2582
2829
  // the removed transpiled lane's spelling teaches at configure time.
2583
2830
  if (!std.mem.eql(u8, raw.core_compiler, "external")) {