| ... | @@ -11,7 +11,7 @@ const fs = std.fs; | ... | @@ -11,7 +11,7 @@ const fs = std.fs; |
| 11 | const InstallDirectoryOptions = std.build.InstallDirectoryOptions; | 11 | const InstallDirectoryOptions = std.build.InstallDirectoryOptions; |
| 12 | const assert = std.debug.assert; | 12 | const assert = std.debug.assert; |
| 13 | | 13 | |
| 14 | const zig_version = std.builtin.Version{ .major = 0, .minor = 7, .patch = 1 }; | 14 | const zig_version = std.builtin.Version{ .major = 0, .minor = 8, .patch = 0 }; |
| 15 | | 15 | |
| 16 | pub fn build(b: *Builder) !void { | 16 | pub fn build(b: *Builder) !void { |
| 17 | b.setPreferredReleaseMode(.ReleaseFast); | 17 | b.setPreferredReleaseMode(.ReleaseFast); |
| ... | @@ -227,24 +227,42 @@ pub fn build(b: *Builder) !void { | ... | @@ -227,24 +227,42 @@ pub fn build(b: *Builder) !void { |
| 227 | const version_string = b.fmt("{}.{}.{}", .{ zig_version.major, zig_version.minor, zig_version.patch }); | 227 | const version_string = b.fmt("{}.{}.{}", .{ zig_version.major, zig_version.minor, zig_version.patch }); |
| 228 | | 228 | |
| 229 | var code: u8 = undefined; | 229 | var code: u8 = undefined; |
| 230 | const git_sha_untrimmed = b.execAllowFail(&[_][]const u8{ | 230 | const git_describe_untrimmed = b.execAllowFail(&[_][]const u8{ |
| 231 | "git", "-C", b.build_root, "name-rev", "HEAD", | 231 | "git", "-C", b.build_root, "describe", "--match", "*.*.*", "--tags", |
| 232 | "--tags", "--name-only", "--no-undefined", "--always", | | |
| 233 | }, &code, .Ignore) catch { | 232 | }, &code, .Ignore) catch { |
| 234 | break :v version_string; | 233 | break :v version_string; |
| 235 | }; | 234 | }; |
| 236 | const git_sha_trimmed = mem.trim(u8, git_sha_untrimmed, " \n\r"); | 235 | const git_describe = mem.trim(u8, git_describe_untrimmed, " \n\r"); |
| 237 | | 236 | |
| 238 | // This will look like e.g. "0.7.0^0" for a tag commit. | 237 | switch (mem.count(u8, git_describe, "-")) { |
| 239 | if (mem.endsWith(u8, git_sha_trimmed, "^0")) { | 238 | 0 => { |
| 240 | const git_ver_string = git_sha_trimmed[0 .. git_sha_trimmed.len - 2]; | 239 | // Tagged release version (e.g. 0.7.0). |
| 241 | if (!mem.eql(u8, git_ver_string, version_string)) { | 240 | if (!mem.eql(u8, git_describe, version_string)) { |
| 242 | std.debug.print("Expected git tag '{}', found '{}'\n", .{ version_string, git_ver_string }); | 241 | std.debug.print("Zig version '{}' does not match Git tag '{}'\n", .{ version_string, git_describe }); |
| 243 | std.process.exit(1); | 242 | std.process.exit(1); |
| 244 | } | 243 | } |
| 245 | break :v b.fmt("{}", .{version_string}); | 244 | break :v version_string; |
| 246 | } else { | 245 | }, |
| 247 | break :v b.fmt("{}+{}", .{ version_string, git_sha_trimmed }); | 246 | 2 => { |
| | 247 | // Untagged development build (e.g. 0.7.0-684-gbbe2cca1a). |
| | 248 | var it = mem.split(git_describe, "-"); |
| | 249 | const tagged_ancestor = it.next() orelse unreachable; |
| | 250 | const commit_height = it.next() orelse unreachable; |
| | 251 | const commit_id = it.next() orelse unreachable; |
| | 252 | |
| | 253 | const ancestor_ver = try std.builtin.Version.parse(tagged_ancestor); |
| | 254 | if (zig_version.order(ancestor_ver) != .gt) { |
| | 255 | std.debug.print("Zig version '{}' must be greater than tagged ancestor '{}'\n", .{ zig_version, ancestor_ver }); |
| | 256 | std.process.exit(1); |
| | 257 | } |
| | 258 | |
| | 259 | // The version is reformatted in accordance with the https://semver.org specification. |
| | 260 | break :v b.fmt("{}-dev.{}+{}", .{ version_string, commit_height, commit_id }); |
| | 261 | }, |
| | 262 | else => { |
| | 263 | std.debug.print("Failed to parse `git describe` output: {}\n", .{git_describe}); |
| | 264 | break :v version_string; |
| | 265 | }, |
| 248 | } | 266 | } |
| 249 | }; | 267 | }; |
| 250 | exe.addBuildOption([:0]const u8, "version", try b.allocator.dupeZ(u8, version)); | 268 | exe.addBuildOption([:0]const u8, "version", try b.allocator.dupeZ(u8, version)); |