From 7b104789aa9bd06c8a5b784a5de84801af7a948e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Arrufat?= Date: Sat, 21 Mar 2026 21:13:50 +0900 Subject: [PATCH] build: simplify dev version resolution --- build.zig | 41 +++++++++++++---------------------------- 1 file changed, 13 insertions(+), 28 deletions(-) diff --git a/build.zig b/build.zig index 179705b5..67657b1e 100644 --- a/build.zig +++ b/build.zig @@ -728,38 +728,23 @@ fn resolveVersion(b: *std.Build) std.SemanticVersion { }; } + // If it's a stable release (no pre or build metadata in build.zig.zon), use it as is if (lightpanda_version.pre == null and lightpanda_version.build == null) return lightpanda_version; - // Check if we're exactly on a tagged release - _ = runGit(b, &.{ "describe", "--tags", "--exact-match" }) catch { - // Not on a tag, need to create a dev version - const git_hash_raw = runGit(b, &.{ "rev-parse", "--short", "HEAD" }) catch return lightpanda_version; - const commit_hash = std.mem.trim(u8, git_hash_raw, " \n\r"); - // Get the commit count - either from base tag or total - const commit_count = blk: { - // Try to find the most recent base version tag (ending with .0) - const base_tag_raw = runGit(b, &.{ "describe", "--tags", "--match=*.0", "--abbrev=0" }) catch { - // No .0 tags found, fall back to total commit count - const git_count_raw = runGit(b, &.{ "rev-list", "--count", "HEAD" }) catch return lightpanda_version; - break :blk std.mem.trim(u8, git_count_raw, " \n\r"); - }; - const base_tag = std.mem.trim(u8, base_tag_raw, " \n\r"); - // Count commits since the base tag - const count_cmd = b.fmt("{s}..HEAD", .{base_tag}); - const git_count_raw = runGit(b, &.{ "rev-list", "--count", count_cmd }) catch return lightpanda_version; - break :blk std.mem.trim(u8, git_count_raw, " \n\r"); - }; + // For dev/nightly versions, calculate the commit count and hash + const git_hash_raw = runGit(b, &.{ "rev-parse", "--short", "HEAD" }) catch return lightpanda_version; + const commit_hash = std.mem.trim(u8, git_hash_raw, " \n\r"); - return .{ - .major = lightpanda_version.major, - .minor = lightpanda_version.minor, - .patch = lightpanda_version.patch, - .pre = b.fmt("dev.{s}", .{commit_count}), - .build = commit_hash, - }; + const git_count_raw = runGit(b, &.{ "rev-list", "--count", "HEAD" }) catch return lightpanda_version; + const commit_count = std.mem.trim(u8, git_count_raw, " \n\r"); + + return .{ + .major = lightpanda_version.major, + .minor = lightpanda_version.minor, + .patch = lightpanda_version.patch, + .pre = b.fmt("{s}.{s}", .{ lightpanda_version.pre.?, commit_count }), + .build = commit_hash, }; - // We're exactly on a tag, return the version as-is - return lightpanda_version; } /// Helper function to run git commands and return stdout