@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
package/src/tooling/package.zig
CHANGED
|
@@ -66,6 +66,13 @@ pub const PackageOptions = struct {
|
|
|
66
66
|
assets_dir: []const u8 = "assets",
|
|
67
67
|
frontend: ?manifest_tool.FrontendMetadata = null,
|
|
68
68
|
web_engine: WebEngine = .system,
|
|
69
|
+
/// The `--web-layer` flag, when the caller passed one: beats app.zon's
|
|
70
|
+
/// `.webview_layer` the same way `-Dweb-layer` beats it in the build
|
|
71
|
+
/// graph. The standard build graphs always pass their RESOLVED layer
|
|
72
|
+
/// decision here (include|exclude), so a graph-driven package never
|
|
73
|
+
/// re-infers what the graph already compiled into the exe. Null means
|
|
74
|
+
/// the manifest field decides.
|
|
75
|
+
web_layer_setting: ?manifest_tool.WebViewLayerSetting = null,
|
|
69
76
|
cef_dir: []const u8 = web_engine_tool.default_cef_dir,
|
|
70
77
|
signing: SigningConfig = .{},
|
|
71
78
|
archive: bool = false,
|
|
@@ -84,9 +91,31 @@ pub const PackageStats = struct {
|
|
|
84
91
|
signing_mode: SigningMode = .none,
|
|
85
92
|
asset_count: usize = 0,
|
|
86
93
|
web_engine: WebEngine = .system,
|
|
94
|
+
web_layer: ?manifest_tool.WebLayer = null,
|
|
87
95
|
archive_path: ?[]const u8 = null,
|
|
88
96
|
};
|
|
89
97
|
|
|
98
|
+
/// The web-layer verdict for a package, from the same declare-to-use
|
|
99
|
+
/// inference the build graph runs — fed the RESOLVED engine
|
|
100
|
+
/// (`--web-engine` orelse app.zon, resolved by the CLI before packaging)
|
|
101
|
+
/// so a Chromium flag on a system manifest still ships the layer, and
|
|
102
|
+
/// the RESOLVED layer setting (`--web-layer` orelse app.zon) so a
|
|
103
|
+
/// flag-overridden exe is packaged under the decision it was built with.
|
|
104
|
+
/// Metadata that cannot be inferred (invalid or contradictory
|
|
105
|
+
/// `.webview_layer`) keeps the layer here — `createPackage` refuses
|
|
106
|
+
/// those loudly up front, and the direct artifact helpers must not
|
|
107
|
+
/// silently strip a layer on bad input.
|
|
108
|
+
fn webLayerFor(options: PackageOptions) manifest_tool.WebLayer {
|
|
109
|
+
return manifest_tool.webLayerResolved(options.metadata, options.web_engine, options.web_layer_setting) catch .{ .enabled = true, .reason = .declared_include };
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/// The verdict line's engine half: what web layer this artifact ships.
|
|
113
|
+
fn webLayerEngineName(layer: manifest_tool.WebLayer, target: PackageTarget, web_engine: WebEngine) []const u8 {
|
|
114
|
+
if (!layer.enabled) return "none";
|
|
115
|
+
if (web_engine == .chromium) return "chromium";
|
|
116
|
+
return if (target == .windows) "webview2" else "system";
|
|
117
|
+
}
|
|
118
|
+
|
|
90
119
|
pub fn artifactName(buffer: []u8, metadata: manifest_tool.Metadata, target: PackageTarget, optimize: []const u8) ![]const u8 {
|
|
91
120
|
return std.fmt.bufPrint(buffer, "{s}-{s}-{s}-{s}{s}", .{
|
|
92
121
|
metadata.name,
|
|
@@ -98,6 +127,16 @@ pub fn artifactName(buffer: []u8, metadata: manifest_tool.Metadata, target: Pack
|
|
|
98
127
|
}
|
|
99
128
|
|
|
100
129
|
pub fn createPackage(allocator: std.mem.Allocator, io: std.Io, options: PackageOptions) !PackageStats {
|
|
130
|
+
// The package boundary of the reject-conflicts contract: an exclude
|
|
131
|
+
// (from `--web-layer` or app.zon) against declared web content — or
|
|
132
|
+
// against a resolved Chromium engine — never becomes an artifact.
|
|
133
|
+
_ = manifest_tool.webLayerResolved(options.metadata, options.web_engine, options.web_layer_setting) catch |err| {
|
|
134
|
+
switch (err) {
|
|
135
|
+
error.WebViewLayerConflict => std.debug.print("error: {s}\n", .{if (options.web_layer_setting == .exclude) manifest_tool.web_layer_flag_conflict_message else manifest_tool.web_layer_conflict_message}),
|
|
136
|
+
error.InvalidWebViewLayer => std.debug.print("error: app.zon webview_layer is invalid - expected \"auto\", \"include\", or \"exclude\"\n", .{}),
|
|
137
|
+
}
|
|
138
|
+
return err;
|
|
139
|
+
};
|
|
101
140
|
try validateWebEngineTarget(options.target, options.web_engine);
|
|
102
141
|
var stats = switch (options.target) {
|
|
103
142
|
.macos => try createMacosApp(allocator, io, options),
|
|
@@ -132,6 +171,9 @@ pub fn printDiagnostic(stats: PackageStats) void {
|
|
|
132
171
|
.message = std.fmt.bufPrint(&message_buffer, "created {s} artifact at {s}", .{ @tagName(stats.target), stats.path }) catch "created package",
|
|
133
172
|
}, &writer) catch return;
|
|
134
173
|
std.debug.print("{s}\n", .{writer.buffered()});
|
|
174
|
+
if (stats.web_layer) |layer| {
|
|
175
|
+
std.debug.print(" web layer: {s} ({s})\n", .{ webLayerEngineName(layer, stats.target, stats.web_engine), layer.sourceText() });
|
|
176
|
+
}
|
|
135
177
|
if (stats.archive_path) |archive| {
|
|
136
178
|
std.debug.print(" archive: {s}\n", .{archive});
|
|
137
179
|
}
|
|
@@ -192,6 +234,7 @@ pub fn createMacosApp(allocator: std.mem.Allocator, io: std.Io, options: Package
|
|
|
192
234
|
.signing_mode = options.signing.mode,
|
|
193
235
|
.asset_count = bundle_stats.asset_count,
|
|
194
236
|
.web_engine = options.web_engine,
|
|
237
|
+
.web_layer = webLayerFor(options),
|
|
195
238
|
};
|
|
196
239
|
}
|
|
197
240
|
|
|
@@ -209,14 +252,48 @@ fn createDesktopArtifact(allocator: std.mem.Allocator, io: std.Io, options: Pack
|
|
|
209
252
|
try allocator.dupe(u8, options.metadata.name);
|
|
210
253
|
defer allocator.free(executable_name);
|
|
211
254
|
|
|
255
|
+
// Native-only apps ship no WebView2 loader: their host was compiled
|
|
256
|
+
// without the embedded web layer, so the loader would be dead bytes
|
|
257
|
+
// pretending the app can spawn a webview.
|
|
258
|
+
const wants_webview2_loader = options.target == .windows and options.web_engine == .system and webLayerFor(options).enabled;
|
|
259
|
+
// The package-time half of the web-layer audit (the build-time half
|
|
260
|
+
// is tools/audit_web_layer.zig): a Windows exe that references
|
|
261
|
+
// WebView2Loader.dll was compiled WITH the embedded web layer, so
|
|
262
|
+
// packaging it loaderless ships an app whose every webview call
|
|
263
|
+
// fails at runtime. Refuse the mismatch and teach the fix — this
|
|
264
|
+
// catches exes built under an override the packaging decision never
|
|
265
|
+
// saw (a stale zig-out binary, a hand-supplied --binary).
|
|
266
|
+
if (options.target == .windows and !wants_webview2_loader) {
|
|
267
|
+
if (options.binary_path) |binary_path| {
|
|
268
|
+
if (try peReferencesWebView2Loader(allocator, io, binary_path)) {
|
|
269
|
+
std.debug.print("error: {s} references WebView2Loader.dll but this package ships no web layer, so its webviews would fail to spawn - the exe was built with the embedded web layer (for example `zig build -Dweb-layer=include`)\n" ++
|
|
270
|
+
" package with `--web-layer include`, or rebuild the binary to match the packaging decision\n", .{binary_path});
|
|
271
|
+
return error.WebViewLayerMismatch;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
// The Linux twin of that guard (the build-time half is the ELF scan
|
|
276
|
+
// in tools/audit_web_layer.zig): an executable that links WebKitGTK
|
|
277
|
+
// was compiled WITH the embedded web layer, so packaging it under a
|
|
278
|
+
// native-only decision ships an app that still demands libwebkitgtk
|
|
279
|
+
// on every user machine while its webviews would fail to spawn.
|
|
280
|
+
if (options.target == .linux and options.web_engine == .system and !webLayerFor(options).enabled) {
|
|
281
|
+
if (options.binary_path) |binary_path| {
|
|
282
|
+
if (try elfReferencesWebKitGtk(allocator, io, binary_path)) {
|
|
283
|
+
std.debug.print("error: {s} references WebKitGTK but this package ships no web layer, so its webviews would fail to spawn - the binary was built with the embedded web layer (for example `zig build -Dweb-layer=include`)\n" ++
|
|
284
|
+
" package with `--web-layer include`, or rebuild the binary to match the packaging decision\n", .{binary_path});
|
|
285
|
+
return error.WebViewLayerMismatch;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}
|
|
212
289
|
if (options.binary_path) |binary_path| {
|
|
213
290
|
const binary_subpath = try std.fmt.allocPrint(allocator, "bin/{s}", .{executable_name});
|
|
214
291
|
defer allocator.free(binary_subpath);
|
|
215
292
|
try copyFileToDir(allocator, io, dir, binary_path, binary_subpath);
|
|
216
|
-
if (
|
|
293
|
+
if (wants_webview2_loader) {
|
|
217
294
|
try copyWindowsWebView2Loader(allocator, io, dir, options, binary_path);
|
|
218
295
|
}
|
|
219
|
-
} else if (
|
|
296
|
+
} else if (wants_webview2_loader) {
|
|
220
297
|
try writeFile(dir, io, "bin/README.txt", "Build the app binary separately and place it here for this target, together with the WebView2Loader.dll for its architecture (vendored in the SDK under third_party/webview2/).\n");
|
|
221
298
|
} else {
|
|
222
299
|
try writeFile(dir, io, "bin/README.txt", "Build the app binary separately and place it here for this target.\n");
|
|
@@ -258,7 +335,7 @@ fn createDesktopArtifact(allocator: std.mem.Allocator, io: std.Io, options: Pack
|
|
|
258
335
|
try copyDesktopCefRuntime(allocator, io, dir, options.target, options.cef_dir);
|
|
259
336
|
}
|
|
260
337
|
try writeReport(allocator, dir, io, "package-manifest.zon", options, executable_name, bundle_stats.asset_count);
|
|
261
|
-
return .{ .path = options.output_path, .artifact_name = std.fs.path.basename(options.output_path), .target = options.target, .asset_count = bundle_stats.asset_count, .web_engine = options.web_engine };
|
|
338
|
+
return .{ .path = options.output_path, .artifact_name = std.fs.path.basename(options.output_path), .target = options.target, .asset_count = bundle_stats.asset_count, .web_engine = options.web_engine, .web_layer = webLayerFor(options) };
|
|
262
339
|
}
|
|
263
340
|
|
|
264
341
|
/// The iOS host tier: a COMPLETE Xcode project the user never edits —
|
|
@@ -330,7 +407,7 @@ fn createIosArtifact(allocator: std.mem.Allocator, io: std.Io, options: PackageO
|
|
|
330
407
|
defer allocator.free(readme);
|
|
331
408
|
try writeFile(dir, io, "README.md", readme);
|
|
332
409
|
try writeReport(allocator, dir, io, "package-manifest.zon", options, "libnative-sdk.a", bundle_stats.asset_count);
|
|
333
|
-
return .{ .path = options.output_path, .artifact_name = std.fs.path.basename(options.output_path), .target = .ios, .asset_count = bundle_stats.asset_count, .web_engine = options.web_engine };
|
|
410
|
+
return .{ .path = options.output_path, .artifact_name = std.fs.path.basename(options.output_path), .target = .ios, .asset_count = bundle_stats.asset_count, .web_engine = options.web_engine, .web_layer = webLayerFor(options) };
|
|
334
411
|
}
|
|
335
412
|
|
|
336
413
|
fn iosProjectReadme(allocator: std.mem.Allocator, metadata: manifest_tool.Metadata) ![]const u8 {
|
|
@@ -397,7 +474,7 @@ fn createAndroidArtifact(allocator: std.mem.Allocator, io: std.Io, options: Pack
|
|
|
397
474
|
if (try assembleAndroidApk(allocator, io, options)) |apk_name| {
|
|
398
475
|
artifact_name = apk_name;
|
|
399
476
|
}
|
|
400
|
-
return .{ .path = options.output_path, .artifact_name = artifact_name, .target = .android, .asset_count = bundle_stats.asset_count, .web_engine = options.web_engine };
|
|
477
|
+
return .{ .path = options.output_path, .artifact_name = artifact_name, .target = .android, .asset_count = bundle_stats.asset_count, .web_engine = options.web_engine, .web_layer = webLayerFor(options) };
|
|
401
478
|
}
|
|
402
479
|
|
|
403
480
|
/// Assemble the debug APK inside the generated project when the caller
|
|
@@ -961,6 +1038,104 @@ fn copyWindowsWebView2Loader(allocator: std.mem.Allocator, io: std.Io, dir: std.
|
|
|
961
1038
|
try copyFileToDir(allocator, io, dir, loader_path, "bin/WebView2Loader.dll");
|
|
962
1039
|
}
|
|
963
1040
|
|
|
1041
|
+
/// Whether a Windows executable carries the embedded web layer: the host
|
|
1042
|
+
/// loads WebView2Loader.dll through LoadLibraryW, so the honest evidence
|
|
1043
|
+
/// is the loader's name in the binary — stored as UTF-16 in a web build
|
|
1044
|
+
/// and compiled out entirely (with the whole layer) in a native-only
|
|
1045
|
+
/// build. The same probe as the build-time auditor
|
|
1046
|
+
/// (tools/audit_web_layer.zig); a non-PE file proves nothing about the
|
|
1047
|
+
/// layer, so it scans as false rather than refusing the package.
|
|
1048
|
+
fn peReferencesWebView2Loader(allocator: std.mem.Allocator, io: std.Io, path: []const u8) !bool {
|
|
1049
|
+
const bytes = try readPath(allocator, io, path);
|
|
1050
|
+
defer allocator.free(bytes);
|
|
1051
|
+
if (bytes.len < 0x40 or bytes[0] != 'M' or bytes[1] != 'Z') return false;
|
|
1052
|
+
const pe_offset: usize = std.mem.readInt(u32, bytes[0x3c..0x40], .little);
|
|
1053
|
+
if (pe_offset + 4 > bytes.len) return false;
|
|
1054
|
+
if (!std.mem.eql(u8, bytes[pe_offset..][0..4], "PE\x00\x00")) return false;
|
|
1055
|
+
const needle_ascii = "WebView2Loader.dll";
|
|
1056
|
+
var needle_wide: [needle_ascii.len * 2]u8 = undefined;
|
|
1057
|
+
for (needle_ascii, 0..) |ch, index| {
|
|
1058
|
+
needle_wide[index * 2] = ch;
|
|
1059
|
+
needle_wide[index * 2 + 1] = 0;
|
|
1060
|
+
}
|
|
1061
|
+
return std.mem.indexOf(u8, bytes, &needle_wide) != null or
|
|
1062
|
+
std.mem.indexOf(u8, bytes, needle_ascii) != null;
|
|
1063
|
+
}
|
|
1064
|
+
|
|
1065
|
+
/// Whether a Linux executable carries the embedded web layer: the GTK
|
|
1066
|
+
/// host links webkitgtk-6.0 directly, so the honest evidence is a
|
|
1067
|
+
/// libwebkitgtk/libjavascriptcoregtk DT_NEEDED entry or a webkit_*/jsc_*
|
|
1068
|
+
/// dynamic-symbol name — all removed by the WebKitGTK compile seam in a
|
|
1069
|
+
/// native-only build. The same probe as the build-time auditor
|
|
1070
|
+
/// (tools/audit_web_layer.zig), hand-rolled over the section headers;
|
|
1071
|
+
/// a non-ELF file (or one this minimal parse cannot walk) proves
|
|
1072
|
+
/// nothing about the layer, so it scans as false rather than refusing
|
|
1073
|
+
/// the package.
|
|
1074
|
+
fn elfReferencesWebKitGtk(allocator: std.mem.Allocator, io: std.Io, path: []const u8) !bool {
|
|
1075
|
+
const bytes = try readPath(allocator, io, path);
|
|
1076
|
+
defer allocator.free(bytes);
|
|
1077
|
+
return elfBytesReferenceWebKitGtk(bytes);
|
|
1078
|
+
}
|
|
1079
|
+
|
|
1080
|
+
fn elfBytesReferenceWebKitGtk(bytes: []const u8) bool {
|
|
1081
|
+
// ELF64 little endian only — every Linux target this toolkit builds.
|
|
1082
|
+
if (bytes.len < 0x40 or !std.mem.eql(u8, bytes[0..4], "\x7fELF")) return false;
|
|
1083
|
+
if (bytes[4] != 2 or bytes[5] != 1) return false;
|
|
1084
|
+
const sh_offset: u64 = std.mem.readInt(u64, bytes[0x28..0x30], .little);
|
|
1085
|
+
const sh_entsize: u16 = std.mem.readInt(u16, bytes[0x3a..0x3c], .little);
|
|
1086
|
+
const sh_count: u16 = std.mem.readInt(u16, bytes[0x3c..0x3e], .little);
|
|
1087
|
+
if (sh_offset == 0 or sh_count == 0 or sh_entsize < 0x40) return false;
|
|
1088
|
+
|
|
1089
|
+
var index: u16 = 0;
|
|
1090
|
+
while (index < sh_count) : (index += 1) {
|
|
1091
|
+
const header = elfSectionSlice(bytes, sh_offset + @as(u64, index) * sh_entsize, 0x40) orelse return false;
|
|
1092
|
+
const sh_type = std.mem.readInt(u32, header[0x04..0x08], .little);
|
|
1093
|
+
const link = std.mem.readInt(u32, header[0x28..0x2c], .little);
|
|
1094
|
+
const offset = std.mem.readInt(u64, header[0x18..0x20], .little);
|
|
1095
|
+
const size = std.mem.readInt(u64, header[0x20..0x28], .little);
|
|
1096
|
+
const entsize = std.mem.readInt(u64, header[0x38..0x40], .little);
|
|
1097
|
+
// SHT_DYNAMIC = 6, SHT_DYNSYM = 11.
|
|
1098
|
+
if (sh_type != 6 and sh_type != 11) continue;
|
|
1099
|
+
if (link >= sh_count) continue;
|
|
1100
|
+
const link_header = elfSectionSlice(bytes, sh_offset + @as(u64, link) * sh_entsize, 0x40) orelse return false;
|
|
1101
|
+
const strtab = elfSectionSlice(bytes, std.mem.readInt(u64, link_header[0x18..0x20], .little), std.mem.readInt(u64, link_header[0x20..0x28], .little)) orelse return false;
|
|
1102
|
+
const table = elfSectionSlice(bytes, offset, size) orelse return false;
|
|
1103
|
+
if (sh_type == 6) {
|
|
1104
|
+
var cursor: usize = 0;
|
|
1105
|
+
while (cursor + 16 <= table.len) : (cursor += 16) {
|
|
1106
|
+
const tag: i64 = @bitCast(std.mem.readInt(u64, table[cursor..][0..8], .little));
|
|
1107
|
+
if (tag != 1) continue; // DT_NEEDED
|
|
1108
|
+
const name = elfStringAt(strtab, std.mem.readInt(u64, table[cursor + 8 ..][0..8], .little)) orelse continue;
|
|
1109
|
+
if (std.mem.indexOf(u8, name, "webkitgtk") != null or std.mem.indexOf(u8, name, "javascriptcoregtk") != null) return true;
|
|
1110
|
+
}
|
|
1111
|
+
} else {
|
|
1112
|
+
const stride: usize = if (entsize >= 24) @intCast(entsize) else 24;
|
|
1113
|
+
var cursor: usize = 0;
|
|
1114
|
+
while (cursor + 24 <= table.len) : (cursor += stride) {
|
|
1115
|
+
const name_offset: u32 = std.mem.readInt(u32, table[cursor..][0..4], .little);
|
|
1116
|
+
if (name_offset == 0) continue;
|
|
1117
|
+
const name = elfStringAt(strtab, name_offset) orelse continue;
|
|
1118
|
+
if (std.mem.startsWith(u8, name, "webkit_") or std.mem.startsWith(u8, name, "jsc_")) return true;
|
|
1119
|
+
}
|
|
1120
|
+
}
|
|
1121
|
+
}
|
|
1122
|
+
return false;
|
|
1123
|
+
}
|
|
1124
|
+
|
|
1125
|
+
fn elfSectionSlice(bytes: []const u8, offset: u64, size: u64) ?[]const u8 {
|
|
1126
|
+
if (offset > bytes.len) return null;
|
|
1127
|
+
const start: usize = @intCast(offset);
|
|
1128
|
+
if (size > bytes.len - start) return null;
|
|
1129
|
+
return bytes[start .. start + @as(usize, @intCast(size))];
|
|
1130
|
+
}
|
|
1131
|
+
|
|
1132
|
+
fn elfStringAt(strtab: []const u8, offset: u64) ?[]const u8 {
|
|
1133
|
+
if (offset >= strtab.len) return null;
|
|
1134
|
+
const start: usize = @intCast(offset);
|
|
1135
|
+
const end = std.mem.indexOfScalarPos(u8, strtab, start, 0) orelse return null;
|
|
1136
|
+
return strtab[start..end];
|
|
1137
|
+
}
|
|
1138
|
+
|
|
964
1139
|
/// Whether a PE executable targets arm64, read from the COFF machine
|
|
965
1140
|
/// field. Anything unrecognized falls back to x64, the default Windows
|
|
966
1141
|
/// build target.
|
|
@@ -1021,6 +1196,15 @@ fn writeReport(allocator: std.mem.Allocator, dir: std.Io.Dir, io: std.Io, subpat
|
|
|
1021
1196
|
defer allocator.free(optimize);
|
|
1022
1197
|
const web_engine = try zonStringAlloc(allocator, @tagName(options.web_engine));
|
|
1023
1198
|
defer allocator.free(web_engine);
|
|
1199
|
+
// The web-layer verdict the artifact was staged under, in the same
|
|
1200
|
+
// "engine (source)" shape the package diagnostic prints — e.g.
|
|
1201
|
+
// "none (inferred: nothing in app.zon declares web use)" or
|
|
1202
|
+
// "webview2 (declared: capabilities)".
|
|
1203
|
+
const layer = webLayerFor(options);
|
|
1204
|
+
const web_layer_value = try std.fmt.allocPrint(allocator, "{s} ({s})", .{ webLayerEngineName(layer, options.target, options.web_engine), layer.sourceText() });
|
|
1205
|
+
defer allocator.free(web_layer_value);
|
|
1206
|
+
const web_layer = try zonStringAlloc(allocator, web_layer_value);
|
|
1207
|
+
defer allocator.free(web_layer);
|
|
1024
1208
|
const signing = try zonStringAlloc(allocator, @tagName(options.signing.mode));
|
|
1025
1209
|
defer allocator.free(signing);
|
|
1026
1210
|
const report = try std.fmt.allocPrint(allocator,
|
|
@@ -1032,6 +1216,7 @@ fn writeReport(allocator: std.mem.Allocator, dir: std.Io.Dir, io: std.Io, subpat
|
|
|
1032
1216
|
\\ .executable = {s},
|
|
1033
1217
|
\\ .optimize = {s},
|
|
1034
1218
|
\\ .web_engine = {s},
|
|
1219
|
+
\\ .web_layer = {s},
|
|
1035
1220
|
\\ .signing = {s},
|
|
1036
1221
|
\\ .asset_count = {d},
|
|
1037
1222
|
\\{s}
|
|
@@ -1048,6 +1233,7 @@ fn writeReport(allocator: std.mem.Allocator, dir: std.Io.Dir, io: std.Io, subpat
|
|
|
1048
1233
|
executable,
|
|
1049
1234
|
optimize,
|
|
1050
1235
|
web_engine,
|
|
1236
|
+
web_layer,
|
|
1051
1237
|
signing,
|
|
1052
1238
|
asset_count,
|
|
1053
1239
|
frontend,
|
|
@@ -1715,7 +1901,6 @@ test "mobile package templates ship the toolkit hosts" {
|
|
|
1715
1901
|
try std.testing.expect(std.mem.indexOf(u8, android_bridge, "WINDOW_FORMAT_RGBA_8888") != null);
|
|
1716
1902
|
}
|
|
1717
1903
|
|
|
1718
|
-
|
|
1719
1904
|
test "mobile package artifacts use manifest identity metadata" {
|
|
1720
1905
|
var cwd = std.Io.Dir.cwd();
|
|
1721
1906
|
try cwd.deleteTree(std.testing.io, ".zig-cache/test-package-mobile-identity");
|
|
@@ -2152,6 +2337,413 @@ test "package report records target signing and assets" {
|
|
|
2152
2337
|
try std.testing.expect(std.mem.indexOf(u8, buffer[0..len], ".asset_count = 2") != null);
|
|
2153
2338
|
}
|
|
2154
2339
|
|
|
2340
|
+
test "native-only windows package ships no WebView2 loader and reports web layer none" {
|
|
2341
|
+
var cwd = std.Io.Dir.cwd();
|
|
2342
|
+
const root = ".zig-cache/test-package-native-only-windows";
|
|
2343
|
+
try cwd.deleteTree(std.testing.io, root);
|
|
2344
|
+
defer cwd.deleteTree(std.testing.io, root) catch {};
|
|
2345
|
+
try cwd.createDirPath(std.testing.io, root ++ "/assets");
|
|
2346
|
+
try cwd.writeFile(std.testing.io, .{ .sub_path = root ++ "/app-binary", .data = "not a real exe" });
|
|
2347
|
+
|
|
2348
|
+
// A canvas app shape: gpu capabilities, no frontend, no webview.
|
|
2349
|
+
const capabilities = [_][]const u8{ "native_views", "gpu_surfaces" };
|
|
2350
|
+
const metadata: manifest_tool.Metadata = .{
|
|
2351
|
+
.id = "dev.example.canvas",
|
|
2352
|
+
.name = "canvas-demo",
|
|
2353
|
+
.version = "1.0.0",
|
|
2354
|
+
.capabilities = &capabilities,
|
|
2355
|
+
};
|
|
2356
|
+
|
|
2357
|
+
const stats = try createPackage(std.testing.allocator, std.testing.io, .{
|
|
2358
|
+
.metadata = metadata,
|
|
2359
|
+
.target = .windows,
|
|
2360
|
+
.output_path = root ++ "/demo-windows",
|
|
2361
|
+
.binary_path = root ++ "/app-binary",
|
|
2362
|
+
.assets_dir = root ++ "/assets",
|
|
2363
|
+
});
|
|
2364
|
+
try std.testing.expect(!stats.web_layer.?.enabled);
|
|
2365
|
+
|
|
2366
|
+
// No loader staged next to the binary.
|
|
2367
|
+
var dir = try cwd.openDir(std.testing.io, root ++ "/demo-windows", .{});
|
|
2368
|
+
defer dir.close(std.testing.io);
|
|
2369
|
+
try std.testing.expectError(error.FileNotFound, dir.openFile(std.testing.io, "bin/WebView2Loader.dll", .{}));
|
|
2370
|
+
|
|
2371
|
+
// No frontend dist directory (native-only packages bundle plain assets).
|
|
2372
|
+
try std.testing.expectError(error.FileNotFound, dir.openDir(std.testing.io, "resources/dist", .{}));
|
|
2373
|
+
|
|
2374
|
+
// The report carries the verdict.
|
|
2375
|
+
const report = try readPath(std.testing.allocator, std.testing.io, root ++ "/demo-windows/package-manifest.zon");
|
|
2376
|
+
defer std.testing.allocator.free(report);
|
|
2377
|
+
try std.testing.expect(std.mem.indexOf(u8, report, ".web_layer = \"none (inferred: nothing in app.zon declares web use)\"") != null);
|
|
2378
|
+
}
|
|
2379
|
+
|
|
2380
|
+
test "webview-declaring package reports the web layer as declared" {
|
|
2381
|
+
var cwd = std.Io.Dir.cwd();
|
|
2382
|
+
const root = ".zig-cache/test-package-web-layer-declared";
|
|
2383
|
+
try cwd.deleteTree(std.testing.io, root);
|
|
2384
|
+
defer cwd.deleteTree(std.testing.io, root) catch {};
|
|
2385
|
+
try cwd.createDirPath(std.testing.io, root ++ "/assets");
|
|
2386
|
+
|
|
2387
|
+
const capabilities = [_][]const u8{ "webview", "js_bridge" };
|
|
2388
|
+
const metadata: manifest_tool.Metadata = .{
|
|
2389
|
+
.id = "dev.example.web",
|
|
2390
|
+
.name = "web-demo",
|
|
2391
|
+
.version = "1.0.0",
|
|
2392
|
+
.capabilities = &capabilities,
|
|
2393
|
+
};
|
|
2394
|
+
|
|
2395
|
+
// No binary: the loader copy is not exercised (it needs a framework
|
|
2396
|
+
// root), but the report and stats still carry the declared verdict.
|
|
2397
|
+
const stats = try createPackage(std.testing.allocator, std.testing.io, .{
|
|
2398
|
+
.metadata = metadata,
|
|
2399
|
+
.target = .windows,
|
|
2400
|
+
.output_path = root ++ "/demo-windows",
|
|
2401
|
+
.assets_dir = root ++ "/assets",
|
|
2402
|
+
});
|
|
2403
|
+
try std.testing.expect(stats.web_layer.?.enabled);
|
|
2404
|
+
try std.testing.expectEqual(manifest_tool.WebLayerReason.capability, stats.web_layer.?.reason);
|
|
2405
|
+
|
|
2406
|
+
const report = try readPath(std.testing.allocator, std.testing.io, root ++ "/demo-windows/package-manifest.zon");
|
|
2407
|
+
defer std.testing.allocator.free(report);
|
|
2408
|
+
try std.testing.expect(std.mem.indexOf(u8, report, ".web_layer = \"webview2 (declared: capabilities)\"") != null);
|
|
2409
|
+
}
|
|
2410
|
+
|
|
2411
|
+
test "package refuses a manifest that excludes the web layer while declaring web content" {
|
|
2412
|
+
const capabilities = [_][]const u8{"webview"};
|
|
2413
|
+
const metadata: manifest_tool.Metadata = .{
|
|
2414
|
+
.id = "dev.example.conflict",
|
|
2415
|
+
.name = "conflict-demo",
|
|
2416
|
+
.version = "1.0.0",
|
|
2417
|
+
.capabilities = &capabilities,
|
|
2418
|
+
.webview_layer = "exclude",
|
|
2419
|
+
};
|
|
2420
|
+
try std.testing.expectError(error.WebViewLayerConflict, createPackage(std.testing.allocator, std.testing.io, .{
|
|
2421
|
+
.metadata = metadata,
|
|
2422
|
+
.target = .windows,
|
|
2423
|
+
.output_path = ".zig-cache/test-package-web-layer-conflict",
|
|
2424
|
+
}));
|
|
2425
|
+
}
|
|
2426
|
+
|
|
2427
|
+
test "package web layer follows the resolved engine, not the raw manifest" {
|
|
2428
|
+
var cwd = std.Io.Dir.cwd();
|
|
2429
|
+
const root = ".zig-cache/test-package-web-layer-resolved-engine";
|
|
2430
|
+
try cwd.deleteTree(std.testing.io, root);
|
|
2431
|
+
defer cwd.deleteTree(std.testing.io, root) catch {};
|
|
2432
|
+
try cwd.createDirPath(std.testing.io, root ++ "/assets");
|
|
2433
|
+
try cwd.writeFile(std.testing.io, .{ .sub_path = root ++ "/assets/index.html", .data = "<h1>Web</h1>" });
|
|
2434
|
+
|
|
2435
|
+
// A system manifest with no web declarations, packaged with the
|
|
2436
|
+
// engine the CLI resolved from `--web-engine chromium`: the layer
|
|
2437
|
+
// ships, and the verdict names the engine as the cause.
|
|
2438
|
+
const metadata: manifest_tool.Metadata = .{
|
|
2439
|
+
.id = "dev.example.resolved",
|
|
2440
|
+
.name = "resolved-demo",
|
|
2441
|
+
.version = "1.0.0",
|
|
2442
|
+
};
|
|
2443
|
+
const stats = try createPackage(std.testing.allocator, std.testing.io, .{
|
|
2444
|
+
.metadata = metadata,
|
|
2445
|
+
.target = .ios,
|
|
2446
|
+
.output_path = root ++ "/ios",
|
|
2447
|
+
.assets_dir = root ++ "/assets",
|
|
2448
|
+
.web_engine = .chromium,
|
|
2449
|
+
});
|
|
2450
|
+
try std.testing.expect(stats.web_layer.?.enabled);
|
|
2451
|
+
try std.testing.expectEqual(manifest_tool.WebLayerReason.chromium_engine, stats.web_layer.?.reason);
|
|
2452
|
+
}
|
|
2453
|
+
|
|
2454
|
+
test "package refuses an exclude against a resolved Chromium engine" {
|
|
2455
|
+
// `.webview_layer = "exclude"` with `--web-engine chromium` is the
|
|
2456
|
+
// same contradiction as exclude + a manifest web declaration: the
|
|
2457
|
+
// package boundary rejects it exactly like build configure does.
|
|
2458
|
+
const metadata: manifest_tool.Metadata = .{
|
|
2459
|
+
.id = "dev.example.exclude-chromium",
|
|
2460
|
+
.name = "exclude-chromium-demo",
|
|
2461
|
+
.version = "1.0.0",
|
|
2462
|
+
.webview_layer = "exclude",
|
|
2463
|
+
};
|
|
2464
|
+
try std.testing.expectError(error.WebViewLayerConflict, createPackage(std.testing.allocator, std.testing.io, .{
|
|
2465
|
+
.metadata = metadata,
|
|
2466
|
+
.target = .macos,
|
|
2467
|
+
.output_path = ".zig-cache/test-package-web-layer-exclude-chromium",
|
|
2468
|
+
.web_engine = .chromium,
|
|
2469
|
+
}));
|
|
2470
|
+
}
|
|
2471
|
+
|
|
2472
|
+
/// A minimal Windows executable for web-layer packaging tests: a valid
|
|
2473
|
+
/// PE header (so the loader-reference scan and the arch sniff both treat
|
|
2474
|
+
/// it as a real exe) followed by the UTF-16 loader name a web build
|
|
2475
|
+
/// carries. The COFF machine field stays zero, which the arch sniff
|
|
2476
|
+
/// reads as x64.
|
|
2477
|
+
fn testWebLayerPeBytes() [0x80 + "WebView2Loader.dll".len * 2]u8 {
|
|
2478
|
+
var bytes = [_]u8{0} ** (0x80 + "WebView2Loader.dll".len * 2);
|
|
2479
|
+
bytes[0] = 'M';
|
|
2480
|
+
bytes[1] = 'Z';
|
|
2481
|
+
std.mem.writeInt(u32, bytes[0x3c..0x40], 0x40, .little);
|
|
2482
|
+
bytes[0x40] = 'P';
|
|
2483
|
+
bytes[0x41] = 'E';
|
|
2484
|
+
for ("WebView2Loader.dll", 0..) |ch, index| {
|
|
2485
|
+
bytes[0x80 + index * 2] = ch;
|
|
2486
|
+
}
|
|
2487
|
+
return bytes;
|
|
2488
|
+
}
|
|
2489
|
+
|
|
2490
|
+
test "package --web-layer include on a canvas manifest stages the loader and names the flag" {
|
|
2491
|
+
var cwd = std.Io.Dir.cwd();
|
|
2492
|
+
const root = ".zig-cache/test-package-web-layer-include-flag";
|
|
2493
|
+
try cwd.deleteTree(std.testing.io, root);
|
|
2494
|
+
defer cwd.deleteTree(std.testing.io, root) catch {};
|
|
2495
|
+
try cwd.createDirPath(std.testing.io, root ++ "/assets");
|
|
2496
|
+
// The exe a `zig build package -Dweb-layer=include` graph produces on
|
|
2497
|
+
// a canvas manifest: a real PE that references the loader.
|
|
2498
|
+
const exe_bytes = testWebLayerPeBytes();
|
|
2499
|
+
try cwd.writeFile(std.testing.io, .{ .sub_path = root ++ "/app.exe", .data = &exe_bytes });
|
|
2500
|
+
|
|
2501
|
+
const capabilities = [_][]const u8{ "native_views", "gpu_surfaces" };
|
|
2502
|
+
const metadata: manifest_tool.Metadata = .{
|
|
2503
|
+
.id = "dev.example.canvas",
|
|
2504
|
+
.name = "canvas-demo",
|
|
2505
|
+
.version = "1.0.0",
|
|
2506
|
+
.capabilities = &capabilities,
|
|
2507
|
+
};
|
|
2508
|
+
|
|
2509
|
+
// The loader copy resolves the framework root from the environment.
|
|
2510
|
+
var env_map = std.process.Environ.Map.init(std.testing.allocator);
|
|
2511
|
+
defer env_map.deinit();
|
|
2512
|
+
try env_map.put("NATIVE_SDK_PATH", ".");
|
|
2513
|
+
|
|
2514
|
+
const stats = try createPackage(std.testing.allocator, std.testing.io, .{
|
|
2515
|
+
.metadata = metadata,
|
|
2516
|
+
.target = .windows,
|
|
2517
|
+
.output_path = root ++ "/demo-windows",
|
|
2518
|
+
.binary_path = root ++ "/app.exe",
|
|
2519
|
+
.assets_dir = root ++ "/assets",
|
|
2520
|
+
.web_layer_setting = .include,
|
|
2521
|
+
.env_map = &env_map,
|
|
2522
|
+
});
|
|
2523
|
+
try std.testing.expect(stats.web_layer.?.enabled);
|
|
2524
|
+
try std.testing.expectEqual(manifest_tool.WebLayerReason.declared_include, stats.web_layer.?.reason);
|
|
2525
|
+
|
|
2526
|
+
// The loader is staged next to the binary, exactly like a manifest
|
|
2527
|
+
// that declares web use.
|
|
2528
|
+
var dir = try cwd.openDir(std.testing.io, root ++ "/demo-windows", .{});
|
|
2529
|
+
defer dir.close(std.testing.io);
|
|
2530
|
+
var loader = try dir.openFile(std.testing.io, "bin/WebView2Loader.dll", .{});
|
|
2531
|
+
loader.close(std.testing.io);
|
|
2532
|
+
|
|
2533
|
+
// The report names the flag as the cause, not app.zon.
|
|
2534
|
+
const report = try readPath(std.testing.allocator, std.testing.io, root ++ "/demo-windows/package-manifest.zon");
|
|
2535
|
+
defer std.testing.allocator.free(report);
|
|
2536
|
+
try std.testing.expect(std.mem.indexOf(u8, report, ".web_layer = \"webview2 (declared: --web-layer include)\"") != null);
|
|
2537
|
+
}
|
|
2538
|
+
|
|
2539
|
+
test "package --web-layer exclude on a web manifest is the same refused conflict" {
|
|
2540
|
+
const capabilities = [_][]const u8{"webview"};
|
|
2541
|
+
const metadata: manifest_tool.Metadata = .{
|
|
2542
|
+
.id = "dev.example.flag-conflict",
|
|
2543
|
+
.name = "flag-conflict-demo",
|
|
2544
|
+
.version = "1.0.0",
|
|
2545
|
+
.capabilities = &capabilities,
|
|
2546
|
+
};
|
|
2547
|
+
try std.testing.expectError(error.WebViewLayerConflict, createPackage(std.testing.allocator, std.testing.io, .{
|
|
2548
|
+
.metadata = metadata,
|
|
2549
|
+
.target = .windows,
|
|
2550
|
+
.output_path = ".zig-cache/test-package-web-layer-flag-conflict",
|
|
2551
|
+
.web_layer_setting = .exclude,
|
|
2552
|
+
}));
|
|
2553
|
+
}
|
|
2554
|
+
|
|
2555
|
+
test "package forwarded include on a web manifest keeps the manifest's reason" {
|
|
2556
|
+
var cwd = std.Io.Dir.cwd();
|
|
2557
|
+
const root = ".zig-cache/test-package-web-layer-forwarded-include";
|
|
2558
|
+
try cwd.deleteTree(std.testing.io, root);
|
|
2559
|
+
defer cwd.deleteTree(std.testing.io, root) catch {};
|
|
2560
|
+
try cwd.createDirPath(std.testing.io, root ++ "/assets");
|
|
2561
|
+
|
|
2562
|
+
// The build graphs forward `--web-layer include` for every web app;
|
|
2563
|
+
// the verdict must keep reporting the manifest's own declaration, so
|
|
2564
|
+
// graph-driven and hand-run packages read identically.
|
|
2565
|
+
const capabilities = [_][]const u8{"webview"};
|
|
2566
|
+
const metadata: manifest_tool.Metadata = .{
|
|
2567
|
+
.id = "dev.example.forwarded",
|
|
2568
|
+
.name = "forwarded-demo",
|
|
2569
|
+
.version = "1.0.0",
|
|
2570
|
+
.capabilities = &capabilities,
|
|
2571
|
+
};
|
|
2572
|
+
const stats = try createPackage(std.testing.allocator, std.testing.io, .{
|
|
2573
|
+
.metadata = metadata,
|
|
2574
|
+
.target = .windows,
|
|
2575
|
+
.output_path = root ++ "/demo-windows",
|
|
2576
|
+
.assets_dir = root ++ "/assets",
|
|
2577
|
+
.web_layer_setting = .include,
|
|
2578
|
+
});
|
|
2579
|
+
try std.testing.expect(stats.web_layer.?.enabled);
|
|
2580
|
+
try std.testing.expectEqual(manifest_tool.WebLayerReason.capability, stats.web_layer.?.reason);
|
|
2581
|
+
}
|
|
2582
|
+
|
|
2583
|
+
test "package refuses to strip the loader from an exe that references it" {
|
|
2584
|
+
var cwd = std.Io.Dir.cwd();
|
|
2585
|
+
const root = ".zig-cache/test-package-web-layer-mismatch";
|
|
2586
|
+
try cwd.deleteTree(std.testing.io, root);
|
|
2587
|
+
defer cwd.deleteTree(std.testing.io, root) catch {};
|
|
2588
|
+
try cwd.createDirPath(std.testing.io, root ++ "/assets");
|
|
2589
|
+
const exe_bytes = testWebLayerPeBytes();
|
|
2590
|
+
try cwd.writeFile(std.testing.io, .{ .sub_path = root ++ "/app.exe", .data = &exe_bytes });
|
|
2591
|
+
|
|
2592
|
+
// A loader-referencing exe (built with the web layer) packaged under
|
|
2593
|
+
// a native-only decision would ship broken webviews: refused, with
|
|
2594
|
+
// `--web-layer include` as the way out. Non-PE payloads (the other
|
|
2595
|
+
// tests' fake binaries) prove nothing and stay packageable.
|
|
2596
|
+
const capabilities = [_][]const u8{ "native_views", "gpu_surfaces" };
|
|
2597
|
+
const metadata: manifest_tool.Metadata = .{
|
|
2598
|
+
.id = "dev.example.mismatch",
|
|
2599
|
+
.name = "mismatch-demo",
|
|
2600
|
+
.version = "1.0.0",
|
|
2601
|
+
.capabilities = &capabilities,
|
|
2602
|
+
};
|
|
2603
|
+
try std.testing.expectError(error.WebViewLayerMismatch, createPackage(std.testing.allocator, std.testing.io, .{
|
|
2604
|
+
.metadata = metadata,
|
|
2605
|
+
.target = .windows,
|
|
2606
|
+
.output_path = root ++ "/demo-windows",
|
|
2607
|
+
.binary_path = root ++ "/app.exe",
|
|
2608
|
+
.assets_dir = root ++ "/assets",
|
|
2609
|
+
}));
|
|
2610
|
+
}
|
|
2611
|
+
|
|
2612
|
+
/// A minimal but structurally valid ELF64 executable for the WebKitGTK
|
|
2613
|
+
/// scan: one .dynstr, one .dynamic with a single DT_NEEDED naming
|
|
2614
|
+
/// `needed_lib`, and one .dynsym whose single real symbol is named
|
|
2615
|
+
/// `symbol_name` — the two evidence channels the Linux web-layer guard
|
|
2616
|
+
/// reads. Caller frees.
|
|
2617
|
+
fn testWebLayerElfBytes(gpa: std.mem.Allocator, needed_lib: []const u8, symbol_name: []const u8) ![]u8 {
|
|
2618
|
+
const dynstr_offset: u64 = 0x100;
|
|
2619
|
+
const dynamic_offset: u64 = 0x180;
|
|
2620
|
+
const dynsym_offset: u64 = 0x1c0;
|
|
2621
|
+
const shdr_offset: u64 = 0x200;
|
|
2622
|
+
const bytes = try gpa.alloc(u8, 0x2c0);
|
|
2623
|
+
@memset(bytes, 0);
|
|
2624
|
+
|
|
2625
|
+
// ELF header: magic, ELFCLASS64, little endian, section table.
|
|
2626
|
+
@memcpy(bytes[0..4], "\x7fELF");
|
|
2627
|
+
bytes[4] = 2;
|
|
2628
|
+
bytes[5] = 1;
|
|
2629
|
+
std.mem.writeInt(u64, bytes[0x28..0x30], shdr_offset, .little);
|
|
2630
|
+
std.mem.writeInt(u16, bytes[0x3a..0x3c], 0x40, .little);
|
|
2631
|
+
std.mem.writeInt(u16, bytes[0x3c..0x3e], 3, .little);
|
|
2632
|
+
|
|
2633
|
+
// .dynstr: "\0<needed_lib>\0<symbol_name>\0".
|
|
2634
|
+
const lib_name_offset: u64 = 1;
|
|
2635
|
+
const symbol_name_offset: u64 = 1 + needed_lib.len + 1;
|
|
2636
|
+
const dynstr_len: u64 = symbol_name_offset + symbol_name.len + 1;
|
|
2637
|
+
@memcpy(bytes[@intCast(dynstr_offset + lib_name_offset)..][0..needed_lib.len], needed_lib);
|
|
2638
|
+
@memcpy(bytes[@intCast(dynstr_offset + symbol_name_offset)..][0..symbol_name.len], symbol_name);
|
|
2639
|
+
|
|
2640
|
+
// .dynamic: DT_NEEDED -> needed_lib, then DT_NULL.
|
|
2641
|
+
std.mem.writeInt(u64, bytes[@intCast(dynamic_offset)..][0..8], 1, .little); // DT_NEEDED
|
|
2642
|
+
std.mem.writeInt(u64, bytes[@intCast(dynamic_offset + 8)..][0..8], lib_name_offset, .little);
|
|
2643
|
+
|
|
2644
|
+
// .dynsym: the null symbol, then one named symbol.
|
|
2645
|
+
std.mem.writeInt(u32, bytes[@intCast(dynsym_offset + 24)..][0..4], @intCast(symbol_name_offset), .little);
|
|
2646
|
+
|
|
2647
|
+
// Section headers: [0] .dynstr (SHT_STRTAB), [1] .dynamic, [2] .dynsym.
|
|
2648
|
+
const shdr = struct {
|
|
2649
|
+
fn write(buffer: []u8, base: u64, index: u64, sh_type: u32, link: u32, offset: u64, size: u64, entsize: u64) void {
|
|
2650
|
+
const header = buffer[@intCast(base + index * 0x40)..][0..0x40];
|
|
2651
|
+
std.mem.writeInt(u32, header[0x04..0x08], sh_type, .little);
|
|
2652
|
+
std.mem.writeInt(u64, header[0x18..0x20], offset, .little);
|
|
2653
|
+
std.mem.writeInt(u64, header[0x20..0x28], size, .little);
|
|
2654
|
+
std.mem.writeInt(u32, header[0x28..0x2c], link, .little);
|
|
2655
|
+
std.mem.writeInt(u64, header[0x38..0x40], entsize, .little);
|
|
2656
|
+
}
|
|
2657
|
+
};
|
|
2658
|
+
shdr.write(bytes, shdr_offset, 0, 3, 0, dynstr_offset, dynstr_len, 0);
|
|
2659
|
+
shdr.write(bytes, shdr_offset, 1, 6, 0, dynamic_offset, 32, 16);
|
|
2660
|
+
shdr.write(bytes, shdr_offset, 2, 11, 0, dynsym_offset, 48, 24);
|
|
2661
|
+
return bytes;
|
|
2662
|
+
}
|
|
2663
|
+
|
|
2664
|
+
test "the linux web-layer scan reads DT_NEEDED and dynamic symbols" {
|
|
2665
|
+
const gpa = std.testing.allocator;
|
|
2666
|
+
// The library link is evidence on its own.
|
|
2667
|
+
const linked = try testWebLayerElfBytes(gpa, "libwebkitgtk-6.0.so.4", "gtk_init");
|
|
2668
|
+
defer gpa.free(linked);
|
|
2669
|
+
try std.testing.expect(elfBytesReferenceWebKitGtk(linked));
|
|
2670
|
+
// So is a lone webkit_/jsc_ dynamic symbol (a hand-linked binary
|
|
2671
|
+
// that dodged the DT_NEEDED entry still calls into WebKit).
|
|
2672
|
+
const symboled = try testWebLayerElfBytes(gpa, "libgtk-4.so.1", "webkit_web_view_new");
|
|
2673
|
+
defer gpa.free(symboled);
|
|
2674
|
+
try std.testing.expect(elfBytesReferenceWebKitGtk(symboled));
|
|
2675
|
+
const jsc = try testWebLayerElfBytes(gpa, "libgtk-4.so.1", "jsc_value_to_string");
|
|
2676
|
+
defer gpa.free(jsc);
|
|
2677
|
+
try std.testing.expect(elfBytesReferenceWebKitGtk(jsc));
|
|
2678
|
+
// A WebKit-free GTK binary scans clean, and a non-ELF payload
|
|
2679
|
+
// proves nothing (stays packageable), mirroring the PE probe.
|
|
2680
|
+
const clean = try testWebLayerElfBytes(gpa, "libgtk-4.so.1", "gtk_init");
|
|
2681
|
+
defer gpa.free(clean);
|
|
2682
|
+
try std.testing.expect(!elfBytesReferenceWebKitGtk(clean));
|
|
2683
|
+
try std.testing.expect(!elfBytesReferenceWebKitGtk("not an executable"));
|
|
2684
|
+
}
|
|
2685
|
+
|
|
2686
|
+
test "package refuses to strip WebKitGTK from a Linux binary that links it" {
|
|
2687
|
+
var cwd = std.Io.Dir.cwd();
|
|
2688
|
+
const root = ".zig-cache/test-package-web-layer-linux-mismatch";
|
|
2689
|
+
try cwd.deleteTree(std.testing.io, root);
|
|
2690
|
+
defer cwd.deleteTree(std.testing.io, root) catch {};
|
|
2691
|
+
try cwd.createDirPath(std.testing.io, root ++ "/assets");
|
|
2692
|
+
const elf_bytes = try testWebLayerElfBytes(std.testing.allocator, "libwebkitgtk-6.0.so.4", "webkit_web_view_new");
|
|
2693
|
+
defer std.testing.allocator.free(elf_bytes);
|
|
2694
|
+
try cwd.writeFile(std.testing.io, .{ .sub_path = root ++ "/app", .data = elf_bytes });
|
|
2695
|
+
|
|
2696
|
+
// A WebKitGTK-linking binary (built with the web layer) packaged
|
|
2697
|
+
// under a native-only decision would ship broken webviews AND a
|
|
2698
|
+
// libwebkitgtk runtime requirement the package claims not to have:
|
|
2699
|
+
// refused, with `--web-layer include` as the way out.
|
|
2700
|
+
const capabilities = [_][]const u8{ "native_views", "gpu_surfaces" };
|
|
2701
|
+
const metadata: manifest_tool.Metadata = .{
|
|
2702
|
+
.id = "dev.example.linux-mismatch",
|
|
2703
|
+
.name = "linux-mismatch-demo",
|
|
2704
|
+
.version = "1.0.0",
|
|
2705
|
+
.capabilities = &capabilities,
|
|
2706
|
+
};
|
|
2707
|
+
try std.testing.expectError(error.WebViewLayerMismatch, createPackage(std.testing.allocator, std.testing.io, .{
|
|
2708
|
+
.metadata = metadata,
|
|
2709
|
+
.target = .linux,
|
|
2710
|
+
.output_path = root ++ "/demo-linux",
|
|
2711
|
+
.binary_path = root ++ "/app",
|
|
2712
|
+
.assets_dir = root ++ "/assets",
|
|
2713
|
+
}));
|
|
2714
|
+
}
|
|
2715
|
+
|
|
2716
|
+
test "native-only linux package accepts a WebKit-free ELF and reports web layer none" {
|
|
2717
|
+
var cwd = std.Io.Dir.cwd();
|
|
2718
|
+
const root = ".zig-cache/test-package-web-layer-linux-clean";
|
|
2719
|
+
try cwd.deleteTree(std.testing.io, root);
|
|
2720
|
+
defer cwd.deleteTree(std.testing.io, root) catch {};
|
|
2721
|
+
try cwd.createDirPath(std.testing.io, root ++ "/assets");
|
|
2722
|
+
const elf_bytes = try testWebLayerElfBytes(std.testing.allocator, "libgtk-4.so.1", "gtk_init");
|
|
2723
|
+
defer std.testing.allocator.free(elf_bytes);
|
|
2724
|
+
try cwd.writeFile(std.testing.io, .{ .sub_path = root ++ "/app", .data = elf_bytes });
|
|
2725
|
+
|
|
2726
|
+
const capabilities = [_][]const u8{ "native_views", "gpu_surfaces" };
|
|
2727
|
+
const metadata: manifest_tool.Metadata = .{
|
|
2728
|
+
.id = "dev.example.linux-clean",
|
|
2729
|
+
.name = "linux-clean-demo",
|
|
2730
|
+
.version = "1.0.0",
|
|
2731
|
+
.capabilities = &capabilities,
|
|
2732
|
+
};
|
|
2733
|
+
const stats = try createPackage(std.testing.allocator, std.testing.io, .{
|
|
2734
|
+
.metadata = metadata,
|
|
2735
|
+
.target = .linux,
|
|
2736
|
+
.output_path = root ++ "/demo-linux",
|
|
2737
|
+
.binary_path = root ++ "/app",
|
|
2738
|
+
.assets_dir = root ++ "/assets",
|
|
2739
|
+
});
|
|
2740
|
+
try std.testing.expect(!stats.web_layer.?.enabled);
|
|
2741
|
+
|
|
2742
|
+
const report = try readPath(std.testing.allocator, std.testing.io, root ++ "/demo-linux/package-manifest.zon");
|
|
2743
|
+
defer std.testing.allocator.free(report);
|
|
2744
|
+
try std.testing.expect(std.mem.indexOf(u8, report, ".web_layer = \"none (inferred: nothing in app.zon declares web use)\"") != null);
|
|
2745
|
+
}
|
|
2746
|
+
|
|
2155
2747
|
// ---------------------------------------------------------------------------
|
|
2156
2748
|
// App icon pipeline tests
|
|
2157
2749
|
// ---------------------------------------------------------------------------
|