~novakane/rivercarro

f7cd883bf3b1b1f8ed35f31b9aa3f5c5f4cbe8e3 — Hugo Machet 6 days ago b5f31d3 main
build: follow semantic versioning for -dev versions

The new version format is 0.2.0-dev.76+d1cf95b which is compliant
to the semantic versioning 2.0.0 spec and sorts better than the
old format.
1 files changed, 16 insertions(+), 6 deletions(-)

M build.zig
M build.zig => build.zig +16 -6
@@ 1,6 1,7 @@
const std = @import("std");
const Builder = @import("std").build.Builder;
const Step = @import("std").build.Step;
const assert = std.debug.assert;
const fs = std.fs;
const mem = std.mem;



@@ 20,15 21,24 @@ pub fn build(b: *Builder) !void {
    const full_version = blk: {
        if (mem.endsWith(u8, version, "-dev")) {
            var ret: u8 = undefined;
            const git_dir = try fs.path.join(b.allocator, &[_][]const u8{ b.build_root, ".git" });
            const git_commit_hash = b.execAllowFail(
                &[_][]const u8{ "git", "--git-dir", git_dir, "--work-tree", b.build_root, "rev-parse", "--short", "HEAD" },

            const git_describe_long = b.execAllowFail(
                &[_][]const u8{ "git", "-C", b.build_root, "describe", "--long" },
                &ret,
                .Inherit,
            ) catch break :blk version;
            break :blk try std.fmt.allocPrintZ(b.allocator, "{s}-{s}", .{
                version,
                mem.trim(u8, git_commit_hash, &std.ascii.spaces),

            var it = mem.split(u8, mem.trim(u8, git_describe_long, &std.ascii.spaces), "-");
            _ = it.next().?; // previous tag
            const commit_count = it.next().?;
            const commit_hash = it.next().?;
            assert(it.next() == null);
            assert(commit_hash[0] == 'g');

            // Follow semantic versioning, e.g. 0.2.0-dev.42+d1cf95b
            break :blk try std.fmt.allocPrintZ(b.allocator, version ++ ".{s}+{s}", .{
                commit_count,
                commit_hash[1..],
            });
        } else {
            break :blk version;