@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
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
//! The web-layer inference contract: the ONE definition of when an app
|
|
2
|
+
//! ships the embedded web layer. An app is WEB when it declares web use
|
|
3
|
+
//! (a `.frontend` block, the `"webview"` capability, a `.shell` webview
|
|
4
|
+
//! view) or the RESOLVED web engine is Chromium; otherwise it is
|
|
5
|
+
//! native-only and the platform host compiles without the embedded
|
|
6
|
+
//! layer. `.webview_layer = "include"|"exclude"` overrides the
|
|
7
|
+
//! inference — and an exclude that contradicts a web declaration is a
|
|
8
|
+
//! refused conflict, never a silently broken app.
|
|
9
|
+
//!
|
|
10
|
+
//! Every boundary consumes this file and feeds it the inputs that
|
|
11
|
+
//! boundary owns:
|
|
12
|
+
//!
|
|
13
|
+
//! - The standard build graph (build/app.zig) sees `-Dweb-engine` and
|
|
14
|
+
//! `-Dweb-layer`: its resolved engine is the flag orelse app.zon, its
|
|
15
|
+
//! effective layer setting is the flag orelse app.zon, and a conflict
|
|
16
|
+
//! is a configure-time error.
|
|
17
|
+
//! - The CLI (src/tooling/manifest.zig `webLayer`/`webLayerResolved`,
|
|
18
|
+
//! consumed by src/tooling/package.zig) sees `--web-engine` and the
|
|
19
|
+
//! package verb's `--web-layer`: each flag beats its app.zon field the
|
|
20
|
+
//! same way the `-D` options do in the build graph, and a conflict
|
|
21
|
+
//! refuses the package. Both standard graph shapes (build/app.zig and
|
|
22
|
+
//! the generated template's build.zig) forward their RESOLVED layer
|
|
23
|
+
//! decision to `native package` as `--web-layer include|exclude`, so a
|
|
24
|
+
//! graph-driven package never re-infers what the graph already decided
|
|
25
|
+
//! and the packaged artifact structurally agrees with the exe.
|
|
26
|
+
//! - The app runner (src/app_runner/root.zig) evaluates the contract at
|
|
27
|
+
//! comptime over the app.zon import. It NEVER sees the `-Dweb-engine`
|
|
28
|
+
//! flag, so its engine input is the manifest's own engine: the
|
|
29
|
+
//! runner's guard fires on every manifest-visible web declaration,
|
|
30
|
+
//! while an engine resolved to Chromium by flag alone stays a
|
|
31
|
+
//! configure-time error in the build graph, which does see the flag.
|
|
32
|
+
|
|
33
|
+
const std = @import("std");
|
|
34
|
+
const types = @import("types.zig");
|
|
35
|
+
|
|
36
|
+
pub const WebEngine = types.WebEngine;
|
|
37
|
+
pub const WebViewLayer = types.WebViewLayer;
|
|
38
|
+
|
|
39
|
+
/// A web declaration: one reason an app needs the embedded web layer.
|
|
40
|
+
/// Scanning stops at the first hit, in this order, so teaching messages
|
|
41
|
+
/// stay deterministic.
|
|
42
|
+
pub const Declaration = enum {
|
|
43
|
+
frontend,
|
|
44
|
+
capability,
|
|
45
|
+
shell_webview,
|
|
46
|
+
chromium_engine,
|
|
47
|
+
/// Not a manifest field: a lenient parse (the build graph reading
|
|
48
|
+
/// app.zon it may not fully understand) could not read the manifest
|
|
49
|
+
/// at all. Absence of proof is not proof of a native-only app, so an
|
|
50
|
+
/// unreadable manifest counts as a web declaration — over-inclusion
|
|
51
|
+
/// costs binary size, a wrong exclusion breaks declared webviews.
|
|
52
|
+
unreadable_manifest,
|
|
53
|
+
|
|
54
|
+
/// The teaching-message half of a declaration, shared so every
|
|
55
|
+
/// boundary names the same cause the same way.
|
|
56
|
+
pub fn text(self: Declaration) []const u8 {
|
|
57
|
+
return switch (self) {
|
|
58
|
+
.frontend => "a .frontend block",
|
|
59
|
+
.capability => "the \"webview\" capability",
|
|
60
|
+
.shell_webview => "a .shell webview view",
|
|
61
|
+
.chromium_engine => "the Chromium web engine",
|
|
62
|
+
.unreadable_manifest => "an app.zon the build graph could not parse",
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
fn reason(self: Declaration) Reason {
|
|
67
|
+
return switch (self) {
|
|
68
|
+
.frontend => .frontend,
|
|
69
|
+
.capability => .capability,
|
|
70
|
+
.shell_webview => .shell_webview,
|
|
71
|
+
.chromium_engine => .chromium_engine,
|
|
72
|
+
.unreadable_manifest => .unreadable_manifest,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
/// Why the web layer is (or is not) in the build, for verdict lines.
|
|
78
|
+
pub const Reason = enum {
|
|
79
|
+
inferred_native_only,
|
|
80
|
+
declared_exclude,
|
|
81
|
+
capability,
|
|
82
|
+
frontend,
|
|
83
|
+
shell_webview,
|
|
84
|
+
chromium_engine,
|
|
85
|
+
declared_include,
|
|
86
|
+
unreadable_manifest,
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
pub const Decision = struct {
|
|
90
|
+
enabled: bool,
|
|
91
|
+
reason: Reason,
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
pub const Error = error{WebViewLayerConflict};
|
|
95
|
+
|
|
96
|
+
/// The decision half of the contract: `include` forces the layer on,
|
|
97
|
+
/// `auto` infers it from the declarations, and `exclude` promises a
|
|
98
|
+
/// native-only app — so an exclude alongside any web declaration is a
|
|
99
|
+
/// contradiction this returns as an error for the boundary to report,
|
|
100
|
+
/// never resolved silently in either direction.
|
|
101
|
+
pub fn decide(setting: WebViewLayer, declaration: ?Declaration) Error!Decision {
|
|
102
|
+
return switch (setting) {
|
|
103
|
+
.include => .{ .enabled = true, .reason = .declared_include },
|
|
104
|
+
.exclude => if (declaration != null) error.WebViewLayerConflict else .{ .enabled = false, .reason = .declared_exclude },
|
|
105
|
+
.auto => if (declaration) |value| .{ .enabled = true, .reason = value.reason() } else .{ .enabled = false, .reason = .inferred_native_only },
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/// The full inference over manifest-shaped data plus the resolved
|
|
110
|
+
/// engine and the effective layer setting (override orelse manifest).
|
|
111
|
+
pub fn infer(manifest: anytype, resolved_engine: WebEngine, setting: WebViewLayer) Error!Decision {
|
|
112
|
+
return decide(setting, webDeclaration(manifest, resolved_engine));
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/// The first web declaration for a build: the manifest scan, then the
|
|
116
|
+
/// RESOLVED engine. Boundaries that resolve an engine flag pass the
|
|
117
|
+
/// resolved value; boundaries without one (validation, the runner) pass
|
|
118
|
+
/// the manifest's own engine.
|
|
119
|
+
pub fn webDeclaration(manifest: anytype, resolved_engine: WebEngine) ?Declaration {
|
|
120
|
+
return foldEngine(manifestDeclaration(manifest), resolved_engine);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/// Fold the resolved engine into an already-computed manifest scan, for
|
|
124
|
+
/// boundaries (the build graph) that scan at parse time and resolve the
|
|
125
|
+
/// engine later.
|
|
126
|
+
pub fn foldEngine(declaration: ?Declaration, resolved_engine: WebEngine) ?Declaration {
|
|
127
|
+
if (declaration) |value| return value;
|
|
128
|
+
return if (resolved_engine == .chromium) .chromium_engine else null;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/// The manifest half of the scan, duck-typed so every boundary feeds
|
|
132
|
+
/// the shape it has: the runner's comptime app.zon import (fields may
|
|
133
|
+
/// be absent, lists are tuples), a lenient build-graph parse and the
|
|
134
|
+
/// CLI's parsed metadata (string kinds, slice lists), and the typed
|
|
135
|
+
/// `Manifest` (Capability unions, ViewKind enums). The engine is NOT
|
|
136
|
+
/// part of this scan — pass the resolved engine to `webDeclaration`.
|
|
137
|
+
pub fn manifestDeclaration(manifest: anytype) ?Declaration {
|
|
138
|
+
if (declaresFrontend(manifest)) return .frontend;
|
|
139
|
+
if (declaresWebviewCapability(manifest)) return .capability;
|
|
140
|
+
if (declaresShellWebviewView(manifest)) return .shell_webview;
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
pub fn parseWebEngine(value: []const u8) ?WebEngine {
|
|
145
|
+
if (std.mem.eql(u8, value, "system")) return .system;
|
|
146
|
+
if (std.mem.eql(u8, value, "chromium")) return .chromium;
|
|
147
|
+
return null;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
pub fn parseWebViewLayer(value: []const u8) ?WebViewLayer {
|
|
151
|
+
if (std.mem.eql(u8, value, "auto")) return .auto;
|
|
152
|
+
if (std.mem.eql(u8, value, "include")) return .include;
|
|
153
|
+
if (std.mem.eql(u8, value, "exclude")) return .exclude;
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
fn declaresFrontend(manifest: anytype) bool {
|
|
158
|
+
if (comptime !@hasField(@TypeOf(manifest), "frontend")) return false;
|
|
159
|
+
const frontend = manifest.frontend;
|
|
160
|
+
const T = @TypeOf(frontend);
|
|
161
|
+
if (comptime T == @TypeOf(null)) return false;
|
|
162
|
+
if (comptime @typeInfo(T) == .optional) return frontend != null;
|
|
163
|
+
// A ZON `.frontend = .{ ... }` block: present means declared.
|
|
164
|
+
return true;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
fn declaresWebviewCapability(manifest: anytype) bool {
|
|
168
|
+
if (comptime !@hasField(@TypeOf(manifest), "capabilities")) return false;
|
|
169
|
+
return anyElement(manifest.capabilities, isWebviewName);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
fn declaresShellWebviewView(manifest: anytype) bool {
|
|
173
|
+
if (comptime !@hasField(@TypeOf(manifest), "shell")) return false;
|
|
174
|
+
const shell = manifest.shell;
|
|
175
|
+
if (comptime !@hasField(@TypeOf(shell), "windows")) return false;
|
|
176
|
+
return anyElement(shell.windows, windowHasWebviewView);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
fn windowHasWebviewView(window: anytype) bool {
|
|
180
|
+
if (comptime !@hasField(@TypeOf(window), "views")) return false;
|
|
181
|
+
return anyElement(window.views, viewIsWebview);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
fn viewIsWebview(view: anytype) bool {
|
|
185
|
+
if (comptime !@hasField(@TypeOf(view), "kind")) return false;
|
|
186
|
+
return isWebviewName(view.kind);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/// Whether a capability or view kind names the webview: an enum tag
|
|
190
|
+
/// (`ViewKind`), a tagged-union tag (`Capability`), or string data (the
|
|
191
|
+
/// ZON import and parsed-metadata shapes).
|
|
192
|
+
fn isWebviewName(value: anytype) bool {
|
|
193
|
+
return switch (@typeInfo(@TypeOf(value))) {
|
|
194
|
+
.@"enum" => value == .webview,
|
|
195
|
+
.@"union" => std.meta.activeTag(value) == .webview,
|
|
196
|
+
else => std.mem.eql(u8, value, "webview"),
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/// Whether any element of `list` matches. Slices and arrays iterate at
|
|
201
|
+
/// runtime; ZON tuples iterate inline so the whole scan stays usable in
|
|
202
|
+
/// the runner's comptime evaluation.
|
|
203
|
+
fn anyElement(list: anytype, comptime match: anytype) bool {
|
|
204
|
+
switch (@typeInfo(@TypeOf(list))) {
|
|
205
|
+
.pointer, .array => {
|
|
206
|
+
for (list) |element| {
|
|
207
|
+
if (match(element)) return true;
|
|
208
|
+
}
|
|
209
|
+
return false;
|
|
210
|
+
},
|
|
211
|
+
.@"struct" => |info| {
|
|
212
|
+
if (comptime info.fields.len == 0) return false;
|
|
213
|
+
inline for (list) |element| {
|
|
214
|
+
if (match(element)) return true;
|
|
215
|
+
}
|
|
216
|
+
return false;
|
|
217
|
+
},
|
|
218
|
+
else => return false,
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// ---------------------------------------------------------------------------
|
|
223
|
+
// Contract matrix: every boundary shape, every inference row.
|
|
224
|
+
// ---------------------------------------------------------------------------
|
|
225
|
+
|
|
226
|
+
/// The typed-Manifest shape (what validation.zig scans).
|
|
227
|
+
const typed = struct {
|
|
228
|
+
const webview_capability = [_]types.Capability{.webview};
|
|
229
|
+
const canvas_capabilities = [_]types.Capability{ .native_views, .gpu_surfaces };
|
|
230
|
+
const webview_views = [_]types.ShellView{.{ .label = "content", .kind = .webview }};
|
|
231
|
+
const toolbar_views = [_]types.ShellView{.{ .label = "bar", .kind = .toolbar }};
|
|
232
|
+
const webview_windows = [_]types.ShellWindow{.{ .label = "main", .views = &webview_views }};
|
|
233
|
+
const toolbar_windows = [_]types.ShellWindow{.{ .label = "main", .views = &toolbar_views }};
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
/// The parsed-metadata shape (what the CLI's manifest tooling scans):
|
|
237
|
+
/// string kinds, slice lists, an optional frontend block.
|
|
238
|
+
const MetadataShape = struct {
|
|
239
|
+
const View = struct { kind: []const u8 };
|
|
240
|
+
const Window = struct { views: []const View = &.{} };
|
|
241
|
+
capabilities: []const []const u8 = &.{},
|
|
242
|
+
frontend: ?struct {} = null,
|
|
243
|
+
shell: struct { windows: []const Window = &.{} } = .{},
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
test "web-layer contract matrix agrees across boundary shapes" {
|
|
247
|
+
// Each row runs the scan over three shapes of the same manifest —
|
|
248
|
+
// the runner's comptime ZON import (tuples, absent fields), the
|
|
249
|
+
// typed Manifest, and the CLI's parsed metadata — and every shape
|
|
250
|
+
// must produce the same declaration. The build graph's lenient
|
|
251
|
+
// parse is the metadata shape with narrower fields, and its adapter
|
|
252
|
+
// (build/app.zig resolveWebLayer) is `foldEngine` + `decide`, both
|
|
253
|
+
// exercised below.
|
|
254
|
+
|
|
255
|
+
// Canvas-only: nothing declared, native-only under auto.
|
|
256
|
+
try std.testing.expectEqual(null, manifestDeclaration(.{ .capabilities = .{ "native_views", "gpu_surfaces" } }));
|
|
257
|
+
try std.testing.expectEqual(null, manifestDeclaration(types.Manifest{
|
|
258
|
+
.identity = .{ .id = "dev.example.canvas", .name = "canvas" },
|
|
259
|
+
.version = .{ .major = 1, .minor = 0, .patch = 0 },
|
|
260
|
+
.capabilities = &typed.canvas_capabilities,
|
|
261
|
+
}));
|
|
262
|
+
try std.testing.expectEqual(null, manifestDeclaration(MetadataShape{ .capabilities = &.{ "native_views", "gpu_surfaces" } }));
|
|
263
|
+
{
|
|
264
|
+
const decision = try infer(.{}, .system, .auto);
|
|
265
|
+
try std.testing.expect(!decision.enabled);
|
|
266
|
+
try std.testing.expectEqual(Reason.inferred_native_only, decision.reason);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
// The "webview" capability.
|
|
270
|
+
try std.testing.expectEqual(Declaration.capability, manifestDeclaration(.{ .capabilities = .{"webview"} }));
|
|
271
|
+
try std.testing.expectEqual(Declaration.capability, manifestDeclaration(types.Manifest{
|
|
272
|
+
.identity = .{ .id = "dev.example.a", .name = "a" },
|
|
273
|
+
.version = .{ .major = 1, .minor = 0, .patch = 0 },
|
|
274
|
+
.capabilities = &typed.webview_capability,
|
|
275
|
+
}));
|
|
276
|
+
try std.testing.expectEqual(Declaration.capability, manifestDeclaration(MetadataShape{ .capabilities = &.{"webview"} }));
|
|
277
|
+
|
|
278
|
+
// A .frontend block.
|
|
279
|
+
try std.testing.expectEqual(Declaration.frontend, manifestDeclaration(.{ .frontend = .{ .dist = "frontend/dist" } }));
|
|
280
|
+
try std.testing.expectEqual(Declaration.frontend, manifestDeclaration(types.Manifest{
|
|
281
|
+
.identity = .{ .id = "dev.example.b", .name = "b" },
|
|
282
|
+
.version = .{ .major = 1, .minor = 0, .patch = 0 },
|
|
283
|
+
.frontend = .{},
|
|
284
|
+
}));
|
|
285
|
+
try std.testing.expectEqual(Declaration.frontend, manifestDeclaration(MetadataShape{ .frontend = .{} }));
|
|
286
|
+
|
|
287
|
+
// A .shell webview view (and a webview-free shell stays native).
|
|
288
|
+
try std.testing.expectEqual(Declaration.shell_webview, manifestDeclaration(.{ .shell = .{ .windows = .{.{ .views = .{.{ .kind = "webview" }} }} } }));
|
|
289
|
+
try std.testing.expectEqual(Declaration.shell_webview, manifestDeclaration(types.Manifest{
|
|
290
|
+
.identity = .{ .id = "dev.example.c", .name = "c" },
|
|
291
|
+
.version = .{ .major = 1, .minor = 0, .patch = 0 },
|
|
292
|
+
.shell = .{ .windows = &typed.webview_windows },
|
|
293
|
+
}));
|
|
294
|
+
try std.testing.expectEqual(Declaration.shell_webview, manifestDeclaration(MetadataShape{ .shell = .{ .windows = &.{.{ .views = &.{.{ .kind = "webview" }} }} } }));
|
|
295
|
+
try std.testing.expectEqual(null, manifestDeclaration(types.Manifest{
|
|
296
|
+
.identity = .{ .id = "dev.example.d", .name = "d" },
|
|
297
|
+
.version = .{ .major = 1, .minor = 0, .patch = 0 },
|
|
298
|
+
.shell = .{ .windows = &typed.toolbar_windows },
|
|
299
|
+
}));
|
|
300
|
+
|
|
301
|
+
// The Chromium engine is web intent wherever it was resolved: from
|
|
302
|
+
// app.zon (every boundary sees it) or from a flag (`-Dweb-engine` /
|
|
303
|
+
// `--web-engine`, seen by the build graph and the CLI; the runner
|
|
304
|
+
// never sees flags and covers only the manifest engine — the split
|
|
305
|
+
// this file's module doc pins down).
|
|
306
|
+
try std.testing.expectEqual(Declaration.chromium_engine, webDeclaration(.{}, .chromium));
|
|
307
|
+
try std.testing.expectEqual(Declaration.chromium_engine, foldEngine(null, .chromium));
|
|
308
|
+
{
|
|
309
|
+
const decision = try infer(.{}, .chromium, .auto);
|
|
310
|
+
try std.testing.expect(decision.enabled);
|
|
311
|
+
try std.testing.expectEqual(Reason.chromium_engine, decision.reason);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
// A vestigial explicit `.web_engine = "system"` is NOT web intent.
|
|
315
|
+
try std.testing.expectEqual(null, webDeclaration(.{ .web_engine = "system" }, .system));
|
|
316
|
+
try std.testing.expectEqual(WebEngine.system, parseWebEngine("system"));
|
|
317
|
+
|
|
318
|
+
// Explicit overrides win in both directions.
|
|
319
|
+
{
|
|
320
|
+
const included = try infer(.{}, .system, .include);
|
|
321
|
+
try std.testing.expect(included.enabled);
|
|
322
|
+
try std.testing.expectEqual(Reason.declared_include, included.reason);
|
|
323
|
+
const excluded = try infer(.{}, .system, .exclude);
|
|
324
|
+
try std.testing.expect(!excluded.enabled);
|
|
325
|
+
try std.testing.expectEqual(Reason.declared_exclude, excluded.reason);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
// Exclude + any web declaration is a refused conflict — including
|
|
329
|
+
// an engine resolved to Chromium with a web-free manifest.
|
|
330
|
+
try std.testing.expectError(error.WebViewLayerConflict, infer(.{ .capabilities = .{"webview"} }, .system, .exclude));
|
|
331
|
+
try std.testing.expectError(error.WebViewLayerConflict, infer(.{}, .chromium, .exclude));
|
|
332
|
+
try std.testing.expectError(error.WebViewLayerConflict, decide(.exclude, .unreadable_manifest));
|
|
333
|
+
|
|
334
|
+
// The package boundary's forwarded resolution: the build graphs hand
|
|
335
|
+
// `native package` their computed decision as `--web-layer
|
|
336
|
+
// include|exclude`, and replaying that setting through `decide` must
|
|
337
|
+
// reproduce the same enabled-ness for every row the graph can reach
|
|
338
|
+
// — forwarding the resolution is lossless, so the exe and the
|
|
339
|
+
// package it lands in can never disagree about the web layer.
|
|
340
|
+
const forward_settings = [_]WebViewLayer{ .auto, .include, .exclude };
|
|
341
|
+
const forward_declarations = [_]?Declaration{ null, .capability, .chromium_engine };
|
|
342
|
+
for (forward_settings) |setting| {
|
|
343
|
+
for (forward_declarations) |declaration| {
|
|
344
|
+
// A refused conflict never configures, so the graph has
|
|
345
|
+
// nothing to forward for that row.
|
|
346
|
+
const original = decide(setting, declaration) catch continue;
|
|
347
|
+
const replayed = try decide(if (original.enabled) .include else .exclude, declaration);
|
|
348
|
+
try std.testing.expectEqual(original.enabled, replayed.enabled);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
// The runner's comptime evaluation: the same scan over a ZON-import
|
|
353
|
+
// shape, forced through comptime.
|
|
354
|
+
comptime {
|
|
355
|
+
if (manifestDeclaration(.{ .capabilities = .{ "native_views", "gpu_surfaces" } }) != null) @compileError("canvas manifest must scan native-only");
|
|
356
|
+
if (manifestDeclaration(.{ .capabilities = .{"webview"} }) != Declaration.capability) @compileError("webview capability must scan as a declaration");
|
|
357
|
+
if (webDeclaration(.{ .web_engine = "chromium" }, parseWebEngine("chromium").?) != Declaration.chromium_engine) @compileError("manifest chromium engine must scan as a declaration");
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
test "web-layer declarations carry the shared teaching text" {
|
|
362
|
+
try std.testing.expectEqualStrings("a .frontend block", Declaration.frontend.text());
|
|
363
|
+
try std.testing.expectEqualStrings("the \"webview\" capability", Declaration.capability.text());
|
|
364
|
+
try std.testing.expectEqualStrings("a .shell webview view", Declaration.shell_webview.text());
|
|
365
|
+
try std.testing.expectEqualStrings("the Chromium web engine", Declaration.chromium_engine.text());
|
|
366
|
+
}
|
package/src/runtime/api.zig
CHANGED
|
@@ -396,6 +396,13 @@ pub const Options = struct {
|
|
|
396
396
|
automation: ?automation.Server = null,
|
|
397
397
|
window_state_store: ?window_state.Store = null,
|
|
398
398
|
js_window_api: bool = false,
|
|
399
|
+
/// Whether this build ships the embedded web layer. The app runner
|
|
400
|
+
/// sets it from the build graph's app.zon inference (declare-to-use:
|
|
401
|
+
/// a .frontend block, the "webview" capability, or a .shell webview
|
|
402
|
+
/// view). When false, every webview-creating path fails fast with
|
|
403
|
+
/// `error.WebViewLayerNotBuilt` and its teaching message instead of
|
|
404
|
+
/// reaching a platform host whose web layer was compiled out.
|
|
405
|
+
web_layer: bool = true,
|
|
399
406
|
gpu_surface_frame_diagnostics: bool = true,
|
|
400
407
|
/// Pixels-only presentation hosts (the mobile embed host) opt in to
|
|
401
408
|
/// keeping the view's keyed command mirror alive across PIXEL
|
|
@@ -299,6 +299,7 @@ pub fn builtinBridgeErrorMessage(err: anyerror) []const u8 {
|
|
|
299
299
|
error.CrossWindowWebViewDenied => "WebView windowId must match the calling window",
|
|
300
300
|
error.InvalidWebViewOptions => "WebView options are invalid",
|
|
301
301
|
error.WebViewNotFound => "WebView was not found",
|
|
302
|
+
error.WebViewLayerNotBuilt => "this app was built without the web layer because nothing in app.zon declared web use; add \"webview\" to .capabilities (or a .frontend block / a .shell webview view) and rebuild",
|
|
302
303
|
error.WebViewLimitReached => "WebView limit reached",
|
|
303
304
|
error.DuplicateWebViewLabel => "WebView label already exists",
|
|
304
305
|
error.ReservedWebViewLabel => "WebView label \"main\" is reserved for the startup WebView",
|
|
@@ -367,6 +368,7 @@ pub fn builtinBridgeErrorCode(err: anyerror) bridge.ErrorCode {
|
|
|
367
368
|
error.CrossWindowWebViewDenied,
|
|
368
369
|
error.InvalidWebViewOptions,
|
|
369
370
|
error.WebViewNotFound,
|
|
371
|
+
error.WebViewLayerNotBuilt,
|
|
370
372
|
error.WebViewLimitReached,
|
|
371
373
|
error.DuplicateWebViewLabel,
|
|
372
374
|
error.ReservedWebViewLabel,
|
|
@@ -148,6 +148,12 @@ pub fn RuntimeBuiltinBridge(comptime Runtime: type) type {
|
|
|
148
148
|
}
|
|
149
149
|
|
|
150
150
|
pub fn dispatchWebViewBridgeCommand(self: *Runtime, request: bridge.Request, source_window_id: platform.WindowId, result_buffer: []u8, response_buffer: []u8) []const u8 {
|
|
151
|
+
// A native-only build has no webviews to command (and no page
|
|
152
|
+
// to command them from); every webview verb answers with the
|
|
153
|
+
// teaching error instead of a misleading not-found.
|
|
154
|
+
if (!self.options.web_layer) {
|
|
155
|
+
return bridge.writeErrorResponse(response_buffer, request.id, builtinBridgeErrorCode(error.WebViewLayerNotBuilt), builtinBridgeErrorMessage(error.WebViewLayerNotBuilt));
|
|
156
|
+
}
|
|
151
157
|
const result = if (std.mem.eql(u8, request.command, "native-sdk.webview.create"))
|
|
152
158
|
Self.createWebViewFromJson(self, request.payload, source_window_id, result_buffer) catch |err| return bridge.writeErrorResponse(response_buffer, request.id, builtinBridgeErrorCode(err), builtinBridgeErrorMessage(err))
|
|
153
159
|
else if (std.mem.eql(u8, request.command, "native-sdk.webview.list"))
|
package/src/runtime/flow.zig
CHANGED
|
@@ -551,6 +551,9 @@ pub fn RuntimeFlow(comptime Runtime: type) type {
|
|
|
551
551
|
}
|
|
552
552
|
|
|
553
553
|
fn loadStartupWindows(self: *Runtime, app: App) anyerror!void {
|
|
554
|
+
// Scene-less startup always materializes the app's webview
|
|
555
|
+
// source into the main window; a native-only build cannot.
|
|
556
|
+
if (!self.options.web_layer) return error.WebViewLayerNotBuilt;
|
|
554
557
|
const source = try WindowViewMethods().copyLoadedSource(self, try app.webViewSource());
|
|
555
558
|
self.loaded_source = source;
|
|
556
559
|
const app_info = self.options.platform.app_info;
|
|
@@ -592,6 +595,7 @@ pub fn RuntimeFlow(comptime Runtime: type) type {
|
|
|
592
595
|
try WindowViewMethods().copyLoadedSource(self, try app.webViewSource())
|
|
593
596
|
else
|
|
594
597
|
null;
|
|
598
|
+
if (source != null and !self.options.web_layer) return error.WebViewLayerNotBuilt;
|
|
595
599
|
self.loaded_source = source;
|
|
596
600
|
|
|
597
601
|
try loadStartupSceneWindow(self, scene.windows[0], source);
|
|
@@ -661,12 +665,16 @@ pub fn RuntimeFlow(comptime Runtime: type) type {
|
|
|
661
665
|
}
|
|
662
666
|
|
|
663
667
|
fn loadWebView(self: *Runtime, app: App) anyerror!void {
|
|
668
|
+
if (!self.options.web_layer) return error.WebViewLayerNotBuilt;
|
|
664
669
|
const source = try WindowViewMethods().copyLoadedSource(self, try app.webViewSource());
|
|
665
670
|
self.loaded_source = source;
|
|
666
671
|
try self.options.platform.services.loadWindowWebView(1, source);
|
|
667
672
|
}
|
|
668
673
|
|
|
669
674
|
pub fn reloadWindows(self: *Runtime, app: App) anyerror!void {
|
|
675
|
+
// Reload re-materializes webview sources; native-only builds
|
|
676
|
+
// have none to reload.
|
|
677
|
+
if (!self.options.web_layer) return error.WebViewLayerNotBuilt;
|
|
670
678
|
const source = try WindowViewMethods().copyLoadedSource(self, try app.webViewSource());
|
|
671
679
|
self.loaded_source = source;
|
|
672
680
|
if (self.window_count == 0) {
|
|
@@ -168,8 +168,10 @@ const RecordedSession = struct {
|
|
|
168
168
|
/// a fetch and a spawn with results fed through the fake executor, an
|
|
169
169
|
/// fx-timer fire via its platform timer event, and per-frame
|
|
170
170
|
/// checkpoints. Returns the final model and fingerprint for the replay
|
|
171
|
-
/// side to match.
|
|
172
|
-
|
|
171
|
+
/// side to match. `web_layer` mirrors the build's inference: the
|
|
172
|
+
/// reference session is a pure canvas app, so it must record (and
|
|
173
|
+
/// replay, below) identically in a native-only build.
|
|
174
|
+
fn recordReferenceSession(gpa: std.mem.Allocator, buffer: *JournalBuffer, web_layer: bool) !RecordedSession {
|
|
173
175
|
const recorder = try std.heap.page_allocator.create(session_record.SessionRecorder);
|
|
174
176
|
defer std.heap.page_allocator.destroy(recorder);
|
|
175
177
|
recorder.* = session_record.SessionRecorder.init(buffer.sink());
|
|
@@ -178,6 +180,7 @@ fn recordReferenceSession(gpa: std.mem.Allocator, buffer: *JournalBuffer) !Recor
|
|
|
178
180
|
const harness = try core.TestHarness().create(gpa, .{ .size = geometry.SizeF.init(400, 300) });
|
|
179
181
|
defer harness.destroy(gpa);
|
|
180
182
|
harness.null_platform.gpu_surfaces = true;
|
|
183
|
+
harness.runtime.options.web_layer = web_layer;
|
|
181
184
|
harness.runtime.options.session_recorder = recorder;
|
|
182
185
|
|
|
183
186
|
const app_state = try gpa.create(SessionApp);
|
|
@@ -248,7 +251,7 @@ fn recordReferenceSession(gpa: std.mem.Allocator, buffer: *JournalBuffer) !Recor
|
|
|
248
251
|
};
|
|
249
252
|
}
|
|
250
253
|
|
|
251
|
-
fn replayIntoFreshApp(gpa: std.mem.Allocator, journal_bytes: []const u8) !struct {
|
|
254
|
+
fn replayIntoFreshApp(gpa: std.mem.Allocator, journal_bytes: []const u8, web_layer: bool) !struct {
|
|
252
255
|
report: session_replay.ReplayReport,
|
|
253
256
|
model: SessionModel,
|
|
254
257
|
fingerprint: u64,
|
|
@@ -256,6 +259,7 @@ fn replayIntoFreshApp(gpa: std.mem.Allocator, journal_bytes: []const u8) !struct
|
|
|
256
259
|
const harness = try core.TestHarness().create(gpa, .{ .size = geometry.SizeF.init(400, 300) });
|
|
257
260
|
defer harness.destroy(gpa);
|
|
258
261
|
harness.null_platform.gpu_surfaces = true;
|
|
262
|
+
harness.runtime.options.web_layer = web_layer;
|
|
259
263
|
|
|
260
264
|
const app_state = try gpa.create(SessionApp);
|
|
261
265
|
defer gpa.destroy(app_state);
|
|
@@ -278,7 +282,7 @@ test "a recorded session replays to identical model state and fingerprints" {
|
|
|
278
282
|
const buffer = try std.heap.page_allocator.create(JournalBuffer);
|
|
279
283
|
defer std.heap.page_allocator.destroy(buffer);
|
|
280
284
|
buffer.len = 0;
|
|
281
|
-
const recorded = try recordReferenceSession(gpa, buffer);
|
|
285
|
+
const recorded = try recordReferenceSession(gpa, buffer, true);
|
|
282
286
|
|
|
283
287
|
// The recording captured real state.
|
|
284
288
|
try std.testing.expectEqual(@as(u32, 2), recorded.model.count);
|
|
@@ -291,7 +295,7 @@ test "a recorded session replays to identical model state and fingerprints" {
|
|
|
291
295
|
try std.testing.expectEqual(@as(u32, 1), recorded.model.spectrum_count);
|
|
292
296
|
try std.testing.expect(recorded.model.band_checksum != 0);
|
|
293
297
|
|
|
294
|
-
const replayed = try replayIntoFreshApp(gpa, buffer.journalBytes());
|
|
298
|
+
const replayed = try replayIntoFreshApp(gpa, buffer.journalBytes(), true);
|
|
295
299
|
try std.testing.expect(replayed.report.ok());
|
|
296
300
|
try std.testing.expect(replayed.report.events_replayed > 0);
|
|
297
301
|
try std.testing.expectEqual(@as(u64, 5), replayed.report.effects_fed);
|
|
@@ -300,12 +304,35 @@ test "a recorded session replays to identical model state and fingerprints" {
|
|
|
300
304
|
try std.testing.expectEqual(recorded.fingerprint, replayed.fingerprint);
|
|
301
305
|
}
|
|
302
306
|
|
|
307
|
+
test "a native-only session records and replays like a web-layer one" {
|
|
308
|
+
// The whole reference session is canvas-only, so a native-only
|
|
309
|
+
// runtime (web_layer = false, the app-runner inference for an
|
|
310
|
+
// app.zon with no web declaration) must journal and replay it
|
|
311
|
+
// byte-for-byte equivalently: same final model, same fingerprint,
|
|
312
|
+
// same checkpoint verification. Record/replay is part of the
|
|
313
|
+
// native-only contract, not a web-layer feature.
|
|
314
|
+
const gpa = std.testing.allocator;
|
|
315
|
+
const buffer = try std.heap.page_allocator.create(JournalBuffer);
|
|
316
|
+
defer std.heap.page_allocator.destroy(buffer);
|
|
317
|
+
buffer.len = 0;
|
|
318
|
+
const recorded = try recordReferenceSession(gpa, buffer, false);
|
|
319
|
+
try std.testing.expectEqual(@as(u32, 2), recorded.model.count);
|
|
320
|
+
try std.testing.expectEqualStrings("hello-from-the-network", recorded.model.bodyText());
|
|
321
|
+
|
|
322
|
+
const replayed = try replayIntoFreshApp(gpa, buffer.journalBytes(), false);
|
|
323
|
+
try std.testing.expect(replayed.report.ok());
|
|
324
|
+
try std.testing.expect(replayed.report.events_replayed > 0);
|
|
325
|
+
try std.testing.expect(replayed.report.checkpoints_verified > 0);
|
|
326
|
+
try std.testing.expectEqualDeep(recorded.model, replayed.model);
|
|
327
|
+
try std.testing.expectEqual(recorded.fingerprint, replayed.fingerprint);
|
|
328
|
+
}
|
|
329
|
+
|
|
303
330
|
test "a truncated journal is refused loudly" {
|
|
304
331
|
const gpa = std.testing.allocator;
|
|
305
332
|
const buffer = try std.heap.page_allocator.create(JournalBuffer);
|
|
306
333
|
defer std.heap.page_allocator.destroy(buffer);
|
|
307
334
|
buffer.len = 0;
|
|
308
|
-
_ = try recordReferenceSession(gpa, buffer);
|
|
335
|
+
_ = try recordReferenceSession(gpa, buffer, true);
|
|
309
336
|
const whole = buffer.journalBytes();
|
|
310
337
|
|
|
311
338
|
const harness = try core.TestHarness().create(gpa, .{ .size = geometry.SizeF.init(400, 300) });
|
|
@@ -328,7 +355,7 @@ test "a tampered effect payload fails verification loudly" {
|
|
|
328
355
|
const buffer = try std.heap.page_allocator.create(JournalBuffer);
|
|
329
356
|
defer std.heap.page_allocator.destroy(buffer);
|
|
330
357
|
buffer.len = 0;
|
|
331
|
-
_ = try recordReferenceSession(gpa, buffer);
|
|
358
|
+
_ = try recordReferenceSession(gpa, buffer, true);
|
|
332
359
|
|
|
333
360
|
// Flip one byte inside the journaled fetch body: framing stays
|
|
334
361
|
// valid, so the tamper is only detectable semantically — the
|
|
@@ -337,7 +364,7 @@ test "a tampered effect payload fails verification loudly" {
|
|
|
337
364
|
const at = std.mem.indexOf(u8, bytes, "hello-from-the-network") orelse unreachable;
|
|
338
365
|
bytes[at] ^= 0x20;
|
|
339
366
|
|
|
340
|
-
const replayed = try replayIntoFreshApp(gpa, buffer.journalBytes());
|
|
367
|
+
const replayed = try replayIntoFreshApp(gpa, buffer.journalBytes(), true);
|
|
341
368
|
try std.testing.expect(!replayed.report.ok());
|
|
342
369
|
try std.testing.expect(replayed.report.mismatch_count >= 1);
|
|
343
370
|
try std.testing.expectEqual(session_replay.ReplayMismatchKind.fingerprint, replayed.report.mismatches[0].kind);
|