From b22fa2638bca470bbd8c5ea4768eb0eaaa3e8195 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Fri, 6 Nov 2026 19:14:11 -0300 Subject: Build: a word that prints this build into a +Build pane (SPC h b): the version line, the commit, the jj change and the build time (stamped as the commit is: release builds and the ~/.local install, else "not stamped"), the zig that built it, its mode, target, platform and grammars, whether the addons are compiled in, the wire's semantics hash and the dependencies; build.zig stamps the change (jj log -r git_head()) and the time (date -u) through one command helper beside gitCommit; a T1 case reads the pane Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- build.zig | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'build.zig') diff --git a/build.zig b/build.zig index c7cbea3d..73902a1b 100644 --- a/build.zig +++ b/build.zig @@ -284,6 +284,8 @@ pub fn build(b: *std.Build) void { .prebuilt_shaders = prebuilt_shaders, .embed_sources = embed_sources, .commit = if (stamp_commit) gitCommit(b) else null, + .change = if (stamp_commit) jjChange(b) else null, + .built = if (stamp_commit) command(b, &.{ "date", "-u", "+%Y-%m-%d %H:%M UTC" }) else null, }; const opts = shellOptions(b, shell_cfg, platform); const gui_opts: ?*std.Build.Step.Options = if (also_gui) shellOptions(b, shell_cfg, .gui) else null; @@ -1916,14 +1918,22 @@ fn installed(sub: []const u8) std.Build.LazyPath { } fn gitCommit(b: *std.Build) ?[]const u8 { - // HEAD is not a file the configure cache can track. + return command(b, &.{ "git", "rev-parse", "--short=12", "HEAD" }); +} + +/// The jj change git HEAD is in, by its commit (jj 0.46 has no revset for +/// git's HEAD), or null without jj. +fn jjChange(b: *std.Build) ?[]const u8 { + const head = command(b, &.{ "git", "rev-parse", "HEAD" }) orelse return null; + return command(b, &.{ "jj", "log", "-r", head, "--no-graph", "-T", "change_id.short()" }); +} + +/// One line a command prints, or null: HEAD, the change, the clock are not +/// files the configure cache can track, so the cache is poisoned. +fn command(b: *std.Build, argv: []const []const u8) ?[]const u8 { b.graph.poisonCache(); var code: u8 = 0; - const out = b.runAllowFail( - &.{ "git", "rev-parse", "--short=12", "HEAD" }, - &code, - .ignore, - ) catch return null; + const out = b.runAllowFail(argv, &code, .ignore) catch return null; const trimmed = std.mem.trim(u8, out, " \t\r\n"); return if (trimmed.len == 0) null else trimmed; } @@ -1937,6 +1947,10 @@ const ShellConfig = struct { prebuilt_shaders: bool, embed_sources: bool, commit: ?[]const u8, + /// The jj change git HEAD is in, and when this configure ran: the + /// `Build` word's, stamped with the commit (see `stamp_commit`). + change: ?[]const u8, + built: ?[]const u8, }; fn shellOptions(b: *std.Build, cfg: ShellConfig, platform: Platform) *std.Build.Step.Options { @@ -1953,6 +1967,8 @@ fn shellOptions(b: *std.Build, cfg: ShellConfig, platform: Platform) *std.Build. // ...and the commit it was built from, when there is one and the build // is stamped at all (see `stamp_commit`). Read at configure time. o.addOption(?[]const u8, "commit", cfg.commit); + o.addOption(?[]const u8, "change", cfg.change); + o.addOption(?[]const u8, "built", cfg.built); o.addOption([]const u8, "deps", deps_text); return o; } -- cgit v1.3