From bcb295d9fa49d2bcd89f37c279bf6edbcd4255a4 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 28 Mar 2026 09:21:47 -0700 Subject: [PATCH] build: read version from VERSION file if available Read the app version from a VERSION file in the build root, trimming whitespace, and fall back to build.zig.zon if the file is not present. This allows source tarballs to carry a VERSION file as the source of truth for the version string. --- build.zig | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/build.zig b/build.zig index 9362eeb59..f95bc6f8b 100644 --- a/build.zig +++ b/build.zig @@ -3,7 +3,7 @@ const assert = std.debug.assert; const builtin = @import("builtin"); const buildpkg = @import("src/build/main.zig"); -const appVersion = @import("build.zig.zon").version; +const buildZonVersion = @import("build.zig.zon").version; const minimumZigVersion = @import("build.zig.zon").minimum_zig_version; comptime { @@ -15,7 +15,20 @@ pub fn build(b: *std.Build) !void { // want to know what options are available, you can run `--help` or // you can read `src/build/Config.zig`. - const config = try buildpkg.Config.init(b, appVersion); + // If we have a VERSION file (present in source tarballs) then we + // use that as the version source of truth. Otherwise we fall back + // to what is in the build.zig.zon. + const app_version: []const u8 = if (b.build_root.handle.readFileAlloc( + b.allocator, + "VERSION", + 128, + )) |content| std.mem.trim( + u8, + content, + &std.ascii.whitespace, + ) else |_| buildZonVersion; + + const config = try buildpkg.Config.init(b, app_version); const test_filters = b.option( [][]const u8, "test-filter",