From 2585075679cbdeb5e9bbbf67949c922571facdca Mon Sep 17 00:00:00 2001 From: yello Date: Mon, 5 Oct 2026 00:45:25 +0200 Subject: [PATCH 1/2] Take patch version from -Dversion argument --- build.zig | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/build.zig b/build.zig index d09ad38eba..3a4e44af27 100644 --- a/build.zig +++ b/build.zig @@ -157,17 +157,19 @@ pub fn build(b: *std.Build) !void { const options = b.addOptions(); const isRelease = b.option(bool, "release", "Removes the -dev flag from the version") orelse false; const sanitizeThread = b.option(bool, "sanitizeThread", "enables the builtin thread sanitizer"); - const version = b.fmt("0.5.0{s}", .{if (isRelease) "" else "-dev"}); - if (b.option([]const u8, "version", "used by the CI to check if the git tag and game version match")) |tagVersion| { + const baseMajor = 0; + const baseMinor = 5; + var patch: usize = 0; + if (b.option([]const u8, "version", "used by the CI to set the patch version, major and minor must match the ones in build.zig")) |tagVersion| { const tagVersionUpperbound: usize = std.mem.indexOfScalar(u8, tagVersion, '-') orelse tagVersion.len; - const versionUpperbound: usize = std.mem.indexOfScalar(u8, version, '-') orelse version.len; const tagParsed = try std.SemanticVersion.parse(tagVersion[0..tagVersionUpperbound]); - const versionParsed = try std.SemanticVersion.parse(version[0..versionUpperbound]); - if (std.SemanticVersion.order(tagParsed, versionParsed) != .eq) { - std.log.err("Provided version {s} does not match version in build.zig: {s}", .{tagVersion, version}); + if (tagParsed.major != baseMajor or tagParsed.minor != baseMinor) { + std.log.err("Provided version {s} does not match version in build.zig: {}.{}.x", .{tagVersion, baseMajor, baseMinor}); return error.VersionMismatch; } + patch = tagParsed.patch; } + const version = b.fmt("{}.{}.{}{s}", .{baseMajor, baseMinor, patch, if (isRelease) "" else "-dev"}); options.addOption([]const u8, "version", version); options.addOption(bool, "isTaggedRelease", isRelease); From 1d113721eff0e60cdc6ac17c6d72b63fba949436 Mon Sep 17 00:00:00 2001 From: yello Date: Wed, 7 Oct 2026 17:56:36 +0200 Subject: [PATCH 2/2] Use SemanticVersion for build version --- build.zig | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/build.zig b/build.zig index 3a4e44af27..5b18c51a16 100644 --- a/build.zig +++ b/build.zig @@ -157,20 +157,17 @@ pub fn build(b: *std.Build) !void { const options = b.addOptions(); const isRelease = b.option(bool, "release", "Removes the -dev flag from the version") orelse false; const sanitizeThread = b.option(bool, "sanitizeThread", "enables the builtin thread sanitizer"); - const baseMajor = 0; - const baseMinor = 5; - var patch: usize = 0; + var version = try std.SemanticVersion.parse("0.5.0"); if (b.option([]const u8, "version", "used by the CI to set the patch version, major and minor must match the ones in build.zig")) |tagVersion| { - const tagVersionUpperbound: usize = std.mem.indexOfScalar(u8, tagVersion, '-') orelse tagVersion.len; - const tagParsed = try std.SemanticVersion.parse(tagVersion[0..tagVersionUpperbound]); - if (tagParsed.major != baseMajor or tagParsed.minor != baseMinor) { - std.log.err("Provided version {s} does not match version in build.zig: {}.{}.x", .{tagVersion, baseMajor, baseMinor}); + const tagParsed = try std.SemanticVersion.parse(tagVersion); + if (tagParsed.major != version.major or tagParsed.minor != version.minor) { + std.log.err("Provided version {s} does not match version in build.zig: {f}", .{tagVersion, version}); return error.VersionMismatch; } - patch = tagParsed.patch; + version.patch = tagParsed.patch; } - const version = b.fmt("{}.{}.{}{s}", .{baseMajor, baseMinor, patch, if (isRelease) "" else "-dev"}); - options.addOption([]const u8, "version", version); + if (!isRelease) version.pre = "dev"; + options.addOption([]const u8, "version", b.fmt("{f}", .{version})); options.addOption(bool, "isTaggedRelease", isRelease); const useLocalDeps = b.option(bool, "local", "Use local cubyz_deps") orelse false;