diff options
| author | Jay Petacat <jay@jayschwa.net> | 2021-01-04 23:48:34 -0500 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2021-01-09 12:50:39 -0800 |
| commit | a0ad2dee6a0b3bb7fd04032f6113206f7b4e73eb (patch) | |
| tree | 3af35b3737044d92a507541684e240be9f86d64d /lib/std/SemanticVersion.zig | |
| parent | 5c49a137d5948310d8abbf9d6f1fb899e7122239 (diff) | |
| download | zig-a0ad2dee6a0b3bb7fd04032f6113206f7b4e73eb.tar.gz zig-a0ad2dee6a0b3bb7fd04032f6113206f7b4e73eb.zip | |
builtin: Add zig_version
This will enable code to perform version checks and make it easier to
support multiple versions of Zig.
Within the SemVer implementation, an intermediate value needed to be
coerced to a slice to workaround a comptime bug.
Closes #6466
Diffstat (limited to 'lib/std/SemanticVersion.zig')
| -rw-r--r-- | lib/std/SemanticVersion.zig | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/lib/std/SemanticVersion.zig b/lib/std/SemanticVersion.zig index dc9e6d8572..76767de8b5 100644 --- a/lib/std/SemanticVersion.zig +++ b/lib/std/SemanticVersion.zig @@ -102,7 +102,7 @@ pub fn parse(text: []const u8) !Version { if (extra_index == null) return ver; // Slice optional pre-release or build metadata components. - const extra = text[extra_index.?..text.len]; + const extra: []const u8 = text[extra_index.?..text.len]; if (extra[0] == '-') { const build_index = std.mem.indexOfScalar(u8, extra, '+'); ver.pre = extra[1..(build_index orelse extra.len)]; @@ -293,3 +293,12 @@ fn testFmt(expected: []const u8, comptime template: []const u8, args: anytype) ! std.debug.warn("\n======================================\n", .{}); return error.TestFailed; } + +test "zig_version" { + // An approximate Zig build that predates this test. + const older_version = .{ .major = 0, .minor = 8, .patch = 0, .pre = "dev.874" }; + + // Simulated compatibility check using Zig version. + const compatible = comptime @import("builtin").zig_version.order(older_version) == .gt; + if (!compatible) @compileError("zig_version test failed"); +} |
