From 54c816567fb68bf6fc026d861b9ff449a67b2383 Mon Sep 17 00:00:00 2001 From: Jeremy Collins Date: Sat, 28 Nov 2026 04:19:52 -0500 Subject: [PATCH] Pin ztk to dd10466, with ztcl 0e9e8bf The new ztcl keeps the JIT code of a Debug build in the .bss of the program, so a debug dockyard no longer loads the unwind tables again for each stack trace through JIT code: the start of the headless window goes from 292 MB to 57 MB of resident memory. Three changes follow the new versions. The build uses the ztcl module that ztk imports, since ztk gives ztcl the option drop and a second dependency made a second module of the same files. ztk.bundle.run now needs the environment, which main gives to apps. ztcl fails a set of a variable in a namespace that does not exist, as Tcl does, so the code creates ::dockyard before it sets the variables. --- build.zig | 9 ++++++--- build.zig.zon | 4 ++-- src/app/apps.zig | 8 +++++++- src/app/crash.zig | 1 + src/app/host.zig | 2 ++ src/audit/audit.zig | 2 +- src/main.zig | 3 +++ src/sandbox/guest_release.zig | 2 ++ src/sandbox/sandbox.zig | 2 ++ 9 files changed, 26 insertions(+), 7 deletions(-) diff --git a/build.zig b/build.zig index ac7ff07..9979dba 100644 --- a/build.zig +++ b/build.zig @@ -5,10 +5,13 @@ pub fn build(b: *std.Build) void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); const ztk_dep = b.dependency("ztk", .{ .target = target, .optimize = optimize }); - const ztcl_dep = ztk_dep.builder.dependency("ztcl", .{ .target = target, .optimize = optimize }); + const ztk_mod = ztk_dep.module("ztk"); + // The ztcl module of ztk: ztk gives ztcl its own options (`drop`), so a + // new dependency on ztcl here makes a second module of the same files. + const ztcl_mod = ztk_mod.import_table.get("ztcl") orelse @panic("ztk imports no ztcl module"); const imports: []const std.Build.Module.Import = &.{ - .{ .name = "ztk", .module = ztk_dep.module("ztk") }, - .{ .name = "ztcl", .module = ztcl_dep.module("ztcl") }, + .{ .name = "ztk", .module = ztk_mod }, + .{ .name = "ztcl", .module = ztcl_mod }, }; const use_lld = target.result.ofmt != .macho; const root = b.createModule(.{ diff --git a/build.zig.zon b/build.zig.zon index 15bcb48..f6349e3 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -5,8 +5,8 @@ .minimum_zig_version = "0.17.0", .dependencies = .{ .ztk = .{ - .url = "git+https://github.com/beetlebugorg/ztk#31af992759944de373c46b4b96e07c5d0b125614", - .hash = "ztk-0.2.0-beta-pPTF2DxZUgC2z60gPx72clYhUBqeCvLgfzPB2Ou0neIE", + .url = "git+https://github.com/beetlebugorg/ztk#dd1046663dd6b29ca452547b5cf25f00027354d8", + .hash = "ztk-1.0.0-beta.1-pPTF2G4wVADy5CJyXdQMxvFs2EamImrt5xD2d3POyNGq", }, }, .paths = .{ "build.zig", "build.zig.zon", "src" }, diff --git a/src/app/apps.zig b/src/app/apps.zig index 93e0603..52c068b 100644 --- a/src/app/apps.zig +++ b/src/app/apps.zig @@ -55,6 +55,11 @@ fn programName(a: std.mem.Allocator, target: []const u8, name: []const u8) ![]co /// `lib/ztk/runtime` next to the folder of this program. pub var runtime_root: ?[]const u8 = null; +/// The environment of the process for `ztk bundle`, which reads the +/// folders of the build tools from it. `main` sets it; with null (the +/// tests), the bundle gets an empty environment. +pub var environ: ?*const std.process.Environ.Map = null; + /// The path of the ztk program of a target. fn runtimePath(a: std.mem.Allocator, target: []const u8) ![]const u8 { const root = runtime_root orelse try std.fs.path.join(a, &.{ try std.process.executableDirPathAlloc(the_io, a), "..", "lib", "ztk", "runtime" }); @@ -155,7 +160,8 @@ fn build(a: std.mem.Allocator, target: []const u8) !BuildResult { } for (try appFiles(a, project)) |f| try args.append(a, try a.dupeSentinel(u8, f, 0)); var log: Io.Writer.Allocating = .init(a); - const status = try ztk.bundle.run(the_io, a, args.items, &log.writer); + var empty: std.process.Environ.Map = .init(a); + const status = try ztk.bundle.run(the_io, a, environ orelse &empty, args.items, &log.writer); return .{ .status = status, .log = log.written(), .path = try std.fmt.allocPrint(a, "/build/{s}/{s}", .{ target, file }) }; } diff --git a/src/app/crash.zig b/src/app/crash.zig index 68d50a9..21fcb18 100644 --- a/src/app/crash.zig +++ b/src/app/crash.zig @@ -71,6 +71,7 @@ pub fn install(arena: std.mem.Allocator, io: Io, env: *const std.process.Environ } const last = prune(arena, io, dir); if (it) |interp| { + _ = interp.eval("namespace eval ::dockyard::crash {}") catch {}; interp.setVar("::dockyard::crash::last", .{ .str = last orelse "" }) catch {}; interp.register("::dockyard::crash::open", cmdOpen) catch {}; } diff --git a/src/app/host.zig b/src/app/host.zig index 2349048..fd52e95 100644 --- a/src/app/host.zig +++ b/src/app/host.zig @@ -292,6 +292,8 @@ pub fn shellOf(map: *const std.process.Environ.Map) []const u8 { /// Sets the variables of `dockyard.tcl`. pub fn setVars(it: *ztcl.Interp, s: Setup) !void { + // The namespace of the variables: ztcl fails a set in a namespace that does not exist, as Tcl does. + _ = try it.eval("namespace eval ::dockyard {}"); try it.setVar("::dockyard::project", .{ .str = s.project }); try it.setVar("::dockyard::agent", .{ .str = s.agent orelse "" }); try it.setVar("::dockyard::agent_name", .{ .str = s.agent_name }); diff --git a/src/audit/audit.zig b/src/audit/audit.zig index 543bf0d..314d5de 100644 --- a/src/audit/audit.zig +++ b/src/audit/audit.zig @@ -1036,7 +1036,7 @@ test "the audit log chains, indexes, and filters the records" { // terminal view of monitor.tcl gives each record a line. try it.allow(@backingInt(ztcl.interp.Capability.event) | @backingInt(ztcl.interp.Capability.clock)); it.event_host = .{ .now = testTicks, .sleep = testSleep }; - _ = try it.eval("set ::dockyard::project /p; set ::dockyard::tui 1"); + _ = try it.eval("namespace eval ::dockyard {}; set ::dockyard::project /p; set ::dockyard::tui 1"); _ = try it.eval(@embedFile("audit.tcl")); _ = it.eval( \\::dockyard::audit::start 1 {claude} diff --git a/src/main.zig b/src/main.zig index 94d5c36..cc07880 100644 --- a/src/main.zig +++ b/src/main.zig @@ -215,6 +215,7 @@ pub fn main(init: std.process.Init) !void { try host.allowPreview(&it, std.fs.path.dirname(f) orelse "/"); } else { try host.allow(&it, folder, env); + apps.environ = init.environ_map; try apps.register(&it, io, folder); try proxy.register(&it); try host.setVars(&it, .{ @@ -226,6 +227,7 @@ pub fn main(init: std.process.Init) !void { .headless = headless, .dark = dark, }); + _ = try it.eval("namespace eval ::dockyard {}"); try it.setVar("::dockyard::view", .{ .str = view }); try it.setVar("::dockyard::audit_import", .{ .str = audit_import }); const sandbox_abs = if (sandbox_dir) |d| try std.fs.path.resolve(arena, &.{ cwd, d }) else null; @@ -240,6 +242,7 @@ pub fn main(init: std.process.Init) !void { try monitor.register(&it, try host.controlPath(arena, host.Dirs.fromMap(init.environ_map), folder)); // Windows has no audit log yet: the writer uses POSIX files. if (comptime @import("builtin").os.tag != .windows) if (audit_dir.len > 0) try audit.register(&it, audit_dir); + _ = try it.eval("namespace eval ::dockyard {}"); try it.setVar("::dockyard::tui", .{ .str = if (tui) "1" else "0" }); } diff --git a/src/sandbox/guest_release.zig b/src/sandbox/guest_release.zig index c796103..781149a 100644 --- a/src/sandbox/guest_release.zig +++ b/src/sandbox/guest_release.zig @@ -77,6 +77,8 @@ pub fn prepare(a: std.mem.Allocator, io: std.Io, project: []const u8, dir: []con pub fn setVars(it: *ztcl.Interp, r: ?Release) !void { var buf: [24]u8 = undefined; + // The namespace of the variables: ztcl fails a set in a namespace that does not exist, as Tcl does. + _ = try it.eval("namespace eval ::dockyard {}"); try it.setVar("::dockyard::sandbox_image", .{ .str = if (r) |x| x.name else "" }); try it.setVar("::dockyard::sandbox_counter", .{ .str = if (r) |x| try std.fmt.bufPrint(&buf, "{d}", .{x.counter}) else "" }); } diff --git a/src/sandbox/sandbox.zig b/src/sandbox/sandbox.zig index dda0b97..f8f6e1a 100644 --- a/src/sandbox/sandbox.zig +++ b/src/sandbox/sandbox.zig @@ -60,6 +60,8 @@ pub fn prepare(a: std.mem.Allocator, io: Io, project: []const u8, dir: []const u } pub fn setVars(it: *ztcl.Interp, g: ?Guest, argv: []const u8, allow: []const u8) !void { + // The namespace of the variables: ztcl fails a set in a namespace that does not exist, as Tcl does. + _ = try it.eval("namespace eval ::dockyard {}"); try it.setVar("::dockyard::sandbox", .{ .str = if (g != null) jail_dir else "" }); try it.setVar("::dockyard::sandbox_kernel", .{ .str = if (g) |x| x.kernel else "" }); try it.setVar("::dockyard::sandbox_argv", .{ .str = argv });