@native-sdk/cli 0.4.3 → 0.4.4

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.
package/build/app.zig CHANGED
@@ -5,6 +5,12 @@
5
5
 
6
6
  const std = @import("std");
7
7
 
8
+ /// The shared web-layer inference contract: this build graph is one thin
9
+ /// adapter over it (the CLI's manifest tooling and the app runner are the
10
+ /// others), feeding it the inputs only this boundary sees — the
11
+ /// `-Dweb-engine` and `-Dweb-layer` flags resolved against app.zon.
12
+ const web_layer_contract = @import("../src/primitives/app_manifest/web_layer.zig");
13
+
8
14
  const PlatformOption = enum {
9
15
  auto,
10
16
  null,
@@ -20,10 +26,9 @@ const TraceOption = enum {
20
26
  all,
21
27
  };
22
28
 
23
- const WebEngineOption = enum {
24
- system,
25
- chromium,
26
- };
29
+ const WebEngineOption = web_layer_contract.WebEngine;
30
+
31
+ const WebLayerOption = web_layer_contract.WebViewLayer;
27
32
 
28
33
  pub const AppOptions = struct {
29
34
  name: []const u8,
@@ -202,6 +207,7 @@ pub fn addAppArtifacts(b: *std.Build, dep: *std.Build.Dependency, app_options: A
202
207
  const automation_enabled = b.option(bool, "automation", "Enable Native SDK automation artifacts") orelse false;
203
208
  const js_bridge_enabled = b.option(bool, "js-bridge", "Enable optional JavaScript bridge stubs") orelse false;
204
209
  const web_engine_override = b.option(WebEngineOption, "web-engine", "Override app.zon web engine: system, chromium");
210
+ const web_layer_override = b.option(WebLayerOption, "web-layer", "Override app.zon webview_layer: auto, include, exclude");
205
211
  const cef_dir_override = b.option([]const u8, "cef-dir", "Override CEF root directory for Chromium builds");
206
212
  const cef_auto_install_override = b.option(bool, "cef-auto-install", "Override app.zon CEF auto-install setting");
207
213
  const selected_platform: PlatformOption = switch (platform_option) {
@@ -217,13 +223,14 @@ pub fn addAppArtifacts(b: *std.Build, dep: *std.Build.Dependency, app_options: A
217
223
  if (selected_platform == .windows and target.result.os.tag != .windows) {
218
224
  @panic("-Dplatform=windows requires a Windows target");
219
225
  }
220
- const app_web_engine = appWebEngineConfig(b, app_options.app_root);
221
- const web_engine = web_engine_override orelse app_web_engine.web_engine;
222
- const cef_dir = cef_dir_override orelse defaultCefDir(selected_platform, app_web_engine.cef_dir);
223
- const cef_auto_install = cef_auto_install_override orelse app_web_engine.cef_auto_install;
226
+ const app_config = appManifestBuildConfig(b, app_options.app_root);
227
+ const web_engine = web_engine_override orelse app_config.web_engine;
228
+ const cef_dir = cef_dir_override orelse defaultCefDir(selected_platform, app_config.cef_dir);
229
+ const cef_auto_install = cef_auto_install_override orelse app_config.cef_auto_install;
224
230
  if (web_engine == .chromium and selected_platform != .macos) {
225
231
  @panic("-Dweb-engine=chromium currently requires -Dplatform=macos");
226
232
  }
233
+ const web_layer = resolveWebLayer(app_config, web_engine, web_layer_override);
227
234
 
228
235
  const options = b.addOptions();
229
236
  options.addOption([]const u8, "platform", switch (selected_platform) {
@@ -238,6 +245,7 @@ pub fn addAppArtifacts(b: *std.Build, dep: *std.Build.Dependency, app_options: A
238
245
  options.addOption(bool, "debug_overlay", debug_overlay);
239
246
  options.addOption(bool, "automation", automation_enabled);
240
247
  options.addOption(bool, "js_bridge", js_bridge_enabled);
248
+ options.addOption(bool, "web_layer", web_layer);
241
249
  const options_mod = options.createModule();
242
250
 
243
251
  const app_mod = appModule(b, dep, target, app_optimize, app_options, options_mod);
@@ -245,13 +253,13 @@ pub fn addAppArtifacts(b: *std.Build, dep: *std.Build.Dependency, app_options: A
245
253
  .name = app_options.name,
246
254
  .root_module = app_mod,
247
255
  });
248
- linkPlatform(b, dep, target, app_mod, exe, selected_platform, web_engine, cef_dir, cef_auto_install);
256
+ linkPlatform(b, dep, target, app_mod, exe, selected_platform, web_engine, web_layer, cef_dir, cef_auto_install);
249
257
  const install = b.addInstallArtifact(exe, .{});
250
258
  b.getInstallStep().dependOn(&install.step);
251
259
 
252
260
  const run = b.addRunArtifact(exe);
253
261
  addCefRuntimeRunFiles(b, target, run, exe, web_engine, cef_dir);
254
- addWebView2RuntimeRunFiles(dep, target, run, web_engine);
262
+ addWebView2RuntimeRunFiles(dep, target, run, web_engine, web_layer);
255
263
  const run_step = b.step("run", "Run the app");
256
264
  run_step.dependOn(&run.step);
257
265
 
@@ -331,6 +339,19 @@ pub fn addAppArtifacts(b: *std.Build, dep: *std.Build.Dependency, app_options: A
331
339
  // build graph knows the packaged binary's REAL mode, so forward
332
340
  // it instead of letting the CLI assume one.
333
341
  package_run.addArgs(&.{ "--optimize", @tagName(app_optimize) });
342
+ // Forward the RESOLVED web-layer decision, never the raw inputs:
343
+ // this graph already decided web vs native-only for the exe it is
344
+ // packaging (app.zon declarations plus -Dweb-layer/-Dweb-engine),
345
+ // and the CLI re-inferring from app.zon alone would miss a
346
+ // flag-driven override — a WebView2-referencing exe packaged
347
+ // without its loader. Handing over the decision itself makes
348
+ // exe/package agreement structural.
349
+ package_run.addArgs(&.{ "--web-layer", if (web_layer) "include" else "exclude" });
350
+ // Same reasoning for the web engine: the CLI defaults to system, so
351
+ // a Chromium exe packaged without these flags would ship no CEF
352
+ // runtime (the generated build graph already forwards them).
353
+ package_run.addArgs(&.{ "--web-engine", @tagName(web_engine), "--cef-dir", cef_dir });
354
+ if (cef_auto_install) package_run.addArg("--cef-auto-install");
334
355
  package_run.has_side_effects = true;
335
356
  const package_step = b.step("package", "Create a distributable package via the native CLI");
336
357
  package_step.dependOn(&package_run.step);
@@ -470,7 +491,7 @@ fn externalModule(b: *std.Build, dep: *std.Build.Dependency, target: std.Build.R
470
491
  // Reproduced with a 10-line `zig cc` program against both the 14.5 and
471
492
  // 26.0 SDKs. Release builds never hit it (no UBSan), which is why only
472
493
  // Debug-built examples (standardOptimizeOption default) crashed.
473
- 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, cef_dir: []const u8, cef_auto_install: bool) void {
494
+ 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 {
474
495
  if (platform == .macos) {
475
496
  switch (web_engine) {
476
497
  .system => {
@@ -521,11 +542,23 @@ fn linkPlatform(b: *std.Build, dep: *std.Build.Dependency, target: std.Build.Res
521
542
  if (web_engine == .chromium) app_mod.linkSystemLibrary("c++", .{});
522
543
  } else if (platform == .linux) {
523
544
  switch (web_engine) {
524
- .system => {
545
+ .system => if (web_layer) {
525
546
  app_mod.addCSourceFile(.{ .file = dep.path("src/platform/linux/gtk_host.c"), .flags = &.{} });
526
547
  app_mod.linkSystemLibrary("gtk4", .{});
527
548
  app_mod.linkSystemLibrary("webkitgtk-6.0", .{});
528
549
  app_mod.linkSystemLibrary("dl", .{});
550
+ } else {
551
+ // Native-only app (nothing in app.zon declares web use):
552
+ // compile the GTK host without the embedded web layer.
553
+ // The stub define excludes the layer outright — the host
554
+ // honors it before probing for the WebKitGTK header, so
555
+ // the layer stays out even on machines where the
556
+ // development package is installed — libwebkitgtk is
557
+ // neither linked nor required at runtime, and the
558
+ // executable carries no WebKit reference at all.
559
+ app_mod.addCSourceFile(.{ .file = dep.path("src/platform/linux/gtk_host.c"), .flags = &.{"-DNATIVE_SDK_ALLOW_WEBKITGTK_STUB"} });
560
+ app_mod.linkSystemLibrary("gtk4", .{});
561
+ app_mod.linkSystemLibrary("dl", .{});
529
562
  },
530
563
  .chromium => {
531
564
  const cef_check = addCefCheck(b, target, cef_dir);
@@ -554,7 +587,7 @@ fn linkPlatform(b: *std.Build, dep: *std.Build.Dependency, target: std.Build.Res
554
587
  // bitmap-stretching a 96-DPI surface on scaled displays.
555
588
  exe.win32_manifest = dep.path("assets/native-sdk.manifest");
556
589
  switch (web_engine) {
557
- .system => {
590
+ .system => if (web_layer) {
558
591
  // The vendored WebView2 SDK header (third_party/webview2)
559
592
  // turns on the host's embedded-WebView layer; the host
560
593
  // fails the compile by design if it cannot be found.
@@ -566,6 +599,16 @@ fn linkPlatform(b: *std.Build, dep: *std.Build.Dependency, target: std.Build.Res
566
599
  // touch it.
567
600
  const loader = b.addInstallBinFile(dep.path(webView2LoaderSubPath(target)), "WebView2Loader.dll");
568
601
  b.getInstallStep().dependOn(&loader.step);
602
+ } else {
603
+ // Native-only app (nothing in app.zon declares web use):
604
+ // compile the host without the embedded-WebView layer.
605
+ // The stub define excludes the layer outright — the host
606
+ // honors it before probing for the WebView2 header, so
607
+ // the layer stays out even on machines where the SDK
608
+ // headers are reachable through the system include paths
609
+ // — no WebView2Loader.dll is installed or path-wired,
610
+ // and the executable carries no reference to it at all.
611
+ app_mod.addCSourceFile(.{ .file = dep.path("src/platform/windows/webview2_host.cpp"), .flags = &.{ "-std=c++17", "-DNATIVE_SDK_ALLOW_WEBVIEW2_STUB" } });
569
612
  },
570
613
  .chromium => {
571
614
  const cef_check = addCefCheck(b, target, cef_dir);
@@ -611,8 +654,9 @@ fn webView2LoaderSubPath(target: std.Build.ResolvedTarget) []const u8 {
611
654
  /// `zig build run` executes the cached artifact, which has no installed
612
655
  /// WebView2Loader.dll beside it; the vendored loader's directory goes on
613
656
  /// the run step's PATH so the host's LoadLibrary resolves it in dev runs.
614
- fn addWebView2RuntimeRunFiles(dep: *std.Build.Dependency, target: std.Build.ResolvedTarget, run: *std.Build.Step.Run, web_engine: WebEngineOption) void {
657
+ fn addWebView2RuntimeRunFiles(dep: *std.Build.Dependency, target: std.Build.ResolvedTarget, run: *std.Build.Step.Run, web_engine: WebEngineOption, web_layer: bool) void {
615
658
  if (web_engine != .system) return;
659
+ if (!web_layer) return;
616
660
  if (target.result.os.tag != .windows) return;
617
661
  const loader_dir = std.fs.path.dirname(webView2LoaderSubPath(target)).?;
618
662
  run.addPathDir(dep.builder.pathFromRoot(loader_dir));
@@ -676,10 +720,41 @@ fn addCefCheck(b: *std.Build, target: std.Build.ResolvedTarget, cef_dir: []const
676
720
  return b.addSystemCommand(&.{ "sh", "-c", script });
677
721
  }
678
722
 
679
- const AppWebEngineConfig = struct {
723
+ /// What the build graph reads out of app.zon: the web-engine/CEF knobs
724
+ /// and the web-layer inference inputs. An unreadable or unparsable
725
+ /// manifest falls back to the system engine WITH the web layer kept —
726
+ /// over-inclusion is a size cost, wrong exclusion is a broken app.
727
+ const AppManifestBuildConfig = struct {
680
728
  web_engine: WebEngineOption = .system,
681
729
  cef_dir: []const u8 = "third_party/cef/macos",
682
730
  cef_auto_install: bool = false,
731
+ webview_layer: WebLayerOption = .auto,
732
+ /// The first web declaration found (for teaching messages), or null
733
+ /// when app.zon declares no web use. `web_engine = "system"` alone is
734
+ /// NOT web intent — it is the default in many canvas manifests.
735
+ web_declaration: ?web_layer_contract.Declaration = null,
736
+ };
737
+
738
+ /// The lenient app.zon shape the build graph parses for inference: only
739
+ /// the fields that decide the web layer and the web engine; everything
740
+ /// else is ignored. Full schema validation stays with `native validate`
741
+ /// and the runner's comptime import.
742
+ const InferenceManifest = struct {
743
+ capabilities: []const []const u8 = &.{},
744
+ web_engine: []const u8 = "system",
745
+ webview_layer: []const u8 = "auto",
746
+ cef: struct {
747
+ dir: []const u8 = "third_party/cef/macos",
748
+ auto_install: bool = false,
749
+ } = .{},
750
+ frontend: ?struct {} = null,
751
+ shell: struct {
752
+ windows: []const struct {
753
+ views: []const struct {
754
+ kind: []const u8 = "",
755
+ } = &.{},
756
+ } = &.{},
757
+ } = .{},
683
758
  };
684
759
 
685
760
  fn defaultCefDir(platform: PlatformOption, configured: []const u8) []const u8 {
@@ -699,57 +774,37 @@ fn appPath(b: *std.Build, app_root: []const u8, sub_path: []const u8) []const u8
699
774
  return b.pathJoin(&.{ app_root, sub_path });
700
775
  }
701
776
 
702
- fn appWebEngineConfig(b: *std.Build, app_root: []const u8) AppWebEngineConfig {
703
- const source = b.build_root.handle.readFileAlloc(b.graph.io, appPath(b, app_root, "app.zon"), b.allocator, .limited(1024 * 1024)) catch return .{};
704
- var config: AppWebEngineConfig = .{};
705
- if (stringField(source, ".web_engine")) |value| {
706
- config.web_engine = parseWebEngine(value) orelse .system;
707
- }
708
- if (objectSection(source, ".cef")) |cef| {
709
- if (stringField(cef, ".dir")) |value| config.cef_dir = value;
710
- if (boolField(cef, ".auto_install")) |value| config.cef_auto_install = value;
711
- }
712
- return config;
713
- }
714
-
715
- fn parseWebEngine(value: []const u8) ?WebEngineOption {
716
- if (std.mem.eql(u8, value, "system")) return .system;
717
- if (std.mem.eql(u8, value, "chromium")) return .chromium;
718
- return null;
719
- }
720
-
721
- fn stringField(source: []const u8, field: []const u8) ?[]const u8 {
722
- const field_index = std.mem.indexOf(u8, source, field) orelse return null;
723
- const equals = std.mem.indexOfScalarPos(u8, source, field_index, '=') orelse return null;
724
- const start_quote = std.mem.indexOfScalarPos(u8, source, equals, '"') orelse return null;
725
- const end_quote = std.mem.indexOfScalarPos(u8, source, start_quote + 1, '"') orelse return null;
726
- return source[start_quote + 1 .. end_quote];
727
- }
728
-
729
- fn objectSection(source: []const u8, field: []const u8) ?[]const u8 {
730
- const field_index = std.mem.indexOf(u8, source, field) orelse return null;
731
- const open = std.mem.indexOfScalarPos(u8, source, field_index, '{') orelse return null;
732
- var depth: usize = 0;
733
- var index = open;
734
- while (index < source.len) : (index += 1) {
735
- switch (source[index]) {
736
- '{' => depth += 1,
737
- '}' => {
738
- depth -= 1;
739
- if (depth == 0) return source[open + 1 .. index];
740
- },
741
- else => {},
742
- }
743
- }
744
- return null;
777
+ fn appManifestBuildConfig(b: *std.Build, app_root: []const u8) AppManifestBuildConfig {
778
+ // The fallback for a manifest this lenient parse cannot read keeps
779
+ // the web layer (see AppManifestBuildConfig): a shape mismatch here
780
+ // is not proof the app declares no web use.
781
+ const fallback: AppManifestBuildConfig = .{ .web_declaration = .unreadable_manifest };
782
+ const source = b.build_root.handle.readFileAlloc(b.graph.io, appPath(b, app_root, "app.zon"), b.allocator, .limited(1024 * 1024)) catch return fallback;
783
+ const source_z = b.allocator.dupeZ(u8, source) catch return fallback;
784
+ @setEvalBranchQuota(2000);
785
+ const raw = std.zon.parse.fromSliceAlloc(InferenceManifest, b.allocator, source_z, null, .{ .ignore_unknown_fields = true }) catch return fallback;
786
+ return .{
787
+ .web_engine = web_layer_contract.parseWebEngine(raw.web_engine) orelse .system,
788
+ .cef_dir = raw.cef.dir,
789
+ .cef_auto_install = raw.cef.auto_install,
790
+ .webview_layer = web_layer_contract.parseWebViewLayer(raw.webview_layer) orelse @panic("app.zon .webview_layer must be \"auto\", \"include\", or \"exclude\""),
791
+ .web_declaration = web_layer_contract.manifestDeclaration(raw),
792
+ };
745
793
  }
746
794
 
747
- fn boolField(source: []const u8, field: []const u8) ?bool {
748
- const field_index = std.mem.indexOf(u8, source, field) orelse return null;
749
- const equals = std.mem.indexOfScalarPos(u8, source, field_index, '=') orelse return null;
750
- var index = equals + 1;
751
- while (index < source.len and std.ascii.isWhitespace(source[index])) : (index += 1) {}
752
- if (std.mem.startsWith(u8, source[index..], "true")) return true;
753
- if (std.mem.startsWith(u8, source[index..], "false")) return false;
754
- return null;
795
+ /// The web-layer decision for this build: the shared contract fed this
796
+ /// boundary's inputs — the manifest declarations from the lenient parse
797
+ /// and the engine RESOLVED from `-Dweb-engine` orelse app.zon. WEB means
798
+ /// the embedded-WebView layer compiles in; NATIVE-ONLY compiles the host
799
+ /// without it. `.webview_layer` (and `-Dweb-layer`) override the
800
+ /// inference — but an exclude that contradicts a web declaration is a
801
+ /// hard configure error, never a silently broken app.
802
+ fn resolveWebLayer(config: AppManifestBuildConfig, web_engine: WebEngineOption, override: ?WebLayerOption) bool {
803
+ const setting = override orelse config.webview_layer;
804
+ const declaration = web_layer_contract.foldEngine(config.web_declaration, web_engine);
805
+ const decision = web_layer_contract.decide(setting, declaration) catch std.debug.panic(
806
+ "the web layer is excluded ({s}) but the app declares web use ({s}); remove the exclude or drop the web declaration",
807
+ .{ if (override != null) "-Dweb-layer=exclude" else "app.zon .webview_layer = \"exclude\"", declaration.?.text() },
808
+ );
809
+ return decision.enabled;
755
810
  }
package/build.zig CHANGED
@@ -482,22 +482,47 @@ pub fn build(b: *std.Build) void {
482
482
  .{ .path = "src/platform/linux/gtk_host.c", .pattern = "change != NATIVE_SDK_GST_STATE_CHANGE_ASYNC" },
483
483
  .{ .path = "src/platform/linux/gtk_host.c", .pattern = "#define NATIVE_SDK_GST_STATE_CHANGE_ASYNC 2" },
484
484
  });
485
- // The embedded-WebView layer must stay real: the vendored WebView2
486
- // SDK header turns the guard on, every first-party build graph puts
487
- // it on the include path, and a build that cannot see it fails at
488
- // compile time instead of quietly shipping the stubbed host (whose
489
- // WebView loads report WebViewNotFound at runtime).
490
- addFileContainsCheckStep(b, file_contains_checker, test_step, "test-windows-webview2-vendor", "Verify the vendored WebView2 SDK stays wired into every Windows build graph", &.{
485
+ // The embedded-WebView layer must stay real AND declare-to-use: the
486
+ // standard build graph puts the vendored WebView2 SDK header on the
487
+ // include path exactly when app.zon declares web use (`if
488
+ // (web_layer)`), and only the native-only branch passes the stub
489
+ // define. In the guard the stub define is tested FIRST, before
490
+ // header visibility: on a machine where the WebView2 SDK headers are
491
+ // reachable through the system include paths, an
492
+ // include-path-decides guard would compile the full layer into a
493
+ // native-only build and reintroduce the WebView2Loader.dll reference
494
+ // its executable must not carry. Without the define the header is
495
+ // required — a web build that cannot see it fails at compile time
496
+ // instead of quietly shipping the stubbed host (whose WebView loads
497
+ // report WebViewNotFound at runtime).
498
+ addFileContainsCheckStep(b, file_contains_checker, test_step, "test-windows-webview2-vendor", "Verify the vendored WebView2 SDK stays wired into every web-declaring Windows build graph", &.{
491
499
  .{ .path = "third_party/webview2/include/WebView2.h", .pattern = "CreateCoreWebView2EnvironmentWithOptions" },
492
500
  .{ .path = "third_party/webview2/include/EventToken.h", .pattern = "EventRegistrationToken" },
493
501
  .{ .path = "third_party/webview2/LICENSE.txt", .pattern = "Redistribution and use in source and binary forms" },
502
+ .{ .path = "src/platform/windows/webview2_host.cpp", .pattern = "#if defined(NATIVE_SDK_ALLOW_WEBVIEW2_STUB)" },
503
+ .{ .path = "src/platform/windows/webview2_host.cpp", .pattern = "#elif __has_include(<WebView2.h>) && __has_include(<wrl.h>)" },
494
504
  .{ .path = "src/platform/windows/webview2_host.cpp", .pattern = "#error \"WebView2.h not found" },
495
505
  .{ .path = "src/platform/windows/webview2_host.cpp", .pattern = "LoadLibraryW(L\"WebView2Loader.dll\")" },
506
+ .{ .path = "build/app.zig", .pattern = ".system => if (web_layer) {" },
496
507
  .{ .path = "build/app.zig", .pattern = "app_mod.addIncludePath(dep.path(\"third_party/webview2/include\"));" },
497
508
  .{ .path = "build/app.zig", .pattern = "third_party/webview2/x64/WebView2Loader.dll" },
509
+ .{ .path = "build/app.zig", .pattern = "\"-DNATIVE_SDK_ALLOW_WEBVIEW2_STUB\"" },
498
510
  .{ .path = "src/tooling/templates.zig", .pattern = "third_party/webview2/include" },
499
511
  .{ .path = "src/tooling/templates.zig", .pattern = "third_party/webview2/x64/WebView2Loader.dll" },
500
512
  });
513
+ // The Linux mirror of the Windows seam: the stub define wins over
514
+ // header visibility (a native-only build never reintroduces the
515
+ // libwebkitgtk link even where the dev package is installed), the
516
+ // header is required for web builds, and both build graphs compile
517
+ // gtk_host.c with the stub and drop the webkitgtk-6.0 link when the
518
+ // web layer is excluded.
519
+ addFileContainsCheckStep(b, file_contains_checker, test_step, "test-linux-webkitgtk-seam", "Verify the WebKitGTK compile seam stays wired through the GTK host and both Linux build graphs", &.{
520
+ .{ .path = "src/platform/linux/gtk_host.c", .pattern = "#if defined(NATIVE_SDK_ALLOW_WEBKITGTK_STUB)" },
521
+ .{ .path = "src/platform/linux/gtk_host.c", .pattern = "#elif __has_include(<webkit/webkit.h>)" },
522
+ .{ .path = "src/platform/linux/gtk_host.c", .pattern = "#error \"webkit/webkit.h not found" },
523
+ .{ .path = "build/app.zig", .pattern = "\"-DNATIVE_SDK_ALLOW_WEBKITGTK_STUB\"" },
524
+ .{ .path = "src/tooling/templates.zig", .pattern = "\"-DNATIVE_SDK_ALLOW_WEBKITGTK_STUB\"" },
525
+ });
501
526
  addLayoutCheckStep(b, test_step, "test-windows-webview2-loader-layout", "Verify the vendored WebView2 loader binaries are present", &.{
502
527
  "third_party/webview2/x64/WebView2Loader.dll",
503
528
  "third_party/webview2/arm64/WebView2Loader.dll",
@@ -797,6 +822,75 @@ pub fn build(b: *std.Build) void {
797
822
  const browser_system_link_step = b.step("test-browser-system-link", "Build the browser example with the system engine");
798
823
  browser_system_link_step.dependOn(&build_browser_system.step);
799
824
 
825
+ // Windows web-layer PE cross-audit: the declare-to-use inference,
826
+ // proven on real executables from any host via cross-compile.
827
+ // ui-inbox's manifest declares no web use, so its exe must carry no
828
+ // WebView2Loader.dll reference (the whole embedded layer compiles
829
+ // out) and no loader may land beside it; the webview example declares
830
+ // the "webview" capability, so its exe must keep the reference. The
831
+ // loader string lives as UTF-16 in the host, so the audit is a
832
+ // dedicated scanner (tools/audit_web_layer.zig), not a text grep.
833
+ const web_layer_auditor = b.addExecutable(.{
834
+ .name = "audit-web-layer",
835
+ .root_module = module(b, host_target, optimize, "tools/audit_web_layer.zig"),
836
+ });
837
+ // A loader installed by a build predating the inference would fail
838
+ // the absence check below without being this build's fault; clear it
839
+ // so the assertion tests what THIS build installs.
840
+ const clean_native_only_loader = b.addSystemCommand(&.{ "sh", "-c", "rm -f examples/ui-inbox/zig-out/bin/WebView2Loader.dll" });
841
+ const build_native_only_windows = b.addSystemCommand(&.{ "zig", "build", "-Dtarget=x86_64-windows-gnu", "-Dplatform=windows" });
842
+ build_native_only_windows.setCwd(b.path("examples/ui-inbox"));
843
+ build_native_only_windows.step.dependOn(&clean_native_only_loader.step);
844
+ const build_webview_windows = b.addSystemCommand(&.{ "zig", "build", "-Dtarget=x86_64-windows-gnu", "-Dplatform=windows", "-Dweb-engine=system" });
845
+ build_webview_windows.setCwd(b.path("examples/webview"));
846
+ const audit_native_only_exe = b.addRunArtifact(web_layer_auditor);
847
+ audit_native_only_exe.addArgs(&.{ "examples/ui-inbox/zig-out/bin/ui-inbox.exe", "absent" });
848
+ audit_native_only_exe.has_side_effects = true;
849
+ audit_native_only_exe.step.dependOn(&build_native_only_windows.step);
850
+ const audit_webview_exe = b.addRunArtifact(web_layer_auditor);
851
+ audit_webview_exe.addArgs(&.{ "examples/webview/zig-out/bin/webview.exe", "present" });
852
+ audit_webview_exe.has_side_effects = true;
853
+ audit_webview_exe.step.dependOn(&build_webview_windows.step);
854
+ const audit_native_only_loader = b.addSystemCommand(&.{
855
+ "sh", "-c",
856
+ \\test ! -f examples/ui-inbox/zig-out/bin/WebView2Loader.dll || {
857
+ \\ echo "web-layer audit FAILED: the native-only build installed WebView2Loader.dll" >&2
858
+ \\ exit 1
859
+ \\}
860
+ });
861
+ audit_native_only_loader.step.dependOn(&build_native_only_windows.step);
862
+ const web_layer_audit_step = b.step("test-windows-web-layer-audit", "Cross-compile a native-only and a web example for Windows and audit the web layer in each exe");
863
+ web_layer_audit_step.dependOn(&audit_native_only_exe.step);
864
+ web_layer_audit_step.dependOn(&audit_webview_exe.step);
865
+ web_layer_audit_step.dependOn(&audit_native_only_loader.step);
866
+
867
+ // Linux web-layer ELF cross-audit: the same declare-to-use proof on
868
+ // real Linux executables. Unlike the Windows step this cannot
869
+ // cross-compile from any host — the GTK host needs the system GTK4
870
+ // (and, for the web example, WebKitGTK) development headers — so the
871
+ // step runs on Linux with both packages installed and proves the
872
+ // SEAM, not the environment: the native-only exe must carry no
873
+ // libwebkitgtk DT_NEEDED entry and no webkit_/jsc_ dynamic symbol
874
+ // even though the dev package was right there, while the web example
875
+ // must keep them. The environment half (a native-only app building
876
+ // on a runner with no WebKitGTK dev package at all) is proven by the
877
+ // linux-canvas-smoke CI job.
878
+ const build_native_only_linux = b.addSystemCommand(&.{ "zig", "build", "-Dplatform=linux" });
879
+ build_native_only_linux.setCwd(b.path("examples/ui-inbox"));
880
+ const build_webview_linux = b.addSystemCommand(&.{ "zig", "build", "-Dplatform=linux", "-Dweb-engine=system" });
881
+ build_webview_linux.setCwd(b.path("examples/webview"));
882
+ const audit_native_only_elf = b.addRunArtifact(web_layer_auditor);
883
+ audit_native_only_elf.addArgs(&.{ "examples/ui-inbox/zig-out/bin/ui-inbox", "absent" });
884
+ audit_native_only_elf.has_side_effects = true;
885
+ audit_native_only_elf.step.dependOn(&build_native_only_linux.step);
886
+ const audit_webview_elf = b.addRunArtifact(web_layer_auditor);
887
+ audit_webview_elf.addArgs(&.{ "examples/webview/zig-out/bin/webview", "present" });
888
+ audit_webview_elf.has_side_effects = true;
889
+ audit_webview_elf.step.dependOn(&build_webview_linux.step);
890
+ const linux_web_layer_audit_step = b.step("test-linux-web-layer-audit", "Build a native-only and a web example for Linux (Linux host with GTK4 + WebKitGTK dev packages) and audit the web layer in each ELF");
891
+ linux_web_layer_audit_step.dependOn(&audit_native_only_elf.step);
892
+ linux_web_layer_audit_step.dependOn(&audit_webview_elf.step);
893
+
800
894
  const frontend_examples_step = b.step("test-examples-frontends", "Run frontend example tests");
801
895
  addExampleTestStep(b, host_cli_exe, frontend_examples_step, "test-example-next", "Run Next example tests", "examples/next", .owned);
802
896
  addExampleTestStep(b, host_cli_exe, frontend_examples_step, "test-example-react", "Run React example tests", "examples/react", .owned);
@@ -1406,6 +1500,16 @@ pub fn build(b: *std.Build) void {
1406
1500
  \\ready_budget_ms="$smoke_budget_ms"
1407
1501
  \\if [ "$ready_budget_ms" -lt 500 ]; then ready_budget_ms=500; fi
1408
1502
  \\ready_budget_ns=$((ready_budget_ms * 1000000))
1503
+ \\# gpu-dashboard is a native-only app (nothing in app.zon declares web
1504
+ \\# use), so its macOS host must never boot the WebKit stack: WKWebView
1505
+ \\# instantiation spawns com.apple.WebKit.* XPC helpers. They are
1506
+ \\# launchd-parented (not app children), so the honest cheap probe is
1507
+ \\# the machine-wide helper set before launch vs at the end of the
1508
+ \\# session — a NEW helper during this headless smoke window means the
1509
+ \\# lazy main-WebView path regressed (the failure lists the processes
1510
+ \\# so a coincidental web app launched mid-smoke is tellable apart).
1511
+ \\webkit_helpers() { pgrep -f 'com\.apple\.WebKit\.(WebContent|Networking|GPU)' 2>/dev/null | tr '\n' ' '; }
1512
+ \\webkit_before="$(webkit_helpers)"
1409
1513
  \\pid=""
1410
1514
  \\trap 'status=$?; kill "$pid" >/dev/null 2>&1 || true; wait "$pid" >/dev/null 2>&1 || true; if [ "$status" -ne 0 ]; then echo "---- app log (.zig-cache/native-sdk-gpu-dashboard-smoke.log) ----" >&2; cat .zig-cache/native-sdk-gpu-dashboard-smoke.log >&2 2>/dev/null || true; fi' EXIT
1411
1515
  \\stop_app() {
@@ -1572,6 +1676,19 @@ pub fn build(b: *std.Build) void {
1572
1676
  \\if ! grep -q "gpu incremental verify view=dashboard-canvas checks=" "$verify_log" 2>/dev/null; then echo "dashboard verify mode recorded no incremental checks" >&2; exit 1; fi
1573
1677
  \\if grep -q "verify MISMATCH" "$verify_log" 2>/dev/null; then echo "dashboard incremental present diverged from a full redraw:" >&2; grep "verify MISMATCH" "$verify_log" >&2; exit 1; fi
1574
1678
  \\if grep "gpu incremental verify view=dashboard-canvas checks=" "$verify_log" | grep -qv "mismatches=0"; then echo "dashboard incremental verify reported mismatches" >&2; exit 1; fi
1679
+ \\# The whole session ran (two launches, clicks, resizes): a native-only
1680
+ \\# macOS app must have spawned ZERO new WebKit helper processes.
1681
+ \\webkit_after="$(webkit_helpers)"
1682
+ \\new_webkit=""
1683
+ \\for helper_pid in $webkit_after; do
1684
+ \\ case " $webkit_before " in *" $helper_pid "*) ;; *) new_webkit="$new_webkit $helper_pid" ;; esac
1685
+ \\done
1686
+ \\if [ -n "$new_webkit" ]; then
1687
+ \\ echo "native-only gpu-dashboard session spawned WebKit helper processes:$new_webkit" >&2
1688
+ \\ for helper_pid in $new_webkit; do ps -p "$helper_pid" -o pid,ppid,command >&2 || true; done
1689
+ \\ exit 1
1690
+ \\fi
1691
+ \\echo "zero new WebKit helper processes during the native-only session"
1575
1692
  \\echo "gpu-dashboard smoke ok"
1576
1693
  ,
1577
1694
  "sh",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@native-sdk/cli",
3
- "version": "0.4.3",
3
+ "version": "0.4.4",
4
4
  "description": "The Native SDK: the complete toolkit for building native desktop applications — declarative markup, native rendering, WebView surfaces, and OS capabilities",
5
5
  "type": "module",
6
6
  "bin": {
@@ -23,14 +23,14 @@
23
23
  "LICENSE"
24
24
  ],
25
25
  "optionalDependencies": {
26
- "@native-sdk/cli-darwin-arm64": "0.4.3",
27
- "@native-sdk/cli-darwin-x64": "0.4.3",
28
- "@native-sdk/cli-linux-arm64-gnu": "0.4.3",
29
- "@native-sdk/cli-linux-arm64-musl": "0.4.3",
30
- "@native-sdk/cli-linux-x64-gnu": "0.4.3",
31
- "@native-sdk/cli-linux-x64-musl": "0.4.3",
32
- "@native-sdk/cli-win32-arm64": "0.4.3",
33
- "@native-sdk/cli-win32-x64": "0.4.3"
26
+ "@native-sdk/cli-darwin-arm64": "0.4.4",
27
+ "@native-sdk/cli-darwin-x64": "0.4.4",
28
+ "@native-sdk/cli-linux-arm64-gnu": "0.4.4",
29
+ "@native-sdk/cli-linux-arm64-musl": "0.4.4",
30
+ "@native-sdk/cli-linux-x64-gnu": "0.4.4",
31
+ "@native-sdk/cli-linux-x64-musl": "0.4.4",
32
+ "@native-sdk/cli-win32-arm64": "0.4.4",
33
+ "@native-sdk/cli-win32-x64": "0.4.4"
34
34
  },
35
35
  "repository": {
36
36
  "type": "git",
@@ -29,6 +29,7 @@ These references are included by `native skills get core --full`. Use them when
29
29
  - App-defined bridge commands, builtin commands, permissions, windows, WebViews, dialogs: `references/bridge-security-native-capabilities.md`
30
30
  - Web engine choice, CEF, packaging, signing, doctor, logs, debugging: `references/web-engines-packaging-debugging.md`
31
31
  - Running-app inspection and smoke tests: `native skills get automation`
32
+ - `zig build` fails on std APIs ("no member named 'cwd'", ArrayList `init`): `native skills get zig` — the Zig 0.16 idioms, indexed by compile error
32
33
 
33
34
  ## Quick start
34
35
 
@@ -226,6 +227,8 @@ zig build package
226
227
 
227
228
  Run BOTH `zig build` and `zig build test` before calling a change done: Zig's lazy analysis means code only tests reference (or only `main()` reference) can sit broken for weeks under the other command alone — tests never analyze `main`, so an API removed from std can keep "passing" until the app build finally touches it.
228
229
 
230
+ The toolkit requires Zig 0.16.0. When a build fails with "no member named" errors on std APIs (`std.fs.cwd`, `ArrayList.init`, `std.io`, `GeneralPurposeAllocator`), the code was written against older Zig idioms — `native skills get zig` maps each such compile error to the 0.16 idiom as this SDK writes it.
231
+
229
232
  For GUI smoke tests, build with automation enabled and use the `automation` skill:
230
233
 
231
234
  ```bash
@@ -1033,6 +1033,22 @@ Md.view(ui, model.body_markdown, .{
1033
1033
  - Not in v1 (degrades to plain text, never fails): reference links, raw HTML, footnotes, backslash escapes (except `\|` in table rows).
1034
1034
  - `<details>` state is elm-style: the CALLER owns the expanded flags. Keep a bounded `details_expanded: [8]bool` in the model, toggle it in `update` on the details message, and pass the slice back in.
1035
1035
 
1036
+ ## Zig 0.16, not 0.15: the std idioms that changed
1037
+
1038
+ The toolkit requires Zig 0.16.0, and code written from memory of older Zig fails with "no member named" errors on std APIs. The recurring ones, old → current:
1039
+
1040
+ | Compile error says | Old idiom | Write instead |
1041
+ | --- | --- | --- |
1042
+ | `struct 'array_list.Aligned(u8,null)' has no member named 'init'` | `std.ArrayList(T).init(allocator)`, `list.append(x)` | `var list: std.ArrayList(T) = .empty;` then `list.append(allocator, x)`, `list.deinit(allocator)` — the allocator rides every call |
1043
+ | `struct 'heap' has no member named 'GeneralPurposeAllocator'` | hand-built GPA in `main` | `pub fn main(init: std.process.Init) !void` — use `init.gpa`, `init.arena.allocator()`, `init.io` (the generated `main` already does) |
1044
+ | `struct 'fs' has no member named 'cwd'` | `std.fs.cwd().openFile(path, .{})` | `std.Io.Dir.cwd().openFile(io, path, .{})` — file IO lives on `std.Io.Dir` and takes an `io`; in `update` use `fx.readFile`/`fx.writeFile` instead |
1045
+ | `struct 'std' has no member named 'io'` | `std.io.getStdOut().writer()` | `std.Io.File.stdout().writer(io, &buffer)` then print through `&writer.interface` and `flush()`; `std.debug.print` is unchanged |
1046
+ | `struct 'time' has no member named 'sleep'`/`'milliTimestamp'` | `std.time.sleep(ns)`, `std.time.milliTimestamp()` | clocks live on `Io` — in app code use `fx.wallMs()` / `native_sdk.nowMs()` / `fx.startTimer` (see Time above), in tests `std.Io.sleep(std.testing.io, ...)` |
1047
+ | `invalid format string 's' for type '...'` | `{s}` on an enum | `{t}` prints the tag name; custom `format` methods take `(self, writer: *std.Io.Writer)` and print with `{f}` |
1048
+ | `struct 'process.Child' has no member named 'init'` | `Child.init` + `child.spawn()` | `fx.spawn` in apps; `std.process.spawn(io, .{ .argv = ... })` + `child.wait(io)` in tools |
1049
+
1050
+ Tests that touch files or clocks get their `Io` from `std.testing.io`. The full catalog — env/args, sockets, readers, `build.zig` shapes, each with the SDK's live reference file — is its own skill: `native skills get zig`.
1051
+
1036
1052
  ## Validate without building
1037
1053
 
1038
1054
  `native markup check src/view.native` — instant grammar/structure validation with `file:line:column` errors, including the font-coverage tofu guard: literal text with a codepoint outside the bundled face (⌘, ✓, ⑂, dingbats, CJK) is a teaching error naming the character, because it renders as a tofu box on the reference/screenshot and mobile paths — use a vector icon (`icon=` / `<icon name>`) or plain words. Dynamic strings get the same lesson as a Debug-build `zero_canvas_ui` diagnostic when the view builds. The accessibility lint rides the same pass: unnamed interactive controls and role misuse are errors, unnamed images and redundant labels are warnings (`--strict` promotes).