@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 +121 -66
- package/build.zig +123 -6
- package/package.json +9 -9
- package/skill-data/core/SKILL.md +3 -0
- package/skill-data/native-ui/SKILL.md +16 -0
- package/skill-data/zig/SKILL.md +198 -0
- package/skills/native-sdk/SKILL.md +1 -1
- package/src/app_runner/root.zig +51 -9
- package/src/platform/linux/gtk_host.c +226 -21
- package/src/platform/windows/webview2_host.cpp +16 -10
- package/src/primitives/app_manifest/root.zig +8 -0
- package/src/primitives/app_manifest/types.zig +14 -0
- package/src/primitives/app_manifest/validation.zig +18 -0
- package/src/primitives/app_manifest/web_layer.zig +366 -0
- package/src/runtime/api.zig +7 -0
- package/src/runtime/bridge_responses.zig +2 -0
- package/src/runtime/builtin_bridge.zig +6 -0
- package/src/runtime/flow.zig +8 -0
- package/src/runtime/platform_bridge_tests.zig +1 -0
- package/src/runtime/session_tests.zig +35 -8
- package/src/runtime/web_layer_gate_tests.zig +242 -0
- package/src/runtime/window_storage.zig +5 -0
- package/src/runtime/window_view_runtime.zig +1 -0
- package/src/tooling/buildgraph.zig +7 -1
- package/src/tooling/manifest.zig +267 -1
- package/src/tooling/package.zig +598 -6
- package/src/tooling/raw_manifest.zig +1 -0
- package/src/tooling/templates.zig +228 -60
- package/src/tooling/verbs.zig +5 -0
|
@@ -12,6 +12,7 @@ pub const RawManifest = struct {
|
|
|
12
12
|
capabilities: []const []const u8 = &.{},
|
|
13
13
|
bridge: RawBridge = .{},
|
|
14
14
|
web_engine: []const u8 = @tagName(web_engine.default_engine),
|
|
15
|
+
webview_layer: []const u8 = "auto",
|
|
15
16
|
theme: ?[]const u8 = null,
|
|
16
17
|
cef: RawCef = .{},
|
|
17
18
|
frontend: ?RawFrontend = null,
|
|
@@ -717,7 +717,11 @@ fn nativeCiYaml(allocator: std.mem.Allocator, names: TemplateNames, framework_pa
|
|
|
717
717
|
\\ with:
|
|
718
718
|
\\ version: 0.16.0
|
|
719
719
|
\\ - name: Install GTK and Xvfb
|
|
720
|
-
\\
|
|
720
|
+
\\ # No WebKitGTK dev package: this app declares no web use, so its
|
|
721
|
+
\\ # Linux host compiles without the embedded web layer and never
|
|
722
|
+
\\ # links WebKitGTK (install it alongside a .frontend block or
|
|
723
|
+
\\ # the "webview" capability if the app grows web content).
|
|
724
|
+
\\ run: sudo apt-get update && sudo apt-get install -y libgtk-4-dev xvfb
|
|
721
725
|
\\ - name: Fetch native-sdk
|
|
722
726
|
\\ run: |
|
|
723
727
|
\\ if [ ! -f "$NATIVE_SDK_PATH/build.zig" ]; then
|
|
@@ -853,6 +857,12 @@ fn buildZig(allocator: std.mem.Allocator, names: TemplateNames, framework_path:
|
|
|
853
857
|
\\ chromium,
|
|
854
858
|
\\};
|
|
855
859
|
\\
|
|
860
|
+
\\const WebLayerOption = enum {
|
|
861
|
+
\\ auto,
|
|
862
|
+
\\ include,
|
|
863
|
+
\\ exclude,
|
|
864
|
+
\\};
|
|
865
|
+
\\
|
|
856
866
|
\\const PackageTarget = enum {
|
|
857
867
|
\\ macos,
|
|
858
868
|
\\ windows,
|
|
@@ -876,6 +886,7 @@ fn buildZig(allocator: std.mem.Allocator, names: TemplateNames, framework_path:
|
|
|
876
886
|
\\ const automation_enabled = b.option(bool, "automation", "Enable Native SDK automation artifacts") orelse false;
|
|
877
887
|
\\ const js_bridge_enabled = b.option(bool, "js-bridge", "Enable optional JavaScript bridge stubs") orelse false;
|
|
878
888
|
\\ const web_engine_override = b.option(WebEngineOption, "web-engine", "Override app.zon web engine: system, chromium");
|
|
889
|
+
\\ const web_layer_override = b.option(WebLayerOption, "web-layer", "Override app.zon webview_layer: auto, include, exclude");
|
|
879
890
|
\\ const cef_dir_override = b.option([]const u8, "cef-dir", "Override CEF root directory for Chromium builds");
|
|
880
891
|
\\ const cef_auto_install_override = b.option(bool, "cef-auto-install", "Override app.zon CEF auto-install setting");
|
|
881
892
|
\\ const package_target = b.option(PackageTarget, "package-target", "Package target: macos, windows, linux") orelse .macos;
|
|
@@ -894,13 +905,14 @@ fn buildZig(allocator: std.mem.Allocator, names: TemplateNames, framework_path:
|
|
|
894
905
|
\\ if (selected_platform == .windows and target.result.os.tag != .windows) {
|
|
895
906
|
\\ @panic("-Dplatform=windows requires a Windows target");
|
|
896
907
|
\\ }
|
|
897
|
-
\\ const
|
|
898
|
-
\\ const web_engine = web_engine_override orelse
|
|
899
|
-
\\ const cef_dir = cef_dir_override orelse defaultCefDir(selected_platform,
|
|
900
|
-
\\ const cef_auto_install = cef_auto_install_override orelse
|
|
908
|
+
\\ const app_config = appManifestBuildConfig(b);
|
|
909
|
+
\\ const web_engine = web_engine_override orelse app_config.web_engine;
|
|
910
|
+
\\ const cef_dir = cef_dir_override orelse defaultCefDir(selected_platform, app_config.cef_dir);
|
|
911
|
+
\\ const cef_auto_install = cef_auto_install_override orelse app_config.cef_auto_install;
|
|
901
912
|
\\ if (web_engine == .chromium and selected_platform != .macos) {
|
|
902
913
|
\\ @panic("-Dweb-engine=chromium currently requires -Dplatform=macos");
|
|
903
914
|
\\ }
|
|
915
|
+
\\ const web_layer = resolveWebLayer(app_config, web_engine, web_layer_override);
|
|
904
916
|
\\
|
|
905
917
|
\\ const native_sdk_mod = nativeSdkModule(b, target, optimize, native_sdk_path);
|
|
906
918
|
\\ const options = b.addOptions();
|
|
@@ -916,6 +928,7 @@ fn buildZig(allocator: std.mem.Allocator, names: TemplateNames, framework_path:
|
|
|
916
928
|
\\ options.addOption(bool, "debug_overlay", debug_overlay);
|
|
917
929
|
\\ options.addOption(bool, "automation", automation_enabled);
|
|
918
930
|
\\ options.addOption(bool, "js_bridge", js_bridge_enabled);
|
|
931
|
+
\\ options.addOption(bool, "web_layer", web_layer);
|
|
919
932
|
\\ const options_mod = options.createModule();
|
|
920
933
|
\\
|
|
921
934
|
\\ const runner_mod = localModule(b, target, optimize, "src/runner.zig");
|
|
@@ -930,7 +943,7 @@ fn buildZig(allocator: std.mem.Allocator, names: TemplateNames, framework_path:
|
|
|
930
943
|
\\ .name = app_exe_name,
|
|
931
944
|
\\ .root_module = app_mod,
|
|
932
945
|
\\ });
|
|
933
|
-
\\ linkPlatform(b, target, app_mod, exe, selected_platform, web_engine, native_sdk_path, cef_dir, cef_auto_install);
|
|
946
|
+
\\ linkPlatform(b, target, app_mod, exe, selected_platform, web_engine, web_layer, native_sdk_path, cef_dir, cef_auto_install);
|
|
934
947
|
\\ b.installArtifact(exe);
|
|
935
948
|
\\
|
|
936
949
|
\\ const frontend_install = b.addSystemCommand(&.{ "npm", "install", "--prefix", "frontend" });
|
|
@@ -945,13 +958,13 @@ fn buildZig(allocator: std.mem.Allocator, names: TemplateNames, framework_path:
|
|
|
945
958
|
\\ const run = b.addRunArtifact(exe);
|
|
946
959
|
\\ run.step.dependOn(&frontend_build.step);
|
|
947
960
|
\\ addCefRuntimeRunFiles(b, target, run, exe, web_engine, cef_dir);
|
|
948
|
-
\\ addWebView2RuntimeRunFiles(b, target, run, web_engine, native_sdk_path);
|
|
961
|
+
\\ addWebView2RuntimeRunFiles(b, target, run, web_engine, web_layer, native_sdk_path);
|
|
949
962
|
\\ const run_step = b.step("run", "Run the app");
|
|
950
963
|
\\ run_step.dependOn(&run.step);
|
|
951
964
|
\\
|
|
952
965
|
\\ const dev = b.addSystemCommand(&.{ "native", "dev", "--manifest", "app.zon", "--binary" });
|
|
953
966
|
\\ dev.addFileArg(exe.getEmittedBin());
|
|
954
|
-
\\ addWebView2RuntimeRunFiles(b, target, dev, web_engine, native_sdk_path);
|
|
967
|
+
\\ addWebView2RuntimeRunFiles(b, target, dev, web_engine, web_layer, native_sdk_path);
|
|
955
968
|
\\ dev.step.dependOn(&exe.step);
|
|
956
969
|
\\ dev.step.dependOn(&frontend_install.step);
|
|
957
970
|
\\ const dev_step = b.step("dev", "Run the frontend dev server and native shell");
|
|
@@ -982,6 +995,13 @@ fn buildZig(allocator: std.mem.Allocator, names: TemplateNames, framework_path:
|
|
|
982
995
|
\\ package.setEnvironmentVariable("NATIVE_SDK_PATH", b.pathFromRoot(native_sdk_path));
|
|
983
996
|
\\ package.addFileArg(exe.getEmittedBin());
|
|
984
997
|
\\ package.addArgs(&.{ "--web-engine", @tagName(web_engine), "--cef-dir", cef_dir });
|
|
998
|
+
\\ // Forward the RESOLVED web-layer decision, never the raw inputs:
|
|
999
|
+
\\ // this graph already decided web vs native-only for the exe it is
|
|
1000
|
+
\\ // packaging (app.zon declarations plus -Dweb-layer/-Dweb-engine),
|
|
1001
|
+
\\ // and the CLI re-inferring from app.zon alone would miss a
|
|
1002
|
+
\\ // flag-driven override. Handing over the decision itself makes
|
|
1003
|
+
\\ // exe/package agreement structural.
|
|
1004
|
+
\\ package.addArgs(&.{ "--web-layer", if (web_layer) "include" else "exclude" });
|
|
985
1005
|
\\ if (cef_auto_install) package.addArg("--cef-auto-install");
|
|
986
1006
|
\\ package.step.dependOn(&exe.step);
|
|
987
1007
|
\\ package.step.dependOn(&frontend_build.step);
|
|
@@ -1074,7 +1094,7 @@ fn buildZig(allocator: std.mem.Allocator, names: TemplateNames, framework_path:
|
|
|
1074
1094
|
\\ });
|
|
1075
1095
|
\\}
|
|
1076
1096
|
\\
|
|
1077
|
-
\\fn linkPlatform(b: *std.Build, target: std.Build.ResolvedTarget, app_mod: *std.Build.Module, exe: *std.Build.Step.Compile, platform: PlatformOption, web_engine: WebEngineOption, native_sdk_path: []const u8, cef_dir: []const u8, cef_auto_install: bool) void {
|
|
1097
|
+
\\fn linkPlatform(b: *std.Build, target: std.Build.ResolvedTarget, app_mod: *std.Build.Module, exe: *std.Build.Step.Compile, platform: PlatformOption, web_engine: WebEngineOption, web_layer: bool, native_sdk_path: []const u8, cef_dir: []const u8, cef_auto_install: bool) void {
|
|
1078
1098
|
\\ if (platform == .macos) {
|
|
1079
1099
|
\\ switch (web_engine) {
|
|
1080
1100
|
\\ .system => {
|
|
@@ -1121,11 +1141,23 @@ fn buildZig(allocator: std.mem.Allocator, names: TemplateNames, framework_path:
|
|
|
1121
1141
|
\\ if (web_engine == .chromium) app_mod.linkSystemLibrary("c++", .{});
|
|
1122
1142
|
\\ } else if (platform == .linux) {
|
|
1123
1143
|
\\ switch (web_engine) {
|
|
1124
|
-
\\ .system => {
|
|
1144
|
+
\\ .system => if (web_layer) {
|
|
1125
1145
|
\\ app_mod.addCSourceFile(.{ .file = nativeSdkPath(b, native_sdk_path, "src/platform/linux/gtk_host.c"), .flags = &.{} });
|
|
1126
1146
|
\\ app_mod.linkSystemLibrary("gtk4", .{});
|
|
1127
1147
|
\\ app_mod.linkSystemLibrary("webkitgtk-6.0", .{});
|
|
1128
1148
|
\\ app_mod.linkSystemLibrary("dl", .{});
|
|
1149
|
+
\\ } else {
|
|
1150
|
+
\\ // Native-only app (nothing in app.zon declares web use):
|
|
1151
|
+
\\ // compile the GTK host without the embedded web layer.
|
|
1152
|
+
\\ // The stub define excludes the layer outright — the host
|
|
1153
|
+
\\ // honors it before probing for the WebKitGTK header, so
|
|
1154
|
+
\\ // the layer stays out even on machines where the
|
|
1155
|
+
\\ // development package is installed — libwebkitgtk is
|
|
1156
|
+
\\ // neither linked nor required at runtime, and the
|
|
1157
|
+
\\ // executable carries no WebKit reference at all.
|
|
1158
|
+
\\ app_mod.addCSourceFile(.{ .file = nativeSdkPath(b, native_sdk_path, "src/platform/linux/gtk_host.c"), .flags = &.{"-DNATIVE_SDK_ALLOW_WEBKITGTK_STUB"} });
|
|
1159
|
+
\\ app_mod.linkSystemLibrary("gtk4", .{});
|
|
1160
|
+
\\ app_mod.linkSystemLibrary("dl", .{});
|
|
1129
1161
|
\\ },
|
|
1130
1162
|
\\ .chromium => {
|
|
1131
1163
|
\\ const cef_check = addCefCheck(b, target, cef_dir);
|
|
@@ -1147,7 +1179,7 @@ fn buildZig(allocator: std.mem.Allocator, names: TemplateNames, framework_path:
|
|
|
1147
1179
|
\\ if (web_engine == .chromium) app_mod.linkSystemLibrary("stdc++", .{});
|
|
1148
1180
|
\\ } else if (platform == .windows) {
|
|
1149
1181
|
\\ switch (web_engine) {
|
|
1150
|
-
\\ .system => {
|
|
1182
|
+
\\ .system => if (web_layer) {
|
|
1151
1183
|
\\ // The vendored WebView2 SDK header (third_party/webview2)
|
|
1152
1184
|
\\ // turns on the host's embedded-WebView layer; the host
|
|
1153
1185
|
\\ // fails the compile by design if it cannot be found.
|
|
@@ -1159,6 +1191,16 @@ fn buildZig(allocator: std.mem.Allocator, names: TemplateNames, framework_path:
|
|
|
1159
1191
|
\\ // touch it.
|
|
1160
1192
|
\\ const loader = b.addInstallBinFile(nativeSdkPath(b, native_sdk_path, webView2LoaderSubPath(target)), "WebView2Loader.dll");
|
|
1161
1193
|
\\ b.getInstallStep().dependOn(&loader.step);
|
|
1194
|
+
\\ } else {
|
|
1195
|
+
\\ // Native-only app (nothing in app.zon declares web use):
|
|
1196
|
+
\\ // compile the host without the embedded-WebView layer.
|
|
1197
|
+
\\ // The stub define excludes the layer outright — the host
|
|
1198
|
+
\\ // honors it before probing for the WebView2 header, so
|
|
1199
|
+
\\ // the layer stays out even on machines where the SDK
|
|
1200
|
+
\\ // headers are reachable through the system include paths
|
|
1201
|
+
\\ // — no WebView2Loader.dll is installed or path-wired,
|
|
1202
|
+
\\ // and the executable carries no reference to it at all.
|
|
1203
|
+
\\ app_mod.addCSourceFile(.{ .file = nativeSdkPath(b, native_sdk_path, "src/platform/windows/webview2_host.cpp"), .flags = &.{ "-std=c++17", "-DNATIVE_SDK_ALLOW_WEBVIEW2_STUB" } });
|
|
1162
1204
|
\\ },
|
|
1163
1205
|
\\ .chromium => {
|
|
1164
1206
|
\\ const cef_check = addCefCheck(b, target, cef_dir);
|
|
@@ -1204,9 +1246,11 @@ fn buildZig(allocator: std.mem.Allocator, names: TemplateNames, framework_path:
|
|
|
1204
1246
|
\\/// `zig build run` and `zig build dev` execute the cached artifact, which
|
|
1205
1247
|
\\/// has no installed WebView2Loader.dll beside it; the vendored loader's
|
|
1206
1248
|
\\/// directory goes on the step's PATH so the host's LoadLibrary resolves it
|
|
1207
|
-
\\/// (`native dev` passes its environment on to the app it spawns).
|
|
1208
|
-
|
|
1249
|
+
\\/// (`native dev` passes its environment on to the app it spawns). A
|
|
1250
|
+
\\/// native-only build never loads the library, so its PATH stays clean.
|
|
1251
|
+
\\fn addWebView2RuntimeRunFiles(b: *std.Build, target: std.Build.ResolvedTarget, run: *std.Build.Step.Run, web_engine: WebEngineOption, web_layer: bool, native_sdk_path: []const u8) void {
|
|
1209
1252
|
\\ if (web_engine != .system) return;
|
|
1253
|
+
\\ if (!web_layer) return;
|
|
1210
1254
|
\\ if (target.result.os.tag != .windows) return;
|
|
1211
1255
|
\\ const loader_dir = std.fs.path.dirname(webView2LoaderSubPath(target)).?;
|
|
1212
1256
|
\\ run.addPathDir(b.pathFromRoot(b.pathJoin(&.{ native_sdk_path, loader_dir })));
|
|
@@ -1280,10 +1324,42 @@ fn buildZig(allocator: std.mem.Allocator, names: TemplateNames, framework_path:
|
|
|
1280
1324
|
\\ };
|
|
1281
1325
|
\\}
|
|
1282
1326
|
\\
|
|
1283
|
-
|
|
1327
|
+
\\/// What this build graph reads out of app.zon: the web-engine/CEF
|
|
1328
|
+
\\/// knobs and the web-layer inference inputs. An unreadable or
|
|
1329
|
+
\\/// unparsable manifest falls back to the system engine WITH the web
|
|
1330
|
+
\\/// layer kept — over-inclusion is a size cost, wrong exclusion is a
|
|
1331
|
+
\\/// broken app.
|
|
1332
|
+
\\const AppManifestBuildConfig = struct {
|
|
1284
1333
|
\\ web_engine: WebEngineOption = .system,
|
|
1285
1334
|
\\ cef_dir: []const u8 = "third_party/cef/macos",
|
|
1286
1335
|
\\ cef_auto_install: bool = false,
|
|
1336
|
+
\\ webview_layer: WebLayerOption = .auto,
|
|
1337
|
+
\\ /// The first web declaration found (for teaching messages), or
|
|
1338
|
+
\\ /// null when app.zon declares no web use. `web_engine = "system"`
|
|
1339
|
+
\\ /// alone is NOT web intent — it is the default in many canvas
|
|
1340
|
+
\\ /// manifests.
|
|
1341
|
+
\\ web_declaration: ?[]const u8 = null,
|
|
1342
|
+
\\};
|
|
1343
|
+
\\
|
|
1344
|
+
\\/// The lenient app.zon shape parsed for inference: only the fields
|
|
1345
|
+
\\/// that decide the web layer and the web engine; everything else is
|
|
1346
|
+
\\/// ignored. Full schema validation stays with `native validate`.
|
|
1347
|
+
\\const InferenceManifest = struct {
|
|
1348
|
+
\\ capabilities: []const []const u8 = &.{},
|
|
1349
|
+
\\ web_engine: []const u8 = "system",
|
|
1350
|
+
\\ webview_layer: []const u8 = "auto",
|
|
1351
|
+
\\ cef: struct {
|
|
1352
|
+
\\ dir: []const u8 = "third_party/cef/macos",
|
|
1353
|
+
\\ auto_install: bool = false,
|
|
1354
|
+
\\ } = .{},
|
|
1355
|
+
\\ frontend: ?struct {} = null,
|
|
1356
|
+
\\ shell: struct {
|
|
1357
|
+
\\ windows: []const struct {
|
|
1358
|
+
\\ views: []const struct {
|
|
1359
|
+
\\ kind: []const u8 = "",
|
|
1360
|
+
\\ } = &.{},
|
|
1361
|
+
\\ } = &.{},
|
|
1362
|
+
\\ } = .{},
|
|
1287
1363
|
\\};
|
|
1288
1364
|
\\
|
|
1289
1365
|
\\fn defaultCefDir(platform: PlatformOption, configured: []const u8) []const u8 {
|
|
@@ -1295,58 +1371,74 @@ fn buildZig(allocator: std.mem.Allocator, names: TemplateNames, framework_path:
|
|
|
1295
1371
|
\\ };
|
|
1296
1372
|
\\}
|
|
1297
1373
|
\\
|
|
1298
|
-
\\fn
|
|
1299
|
-
\\
|
|
1300
|
-
\\
|
|
1301
|
-
\\
|
|
1302
|
-
\\
|
|
1303
|
-
\\
|
|
1304
|
-
\\
|
|
1305
|
-
\\
|
|
1306
|
-
\\
|
|
1307
|
-
\\
|
|
1374
|
+
\\fn appManifestBuildConfig(b: *std.Build) AppManifestBuildConfig {
|
|
1375
|
+
\\ // The fallback for a manifest this lenient parse cannot read
|
|
1376
|
+
\\ // keeps the web layer (see AppManifestBuildConfig): a shape
|
|
1377
|
+
\\ // mismatch here is not proof the app declares no web use.
|
|
1378
|
+
\\ const fallback: AppManifestBuildConfig = .{ .web_declaration = "an app.zon this build graph could not parse" };
|
|
1379
|
+
\\ const source: [:0]const u8 = @embedFile("app.zon");
|
|
1380
|
+
\\ @setEvalBranchQuota(2000);
|
|
1381
|
+
\\ const raw = std.zon.parse.fromSliceAlloc(InferenceManifest, b.allocator, source, null, .{ .ignore_unknown_fields = true }) catch return fallback;
|
|
1382
|
+
\\ var config: AppManifestBuildConfig = .{
|
|
1383
|
+
\\ .web_engine = parseWebEngine(raw.web_engine) orelse .system,
|
|
1384
|
+
\\ .cef_dir = raw.cef.dir,
|
|
1385
|
+
\\ .cef_auto_install = raw.cef.auto_install,
|
|
1386
|
+
\\ .webview_layer = parseWebLayer(raw.webview_layer) orelse @panic("app.zon .webview_layer must be \"auto\", \"include\", or \"exclude\""),
|
|
1387
|
+
\\ };
|
|
1388
|
+
\\ config.web_declaration = blk: {
|
|
1389
|
+
\\ if (raw.frontend != null) break :blk "a .frontend block";
|
|
1390
|
+
\\ for (raw.capabilities) |capability| {
|
|
1391
|
+
\\ if (std.mem.eql(u8, capability, "webview")) break :blk "the \"webview\" capability";
|
|
1392
|
+
\\ }
|
|
1393
|
+
\\ for (raw.shell.windows) |window| {
|
|
1394
|
+
\\ for (window.views) |view| {
|
|
1395
|
+
\\ if (std.mem.eql(u8, view.kind, "webview")) break :blk "a .shell webview view";
|
|
1396
|
+
\\ }
|
|
1397
|
+
\\ }
|
|
1398
|
+
\\ break :blk null;
|
|
1399
|
+
\\ };
|
|
1308
1400
|
\\ return config;
|
|
1309
1401
|
\\}
|
|
1310
1402
|
\\
|
|
1403
|
+
\\/// The web-layer decision for this build — the same declare-to-use
|
|
1404
|
+
\\/// contract the Native SDK's standard build graph, CLI, and runner
|
|
1405
|
+
\\/// apply: an app is WEB when app.zon declares web use (a .frontend
|
|
1406
|
+
\\/// block, the "webview" capability, a .shell webview view) or the
|
|
1407
|
+
\\/// build resolves to the Chromium engine; otherwise it is
|
|
1408
|
+
\\/// NATIVE-ONLY and the platform host compiles without the
|
|
1409
|
+
\\/// embedded-WebView layer. `.webview_layer` (and `-Dweb-layer`)
|
|
1410
|
+
\\/// override the inference — but an exclude that contradicts a web
|
|
1411
|
+
\\/// declaration is a hard configure error, never a silently broken
|
|
1412
|
+
\\/// app.
|
|
1413
|
+
\\fn resolveWebLayer(config: AppManifestBuildConfig, web_engine: WebEngineOption, override: ?WebLayerOption) bool {
|
|
1414
|
+
\\ const setting = override orelse config.webview_layer;
|
|
1415
|
+
\\ const declaration: ?[]const u8 = config.web_declaration orelse
|
|
1416
|
+
\\ (if (web_engine == .chromium) "the Chromium web engine" else null);
|
|
1417
|
+
\\ return switch (setting) {
|
|
1418
|
+
\\ .include => true,
|
|
1419
|
+
\\ .auto => declaration != null,
|
|
1420
|
+
\\ .exclude => {
|
|
1421
|
+
\\ if (declaration) |reason| {
|
|
1422
|
+
\\ std.debug.panic(
|
|
1423
|
+
\\ "the web layer is excluded ({s}) but the app declares web use ({s}); remove the exclude or drop the web declaration",
|
|
1424
|
+
\\ .{ if (override != null) "-Dweb-layer=exclude" else "app.zon .webview_layer = \"exclude\"", reason },
|
|
1425
|
+
\\ );
|
|
1426
|
+
\\ }
|
|
1427
|
+
\\ return false;
|
|
1428
|
+
\\ },
|
|
1429
|
+
\\ };
|
|
1430
|
+
\\}
|
|
1431
|
+
\\
|
|
1311
1432
|
\\fn parseWebEngine(value: []const u8) ?WebEngineOption {
|
|
1312
1433
|
\\ if (std.mem.eql(u8, value, "system")) return .system;
|
|
1313
1434
|
\\ if (std.mem.eql(u8, value, "chromium")) return .chromium;
|
|
1314
1435
|
\\ return null;
|
|
1315
1436
|
\\}
|
|
1316
1437
|
\\
|
|
1317
|
-
\\fn
|
|
1318
|
-
\\
|
|
1319
|
-
\\
|
|
1320
|
-
\\
|
|
1321
|
-
\\ const end_quote = std.mem.indexOfScalarPos(u8, source, start_quote + 1, '"') orelse return null;
|
|
1322
|
-
\\ return source[start_quote + 1 .. end_quote];
|
|
1323
|
-
\\}
|
|
1324
|
-
\\
|
|
1325
|
-
\\fn objectSection(source: []const u8, field: []const u8) ?[]const u8 {
|
|
1326
|
-
\\ const field_index = std.mem.indexOf(u8, source, field) orelse return null;
|
|
1327
|
-
\\ const open = std.mem.indexOfScalarPos(u8, source, field_index, '{') orelse return null;
|
|
1328
|
-
\\ var depth: usize = 0;
|
|
1329
|
-
\\ var index = open;
|
|
1330
|
-
\\ while (index < source.len) : (index += 1) {
|
|
1331
|
-
\\ switch (source[index]) {
|
|
1332
|
-
\\ '{' => depth += 1,
|
|
1333
|
-
\\ '}' => {
|
|
1334
|
-
\\ depth -= 1;
|
|
1335
|
-
\\ if (depth == 0) return source[open + 1 .. index];
|
|
1336
|
-
\\ },
|
|
1337
|
-
\\ else => {},
|
|
1338
|
-
\\ }
|
|
1339
|
-
\\ }
|
|
1340
|
-
\\ return null;
|
|
1341
|
-
\\}
|
|
1342
|
-
\\
|
|
1343
|
-
\\fn boolField(source: []const u8, field: []const u8) ?bool {
|
|
1344
|
-
\\ const field_index = std.mem.indexOf(u8, source, field) orelse return null;
|
|
1345
|
-
\\ const equals = std.mem.indexOfScalarPos(u8, source, field_index, '=') orelse return null;
|
|
1346
|
-
\\ var index = equals + 1;
|
|
1347
|
-
\\ while (index < source.len and std.ascii.isWhitespace(source[index])) : (index += 1) {}
|
|
1348
|
-
\\ if (std.mem.startsWith(u8, source[index..], "true")) return true;
|
|
1349
|
-
\\ if (std.mem.startsWith(u8, source[index..], "false")) return false;
|
|
1438
|
+
\\fn parseWebLayer(value: []const u8) ?WebLayerOption {
|
|
1439
|
+
\\ if (std.mem.eql(u8, value, "auto")) return .auto;
|
|
1440
|
+
\\ if (std.mem.eql(u8, value, "include")) return .include;
|
|
1441
|
+
\\ if (std.mem.eql(u8, value, "exclude")) return .exclude;
|
|
1350
1442
|
\\ return null;
|
|
1351
1443
|
\\}
|
|
1352
1444
|
\\
|
|
@@ -1516,6 +1608,7 @@ fn runnerZig() []const u8 {
|
|
|
1516
1608
|
\\ fn appInfo(self: RunOptions, buffers: *StateBuffers) native_sdk.AppInfo {
|
|
1517
1609
|
\\ var info: native_sdk.AppInfo = .{
|
|
1518
1610
|
\\ .app_name = self.app_name,
|
|
1611
|
+
\\ .has_web_content = manifestHasWebContent(),
|
|
1519
1612
|
\\ .window_title = self.window_title,
|
|
1520
1613
|
\\ .bundle_id = self.bundle_id,
|
|
1521
1614
|
\\ .icon_path = self.icon_path,
|
|
@@ -1766,6 +1859,7 @@ fn runnerZig() []const u8 {
|
|
|
1766
1859
|
\\ .builtin_bridge = options.builtin_bridge,
|
|
1767
1860
|
\\ .security = options.security,
|
|
1768
1861
|
\\ .js_window_api = options.js_window_api,
|
|
1862
|
+
\\ .web_layer = webLayerEnabled(),
|
|
1769
1863
|
\\ .commands = commands,
|
|
1770
1864
|
\\ .menus = menus,
|
|
1771
1865
|
\\ .shortcuts = shortcuts,
|
|
@@ -1815,6 +1909,7 @@ fn runnerZig() []const u8 {
|
|
|
1815
1909
|
\\ .builtin_bridge = options.builtin_bridge,
|
|
1816
1910
|
\\ .security = options.security,
|
|
1817
1911
|
\\ .js_window_api = options.js_window_api,
|
|
1912
|
+
\\ .web_layer = webLayerEnabled(),
|
|
1818
1913
|
\\ .commands = commands,
|
|
1819
1914
|
\\ .menus = menus,
|
|
1820
1915
|
\\ .shortcuts = shortcuts,
|
|
@@ -1864,6 +1959,7 @@ fn runnerZig() []const u8 {
|
|
|
1864
1959
|
\\ .builtin_bridge = options.builtin_bridge,
|
|
1865
1960
|
\\ .security = options.security,
|
|
1866
1961
|
\\ .js_window_api = options.js_window_api,
|
|
1962
|
+
\\ .web_layer = webLayerEnabled(),
|
|
1867
1963
|
\\ .commands = commands,
|
|
1868
1964
|
\\ .menus = menus,
|
|
1869
1965
|
\\ .shortcuts = shortcuts,
|
|
@@ -1913,6 +2009,7 @@ fn runnerZig() []const u8 {
|
|
|
1913
2009
|
\\ .builtin_bridge = options.builtin_bridge,
|
|
1914
2010
|
\\ .security = options.security,
|
|
1915
2011
|
\\ .js_window_api = options.js_window_api,
|
|
2012
|
+
\\ .web_layer = webLayerEnabled(),
|
|
1916
2013
|
\\ .commands = commands,
|
|
1917
2014
|
\\ .menus = menus,
|
|
1918
2015
|
\\ .shortcuts = shortcuts,
|
|
@@ -1936,6 +2033,48 @@ fn runnerZig() []const u8 {
|
|
|
1936
2033
|
\\ return .system;
|
|
1937
2034
|
\\}
|
|
1938
2035
|
\\
|
|
2036
|
+
\\/// Whether app.zon declares web content — the shared declare-to-use
|
|
2037
|
+
\\/// contract (native_sdk.app_manifest.web_layer) over the comptime
|
|
2038
|
+
\\/// manifest import: a .frontend block, the "webview" capability, a
|
|
2039
|
+
\\/// .shell webview view, or .web_engine = "chromium". Hosts build
|
|
2040
|
+
\\/// honest default menus from this — web items like Reload only exist
|
|
2041
|
+
\\/// when a webview can answer them.
|
|
2042
|
+
\\fn manifestHasWebContent() bool {
|
|
2043
|
+
\\ return manifestWebDeclaration() != null;
|
|
2044
|
+
\\}
|
|
2045
|
+
\\
|
|
2046
|
+
\\/// The first web declaration visible in app.zon, evaluated at
|
|
2047
|
+
\\/// comptime. The engine input is the MANIFEST engine: the runner
|
|
2048
|
+
\\/// never sees the -Dweb-engine flag, so an engine resolved to
|
|
2049
|
+
\\/// Chromium by flag alone stays a configure-time error in build.zig,
|
|
2050
|
+
\\/// which does see the flag.
|
|
2051
|
+
\\fn manifestWebDeclaration() ?native_sdk.app_manifest.web_layer.Declaration {
|
|
2052
|
+
\\ const engine: native_sdk.app_manifest.WebEngine = comptime blk: {
|
|
2053
|
+
\\ if (!@hasField(@TypeOf(app_manifest), "web_engine")) break :blk .system;
|
|
2054
|
+
\\ break :blk native_sdk.app_manifest.web_layer.parseWebEngine(app_manifest.web_engine) orelse .system;
|
|
2055
|
+
\\ };
|
|
2056
|
+
\\ return comptime native_sdk.app_manifest.web_layer.webDeclaration(app_manifest, engine);
|
|
2057
|
+
\\}
|
|
2058
|
+
\\
|
|
2059
|
+
\\/// Whether this build ships the embedded web layer (build.zig's
|
|
2060
|
+
\\/// -Dweb-layer inference); a build_options module that predates the
|
|
2061
|
+
\\/// option keeps the layer — over-inclusion is safe.
|
|
2062
|
+
\\fn webLayerEnabled() bool {
|
|
2063
|
+
\\ if (comptime !@hasDecl(build_options, "web_layer")) return true;
|
|
2064
|
+
\\ return build_options.web_layer;
|
|
2065
|
+
\\}
|
|
2066
|
+
\\
|
|
2067
|
+
\\// A build that excludes the web layer while app.zon declares web use
|
|
2068
|
+
\\// must fail at compile time: the declared webviews of a layerless
|
|
2069
|
+
\\// host would otherwise only fail later, at runtime.
|
|
2070
|
+
\\comptime {
|
|
2071
|
+
\\ if (!webLayerEnabled()) {
|
|
2072
|
+
\\ if (manifestWebDeclaration()) |declaration| {
|
|
2073
|
+
\\ @compileError("this build excludes the web layer (-Dweb-layer=exclude) but app.zon declares web use (" ++ declaration.text() ++ "); remove the exclude or drop the web declaration");
|
|
2074
|
+
\\ }
|
|
2075
|
+
\\ }
|
|
2076
|
+
\\}
|
|
2077
|
+
\\
|
|
1939
2078
|
\\const StateBuffers = struct {
|
|
1940
2079
|
\\ state_dir: [1024]u8 = undefined,
|
|
1941
2080
|
\\ file_path: [1200]u8 = undefined,
|
|
@@ -2875,13 +3014,32 @@ test "writeDefaultApp emits Vite project files" {
|
|
|
2875
3014
|
try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "frontend_build.step.dependOn(&frontend_install.step)") != null);
|
|
2876
3015
|
try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "\"native\", \"dev\"") != null);
|
|
2877
3016
|
try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "dev.step.dependOn(&frontend_install.step)") != null);
|
|
2878
|
-
try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "addWebView2RuntimeRunFiles(b, target, dev, web_engine, native_sdk_path)") != null);
|
|
3017
|
+
try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "addWebView2RuntimeRunFiles(b, target, dev, web_engine, web_layer, native_sdk_path)") != null);
|
|
2879
3018
|
try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "package.setEnvironmentVariable(\"NATIVE_SDK_PATH\", b.pathFromRoot(native_sdk_path))") != null);
|
|
2880
3019
|
try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "chromium") != null);
|
|
2881
3020
|
try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "cef-dir") != null);
|
|
2882
3021
|
try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "src/platform/macos/cef_host.mm") != null);
|
|
2883
3022
|
try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "src/platform/linux/gtk_host.c") != null);
|
|
2884
3023
|
try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "app_manifest_zon") != null);
|
|
3024
|
+
// The generated graph carries the whole web-layer feature: the
|
|
3025
|
+
// override option, the app.zon inference with its conflict panic,
|
|
3026
|
+
// the option handed to the runner, and the conditional WebView2
|
|
3027
|
+
// wiring (include + source + loader when web, stubbed host and no
|
|
3028
|
+
// loader when native-only).
|
|
3029
|
+
try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "b.option(WebLayerOption, \"web-layer\", \"Override app.zon webview_layer: auto, include, exclude\")") != null);
|
|
3030
|
+
try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "const web_layer = resolveWebLayer(app_config, web_engine, web_layer_override)") != null);
|
|
3031
|
+
// The emitted package step forwards the graph's resolved decision so
|
|
3032
|
+
// the packaged artifact structurally agrees with the compiled exe.
|
|
3033
|
+
try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "package.addArgs(&.{ \"--web-layer\", if (web_layer) \"include\" else \"exclude\" })") != null);
|
|
3034
|
+
try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "options.addOption(bool, \"web_layer\", web_layer)") != null);
|
|
3035
|
+
try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "std.zon.parse.fromSliceAlloc(InferenceManifest") != null);
|
|
3036
|
+
try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "the web layer is excluded ({s}) but the app declares web use ({s})") != null);
|
|
3037
|
+
try std.testing.expect(std.mem.indexOf(u8, build_zig_text, ".system => if (web_layer) {") != null);
|
|
3038
|
+
try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "\"-DNATIVE_SDK_ALLOW_WEBVIEW2_STUB\"") != null);
|
|
3039
|
+
// The Linux seam mirrors it: gtk_host.c compiles with the WebKitGTK
|
|
3040
|
+
// stub define and webkitgtk-6.0 is not linked when native-only.
|
|
3041
|
+
try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "\"-DNATIVE_SDK_ALLOW_WEBKITGTK_STUB\"") != null);
|
|
3042
|
+
try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "if (!web_layer) return;") != null);
|
|
2885
3043
|
try std.testing.expect(std.mem.indexOf(u8, main_zig_text, "frontend/dist") != null);
|
|
2886
3044
|
try std.testing.expect(std.mem.indexOf(u8, main_zig_text, "127.0.0.1:5173") != null);
|
|
2887
3045
|
try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, "@import(\"app_manifest_zon\")") != null);
|
|
@@ -2902,6 +3060,13 @@ test "writeDefaultApp emits Vite project files" {
|
|
|
2902
3060
|
try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, "defer std.heap.page_allocator.destroy(runtime)") != null);
|
|
2903
3061
|
try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, "native_sdk.Runtime.initAt(runtime, .{") != null);
|
|
2904
3062
|
try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, "Runtime.init(.{") == null);
|
|
3063
|
+
// The generated runner consumes the same web-layer contract: the
|
|
3064
|
+
// shared inference for honest menus, the build option threaded into
|
|
3065
|
+
// every runtime init, and the comptime conflict guard.
|
|
3066
|
+
try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, ".has_web_content = manifestHasWebContent()") != null);
|
|
3067
|
+
try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, "native_sdk.app_manifest.web_layer.webDeclaration(app_manifest, engine)") != null);
|
|
3068
|
+
try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, ".web_layer = webLayerEnabled(),") != null);
|
|
3069
|
+
try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, "@compileError(\"this build excludes the web layer") != null);
|
|
2905
3070
|
try std.testing.expect(std.mem.indexOf(u8, package_json_text, "\"vite\"") != null);
|
|
2906
3071
|
try std.testing.expect(std.mem.indexOf(u8, main_js_text, "window.zero") != null);
|
|
2907
3072
|
|
|
@@ -3033,8 +3198,11 @@ test "writeDefaultApp emits a CI workflow for native apps" {
|
|
|
3033
3198
|
try std.testing.expect(std.mem.indexOf(u8, ci_yaml_text, "version: 0.16.0") != null);
|
|
3034
3199
|
try std.testing.expect(std.mem.indexOf(u8, ci_yaml_text, "zig build test -Dplatform=null") != null);
|
|
3035
3200
|
// The smoke job builds with automation, launches under Xvfb, and drives
|
|
3036
|
-
// the snapshot: the binary name comes from the template context.
|
|
3037
|
-
|
|
3201
|
+
// the snapshot: the binary name comes from the template context. A
|
|
3202
|
+
// native app's smoke never needs WebKitGTK — its host compiles
|
|
3203
|
+
// without the embedded web layer.
|
|
3204
|
+
try std.testing.expect(std.mem.indexOf(u8, ci_yaml_text, "libgtk-4-dev xvfb") != null);
|
|
3205
|
+
try std.testing.expect(std.mem.indexOf(u8, ci_yaml_text, "libwebkitgtk-6.0-dev") == null);
|
|
3038
3206
|
try std.testing.expect(std.mem.indexOf(u8, ci_yaml_text, "zig build -Dplatform=linux -Dweb-engine=system -Dautomation=true") != null);
|
|
3039
3207
|
try std.testing.expect(std.mem.indexOf(u8, ci_yaml_text, "xvfb-run -a ./zig-out/bin/my-app &") != null);
|
|
3040
3208
|
try std.testing.expect(std.mem.indexOf(u8, ci_yaml_text, "automate wait") != null);
|
package/src/tooling/verbs.zig
CHANGED
|
@@ -193,6 +193,11 @@ fn runZig(io: std.Io, verb: Verb, argv: []const []const u8) !void {
|
|
|
193
193
|
.exited => |code| std.debug.print("native {t}: `zig build` step failed (exit code {d})\n", .{ verb, code }),
|
|
194
194
|
else => std.debug.print("native {t}: `zig build` step terminated abnormally ({t})\n", .{ verb, term }),
|
|
195
195
|
}
|
|
196
|
+
// The child's compile errors streamed straight through above. The one
|
|
197
|
+
// failure class worth a pointer is code written for an older Zig — the
|
|
198
|
+
// SDK builds with Zig 0.16, where std APIs moved, and those failures
|
|
199
|
+
// read "no member named 'cwd'/'init'/'io'" on std types.
|
|
200
|
+
std.debug.print("if the errors above name missing std members, the code may use pre-0.16 Zig idioms - run `native skills get zig` or see https://native-sdk.dev/zig\n", .{});
|
|
196
201
|
return error.ZigBuildFailed;
|
|
197
202
|
}
|
|
198
203
|
|