aboutsummaryrefslogtreecommitdiff
path: root/build.zig
diff options
context:
space:
mode:
authorJay Petacat <jay@jayschwa.net>2020-12-29 20:35:47 -0600
committerJay Petacat <jay@jayschwa.net>2020-12-29 23:25:58 -0600
commit4af763d401b48f7186650335c8e42e8fe29751bf (patch)
tree1d7738e9271540b145be4fb4eb5dfa79d194ce1a /build.zig
parent3634d44d08c73326c7783cf2a3095acb50eb2e1c (diff)
downloadzig-4af763d401b48f7186650335c8e42e8fe29751bf.tar.gz
zig-4af763d401b48f7186650335c8e42e8fe29751bf.zip
stage2: SemVer compliance for development builds
This matches the behavior of CMake builds. These changes should have been in PR #6509, but were missed.
Diffstat (limited to 'build.zig')
-rw-r--r--build.zig50
1 files changed, 34 insertions, 16 deletions
diff --git a/build.zig b/build.zig
index bef3b3b58f..197dd0bbed 100644
--- a/build.zig
+++ b/build.zig
@@ -11,7 +11,7 @@ const fs = std.fs;
const InstallDirectoryOptions = std.build.InstallDirectoryOptions;
const assert = std.debug.assert;
-const zig_version = std.builtin.Version{ .major = 0, .minor = 7, .patch = 1 };
+const zig_version = std.builtin.Version{ .major = 0, .minor = 8, .patch = 0 };
pub fn build(b: *Builder) !void {
b.setPreferredReleaseMode(.ReleaseFast);
@@ -227,24 +227,42 @@ pub fn build(b: *Builder) !void {
const version_string = b.fmt("{}.{}.{}", .{ zig_version.major, zig_version.minor, zig_version.patch });
var code: u8 = undefined;
- const git_sha_untrimmed = b.execAllowFail(&[_][]const u8{
- "git", "-C", b.build_root, "name-rev", "HEAD",
- "--tags", "--name-only", "--no-undefined", "--always",
+ const git_describe_untrimmed = b.execAllowFail(&[_][]const u8{
+ "git", "-C", b.build_root, "describe", "--match", "*.*.*", "--tags",
}, &code, .Ignore) catch {
break :v version_string;
};
- const git_sha_trimmed = mem.trim(u8, git_sha_untrimmed, " \n\r");
-
- // This will look like e.g. "0.7.0^0" for a tag commit.
- if (mem.endsWith(u8, git_sha_trimmed, "^0")) {
- const git_ver_string = git_sha_trimmed[0 .. git_sha_trimmed.len - 2];
- if (!mem.eql(u8, git_ver_string, version_string)) {
- std.debug.print("Expected git tag '{}', found '{}'\n", .{ version_string, git_ver_string });
- std.process.exit(1);
- }
- break :v b.fmt("{}", .{version_string});
- } else {
- break :v b.fmt("{}+{}", .{ version_string, git_sha_trimmed });
+ const git_describe = mem.trim(u8, git_describe_untrimmed, " \n\r");
+
+ switch (mem.count(u8, git_describe, "-")) {
+ 0 => {
+ // Tagged release version (e.g. 0.7.0).
+ if (!mem.eql(u8, git_describe, version_string)) {
+ std.debug.print("Zig version '{}' does not match Git tag '{}'\n", .{ version_string, git_describe });
+ std.process.exit(1);
+ }
+ break :v version_string;
+ },
+ 2 => {
+ // Untagged development build (e.g. 0.7.0-684-gbbe2cca1a).
+ var it = mem.split(git_describe, "-");
+ const tagged_ancestor = it.next() orelse unreachable;
+ const commit_height = it.next() orelse unreachable;
+ const commit_id = it.next() orelse unreachable;
+
+ const ancestor_ver = try std.builtin.Version.parse(tagged_ancestor);
+ if (zig_version.order(ancestor_ver) != .gt) {
+ std.debug.print("Zig version '{}' must be greater than tagged ancestor '{}'\n", .{ zig_version, ancestor_ver });
+ std.process.exit(1);
+ }
+
+ // The version is reformatted in accordance with the https://semver.org specification.
+ break :v b.fmt("{}-dev.{}+{}", .{ version_string, commit_height, commit_id });
+ },
+ else => {
+ std.debug.print("Failed to parse `git describe` output: {}\n", .{git_describe});
+ break :v version_string;
+ },
}
};
exe.addBuildOption([:0]const u8, "version", try b.allocator.dupeZ(u8, version));