@native-sdk/cli 0.9.2 → 0.9.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 +273 -37
- package/build/ts_run.mjs +15 -18
- package/build.zig +141 -9
- package/package.json +13 -10
- package/packages/core/compile-surface/core.ts +1 -0
- package/packages/core/package-lock.json +16 -13
- package/packages/core/package.json +5 -2
- package/packages/core/scripts/compiler_command.mjs +71 -0
- package/packages/core/scripts/compiler_typecheck.mjs +4 -4
- package/packages/core/scripts/embed_markup_c.mjs +25 -0
- package/packages/core/scripts/npm_static_spike.mjs +3 -3
- package/packages/core/scripts/run_external_core_compiler.mjs +4 -3
- package/packages/core/scripts/run_external_service_compiler.mjs +2 -1
- package/packages/core/sdk/core.ts +1 -0
- package/packages/core/sdk/events.d.ts +10 -0
- package/packages/core/sdk/events.ts +30 -5
- package/packages/core/sdk/text.d.ts +4 -0
- package/packages/core/sdk/text.ts +51 -0
- package/packages/core/src/checker.ts +61 -3
- package/packages/core/src/contract.ts +5 -4
- package/packages/core/src/devhost_journal.mjs +2 -2
- package/packages/core/src/diagnostics.ts +2 -2
- package/packages/core/src/service_contract.ts +10 -0
- package/packages/core/src/typed_ast.ts +9 -7
- package/packages/core/src/types.ts +28 -8
- package/skill-data/automation/SKILL.md +4 -3
- package/skill-data/native-ui/SKILL.md +5 -2
- package/skill-data/ts-core/SKILL.md +10 -4
- package/skill-data/ts-services/references/service-surface.md +1 -1
- package/src/app_runner/root.zig +208 -6
- package/src/app_runner/ts_core_main.zig +14 -4
- package/src/app_runner/ts_core_mobile.zig +6 -2
- package/src/automation/protocol.zig +5 -1
- package/src/automation/snapshot.zig +119 -0
- package/src/platform/macos/appkit_host.m +79 -12
- package/src/platform/macos/root.zig +68 -5
- package/src/primitives/canvas/events.zig +79 -1
- package/src/primitives/canvas/root.zig +1 -0
- package/src/primitives/canvas/text_interaction.zig +23 -0
- package/src/primitives/canvas/text_tests.zig +45 -0
- package/src/primitives/canvas/ui.zig +11 -8
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +3 -0
- package/src/primitives/canvas/ui_markup_reflect.zig +6 -5
- package/src/primitives/canvas/ui_markup_view_tests.zig +18 -2
- package/src/primitives/canvas/ui_tests.zig +37 -0
- package/src/primitives/canvas/widget_builtin_tests.zig +13 -0
- package/src/runtime/automation_snapshot.zig +4 -0
- package/src/runtime/canvas_widget_control_tests.zig +2 -0
- package/src/runtime/canvas_widget_text_tests.zig +124 -0
- package/src/runtime/native_command_event_tests.zig +29 -0
- package/src/runtime/session_journal.zig +21 -2
- package/src/runtime/ts_ui_app.zig +184 -7
- package/src/runtime/ui_app.zig +98 -18
- package/src/runtime/ui_app_tests.zig +232 -13
- package/src/runtime/ui_app_window_tests.zig +23 -0
- package/src/runtime/view_widget_text.zig +1 -1
- package/src/tooling/templates.zig +6 -2
- package/src/tooling/ts_core.zig +1 -1
- package/src/tooling/verbs.zig +228 -0
- package/tools/corewire/emit.zig +31 -12
- package/tools/corewire/emit_facade.zig +57 -2
- package/tools/corewire/emit_profile.zig +20 -7
- package/tools/corewire/emit_service.zig +49 -24
- package/tools/corewire/main.zig +21 -2
- package/tools/corewire/shim_rt.zig +20 -0
package/src/tooling/verbs.zig
CHANGED
|
@@ -38,6 +38,8 @@ pub const Options = struct {
|
|
|
38
38
|
url_override: ?[]const u8 = null,
|
|
39
39
|
command_override: ?[]const []const u8 = null,
|
|
40
40
|
timeout_ms: ?u32 = null,
|
|
41
|
+
/// Explain authored-input changes and the content-gated downstream graph.
|
|
42
|
+
explain_rebuild: bool = false,
|
|
41
43
|
};
|
|
42
44
|
|
|
43
45
|
pub fn run(allocator: std.mem.Allocator, io: std.Io, verb: Verb, options: Options) !void {
|
|
@@ -50,6 +52,11 @@ pub fn run(allocator: std.mem.Allocator, io: std.Io, verb: Verb, options: Option
|
|
|
50
52
|
return error.MissingManifest;
|
|
51
53
|
}
|
|
52
54
|
const metadata = try manifest_tool.readMetadata(allocator, io, "app.zon");
|
|
55
|
+
const rebuild_snapshot = if (options.explain_rebuild)
|
|
56
|
+
try explainRebuild(allocator, io)
|
|
57
|
+
else
|
|
58
|
+
null;
|
|
59
|
+
defer if (rebuild_snapshot) |snapshot| allocator.free(snapshot);
|
|
53
60
|
|
|
54
61
|
// Tree detection happens here too (the build graph re-derives it), so
|
|
55
62
|
// a both-cores tree fails with one clean teaching message before any
|
|
@@ -122,6 +129,12 @@ pub fn run(allocator: std.mem.Allocator, io: std.Io, verb: Verb, options: Option
|
|
|
122
129
|
switch (verb) {
|
|
123
130
|
.dev => {
|
|
124
131
|
if (!wants_frontend_dev) try argv.append(allocator, "run");
|
|
132
|
+
// Zig's full summary reports each named build step's duration,
|
|
133
|
+
// cache status, and peak RSS. Native's generated graph names the
|
|
134
|
+
// frontend, corewire, staging, scriptc, and final Zig phases, so
|
|
135
|
+
// slow iterative builds are attributable without reproducing
|
|
136
|
+
// them under an external profiler.
|
|
137
|
+
try argv.appendSlice(allocator, &.{ "--summary", "all" });
|
|
125
138
|
if (!hasOptimizeFlag(options.forwarded_args)) {
|
|
126
139
|
// The dev loop is a Debug loop: the markup hot-reload
|
|
127
140
|
// watcher and the teaching diagnostics are compiled in only
|
|
@@ -133,6 +146,8 @@ pub fn run(allocator: std.mem.Allocator, io: std.Io, verb: Verb, options: Option
|
|
|
133
146
|
}
|
|
134
147
|
},
|
|
135
148
|
.build => {
|
|
149
|
+
try argv.appendSlice(allocator, &.{ "--summary", "all" });
|
|
150
|
+
if (options.explain_rebuild) try argv.append(allocator, "-Dbuild-trace=true");
|
|
136
151
|
if (!hasOptimizeFlag(options.forwarded_args)) {
|
|
137
152
|
// Both build shapes register -Doptimize (addApp and the
|
|
138
153
|
// expanded template each b.option it by hand).
|
|
@@ -157,6 +172,7 @@ pub fn run(allocator: std.mem.Allocator, io: std.Io, verb: Verb, options: Option
|
|
|
157
172
|
}
|
|
158
173
|
|
|
159
174
|
try runZig(io, verb, argv.items);
|
|
175
|
+
if (rebuild_snapshot) |snapshot| try persistRebuildSnapshot(io, snapshot);
|
|
160
176
|
|
|
161
177
|
if (wants_frontend_dev) {
|
|
162
178
|
// WebView apps with a dev server config: the binary is built, now
|
|
@@ -219,6 +235,168 @@ fn hasOptimizeFlag(args: []const []const u8) bool {
|
|
|
219
235
|
return false;
|
|
220
236
|
}
|
|
221
237
|
|
|
238
|
+
const rebuild_snapshot_path = ".native/cache/rebuild-inputs.tsv";
|
|
239
|
+
|
|
240
|
+
const RebuildInput = struct {
|
|
241
|
+
path: []const u8,
|
|
242
|
+
hash: [std.crypto.hash.sha2.Sha256.digest_length * 2]u8,
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
fn appendRebuildInput(allocator: std.mem.Allocator, io: std.Io, inputs: *std.ArrayList(RebuildInput), path: []const u8) !void {
|
|
246
|
+
const owned_path = try allocator.dupe(u8, path);
|
|
247
|
+
errdefer allocator.free(owned_path);
|
|
248
|
+
var file = try std.Io.Dir.cwd().openFile(io, path, .{});
|
|
249
|
+
defer file.close(io);
|
|
250
|
+
var read_buffer: [64 * 1024]u8 = undefined;
|
|
251
|
+
var reader = file.reader(io, &read_buffer);
|
|
252
|
+
var hasher = std.crypto.hash.sha2.Sha256.init(.{});
|
|
253
|
+
var chunk: [64 * 1024]u8 = undefined;
|
|
254
|
+
while (true) {
|
|
255
|
+
const len = try reader.interface.readSliceShort(&chunk);
|
|
256
|
+
hasher.update(chunk[0..len]);
|
|
257
|
+
if (len < chunk.len) break;
|
|
258
|
+
}
|
|
259
|
+
const digest = hasher.finalResult();
|
|
260
|
+
try inputs.append(allocator, .{ .path = owned_path, .hash = std.fmt.bytesToHex(digest, .lower) });
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
fn rebuildPathIgnored(path: []const u8) bool {
|
|
264
|
+
var components = std.mem.splitScalar(u8, path, '/');
|
|
265
|
+
while (components.next()) |component| {
|
|
266
|
+
if (std.mem.eql(u8, component, ".git") or
|
|
267
|
+
std.mem.eql(u8, component, ".native") or
|
|
268
|
+
std.mem.eql(u8, component, ".zig-cache") or
|
|
269
|
+
std.mem.eql(u8, component, "zig-out") or
|
|
270
|
+
std.mem.eql(u8, component, "node_modules")) return true;
|
|
271
|
+
}
|
|
272
|
+
return false;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
fn rebuildInputs(allocator: std.mem.Allocator, io: std.Io) ![]RebuildInput {
|
|
276
|
+
var inputs: std.ArrayList(RebuildInput) = .empty;
|
|
277
|
+
errdefer {
|
|
278
|
+
for (inputs.items) |input| allocator.free(input.path);
|
|
279
|
+
inputs.deinit(allocator);
|
|
280
|
+
}
|
|
281
|
+
// Ejected builds can consume any authored file, and even the standard
|
|
282
|
+
// graph has non-extension inputs: Zig sources, migration lock JSON,
|
|
283
|
+
// vendored service packages, assets, and frontend configuration. Hash the
|
|
284
|
+
// app tree instead of maintaining an inevitably incomplete suffix list;
|
|
285
|
+
// exclude only directories owned by VCS, dependency installs, and build
|
|
286
|
+
// outputs (including this snapshot itself under .native/).
|
|
287
|
+
var root = try std.Io.Dir.cwd().openDir(io, ".", .{ .iterate = true });
|
|
288
|
+
defer root.close(io);
|
|
289
|
+
var walker = try root.walkSelectively(allocator);
|
|
290
|
+
defer walker.deinit();
|
|
291
|
+
while (try walker.next(io)) |entry| {
|
|
292
|
+
const path = try allocator.dupe(u8, entry.path);
|
|
293
|
+
defer allocator.free(path);
|
|
294
|
+
for (path) |*char| if (char.* == '\\') {
|
|
295
|
+
char.* = '/';
|
|
296
|
+
};
|
|
297
|
+
if (entry.kind == .directory) {
|
|
298
|
+
if (!rebuildPathIgnored(path)) try walker.enter(io, entry);
|
|
299
|
+
continue;
|
|
300
|
+
}
|
|
301
|
+
if (entry.kind != .file) continue;
|
|
302
|
+
if (rebuildPathIgnored(path)) continue;
|
|
303
|
+
try appendRebuildInput(allocator, io, &inputs, path);
|
|
304
|
+
}
|
|
305
|
+
std.mem.sort(RebuildInput, inputs.items, {}, struct {
|
|
306
|
+
fn less(_: void, a: RebuildInput, b: RebuildInput) bool {
|
|
307
|
+
return std.mem.order(u8, a.path, b.path) == .lt;
|
|
308
|
+
}
|
|
309
|
+
}.less);
|
|
310
|
+
return inputs.toOwnedSlice(allocator);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
fn explainRebuild(allocator: std.mem.Allocator, io: std.Io) ![]u8 {
|
|
314
|
+
const inputs = try rebuildInputs(allocator, io);
|
|
315
|
+
defer {
|
|
316
|
+
for (inputs) |input| allocator.free(input.path);
|
|
317
|
+
allocator.free(inputs);
|
|
318
|
+
}
|
|
319
|
+
const prior = std.Io.Dir.cwd().readFileAlloc(io, rebuild_snapshot_path, allocator, .limited(16 * 1024 * 1024)) catch null;
|
|
320
|
+
defer if (prior) |bytes| allocator.free(bytes);
|
|
321
|
+
|
|
322
|
+
var snapshot = std.Io.Writer.Allocating.init(allocator);
|
|
323
|
+
errdefer snapshot.deinit();
|
|
324
|
+
var changed: usize = 0;
|
|
325
|
+
for (inputs) |input| {
|
|
326
|
+
try snapshot.writer.print("{s}\t{s}\n", .{ &input.hash, input.path });
|
|
327
|
+
const old_hash: ?[]const u8 = if (prior) |bytes| old: {
|
|
328
|
+
var lines = std.mem.splitScalar(u8, bytes, '\n');
|
|
329
|
+
while (lines.next()) |line| {
|
|
330
|
+
const tab = std.mem.indexOfScalar(u8, line, '\t') orelse continue;
|
|
331
|
+
if (std.mem.eql(u8, line[tab + 1 ..], input.path)) break :old line[0..tab];
|
|
332
|
+
}
|
|
333
|
+
break :old null;
|
|
334
|
+
} else null;
|
|
335
|
+
if (old_hash != null and std.mem.eql(u8, old_hash.?, &input.hash)) continue;
|
|
336
|
+
changed += 1;
|
|
337
|
+
std.debug.print("native rebuild: {s} {s} -> {s}\n", .{ input.path, old_hash orelse "<new>", &input.hash });
|
|
338
|
+
if (std.mem.eql(u8, input.path, "app.zon")) {
|
|
339
|
+
std.debug.print(" invalidates manifest-derived configuration -> affected contracts, app-code/platform link, and final artifact\n", .{});
|
|
340
|
+
} else if (std.mem.eql(u8, input.path, "build.zig") or std.mem.eql(u8, input.path, "build.zig.zon")) {
|
|
341
|
+
std.debug.print(" invalidates the owned build graph -> graph-selected compilation and final artifact\n", .{});
|
|
342
|
+
} else if (std.mem.eql(u8, input.path, "src/app.native")) {
|
|
343
|
+
std.debug.print(" invalidates markup data object -> final app link; app-code/core scriptc remain content-gated\n", .{});
|
|
344
|
+
} else if (std.mem.endsWith(u8, input.path, ".native")) {
|
|
345
|
+
std.debug.print(" invalidates staged markup source set -> app-code object -> final link; core scriptc remains content-gated\n", .{});
|
|
346
|
+
} else if (std.mem.startsWith(u8, input.path, "src/services/")) {
|
|
347
|
+
std.debug.print(" invalidates TS frontend -> service contract/source hash -> service host compile; API client/registry/core scriptc change only if API shape changes\n", .{});
|
|
348
|
+
} else if (std.mem.endsWith(u8, input.path, ".ts")) {
|
|
349
|
+
std.debug.print(" invalidates TS frontend -> core contract/facade/stage -> core scriptc -> app-code object -> final link\n", .{});
|
|
350
|
+
} else if (std.mem.endsWith(u8, input.path, ".zig")) {
|
|
351
|
+
std.debug.print(" invalidates Zig build/app code -> affected compile and final link\n", .{});
|
|
352
|
+
} else if (std.mem.endsWith(u8, input.path, ".sql") or std.mem.endsWith(u8, input.path, "/migrations.lock.json")) {
|
|
353
|
+
std.debug.print(" invalidates SQLite schema/migration generation -> app-code object -> final link\n", .{});
|
|
354
|
+
} else if (std.mem.startsWith(u8, input.path, "frontend/")) {
|
|
355
|
+
std.debug.print(" invalidates frontend build inputs -> bundled web assets and final package\n", .{});
|
|
356
|
+
} else if (std.mem.startsWith(u8, input.path, "assets/")) {
|
|
357
|
+
std.debug.print(" invalidates authored assets -> affected runtime/package artifact\n", .{});
|
|
358
|
+
} else {
|
|
359
|
+
std.debug.print(" changes an authored app input -> the build graph determines affected downstream steps\n", .{});
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
if (prior) |bytes| {
|
|
363
|
+
var lines = std.mem.splitScalar(u8, bytes, '\n');
|
|
364
|
+
while (lines.next()) |line| {
|
|
365
|
+
const tab = std.mem.indexOfScalar(u8, line, '\t') orelse continue;
|
|
366
|
+
const old_hash = line[0..tab];
|
|
367
|
+
const old_path = line[tab + 1 ..];
|
|
368
|
+
const present = for (inputs) |input| {
|
|
369
|
+
if (std.mem.eql(u8, input.path, old_path)) break true;
|
|
370
|
+
} else false;
|
|
371
|
+
if (present) continue;
|
|
372
|
+
changed += 1;
|
|
373
|
+
std.debug.print("native rebuild: {s} {s} -> <deleted>\n", .{ old_path, old_hash });
|
|
374
|
+
if (std.mem.startsWith(u8, old_path, "src/services/")) {
|
|
375
|
+
std.debug.print(" invalidates TS frontend -> service API/source set -> service host; core scriptc changes if the removed module changed API shape\n", .{});
|
|
376
|
+
} else if (std.mem.eql(u8, old_path, "src/app.native")) {
|
|
377
|
+
std.debug.print(" invalidates primary markup data object -> final app link\n", .{});
|
|
378
|
+
} else if (std.mem.endsWith(u8, old_path, ".native")) {
|
|
379
|
+
std.debug.print(" invalidates markup source set -> app-code object -> final link\n", .{});
|
|
380
|
+
} else if (std.mem.endsWith(u8, old_path, ".zig")) {
|
|
381
|
+
std.debug.print(" invalidates Zig build/app code -> affected compile and final link\n", .{});
|
|
382
|
+
} else {
|
|
383
|
+
std.debug.print(" removes an authored app input -> the build graph determines affected downstream steps\n", .{});
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
if (prior == null) std.debug.print("native rebuild: no prior successful snapshot; current inputs are the baseline\n", .{});
|
|
388
|
+
if (prior != null and changed == 0) std.debug.print("native rebuild: no authored input hashes changed\n", .{});
|
|
389
|
+
return snapshot.toOwnedSlice();
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
fn persistRebuildSnapshot(io: std.Io, snapshot: []const u8) !void {
|
|
393
|
+
try std.Io.Dir.cwd().createDirPath(io, ".native/cache");
|
|
394
|
+
var atomic = try std.Io.Dir.cwd().createFileAtomic(io, rebuild_snapshot_path, .{ .make_path = true, .replace = true });
|
|
395
|
+
defer atomic.deinit(io);
|
|
396
|
+
try atomic.file.writeStreamingAll(io, snapshot);
|
|
397
|
+
try atomic.replace(io);
|
|
398
|
+
}
|
|
399
|
+
|
|
222
400
|
fn runZig(io: std.Io, verb: Verb, argv: []const []const u8) !void {
|
|
223
401
|
// The dev verb owns a whole process TREE: `zig build run` spawns the
|
|
224
402
|
// app as its child, and a `native dev` that dies (Ctrl-C, a driver
|
|
@@ -254,6 +432,7 @@ fn runZig(io: std.Io, verb: Verb, argv: []const []const u8) !void {
|
|
|
254
432
|
// SDK builds with Zig 0.16, where std APIs moved, and those failures
|
|
255
433
|
// read "no member named 'cwd'/'init'/'io'" on std types.
|
|
256
434
|
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", .{});
|
|
435
|
+
std.debug.print("if generated core wiring exceeds Zig's eval branch quota, do not regenerate the TypeScript contract or add an app-side quota - update or report the SDK-generated scan\n", .{});
|
|
257
436
|
return error.ZigBuildFailed;
|
|
258
437
|
}
|
|
259
438
|
|
|
@@ -317,3 +496,52 @@ test "optimize flags are detected among forwarded args" {
|
|
|
317
496
|
try std.testing.expect(!hasOptimizeFlag(&.{"-Dautomation=true"}));
|
|
318
497
|
try std.testing.expect(!hasOptimizeFlag(&.{}));
|
|
319
498
|
}
|
|
499
|
+
|
|
500
|
+
test "rebuild explanations persist manifest and source hashes" {
|
|
501
|
+
const allocator = std.testing.allocator;
|
|
502
|
+
const io = std.testing.io;
|
|
503
|
+
const root = ".zig-cache/test-rebuild-explain";
|
|
504
|
+
var cwd = std.Io.Dir.cwd();
|
|
505
|
+
cwd.deleteTree(io, root) catch {};
|
|
506
|
+
defer cwd.deleteTree(io, root) catch {};
|
|
507
|
+
try cwd.createDirPath(io, root ++ "/src/services");
|
|
508
|
+
try cwd.createDirPath(io, root ++ "/src/schema");
|
|
509
|
+
try cwd.createDirPath(io, root ++ "/assets");
|
|
510
|
+
try cwd.createDirPath(io, root ++ "/.native/cache");
|
|
511
|
+
try cwd.createDirPath(io, root ++ "/node_modules/package");
|
|
512
|
+
try cwd.writeFile(io, .{ .sub_path = root ++ "/app.zon", .data = ".{ .name = \"rebuild-test\" }\n" });
|
|
513
|
+
try cwd.writeFile(io, .{ .sub_path = root ++ "/build.zig", .data = "pub fn build() void {}\n" });
|
|
514
|
+
try cwd.writeFile(io, .{ .sub_path = root ++ "/src/core.ts", .data = "export const core = 1;\n" });
|
|
515
|
+
try cwd.writeFile(io, .{ .sub_path = root ++ "/src/main.zig", .data = "pub fn main() void {}\n" });
|
|
516
|
+
try cwd.writeFile(io, .{ .sub_path = root ++ "/src/app.native", .data = "<column/>\n" });
|
|
517
|
+
try cwd.writeFile(io, .{ .sub_path = root ++ "/src/services/work.ts", .data = "export function work(): number { return 1; }\n" });
|
|
518
|
+
try cwd.writeFile(io, .{ .sub_path = root ++ "/src/schema/migrations.lock.json", .data = "{}\n" });
|
|
519
|
+
try cwd.writeFile(io, .{ .sub_path = root ++ "/assets/icon.bin", .data = "authored asset\n" });
|
|
520
|
+
try cwd.writeFile(io, .{ .sub_path = root ++ "/.native/cache/generated", .data = "generated\n" });
|
|
521
|
+
try cwd.writeFile(io, .{ .sub_path = root ++ "/node_modules/package/index.js", .data = "dependency\n" });
|
|
522
|
+
const original = try std.process.currentPathAlloc(io, allocator);
|
|
523
|
+
defer allocator.free(original);
|
|
524
|
+
try std.process.setCurrentPath(io, root);
|
|
525
|
+
defer std.process.setCurrentPath(io, original) catch {};
|
|
526
|
+
const first = try explainRebuild(allocator, io);
|
|
527
|
+
defer allocator.free(first);
|
|
528
|
+
try std.testing.expect(std.mem.indexOf(u8, first, "\tapp.zon\n") != null);
|
|
529
|
+
try std.testing.expect(std.mem.indexOf(u8, first, "\tbuild.zig\n") != null);
|
|
530
|
+
try std.testing.expect(std.mem.indexOf(u8, first, "\tsrc/main.zig\n") != null);
|
|
531
|
+
try std.testing.expect(std.mem.indexOf(u8, first, "\tsrc/schema/migrations.lock.json\n") != null);
|
|
532
|
+
try std.testing.expect(std.mem.indexOf(u8, first, "\tassets/icon.bin\n") != null);
|
|
533
|
+
try std.testing.expect(std.mem.indexOf(u8, first, "\t.native/") == null);
|
|
534
|
+
try std.testing.expect(std.mem.indexOf(u8, first, "\tnode_modules/") == null);
|
|
535
|
+
try persistRebuildSnapshot(io, first);
|
|
536
|
+
const second = try explainRebuild(allocator, io);
|
|
537
|
+
defer allocator.free(second);
|
|
538
|
+
try std.testing.expectEqualStrings(first, second);
|
|
539
|
+
try cwd.writeFile(io, .{ .sub_path = "src/services/work.ts", .data = "// comment\nexport function work(): number { return 1; }\n" });
|
|
540
|
+
const changed = try explainRebuild(allocator, io);
|
|
541
|
+
defer allocator.free(changed);
|
|
542
|
+
try std.testing.expect(!std.mem.eql(u8, first, changed));
|
|
543
|
+
try cwd.writeFile(io, .{ .sub_path = "app.zon", .data = ".{ .name = \"rebuild-test\", .capabilities = .{\"store\"} }\n" });
|
|
544
|
+
const manifest_changed = try explainRebuild(allocator, io);
|
|
545
|
+
defer allocator.free(manifest_changed);
|
|
546
|
+
try std.testing.expect(!std.mem.eql(u8, changed, manifest_changed));
|
|
547
|
+
}
|
package/tools/corewire/emit.zig
CHANGED
|
@@ -42,17 +42,31 @@ const Sidecar = sidecar_mod.Sidecar;
|
|
|
42
42
|
const TypeRef = sidecar_mod.TypeRef;
|
|
43
43
|
const Payload = sidecar_mod.Payload;
|
|
44
44
|
|
|
45
|
-
///
|
|
45
|
+
/// Comptime string scans pay for every arm and every byte in its name.
|
|
46
|
+
/// Keep the generated consistency fence independent of Zig's default
|
|
47
|
+
/// 1000-backwards-branch quota: the sidecar admits 256 arms, and long legal
|
|
48
|
+
/// TypeScript identifiers must remain legal here too. The fixed floor covers
|
|
49
|
+
/// the surrounding reflection; the linear terms leave generous headroom over
|
|
50
|
+
/// `std.mem.eql`'s scalar comptime path.
|
|
51
|
+
fn msgTagConsistencyQuota(arms: []const sidecar_mod.MsgArm) u32 {
|
|
52
|
+
var name_bytes: u64 = 0;
|
|
53
|
+
for (arms) |arm| name_bytes += arm.name.len;
|
|
54
|
+
const quota: u64 = 100_000 + @as(u64, arms.len) * 1_024 + name_bytes * 256;
|
|
55
|
+
return @intCast(@min(quota, std.math.maxInt(u32)));
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/// The thirteen text-input event tags the markup engines recognize
|
|
46
59
|
/// structurally; a union payload carrying exactly these dispatches
|
|
47
60
|
/// through the ABI's text_input entry.
|
|
48
61
|
const text_input_event_tags = [_][]const u8{
|
|
49
|
-
"insert_text", "delete_backward",
|
|
50
|
-
"delete_word_forward", "
|
|
51
|
-
"
|
|
62
|
+
"insert_text", "delete_backward", "delete_forward", "delete_word_backward",
|
|
63
|
+
"delete_word_forward", "delete_to_start", "delete_to_line_start", "clear",
|
|
64
|
+
"move_caret", "set_selection", "set_composition", "commit_composition",
|
|
65
|
+
"cancel_composition",
|
|
52
66
|
};
|
|
53
67
|
|
|
54
68
|
/// Whether a union payload declares the text-input event shape the markup
|
|
55
|
-
/// engines route through the dedicated ABI entry: exactly the
|
|
69
|
+
/// engines route through the dedicated ABI entry: exactly the thirteen tags,
|
|
56
70
|
/// with the same structural payload vocabulary. This is public because the
|
|
57
71
|
/// generated facade must make the identical decision when selecting the one
|
|
58
72
|
/// sentinel-saturating decoder; one contract cannot have two recognizers.
|
|
@@ -883,6 +897,7 @@ const Emitter = struct {
|
|
|
883
897
|
}
|
|
884
898
|
|
|
885
899
|
fn tagTable(self: *Emitter) Error!void {
|
|
900
|
+
const consistency_quota = msgTagConsistencyQuota(self.sidecar.msg.arms);
|
|
886
901
|
try self.raw(
|
|
887
902
|
\\
|
|
888
903
|
\\/// Declaration-order wire tags: the arm's index in this table IS
|
|
@@ -898,16 +913,17 @@ const Emitter = struct {
|
|
|
898
913
|
try self.print(
|
|
899
914
|
\\
|
|
900
915
|
\\comptime {{
|
|
916
|
+
\\ @setEvalBranchQuota({d});
|
|
901
917
|
\\ // The union and the tag table are emitted from one arm list;
|
|
902
918
|
\\ // hold them equal anyway so a hand edit cannot skew dispatch.
|
|
903
919
|
\\ const fields = @typeInfo({f}).@"union".fields;
|
|
904
|
-
\\ if (fields.len != msg_tags.len) @compileError("core_shim:
|
|
920
|
+
\\ if (fields.len != msg_tags.len) @compileError("core_shim: Msg arm count does not match msg_tags");
|
|
905
921
|
\\ for (fields, msg_tags) |field, tag_name| {{
|
|
906
|
-
\\ if (!std.mem.eql(u8, field.name, tag_name)) @compileError("core_shim:
|
|
922
|
+
\\ if (!std.mem.eql(u8, field.name, tag_name)) @compileError("core_shim: Msg arm names do not match msg_tags");
|
|
907
923
|
\\ }}
|
|
908
924
|
\\}}
|
|
909
925
|
\\
|
|
910
|
-
, .{ident(self.sidecar.msg.name)});
|
|
926
|
+
, .{ consistency_quota, ident(self.sidecar.msg.name) });
|
|
911
927
|
}
|
|
912
928
|
|
|
913
929
|
// --------------------------------------------------- entry points
|
|
@@ -1852,6 +1868,8 @@ test "u64 attestations on selection bounds are accepted (the host supplies unsig
|
|
|
1852
1868
|
\\ {"name": "delete_forward", "payload": {"kind": "void"}},
|
|
1853
1869
|
\\ {"name": "delete_word_backward", "payload": {"kind": "void"}},
|
|
1854
1870
|
\\ {"name": "delete_word_forward", "payload": {"kind": "void"}},
|
|
1871
|
+
\\ {"name": "delete_to_start", "payload": {"kind": "void"}},
|
|
1872
|
+
\\ {"name": "delete_to_line_start", "payload": {"kind": "void"}},
|
|
1855
1873
|
\\ {"name": "clear", "payload": {"kind": "void"}},
|
|
1856
1874
|
\\ {"name": "move_caret", "payload": {"kind": "value", "name": "Move"}},
|
|
1857
1875
|
\\ {"name": "set_selection", "payload": {"kind": "value", "name": "Sel"}},
|
|
@@ -2210,14 +2228,15 @@ test "a text-input-named union without the payload shapes rides the record entry
|
|
|
2210
2228
|
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
2211
2229
|
defer arena_state.deinit();
|
|
2212
2230
|
const arena = arena_state.allocator();
|
|
2213
|
-
//
|
|
2231
|
+
// Thirteen right names, wrong insert_text payload (void): the markup
|
|
2214
2232
|
// predicate would not bind this as text input, so dispatch must
|
|
2215
2233
|
// not route it to the text_input entry either.
|
|
2216
2234
|
var arms: std.ArrayListUnmanaged(u8) = .empty;
|
|
2217
2235
|
const tags = [_][]const u8{
|
|
2218
|
-
"insert_text", "delete_backward",
|
|
2219
|
-
"delete_word_forward", "
|
|
2220
|
-
"
|
|
2236
|
+
"insert_text", "delete_backward", "delete_forward", "delete_word_backward",
|
|
2237
|
+
"delete_word_forward", "delete_to_start", "delete_to_line_start", "clear",
|
|
2238
|
+
"move_caret", "set_selection", "set_composition", "commit_composition",
|
|
2239
|
+
"cancel_composition",
|
|
2221
2240
|
};
|
|
2222
2241
|
for (tags, 0..) |tag, index| {
|
|
2223
2242
|
if (index > 0) try arms.appendSlice(arena, ", ");
|
|
@@ -2101,14 +2101,24 @@ const FacadeEmitter = struct {
|
|
|
2101
2101
|
},
|
|
2102
2102
|
.bytes => {
|
|
2103
2103
|
self.use(.w_bytes);
|
|
2104
|
-
|
|
2104
|
+
if (self.isThemeStateAccent(container, member)) {
|
|
2105
|
+
// ThemeState.accent is author-facing `string` (the
|
|
2106
|
+
// ergonomic "#rrggbb" API) but the core ABI's one text
|
|
2107
|
+
// representation is bytes. The contract intentionally
|
|
2108
|
+
// reflects strings as bytes; bridge this one exact
|
|
2109
|
+
// launcher record at the generated boundary.
|
|
2110
|
+
self.use(.utf8_text);
|
|
2111
|
+
try self.print("{s}nscfWBytes(sink, nscfUtf8TextBytes({s}));\n", .{ pad, expr });
|
|
2112
|
+
} else {
|
|
2113
|
+
try self.print("{s}nscfWBytes(sink, {s});\n", .{ pad, expr });
|
|
2114
|
+
}
|
|
2105
2115
|
},
|
|
2106
2116
|
.void => {},
|
|
2107
2117
|
.optional => |inner| {
|
|
2108
2118
|
self.use(.w_bool);
|
|
2109
2119
|
const temp = try std.fmt.allocPrint(self.arena, "nscfOpt{d}", .{self.temp_counter});
|
|
2110
2120
|
self.temp_counter += 1;
|
|
2111
|
-
try self.print("{s}const {s} = {s};\n{s}if ({s} === null) {{\n{s} nscfWBool(sink, false);\n{s}}} else {{\n{s} nscfWBool(sink, true);\n", .{ pad, temp, expr, pad, temp, pad, pad, pad });
|
|
2121
|
+
try self.print("{s}const {s} = {s};\n{s}if ({s} === null || {s} === undefined) {{\n{s} nscfWBool(sink, false);\n{s}}} else {{\n{s} nscfWBool(sink, true);\n", .{ pad, temp, expr, pad, temp, temp, pad, pad, pad });
|
|
2112
2122
|
try self.fieldWriteStatements(inner.*, temp, container, member, depth + 1);
|
|
2113
2123
|
try self.print("{s}}}\n", .{pad});
|
|
2114
2124
|
},
|
|
@@ -2145,6 +2155,18 @@ const FacadeEmitter = struct {
|
|
|
2145
2155
|
}
|
|
2146
2156
|
}
|
|
2147
2157
|
|
|
2158
|
+
fn isThemeStateAccent(self: *FacadeEmitter, container: []const u8, member: []const u8) bool {
|
|
2159
|
+
if (!std.mem.eql(u8, member, "accent")) return false;
|
|
2160
|
+
for (self.sidecar.model_helpers) |helper| {
|
|
2161
|
+
if (!std.mem.eql(u8, helper.name, "themeState")) continue;
|
|
2162
|
+
return switch (helper.returns) {
|
|
2163
|
+
.node, .value => |name| std.mem.eql(u8, name, container),
|
|
2164
|
+
else => false,
|
|
2165
|
+
};
|
|
2166
|
+
}
|
|
2167
|
+
return false;
|
|
2168
|
+
}
|
|
2169
|
+
|
|
2148
2170
|
fn recordWriter(self: *FacadeEmitter, name: []const u8) Error!void {
|
|
2149
2171
|
const entry = sidecar_mod.findStruct(self.sidecar.types, name).?;
|
|
2150
2172
|
self.use(.sink);
|
|
@@ -4004,6 +4026,37 @@ test "helpers wrap in declaration order with classed-return proofs" {
|
|
|
4004
4026
|
try testing.expect(std.mem.indexOf(u8, generated, "nscfWI64(sink, nscfValue);") != null);
|
|
4005
4027
|
}
|
|
4006
4028
|
|
|
4029
|
+
test "themeState helper encodes omitted fields and UTF-8 string accent" {
|
|
4030
|
+
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
4031
|
+
defer arena_state.deinit();
|
|
4032
|
+
const arena = arena_state.allocator();
|
|
4033
|
+
var source = try std.mem.replaceOwned(
|
|
4034
|
+
u8,
|
|
4035
|
+
arena,
|
|
4036
|
+
sidecar_mod.minimal_valid_json,
|
|
4037
|
+
"\"structs\": [",
|
|
4038
|
+
"\"structs\": [\n {\"name\": \"ThemeState\", \"origin\": \"sdk/events.ts\", \"fields\": [{\"name\": \"pack\", \"type\": {\"kind\": \"optional\", \"inner\": {\"kind\": \"enum\", \"name\": \"ThemeStatePack\"}}}, {\"name\": \"colorScheme\", \"type\": {\"kind\": \"optional\", \"inner\": {\"kind\": \"enum\", \"name\": \"ThemeStateColorScheme\"}}}, {\"name\": \"accent\", \"type\": {\"kind\": \"optional\", \"inner\": {\"kind\": \"bytes\"}}}] },",
|
|
4039
|
+
);
|
|
4040
|
+
source = try std.mem.replaceOwned(
|
|
4041
|
+
u8,
|
|
4042
|
+
arena,
|
|
4043
|
+
source,
|
|
4044
|
+
"\"enums\": []",
|
|
4045
|
+
"\"enums\": [{\"name\": \"ThemeStatePack\", \"origin\": \"sdk/events.ts\", \"members\": [\"house\", \"geist\"]}, {\"name\": \"ThemeStateColorScheme\", \"origin\": \"sdk/events.ts\", \"members\": [\"light\", \"dark\", \"system\"]}]",
|
|
4046
|
+
);
|
|
4047
|
+
source = try std.mem.replaceOwned(
|
|
4048
|
+
u8,
|
|
4049
|
+
arena,
|
|
4050
|
+
source,
|
|
4051
|
+
"\"model_helpers\": []",
|
|
4052
|
+
"\"model_helpers\": [{\"name\": \"themeState\", \"params\": [], \"returns\": {\"kind\": \"value\", \"name\": \"ThemeState\"}, \"arena\": false}]",
|
|
4053
|
+
);
|
|
4054
|
+
const generated = try facadeFromJson(arena, source);
|
|
4055
|
+
try testing.expect(std.mem.indexOf(u8, generated, "=== null ||") != null);
|
|
4056
|
+
try testing.expect(std.mem.indexOf(u8, generated, "=== undefined") != null);
|
|
4057
|
+
try testing.expect(std.mem.indexOf(u8, generated, "nscfWBytes(sink, nscfUtf8TextBytes(") != null);
|
|
4058
|
+
}
|
|
4059
|
+
|
|
4007
4060
|
test "nullable integer helper returns prove their present branch" {
|
|
4008
4061
|
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
4009
4062
|
defer arena_state.deinit();
|
|
@@ -4424,6 +4477,8 @@ test "text-input selection saturates signed and unsigned select-all sentinels" {
|
|
|
4424
4477
|
\\ {"name": "delete_forward", "payload": {"kind": "void"}},
|
|
4425
4478
|
\\ {"name": "delete_word_backward", "payload": {"kind": "void"}},
|
|
4426
4479
|
\\ {"name": "delete_word_forward", "payload": {"kind": "void"}},
|
|
4480
|
+
\\ {"name": "delete_to_start", "payload": {"kind": "void"}},
|
|
4481
|
+
\\ {"name": "delete_to_line_start", "payload": {"kind": "void"}},
|
|
4427
4482
|
\\ {"name": "clear", "payload": {"kind": "void"}},
|
|
4428
4483
|
\\ {"name": "move_caret", "member": "move", "payload": {"kind": "value", "name": "Move"}},
|
|
4429
4484
|
\\ {"name": "set_selection", "member": "selection", "payload": {"kind": "value", "name": "Sel"}},
|
|
@@ -153,7 +153,7 @@ const determinism_remediations = [_]Rider{
|
|
|
153
153
|
.{ .code = "SC4017", .text = "restart the app process: a trapped core is poisoned and never resumes in place, and the recorded session replays deterministically." },
|
|
154
154
|
};
|
|
155
155
|
|
|
156
|
-
pub fn emitProfile(arena: std.mem.Allocator, sidecar: Sidecar, entry: []const u8, diags: *sidecar_mod.Diagnostics) Error![]const u8 {
|
|
156
|
+
pub fn emitProfile(arena: std.mem.Allocator, sidecar: Sidecar, entry: []const u8, optimization: ?[]const u8, diags: *sidecar_mod.Diagnostics) Error![]const u8 {
|
|
157
157
|
// The profile is ENFORCEMENT data: a compile that succeeds under its
|
|
158
158
|
// determinism fences attests deterministic, and the compilation mode
|
|
159
159
|
// is structurally async-free — so a contract attesting false for
|
|
@@ -168,7 +168,7 @@ pub fn emitProfile(arena: std.mem.Allocator, sidecar: Sidecar, entry: []const u8
|
|
|
168
168
|
diags.flag("async_free", "the contract attests async_free: false, but this profile's compilation mode is structurally async-free — a core reaching async surface refuses under it, so this contract cannot have come from the profile it asks for; remove the async surface and regenerate the contract", .{});
|
|
169
169
|
}
|
|
170
170
|
if (diags.hasErrors()) return error.Refused;
|
|
171
|
-
var emitter = ProfileEmitter{ .arena = arena, .sidecar = sidecar, .out = .empty };
|
|
171
|
+
var emitter = ProfileEmitter{ .arena = arena, .sidecar = sidecar, .optimization = optimization, .out = .empty };
|
|
172
172
|
try emitter.run(entry);
|
|
173
173
|
return emitter.out.items;
|
|
174
174
|
}
|
|
@@ -176,6 +176,7 @@ pub fn emitProfile(arena: std.mem.Allocator, sidecar: Sidecar, entry: []const u8
|
|
|
176
176
|
const ProfileEmitter = struct {
|
|
177
177
|
arena: std.mem.Allocator,
|
|
178
178
|
sidecar: Sidecar,
|
|
179
|
+
optimization: ?[]const u8,
|
|
179
180
|
out: std.ArrayListUnmanaged(u8),
|
|
180
181
|
|
|
181
182
|
fn print(self: *ProfileEmitter, comptime fmt: []const u8, args: anytype) Error!void {
|
|
@@ -195,6 +196,14 @@ const ProfileEmitter = struct {
|
|
|
195
196
|
\\ "name": "native-sdk-core",
|
|
196
197
|
\\ "entry": {s},
|
|
197
198
|
\\ "emission": "llvm",
|
|
199
|
+
, .{try self.jsonString(entry)});
|
|
200
|
+
if (self.optimization) |optimization| {
|
|
201
|
+
try self.print(
|
|
202
|
+
\\ "optimization": {s},
|
|
203
|
+
, .{try self.jsonString(optimization)});
|
|
204
|
+
try self.raw("\n");
|
|
205
|
+
}
|
|
206
|
+
try self.print(
|
|
198
207
|
\\ "abi": {{
|
|
199
208
|
\\ "prefix": {s},
|
|
200
209
|
\\ "init_symbol": {s},
|
|
@@ -205,7 +214,6 @@ const ProfileEmitter = struct {
|
|
|
205
214
|
\\ "exports": [
|
|
206
215
|
\\
|
|
207
216
|
, .{
|
|
208
|
-
try self.jsonString(entry),
|
|
209
217
|
try self.jsonString(prefix),
|
|
210
218
|
try self.symbol(prefix, "init"),
|
|
211
219
|
try self.symbol(prefix, "set_panic_sink"),
|
|
@@ -361,7 +369,7 @@ const testing = std.testing;
|
|
|
361
369
|
fn profileFromJson(arena: std.mem.Allocator, json: []const u8, entry: []const u8) ![]const u8 {
|
|
362
370
|
var diags = sidecar_mod.Diagnostics{ .arena = arena };
|
|
363
371
|
const parsed = try sidecar_mod.read(arena, json, &diags);
|
|
364
|
-
return emitProfile(arena, parsed, entry, &diags);
|
|
372
|
+
return emitProfile(arena, parsed, entry, "release", &diags);
|
|
365
373
|
}
|
|
366
374
|
|
|
367
375
|
test "profile emission is deterministic and carries the library-mode surface" {
|
|
@@ -373,6 +381,11 @@ test "profile emission is deterministic and carries the library-mode surface" {
|
|
|
373
381
|
try testing.expectEqualStrings(first, second);
|
|
374
382
|
try testing.expect(std.mem.indexOf(u8, first, "\"profile_format\": 1") != null);
|
|
375
383
|
try testing.expect(std.mem.indexOf(u8, first, "\"entry\": \"core_facade.ts\"") != null);
|
|
384
|
+
try testing.expect(std.mem.indexOf(u8, first, "\"optimization\": \"release\"") != null);
|
|
385
|
+
var dev_diags = sidecar_mod.Diagnostics{ .arena = arena };
|
|
386
|
+
const parsed_for_dev = try sidecar_mod.read(arena, sidecar_mod.minimal_valid_json, &dev_diags);
|
|
387
|
+
const dev = try emitProfile(arena, parsed_for_dev, default_entry, "dev", &dev_diags);
|
|
388
|
+
try testing.expect(std.mem.indexOf(u8, dev, "\"optimization\": \"dev\"") != null);
|
|
376
389
|
// Mode symbols ride the abi block under the contract's prefix.
|
|
377
390
|
try testing.expect(std.mem.indexOf(u8, first, "\"init_symbol\": \"nsc_core_init\"") != null);
|
|
378
391
|
try testing.expect(std.mem.indexOf(u8, first, "\"sink_register_symbol\": \"nsc_core_set_panic_sink\"") != null);
|
|
@@ -459,7 +472,7 @@ test "a non-UTF-8 entry spelling refuses instead of corrupting the JSON" {
|
|
|
459
472
|
const arena = arena_state.allocator();
|
|
460
473
|
var diags = sidecar_mod.Diagnostics{ .arena = arena };
|
|
461
474
|
const parsed = try sidecar_mod.read(arena, sidecar_mod.minimal_valid_json, &diags);
|
|
462
|
-
try testing.expectError(error.Refused, emitProfile(arena, parsed, "core_\xfffacade.ts", &diags));
|
|
475
|
+
try testing.expectError(error.Refused, emitProfile(arena, parsed, "core_\xfffacade.ts", "release", &diags));
|
|
463
476
|
}
|
|
464
477
|
|
|
465
478
|
test "a contract attesting false for an enforced posture refuses" {
|
|
@@ -473,7 +486,7 @@ test "a contract attesting false for an enforced posture refuses" {
|
|
|
473
486
|
const source = try std.mem.replaceOwned(u8, arena, sidecar_mod.minimal_valid_json, case.needle, case.replacement);
|
|
474
487
|
var diags = sidecar_mod.Diagnostics{ .arena = arena };
|
|
475
488
|
const parsed = try sidecar_mod.read(arena, source, &diags);
|
|
476
|
-
try testing.expectError(error.Refused, emitProfile(arena, parsed, default_entry, &diags));
|
|
489
|
+
try testing.expectError(error.Refused, emitProfile(arena, parsed, default_entry, "release", &diags));
|
|
477
490
|
var found = false;
|
|
478
491
|
for (diags.list.items) |item| {
|
|
479
492
|
if (item.severity == .@"error" and std.mem.indexOf(u8, item.message, case.fragment) != null) found = true;
|
|
@@ -489,7 +502,7 @@ test "the emitted profile parses as JSON with the expected top-level keys" {
|
|
|
489
502
|
const generated = try profileFromJson(arena, sidecar_mod.minimal_valid_json, default_entry);
|
|
490
503
|
const parsed = try std.json.parseFromSliceLeaky(std.json.Value, arena, generated, .{});
|
|
491
504
|
const top = parsed.object;
|
|
492
|
-
for ([_][]const u8{ "profile_format", "name", "entry", "emission", "abi", "exports", "sidecar", "determinism" }) |key| {
|
|
505
|
+
for ([_][]const u8{ "profile_format", "name", "entry", "emission", "optimization", "abi", "exports", "sidecar", "determinism" }) |key| {
|
|
493
506
|
try testing.expect(top.contains(key));
|
|
494
507
|
}
|
|
495
508
|
const determinism = top.get("determinism").?.object;
|