@native-sdk/cli 0.4.2 → 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/primitives/canvas/chart_tests.zig +2 -2
- package/src/primitives/canvas/markdown_tests.zig +1 -1
- package/src/primitives/canvas/reference.zig +135 -6
- package/src/primitives/canvas/reference_tests.zig +171 -6
- package/src/primitives/canvas/root.zig +3 -0
- package/src/primitives/canvas/test_support.zig +3 -0
- package/src/primitives/canvas/widget_builtin_tests.zig +249 -4
- package/src/primitives/canvas/widget_render_controls.zig +18 -1
- package/src/primitives/canvas/widget_runtime.zig +3 -0
- package/src/primitives/canvas/widget_text_input.zig +104 -1
- 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/canvas_widget_runtime.zig +23 -3
- package/src/runtime/canvas_widget_text_tests.zig +101 -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/view.zig +1 -1
- package/src/runtime/view_widget_scroll.zig +12 -1
- package/src/runtime/view_widget_text.zig +6 -2
- 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 +119 -3
- package/src/tooling/junction.zig +247 -0
- 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/root.zig +1 -0
- package/src/tooling/templates.zig +288 -61
- 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,
|
package/src/tooling/root.zig
CHANGED
|
@@ -9,6 +9,7 @@ pub const dev = @import("dev.zig");
|
|
|
9
9
|
pub const cef = @import("cef.zig");
|
|
10
10
|
pub const web_engine = @import("web_engine.zig");
|
|
11
11
|
pub const buildgraph = @import("buildgraph.zig");
|
|
12
|
+
pub const junction = @import("junction.zig");
|
|
12
13
|
pub const embedlib = @import("embedlib.zig");
|
|
13
14
|
pub const eject_components = @import("eject_components.zig");
|
|
14
15
|
pub const toolchain = @import("toolchain.zig");
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const std = @import("std");
|
|
2
|
+
const junction = @import("junction.zig");
|
|
2
3
|
|
|
3
4
|
/// The SDK's default app icon, rendered from vector source by
|
|
4
5
|
/// `zig build generate-icon` (tools/generate_app_icon.zig). Embedded so
|
|
@@ -716,7 +717,11 @@ fn nativeCiYaml(allocator: std.mem.Allocator, names: TemplateNames, framework_pa
|
|
|
716
717
|
\\ with:
|
|
717
718
|
\\ version: 0.16.0
|
|
718
719
|
\\ - name: Install GTK and Xvfb
|
|
719
|
-
\\
|
|
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
|
|
720
725
|
\\ - name: Fetch native-sdk
|
|
721
726
|
\\ run: |
|
|
722
727
|
\\ if [ ! -f "$NATIVE_SDK_PATH/build.zig" ]; then
|
|
@@ -852,6 +857,12 @@ fn buildZig(allocator: std.mem.Allocator, names: TemplateNames, framework_path:
|
|
|
852
857
|
\\ chromium,
|
|
853
858
|
\\};
|
|
854
859
|
\\
|
|
860
|
+
\\const WebLayerOption = enum {
|
|
861
|
+
\\ auto,
|
|
862
|
+
\\ include,
|
|
863
|
+
\\ exclude,
|
|
864
|
+
\\};
|
|
865
|
+
\\
|
|
855
866
|
\\const PackageTarget = enum {
|
|
856
867
|
\\ macos,
|
|
857
868
|
\\ windows,
|
|
@@ -875,6 +886,7 @@ fn buildZig(allocator: std.mem.Allocator, names: TemplateNames, framework_path:
|
|
|
875
886
|
\\ const automation_enabled = b.option(bool, "automation", "Enable Native SDK automation artifacts") orelse false;
|
|
876
887
|
\\ const js_bridge_enabled = b.option(bool, "js-bridge", "Enable optional JavaScript bridge stubs") orelse false;
|
|
877
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");
|
|
878
890
|
\\ const cef_dir_override = b.option([]const u8, "cef-dir", "Override CEF root directory for Chromium builds");
|
|
879
891
|
\\ const cef_auto_install_override = b.option(bool, "cef-auto-install", "Override app.zon CEF auto-install setting");
|
|
880
892
|
\\ const package_target = b.option(PackageTarget, "package-target", "Package target: macos, windows, linux") orelse .macos;
|
|
@@ -893,13 +905,14 @@ fn buildZig(allocator: std.mem.Allocator, names: TemplateNames, framework_path:
|
|
|
893
905
|
\\ if (selected_platform == .windows and target.result.os.tag != .windows) {
|
|
894
906
|
\\ @panic("-Dplatform=windows requires a Windows target");
|
|
895
907
|
\\ }
|
|
896
|
-
\\ const
|
|
897
|
-
\\ const web_engine = web_engine_override orelse
|
|
898
|
-
\\ const cef_dir = cef_dir_override orelse defaultCefDir(selected_platform,
|
|
899
|
-
\\ 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;
|
|
900
912
|
\\ if (web_engine == .chromium and selected_platform != .macos) {
|
|
901
913
|
\\ @panic("-Dweb-engine=chromium currently requires -Dplatform=macos");
|
|
902
914
|
\\ }
|
|
915
|
+
\\ const web_layer = resolveWebLayer(app_config, web_engine, web_layer_override);
|
|
903
916
|
\\
|
|
904
917
|
\\ const native_sdk_mod = nativeSdkModule(b, target, optimize, native_sdk_path);
|
|
905
918
|
\\ const options = b.addOptions();
|
|
@@ -915,6 +928,7 @@ fn buildZig(allocator: std.mem.Allocator, names: TemplateNames, framework_path:
|
|
|
915
928
|
\\ options.addOption(bool, "debug_overlay", debug_overlay);
|
|
916
929
|
\\ options.addOption(bool, "automation", automation_enabled);
|
|
917
930
|
\\ options.addOption(bool, "js_bridge", js_bridge_enabled);
|
|
931
|
+
\\ options.addOption(bool, "web_layer", web_layer);
|
|
918
932
|
\\ const options_mod = options.createModule();
|
|
919
933
|
\\
|
|
920
934
|
\\ const runner_mod = localModule(b, target, optimize, "src/runner.zig");
|
|
@@ -929,7 +943,7 @@ fn buildZig(allocator: std.mem.Allocator, names: TemplateNames, framework_path:
|
|
|
929
943
|
\\ .name = app_exe_name,
|
|
930
944
|
\\ .root_module = app_mod,
|
|
931
945
|
\\ });
|
|
932
|
-
\\ 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);
|
|
933
947
|
\\ b.installArtifact(exe);
|
|
934
948
|
\\
|
|
935
949
|
\\ const frontend_install = b.addSystemCommand(&.{ "npm", "install", "--prefix", "frontend" });
|
|
@@ -944,13 +958,13 @@ fn buildZig(allocator: std.mem.Allocator, names: TemplateNames, framework_path:
|
|
|
944
958
|
\\ const run = b.addRunArtifact(exe);
|
|
945
959
|
\\ run.step.dependOn(&frontend_build.step);
|
|
946
960
|
\\ addCefRuntimeRunFiles(b, target, run, exe, web_engine, cef_dir);
|
|
947
|
-
\\ addWebView2RuntimeRunFiles(b, target, run, web_engine, native_sdk_path);
|
|
961
|
+
\\ addWebView2RuntimeRunFiles(b, target, run, web_engine, web_layer, native_sdk_path);
|
|
948
962
|
\\ const run_step = b.step("run", "Run the app");
|
|
949
963
|
\\ run_step.dependOn(&run.step);
|
|
950
964
|
\\
|
|
951
965
|
\\ const dev = b.addSystemCommand(&.{ "native", "dev", "--manifest", "app.zon", "--binary" });
|
|
952
966
|
\\ dev.addFileArg(exe.getEmittedBin());
|
|
953
|
-
\\ addWebView2RuntimeRunFiles(b, target, dev, web_engine, native_sdk_path);
|
|
967
|
+
\\ addWebView2RuntimeRunFiles(b, target, dev, web_engine, web_layer, native_sdk_path);
|
|
954
968
|
\\ dev.step.dependOn(&exe.step);
|
|
955
969
|
\\ dev.step.dependOn(&frontend_install.step);
|
|
956
970
|
\\ const dev_step = b.step("dev", "Run the frontend dev server and native shell");
|
|
@@ -981,6 +995,13 @@ fn buildZig(allocator: std.mem.Allocator, names: TemplateNames, framework_path:
|
|
|
981
995
|
\\ package.setEnvironmentVariable("NATIVE_SDK_PATH", b.pathFromRoot(native_sdk_path));
|
|
982
996
|
\\ package.addFileArg(exe.getEmittedBin());
|
|
983
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" });
|
|
984
1005
|
\\ if (cef_auto_install) package.addArg("--cef-auto-install");
|
|
985
1006
|
\\ package.step.dependOn(&exe.step);
|
|
986
1007
|
\\ package.step.dependOn(&frontend_build.step);
|
|
@@ -1073,7 +1094,7 @@ fn buildZig(allocator: std.mem.Allocator, names: TemplateNames, framework_path:
|
|
|
1073
1094
|
\\ });
|
|
1074
1095
|
\\}
|
|
1075
1096
|
\\
|
|
1076
|
-
\\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 {
|
|
1077
1098
|
\\ if (platform == .macos) {
|
|
1078
1099
|
\\ switch (web_engine) {
|
|
1079
1100
|
\\ .system => {
|
|
@@ -1120,11 +1141,23 @@ fn buildZig(allocator: std.mem.Allocator, names: TemplateNames, framework_path:
|
|
|
1120
1141
|
\\ if (web_engine == .chromium) app_mod.linkSystemLibrary("c++", .{});
|
|
1121
1142
|
\\ } else if (platform == .linux) {
|
|
1122
1143
|
\\ switch (web_engine) {
|
|
1123
|
-
\\ .system => {
|
|
1144
|
+
\\ .system => if (web_layer) {
|
|
1124
1145
|
\\ app_mod.addCSourceFile(.{ .file = nativeSdkPath(b, native_sdk_path, "src/platform/linux/gtk_host.c"), .flags = &.{} });
|
|
1125
1146
|
\\ app_mod.linkSystemLibrary("gtk4", .{});
|
|
1126
1147
|
\\ app_mod.linkSystemLibrary("webkitgtk-6.0", .{});
|
|
1127
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", .{});
|
|
1128
1161
|
\\ },
|
|
1129
1162
|
\\ .chromium => {
|
|
1130
1163
|
\\ const cef_check = addCefCheck(b, target, cef_dir);
|
|
@@ -1146,7 +1179,7 @@ fn buildZig(allocator: std.mem.Allocator, names: TemplateNames, framework_path:
|
|
|
1146
1179
|
\\ if (web_engine == .chromium) app_mod.linkSystemLibrary("stdc++", .{});
|
|
1147
1180
|
\\ } else if (platform == .windows) {
|
|
1148
1181
|
\\ switch (web_engine) {
|
|
1149
|
-
\\ .system => {
|
|
1182
|
+
\\ .system => if (web_layer) {
|
|
1150
1183
|
\\ // The vendored WebView2 SDK header (third_party/webview2)
|
|
1151
1184
|
\\ // turns on the host's embedded-WebView layer; the host
|
|
1152
1185
|
\\ // fails the compile by design if it cannot be found.
|
|
@@ -1158,6 +1191,16 @@ fn buildZig(allocator: std.mem.Allocator, names: TemplateNames, framework_path:
|
|
|
1158
1191
|
\\ // touch it.
|
|
1159
1192
|
\\ const loader = b.addInstallBinFile(nativeSdkPath(b, native_sdk_path, webView2LoaderSubPath(target)), "WebView2Loader.dll");
|
|
1160
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" } });
|
|
1161
1204
|
\\ },
|
|
1162
1205
|
\\ .chromium => {
|
|
1163
1206
|
\\ const cef_check = addCefCheck(b, target, cef_dir);
|
|
@@ -1203,9 +1246,11 @@ fn buildZig(allocator: std.mem.Allocator, names: TemplateNames, framework_path:
|
|
|
1203
1246
|
\\/// `zig build run` and `zig build dev` execute the cached artifact, which
|
|
1204
1247
|
\\/// has no installed WebView2Loader.dll beside it; the vendored loader's
|
|
1205
1248
|
\\/// directory goes on the step's PATH so the host's LoadLibrary resolves it
|
|
1206
|
-
\\/// (`native dev` passes its environment on to the app it spawns).
|
|
1207
|
-
|
|
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 {
|
|
1208
1252
|
\\ if (web_engine != .system) return;
|
|
1253
|
+
\\ if (!web_layer) return;
|
|
1209
1254
|
\\ if (target.result.os.tag != .windows) return;
|
|
1210
1255
|
\\ const loader_dir = std.fs.path.dirname(webView2LoaderSubPath(target)).?;
|
|
1211
1256
|
\\ run.addPathDir(b.pathFromRoot(b.pathJoin(&.{ native_sdk_path, loader_dir })));
|
|
@@ -1279,10 +1324,42 @@ fn buildZig(allocator: std.mem.Allocator, names: TemplateNames, framework_path:
|
|
|
1279
1324
|
\\ };
|
|
1280
1325
|
\\}
|
|
1281
1326
|
\\
|
|
1282
|
-
|
|
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 {
|
|
1283
1333
|
\\ web_engine: WebEngineOption = .system,
|
|
1284
1334
|
\\ cef_dir: []const u8 = "third_party/cef/macos",
|
|
1285
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
|
+
\\ } = .{},
|
|
1286
1363
|
\\};
|
|
1287
1364
|
\\
|
|
1288
1365
|
\\fn defaultCefDir(platform: PlatformOption, configured: []const u8) []const u8 {
|
|
@@ -1294,58 +1371,74 @@ fn buildZig(allocator: std.mem.Allocator, names: TemplateNames, framework_path:
|
|
|
1294
1371
|
\\ };
|
|
1295
1372
|
\\}
|
|
1296
1373
|
\\
|
|
1297
|
-
\\fn
|
|
1298
|
-
\\
|
|
1299
|
-
\\
|
|
1300
|
-
\\
|
|
1301
|
-
\\
|
|
1302
|
-
\\
|
|
1303
|
-
\\
|
|
1304
|
-
\\
|
|
1305
|
-
\\
|
|
1306
|
-
\\
|
|
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
|
+
\\ };
|
|
1307
1400
|
\\ return config;
|
|
1308
1401
|
\\}
|
|
1309
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
|
+
\\
|
|
1310
1432
|
\\fn parseWebEngine(value: []const u8) ?WebEngineOption {
|
|
1311
1433
|
\\ if (std.mem.eql(u8, value, "system")) return .system;
|
|
1312
1434
|
\\ if (std.mem.eql(u8, value, "chromium")) return .chromium;
|
|
1313
1435
|
\\ return null;
|
|
1314
1436
|
\\}
|
|
1315
1437
|
\\
|
|
1316
|
-
\\fn
|
|
1317
|
-
\\
|
|
1318
|
-
\\
|
|
1319
|
-
\\
|
|
1320
|
-
\\ const end_quote = std.mem.indexOfScalarPos(u8, source, start_quote + 1, '"') orelse return null;
|
|
1321
|
-
\\ return source[start_quote + 1 .. end_quote];
|
|
1322
|
-
\\}
|
|
1323
|
-
\\
|
|
1324
|
-
\\fn objectSection(source: []const u8, field: []const u8) ?[]const u8 {
|
|
1325
|
-
\\ const field_index = std.mem.indexOf(u8, source, field) orelse return null;
|
|
1326
|
-
\\ const open = std.mem.indexOfScalarPos(u8, source, field_index, '{') orelse return null;
|
|
1327
|
-
\\ var depth: usize = 0;
|
|
1328
|
-
\\ var index = open;
|
|
1329
|
-
\\ while (index < source.len) : (index += 1) {
|
|
1330
|
-
\\ switch (source[index]) {
|
|
1331
|
-
\\ '{' => depth += 1,
|
|
1332
|
-
\\ '}' => {
|
|
1333
|
-
\\ depth -= 1;
|
|
1334
|
-
\\ if (depth == 0) return source[open + 1 .. index];
|
|
1335
|
-
\\ },
|
|
1336
|
-
\\ else => {},
|
|
1337
|
-
\\ }
|
|
1338
|
-
\\ }
|
|
1339
|
-
\\ return null;
|
|
1340
|
-
\\}
|
|
1341
|
-
\\
|
|
1342
|
-
\\fn boolField(source: []const u8, field: []const u8) ?bool {
|
|
1343
|
-
\\ const field_index = std.mem.indexOf(u8, source, field) orelse return null;
|
|
1344
|
-
\\ const equals = std.mem.indexOfScalarPos(u8, source, field_index, '=') orelse return null;
|
|
1345
|
-
\\ var index = equals + 1;
|
|
1346
|
-
\\ while (index < source.len and std.ascii.isWhitespace(source[index])) : (index += 1) {}
|
|
1347
|
-
\\ if (std.mem.startsWith(u8, source[index..], "true")) return true;
|
|
1348
|
-
\\ 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;
|
|
1349
1442
|
\\ return null;
|
|
1350
1443
|
\\}
|
|
1351
1444
|
\\
|
|
@@ -1515,6 +1608,7 @@ fn runnerZig() []const u8 {
|
|
|
1515
1608
|
\\ fn appInfo(self: RunOptions, buffers: *StateBuffers) native_sdk.AppInfo {
|
|
1516
1609
|
\\ var info: native_sdk.AppInfo = .{
|
|
1517
1610
|
\\ .app_name = self.app_name,
|
|
1611
|
+
\\ .has_web_content = manifestHasWebContent(),
|
|
1518
1612
|
\\ .window_title = self.window_title,
|
|
1519
1613
|
\\ .bundle_id = self.bundle_id,
|
|
1520
1614
|
\\ .icon_path = self.icon_path,
|
|
@@ -1765,6 +1859,7 @@ fn runnerZig() []const u8 {
|
|
|
1765
1859
|
\\ .builtin_bridge = options.builtin_bridge,
|
|
1766
1860
|
\\ .security = options.security,
|
|
1767
1861
|
\\ .js_window_api = options.js_window_api,
|
|
1862
|
+
\\ .web_layer = webLayerEnabled(),
|
|
1768
1863
|
\\ .commands = commands,
|
|
1769
1864
|
\\ .menus = menus,
|
|
1770
1865
|
\\ .shortcuts = shortcuts,
|
|
@@ -1814,6 +1909,7 @@ fn runnerZig() []const u8 {
|
|
|
1814
1909
|
\\ .builtin_bridge = options.builtin_bridge,
|
|
1815
1910
|
\\ .security = options.security,
|
|
1816
1911
|
\\ .js_window_api = options.js_window_api,
|
|
1912
|
+
\\ .web_layer = webLayerEnabled(),
|
|
1817
1913
|
\\ .commands = commands,
|
|
1818
1914
|
\\ .menus = menus,
|
|
1819
1915
|
\\ .shortcuts = shortcuts,
|
|
@@ -1863,6 +1959,7 @@ fn runnerZig() []const u8 {
|
|
|
1863
1959
|
\\ .builtin_bridge = options.builtin_bridge,
|
|
1864
1960
|
\\ .security = options.security,
|
|
1865
1961
|
\\ .js_window_api = options.js_window_api,
|
|
1962
|
+
\\ .web_layer = webLayerEnabled(),
|
|
1866
1963
|
\\ .commands = commands,
|
|
1867
1964
|
\\ .menus = menus,
|
|
1868
1965
|
\\ .shortcuts = shortcuts,
|
|
@@ -1912,6 +2009,7 @@ fn runnerZig() []const u8 {
|
|
|
1912
2009
|
\\ .builtin_bridge = options.builtin_bridge,
|
|
1913
2010
|
\\ .security = options.security,
|
|
1914
2011
|
\\ .js_window_api = options.js_window_api,
|
|
2012
|
+
\\ .web_layer = webLayerEnabled(),
|
|
1915
2013
|
\\ .commands = commands,
|
|
1916
2014
|
\\ .menus = menus,
|
|
1917
2015
|
\\ .shortcuts = shortcuts,
|
|
@@ -1935,6 +2033,48 @@ fn runnerZig() []const u8 {
|
|
|
1935
2033
|
\\ return .system;
|
|
1936
2034
|
\\}
|
|
1937
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
|
+
\\
|
|
1938
2078
|
\\const StateBuffers = struct {
|
|
1939
2079
|
\\ state_dir: [1024]u8 = undefined,
|
|
1940
2080
|
\\ file_path: [1200]u8 = undefined,
|
|
@@ -2874,13 +3014,32 @@ test "writeDefaultApp emits Vite project files" {
|
|
|
2874
3014
|
try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "frontend_build.step.dependOn(&frontend_install.step)") != null);
|
|
2875
3015
|
try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "\"native\", \"dev\"") != null);
|
|
2876
3016
|
try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "dev.step.dependOn(&frontend_install.step)") != null);
|
|
2877
|
-
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);
|
|
2878
3018
|
try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "package.setEnvironmentVariable(\"NATIVE_SDK_PATH\", b.pathFromRoot(native_sdk_path))") != null);
|
|
2879
3019
|
try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "chromium") != null);
|
|
2880
3020
|
try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "cef-dir") != null);
|
|
2881
3021
|
try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "src/platform/macos/cef_host.mm") != null);
|
|
2882
3022
|
try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "src/platform/linux/gtk_host.c") != null);
|
|
2883
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);
|
|
2884
3043
|
try std.testing.expect(std.mem.indexOf(u8, main_zig_text, "frontend/dist") != null);
|
|
2885
3044
|
try std.testing.expect(std.mem.indexOf(u8, main_zig_text, "127.0.0.1:5173") != null);
|
|
2886
3045
|
try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, "@import(\"app_manifest_zon\")") != null);
|
|
@@ -2901,6 +3060,13 @@ test "writeDefaultApp emits Vite project files" {
|
|
|
2901
3060
|
try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, "defer std.heap.page_allocator.destroy(runtime)") != null);
|
|
2902
3061
|
try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, "native_sdk.Runtime.initAt(runtime, .{") != null);
|
|
2903
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);
|
|
2904
3070
|
try std.testing.expect(std.mem.indexOf(u8, package_json_text, "\"vite\"") != null);
|
|
2905
3071
|
try std.testing.expect(std.mem.indexOf(u8, main_js_text, "window.zero") != null);
|
|
2906
3072
|
|
|
@@ -3032,8 +3198,11 @@ test "writeDefaultApp emits a CI workflow for native apps" {
|
|
|
3032
3198
|
try std.testing.expect(std.mem.indexOf(u8, ci_yaml_text, "version: 0.16.0") != null);
|
|
3033
3199
|
try std.testing.expect(std.mem.indexOf(u8, ci_yaml_text, "zig build test -Dplatform=null") != null);
|
|
3034
3200
|
// The smoke job builds with automation, launches under Xvfb, and drives
|
|
3035
|
-
// the snapshot: the binary name comes from the template context.
|
|
3036
|
-
|
|
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);
|
|
3037
3206
|
try std.testing.expect(std.mem.indexOf(u8, ci_yaml_text, "zig build -Dplatform=linux -Dweb-engine=system -Dautomation=true") != null);
|
|
3038
3207
|
try std.testing.expect(std.mem.indexOf(u8, ci_yaml_text, "xvfb-run -a ./zig-out/bin/my-app &") != null);
|
|
3039
3208
|
try std.testing.expect(std.mem.indexOf(u8, ci_yaml_text, "automate wait") != null);
|
|
@@ -3183,13 +3352,71 @@ fn nativeDependencyPath(allocator: std.mem.Allocator, io: std.Io, destination: [
|
|
|
3183
3352
|
defer allocator.free(framework_real);
|
|
3184
3353
|
|
|
3185
3354
|
const relative = try std.fs.path.relative(allocator, cwd, null, destination_real, framework_real);
|
|
3355
|
+
errdefer allocator.free(relative);
|
|
3356
|
+
// On Windows, two different volumes (drive letters or UNC shares) have
|
|
3357
|
+
// no relative path between them, and std.fs.path.relative degrades to
|
|
3358
|
+
// the absolute target — which build.zig.zon rejects. The full scaffold's
|
|
3359
|
+
// build files are user-owned from day one, so the CLI cannot bridge with
|
|
3360
|
+
// a junction it would never refresh; teach the constraint instead.
|
|
3361
|
+
if (junction.crossesVolumes(relative)) {
|
|
3362
|
+
std.debug.print(
|
|
3363
|
+
\\cannot scaffold a full-shape app at {s}:
|
|
3364
|
+
\\the Native SDK ({s})
|
|
3365
|
+
\\sits on a different Windows volume, and the scaffolded
|
|
3366
|
+
\\build.zig.zon needs a relative SDK path — no relative path
|
|
3367
|
+
\\crosses volumes.
|
|
3368
|
+
\\
|
|
3369
|
+
, .{ destination_real, framework_real });
|
|
3370
|
+
std.debug.print(junction.cross_volume_ways_out, .{});
|
|
3371
|
+
return error.CrossVolumeFramework;
|
|
3372
|
+
}
|
|
3186
3373
|
if (relative.len == 0) {
|
|
3374
|
+
// Dupe before freeing `relative`: if the dupe fails, the errdefer
|
|
3375
|
+
// above still owns `relative` and must free it exactly once.
|
|
3376
|
+
const dot = try allocator.dupe(u8, ".");
|
|
3187
3377
|
allocator.free(relative);
|
|
3188
|
-
return
|
|
3378
|
+
return dot;
|
|
3189
3379
|
}
|
|
3190
3380
|
return relative;
|
|
3191
3381
|
}
|
|
3192
3382
|
|
|
3383
|
+
test "nativeDependencyPath falls back to `.` for a same-directory scaffold" {
|
|
3384
|
+
const io = std.testing.io;
|
|
3385
|
+
const destination = ".zig-cache/test-native-dependency-same-dir";
|
|
3386
|
+
try std.Io.Dir.cwd().createDirPath(io, destination);
|
|
3387
|
+
const destination_real = try std.Io.Dir.cwd().realPathFileAlloc(io, destination, std.testing.allocator);
|
|
3388
|
+
defer std.testing.allocator.free(destination_real);
|
|
3389
|
+
|
|
3390
|
+
const dependency = try nativeDependencyPath(std.testing.allocator, io, destination, destination_real);
|
|
3391
|
+
defer std.testing.allocator.free(dependency);
|
|
3392
|
+
try std.testing.expectEqualStrings(".", dependency);
|
|
3393
|
+
}
|
|
3394
|
+
|
|
3395
|
+
fn expectSameDirDependencyDot(allocator: std.mem.Allocator, io: std.Io, destination: []const u8, framework_path: []const u8) !void {
|
|
3396
|
+
const dependency = try nativeDependencyPath(allocator, io, destination, framework_path);
|
|
3397
|
+
defer allocator.free(dependency);
|
|
3398
|
+
try std.testing.expectEqualStrings(".", dependency);
|
|
3399
|
+
}
|
|
3400
|
+
|
|
3401
|
+
test "nativeDependencyPath survives every allocation-failure point of the `.` fallback" {
|
|
3402
|
+
// Walks every allocation-failure point of the `.` fallback and asserts
|
|
3403
|
+
// no leak and no swallowed OutOfMemory at each index. The fallback's
|
|
3404
|
+
// ownership rule — the errdefer releases the relative path exactly
|
|
3405
|
+
// once, so the fallible dupe must run before the manual free — keeps
|
|
3406
|
+
// this loop clean at the index where the dupe itself fails. (The slice
|
|
3407
|
+
// in this branch is empty, and freeing an empty slice is a no-op, so a
|
|
3408
|
+
// free-then-dupe ordering would not crash here today; the test pins
|
|
3409
|
+
// the ordering so the branch stays safe if it ever handles a non-empty
|
|
3410
|
+
// allocation.)
|
|
3411
|
+
const io = std.testing.io;
|
|
3412
|
+
const destination = ".zig-cache/test-native-dependency-oom";
|
|
3413
|
+
try std.Io.Dir.cwd().createDirPath(io, destination);
|
|
3414
|
+
const destination_real = try std.Io.Dir.cwd().realPathFileAlloc(io, destination, std.testing.allocator);
|
|
3415
|
+
defer std.testing.allocator.free(destination_real);
|
|
3416
|
+
|
|
3417
|
+
try std.testing.checkAllAllocationFailures(std.testing.allocator, expectSameDirDependencyDot, .{ io, destination, destination_real });
|
|
3418
|
+
}
|
|
3419
|
+
|
|
3193
3420
|
fn appendZigString(out: *std.ArrayList(u8), allocator: std.mem.Allocator, value: []const u8) !void {
|
|
3194
3421
|
try appendEscapedString(out, allocator, value);
|
|
3195
3422
|
}
|
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
|
|