version.zig

1.5 KB · raw

1const std = @import("std");2const builtin = @import("builtin");3const build_options = @import("build_options");45pub const VERSION = build_options.version;67pub const PLATFORM: []const u8 = switch (builtin.os.tag) {8    .macos => switch (builtin.cpu.arch) {9        .aarch64 => "macos-aarch64",10        .x86_64 => "macos-x86_64",11        else => "unsupported",12    },13    .linux => switch (builtin.cpu.arch) {14        .aarch64 => "linux-aarch64",15        .x86_64 => "linux-x86_64",16        else => "unsupported",17    },18    else => "unsupported",19};2021// NINA-018 drift guard: build.zig.zon's `.version` field is a hand-maintained22// fallback the kepr publishing pipeline uses if VERSION is ever lost, so it23// must never silently drift from the real VERSION file. build.zig.zon lives24// outside src/'s package boundary, so it's read at its build-time-baked25// absolute path (build_options.zon_path, same trick as man.zig's readme_path)26// rather than @embedFile'd.27test "build.zig.zon .version matches VERSION" {28    const gpa = std.testing.allocator;29    const zon = try std.Io.Dir.readFileAlloc(.cwd(), std.testing.io, build_options.zon_path, gpa, .unlimited);30    defer gpa.free(zon);3132    const needle = ".version = \"";33    const start = (std.mem.indexOf(u8, zon, needle) orelse34        return error.VersionFieldNotFound) + needle.len;35    const end = std.mem.indexOfScalarPos(u8, zon, start, '"') orelse36        return error.VersionFieldNotFound;37    const zon_version = zon[start..end];3839    try std.testing.expectEqualStrings(VERSION, zon_version);40}