authorgravatar for r00ster91@proton.meWooster <r00ster91@proton.me> 2023-02-21 18:39:22+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-06-17 13:17:34-07:00
log6e84f469904a24615a6721265a88ad8dcb4ed83a
treed390e7738b996686749adbbd9a1c18f647058b3b
parent96acc204b2c6080f0169ca3721c3b95a433c185b

std: replace builtin.Version with SemanticVersion


34 files changed, 189 insertions(+), 280 deletions(-)

build.zig+2-2
......@@ -9,7 +9,7 @@ const fs = std.fs;
99const InstallDirectoryOptions = std.Build.InstallDirectoryOptions;
1010const assert = std.debug.assert;
1111
12const zig_version = std.builtin.Version{ .major = 0, .minor = 11, .patch = 0 };
12const zig_version = std.SemanticVersion{ .major = 0, .minor = 11, .patch = 0 };
1313const stack_size = 32 * 1024 * 1024;
1414
1515pub fn build(b: *std.Build) !void {
......@@ -242,7 +242,7 @@ pub fn build(b: *std.Build) !void {
242242 const commit_height = it.next().?;
243243 const commit_id = it.next().?;
244244
245 const ancestor_ver = try std.builtin.Version.parse(tagged_ancestor);
245 const ancestor_ver = try std.SemanticVersion.parse(tagged_ancestor);
246246 if (zig_version.order(ancestor_ver) != .gt) {
247247 std.debug.print("Zig version '{}' must be greater than tagged ancestor '{}'\n", .{ zig_version, ancestor_ver });
248248 std.process.exit(1);
lib/std/Build.zig+4-4
......@@ -472,7 +472,7 @@ pub fn addOptions(self: *Build) *Step.Options {
472472pub const ExecutableOptions = struct {
473473 name: []const u8,
474474 root_source_file: ?FileSource = null,
475 version: ?std.builtin.Version = null,
475 version: ?std.SemanticVersion = null,
476476 target: CrossTarget = .{},
477477 optimize: std.builtin.Mode = .Debug,
478478 linkage: ?Step.Compile.Linkage = null,
......@@ -530,7 +530,7 @@ pub fn addObject(b: *Build, options: ObjectOptions) *Step.Compile {
530530pub const SharedLibraryOptions = struct {
531531 name: []const u8,
532532 root_source_file: ?FileSource = null,
533 version: ?std.builtin.Version = null,
533 version: ?std.SemanticVersion = null,
534534 target: CrossTarget,
535535 optimize: std.builtin.Mode,
536536 max_rss: usize = 0,
......@@ -562,7 +562,7 @@ pub const StaticLibraryOptions = struct {
562562 root_source_file: ?FileSource = null,
563563 target: CrossTarget,
564564 optimize: std.builtin.Mode,
565 version: ?std.builtin.Version = null,
565 version: ?std.SemanticVersion = null,
566566 max_rss: usize = 0,
567567 link_libc: ?bool = null,
568568 single_threaded: ?bool = null,
......@@ -592,7 +592,7 @@ pub const TestOptions = struct {
592592 root_source_file: FileSource,
593593 target: CrossTarget = .{},
594594 optimize: std.builtin.Mode = .Debug,
595 version: ?std.builtin.Version = null,
595 version: ?std.SemanticVersion = null,
596596 max_rss: usize = 0,
597597 filter: ?[]const u8 = null,
598598 test_runner: ?[]const u8 = null,
lib/std/Build/Cache.zig+1-1
......@@ -212,7 +212,7 @@ pub const HashHelper = struct {
212212 /// Convert the input value into bytes and record it as a dependency of the process being cached.
213213 pub fn add(hh: *HashHelper, x: anytype) void {
214214 switch (@TypeOf(x)) {
215 std.builtin.Version => {
215 std.SemanticVersion => {
216216 hh.add(x.major);
217217 hh.add(x.minor);
218218 hh.add(x.patch);
lib/std/Build/Step/Compile.zig+2-2
......@@ -32,7 +32,7 @@ linker_script: ?FileSource = null,
3232version_script: ?[]const u8 = null,
3333out_filename: []const u8,
3434linkage: ?Linkage = null,
35version: ?std.builtin.Version,
35version: ?std.SemanticVersion,
3636kind: Kind,
3737major_only_filename: ?[]const u8,
3838name_only_filename: ?[]const u8,
......@@ -278,7 +278,7 @@ pub const Options = struct {
278278 optimize: std.builtin.Mode,
279279 kind: Kind,
280280 linkage: ?Linkage = null,
281 version: ?std.builtin.Version = null,
281 version: ?std.SemanticVersion = null,
282282 max_rss: usize = 0,
283283 filter: ?[]const u8 = null,
284284 test_runner: ?[]const u8 = null,
lib/std/Build/Step/Options.zig-23
......@@ -76,23 +76,6 @@ fn addOptionFallible(self: *Options, comptime T: type, name: []const u8, value:
7676 }
7777 return;
7878 },
79 std.builtin.Version => {
80 try out.print(
81 \\pub const {}: @import("std").builtin.Version = .{{
82 \\ .major = {d},
83 \\ .minor = {d},
84 \\ .patch = {d},
85 \\}};
86 \\
87 , .{
88 std.zig.fmtId(name),
89
90 value.major,
91 value.minor,
92 value.patch,
93 });
94 return;
95 },
9679 std.SemanticVersion => {
9780 try out.print(
9881 \\pub const {}: @import("std").SemanticVersion = .{{
......@@ -367,7 +350,6 @@ test Options {
367350 options.addOption([2][2]u16, "nested_array", nested_array);
368351 options.addOption([]const []const u16, "nested_slice", nested_slice);
369352 //options.addOption(KeywordEnum, "keyword_enum", .@"0.8.1");
370 options.addOption(std.builtin.Version, "version", try std.builtin.Version.parse("0.1.2"));
371353 options.addOption(std.SemanticVersion, "semantic_version", try std.SemanticVersion.parse("0.1.2-foo+bar"));
372354
373355 try std.testing.expectEqualStrings(
......@@ -401,11 +383,6 @@ test Options {
401383 //\\ @"0.8.1",
402384 //\\};
403385 //\\pub const keyword_enum: KeywordEnum = KeywordEnum.@"0.8.1";
404 \\pub const version: @import("std").builtin.Version = .{
405 \\ .major = 0,
406 \\ .minor = 1,
407 \\ .patch = 2,
408 \\};
409386 \\pub const semantic_version: @import("std").SemanticVersion = .{
410387 \\ .major = 0,
411388 \\ .minor = 1,
lib/std/Build/Step/TranslateC.zig+1-1
......@@ -47,7 +47,7 @@ pub fn create(owner: *std.Build, options: Options) *TranslateC {
4747
4848pub const AddExecutableOptions = struct {
4949 name: ?[]const u8 = null,
50 version: ?std.builtin.Version = null,
50 version: ?std.SemanticVersion = null,
5151 target: ?CrossTarget = null,
5252 optimize: ?std.builtin.Mode = null,
5353 linkage: ?Step.Compile.Linkage = null,
lib/std/SemanticVersion.zig+22-2
......@@ -1,4 +1,4 @@
1//! A software version formatted according to the Semantic Version 2 specification.
1//! A software version formatted according to the Semantic Versioning 2.0.0 specification.
22//!
33//! See: https://semver.org
44
......@@ -167,7 +167,7 @@ const expect = std.testing.expect;
167167const expectError = std.testing.expectError;
168168
169169test "SemanticVersion format" {
170 // Test vectors are from https://github.com/semver/semver.org/issues/59#issuecomment-390854010.
170 // Many of these test strings are from https://github.com/semver/semver.org/issues/59#issuecomment-390854010.
171171
172172 // Valid version strings should be accepted.
173173 for ([_][]const u8{
......@@ -200,6 +200,8 @@ test "SemanticVersion format" {
200200 "1.2.3----R-S.12.9.1--.12+meta",
201201 "1.2.3----RC-SNAPSHOT.12.9.1--.12",
202202 "1.0.0+0.build.1-rc.10000aaa-kk-0.1",
203 "5.4.0-1018-raspi",
204 "5.7.123",
203205 }) |valid| try std.testing.expectFmt(valid, "{}", .{try parse(valid)});
204206
205207 // Invalid version strings should be rejected.
......@@ -244,6 +246,24 @@ test "SemanticVersion format" {
244246 "+justmeta",
245247 "9.8.7+meta+meta",
246248 "9.8.7-whatever+meta+meta",
249 "2.6.32.11-svn21605",
250 "2.11.2(0.329/5/3)",
251 "2.13-DEVELOPMENT",
252 "2.3-35",
253 "1a.4",
254 "3.b1.0",
255 "1.4beta",
256 "2.7.pre",
257 "0..3",
258 "8.008.",
259 "01...",
260 "55",
261 "foobar",
262 "",
263 "-1",
264 "+4",
265 ".",
266 "....3",
247267 }) |invalid| try expectError(error.InvalidVersion, parse(invalid));
248268
249269 // Valid version string that may overflow.
lib/std/builtin.zig-133
......@@ -483,139 +483,6 @@ pub const WasiExecModel = enum {
483483 reactor,
484484};
485485
486/// This data structure is used by the Zig language code generation and
487/// therefore must be kept in sync with the compiler implementation.
488pub const Version = struct {
489 major: u32,
490 minor: u32,
491 patch: u32 = 0,
492
493 pub const Range = struct {
494 min: Version,
495 max: Version,
496
497 pub fn includesVersion(self: Range, ver: Version) bool {
498 if (self.min.order(ver) == .gt) return false;
499 if (self.max.order(ver) == .lt) return false;
500 return true;
501 }
502
503 /// Checks if system is guaranteed to be at least `version` or older than `version`.
504 /// Returns `null` if a runtime check is required.
505 pub fn isAtLeast(self: Range, ver: Version) ?bool {
506 if (self.min.order(ver) != .lt) return true;
507 if (self.max.order(ver) == .lt) return false;
508 return null;
509 }
510 };
511
512 pub fn order(lhs: Version, rhs: Version) std.math.Order {
513 if (lhs.major < rhs.major) return .lt;
514 if (lhs.major > rhs.major) return .gt;
515 if (lhs.minor < rhs.minor) return .lt;
516 if (lhs.minor > rhs.minor) return .gt;
517 if (lhs.patch < rhs.patch) return .lt;
518 if (lhs.patch > rhs.patch) return .gt;
519 return .eq;
520 }
521
522 pub fn parse(text: []const u8) !Version {
523 var end: usize = 0;
524 while (end < text.len) : (end += 1) {
525 const c = text[end];
526 if (!std.ascii.isDigit(c) and c != '.') break;
527 }
528 // found no digits or '.' before unexpected character
529 if (end == 0) return error.InvalidVersion;
530
531 var it = std.mem.splitScalar(u8, text[0..end], '.');
532 // substring is not empty, first call will succeed
533 const major = it.first();
534 if (major.len == 0) return error.InvalidVersion;
535 const minor = it.next() orelse "0";
536 // ignore 'patch' if 'minor' is invalid
537 const patch = if (minor.len == 0) "0" else (it.next() orelse "0");
538
539 return Version{
540 .major = try std.fmt.parseUnsigned(u32, major, 10),
541 .minor = try std.fmt.parseUnsigned(u32, if (minor.len == 0) "0" else minor, 10),
542 .patch = try std.fmt.parseUnsigned(u32, if (patch.len == 0) "0" else patch, 10),
543 };
544 }
545
546 pub fn format(
547 self: Version,
548 comptime fmt: []const u8,
549 options: std.fmt.FormatOptions,
550 out_stream: anytype,
551 ) !void {
552 _ = options;
553 if (fmt.len == 0) {
554 if (self.patch == 0) {
555 if (self.minor == 0) {
556 return std.fmt.format(out_stream, "{d}", .{self.major});
557 } else {
558 return std.fmt.format(out_stream, "{d}.{d}", .{ self.major, self.minor });
559 }
560 } else {
561 return std.fmt.format(out_stream, "{d}.{d}.{d}", .{ self.major, self.minor, self.patch });
562 }
563 } else {
564 std.fmt.invalidFmtError(fmt, self);
565 }
566 }
567};
568
569test "Version.parse" {
570 @setEvalBranchQuota(3000);
571 try testVersionParse();
572 comptime (try testVersionParse());
573}
574
575fn testVersionParse() !void {
576 const f = struct {
577 fn eql(text: []const u8, v1: u32, v2: u32, v3: u32) !void {
578 const v = try Version.parse(text);
579 try std.testing.expect(v.major == v1 and v.minor == v2 and v.patch == v3);
580 }
581
582 fn err(text: []const u8, expected_err: anyerror) !void {
583 _ = Version.parse(text) catch |actual_err| {
584 if (actual_err == expected_err) return;
585 return actual_err;
586 };
587 return error.Unreachable;
588 }
589 };
590
591 try f.eql("2.6.32.11-svn21605", 2, 6, 32); // Debian PPC
592 try f.eql("2.11.2(0.329/5/3)", 2, 11, 2); // MinGW
593 try f.eql("5.4.0-1018-raspi", 5, 4, 0); // Ubuntu
594 try f.eql("5.7.12_3", 5, 7, 12); // Void
595 try f.eql("2.13-DEVELOPMENT", 2, 13, 0); // DragonFly
596 try f.eql("2.3-35", 2, 3, 0);
597 try f.eql("1a.4", 1, 0, 0);
598 try f.eql("3.b1.0", 3, 0, 0);
599 try f.eql("1.4beta", 1, 4, 0);
600 try f.eql("2.7.pre", 2, 7, 0);
601 try f.eql("0..3", 0, 0, 0);
602 try f.eql("8.008.", 8, 8, 0);
603 try f.eql("01...", 1, 0, 0);
604 try f.eql("55", 55, 0, 0);
605 try f.eql("4294967295.0.1", 4294967295, 0, 1);
606 try f.eql("429496729_6", 429496729, 0, 0);
607
608 try f.err("foobar", error.InvalidVersion);
609 try f.err("", error.InvalidVersion);
610 try f.err("-1", error.InvalidVersion);
611 try f.err("+4", error.InvalidVersion);
612 try f.err(".", error.InvalidVersion);
613 try f.err("....3", error.InvalidVersion);
614 try f.err("4294967296", error.Overflow);
615 try f.err("5000877755", error.Overflow);
616 // error.InvalidCharacter is not possible anymore
617}
618
619486/// This data structure is used by the Zig language code generation and
620487/// therefore must be kept in sync with the compiler implementation.
621488pub const CallModifier = enum {
lib/std/c.zig+1-1
......@@ -20,7 +20,7 @@ pub const Tokenizer = tokenizer.Tokenizer;
2020/// If linking gnu libc (glibc), the `ok` value will be true if the target
2121/// version is greater than or equal to `glibc_version`.
2222/// If linking a libc other than these, returns `false`.
23pub fn versionCheck(comptime glibc_version: std.builtin.Version) type {
23pub fn versionCheck(comptime glibc_version: std.SemanticVersion) type {
2424 return struct {
2525 pub const ok = blk: {
2626 if (!builtin.link_libc) break :blk false;
lib/std/crypto/tlcsprng.zig+1
......@@ -38,6 +38,7 @@ const want_fork_safety = os_has_fork and !os_has_arc4random and
3838const maybe_have_wipe_on_fork = builtin.os.isAtLeast(.linux, .{
3939 .major = 4,
4040 .minor = 14,
41 .patch = 0,
4142}) orelse true;
4243const is_haiku = builtin.os.tag == .haiku;
4344
lib/std/os.zig+9-9
......@@ -488,7 +488,7 @@ pub fn getrandom(buffer: []u8) GetRandomError!void {
488488 if (builtin.os.tag == .linux or builtin.os.tag == .freebsd) {
489489 var buf = buffer;
490490 const use_c = builtin.os.tag != .linux or
491 std.c.versionCheck(std.builtin.Version{ .major = 2, .minor = 25, .patch = 0 }).ok;
491 std.c.versionCheck(std.SemanticVersion{ .major = 2, .minor = 25, .patch = 0 }).ok;
492492
493493 while (buf.len != 0) {
494494 const res = if (use_c) blk: {
......@@ -5272,7 +5272,7 @@ pub fn getFdPath(fd: fd_t, out_buffer: *[MAX_PATH_BYTES]u8) RealPathError![]u8 {
52725272 return target;
52735273 },
52745274 .freebsd => {
5275 if (comptime builtin.os.version_range.semver.max.order(.{ .major = 13, .minor = 0 }) == .gt) {
5275 if (comptime builtin.os.version_range.semver.max.order(.{ .major = 13, .minor = 0, .patch = 0 }) == .gt) {
52765276 var kfile: system.kinfo_file = undefined;
52775277 kfile.structsize = system.KINFO_FILE_SIZE;
52785278 switch (errno(system.fcntl(fd, system.F.KINFO, @ptrToInt(&kfile)))) {
......@@ -5325,7 +5325,7 @@ pub fn getFdPath(fd: fd_t, out_buffer: *[MAX_PATH_BYTES]u8) RealPathError![]u8 {
53255325 }
53265326 },
53275327 .dragonfly => {
5328 if (comptime builtin.os.version_range.semver.max.order(.{ .major = 6, .minor = 0 }) == .lt) {
5328 if (comptime builtin.os.version_range.semver.max.order(.{ .major = 6, .minor = 0, .patch = 0 }) == .lt) {
53295329 @compileError("querying for canonical path of a handle is unsupported on this host");
53305330 }
53315331 @memset(out_buffer[0..MAX_PATH_BYTES], 0);
......@@ -5339,7 +5339,7 @@ pub fn getFdPath(fd: fd_t, out_buffer: *[MAX_PATH_BYTES]u8) RealPathError![]u8 {
53395339 return out_buffer[0..len];
53405340 },
53415341 .netbsd => {
5342 if (comptime builtin.os.version_range.semver.max.order(.{ .major = 10, .minor = 0 }) == .lt) {
5342 if (comptime builtin.os.version_range.semver.max.order(.{ .major = 10, .minor = 0, .patch = 0 }) == .lt) {
53435343 @compileError("querying for canonical path of a handle is unsupported on this host");
53445344 }
53455345 @memset(out_buffer[0..MAX_PATH_BYTES], 0);
......@@ -6152,9 +6152,9 @@ pub fn sendfile(
61526152 .linux => sf: {
61536153 // sendfile() first appeared in Linux 2.2, glibc 2.1.
61546154 const call_sf = comptime if (builtin.link_libc)
6155 std.c.versionCheck(.{ .major = 2, .minor = 1 }).ok
6155 std.c.versionCheck(.{ .major = 2, .minor = 1, .patch = 0 }).ok
61566156 else
6157 builtin.os.version_range.linux.range.max.order(.{ .major = 2, .minor = 2 }) != .lt;
6157 builtin.os.version_range.linux.range.max.order(.{ .major = 2, .minor = 2, .patch = 0 }) != .lt;
61586158 if (!call_sf) break :sf;
61596159
61606160 if (headers.len != 0) {
......@@ -6453,8 +6453,8 @@ var has_copy_file_range_syscall = std.atomic.Atomic(bool).init(true);
64536453///
64546454/// Maximum offsets on Linux and FreeBSD are `math.maxInt(i64)`.
64556455pub fn copy_file_range(fd_in: fd_t, off_in: u64, fd_out: fd_t, off_out: u64, len: usize, flags: u32) CopyFileRangeError!usize {
6456 if ((comptime builtin.os.isAtLeast(.freebsd, .{ .major = 13, .minor = 0 }) orelse false) or
6457 ((comptime builtin.os.isAtLeast(.linux, .{ .major = 4, .minor = 5 }) orelse false and
6456 if ((comptime builtin.os.isAtLeast(.freebsd, .{ .major = 13, .minor = 0, .patch = 0 }) orelse false) or
6457 ((comptime builtin.os.isAtLeast(.linux, .{ .major = 4, .minor = 5, .patch = 0 }) orelse false and
64586458 std.c.versionCheck(.{ .major = 2, .minor = 27, .patch = 0 }).ok) and
64596459 has_copy_file_range_syscall.load(.Monotonic)))
64606460 {
......@@ -6787,7 +6787,7 @@ pub fn memfd_createZ(name: [*:0]const u8, flags: u32) MemFdCreateError!fd_t {
67876787 }
67886788 },
67896789 .freebsd => {
6790 if (comptime builtin.os.version_range.semver.max.order(.{ .major = 13, .minor = 0 }) == .lt)
6790 if (comptime builtin.os.version_range.semver.max.order(.{ .major = 13, .minor = 0, .patch = 0 }) == .lt)
67916791 @compileError("memfd_create is unavailable on FreeBSD < 13.0");
67926792 const rc = system.memfd_create(name, flags);
67936793 switch (errno(rc)) {
lib/std/os/test.zig+1-1
......@@ -541,7 +541,7 @@ test "memfd_create" {
541541 switch (native_os) {
542542 .linux => {},
543543 .freebsd => {
544 if (comptime builtin.os.version_range.semver.max.order(.{ .major = 13, .minor = 0 }) == .lt)
544 if (comptime builtin.os.version_range.semver.max.order(.{ .major = 13, .minor = 0, .patch = 0 }) == .lt)
545545 return error.SkipZigTest;
546546 },
547547 else => return error.SkipZigTest,
lib/std/target.zig+18-18
......@@ -1,7 +1,7 @@
11const std = @import("std.zig");
22const builtin = @import("builtin");
33const mem = std.mem;
4const Version = std.builtin.Version;
4const Version = std.SemanticVersion;
55
66/// TODO Nearly all the functions in this namespace would be
77/// better off if https://github.com/ziglang/zig/issues/425
......@@ -272,75 +272,75 @@ pub const Target = struct {
272272
273273 .freebsd => return .{
274274 .semver = Version.Range{
275 .min = .{ .major = 12, .minor = 0 },
276 .max = .{ .major = 13, .minor = 1 },
275 .min = .{ .major = 12, .minor = 0, .patch = 0 },
276 .max = .{ .major = 13, .minor = 1, .patch = 0 },
277277 },
278278 },
279279 .macos => return switch (arch) {
280280 .aarch64 => VersionRange{
281281 .semver = .{
282282 .min = .{ .major = 11, .minor = 7, .patch = 1 },
283 .max = .{ .major = 13, .minor = 3 },
283 .max = .{ .major = 13, .minor = 3, .patch = 0 },
284284 },
285285 },
286286 .x86_64 => VersionRange{
287287 .semver = .{
288288 .min = .{ .major = 11, .minor = 7, .patch = 1 },
289 .max = .{ .major = 13, .minor = 3 },
289 .max = .{ .major = 13, .minor = 3, .patch = 0 },
290290 },
291291 },
292292 else => unreachable,
293293 },
294294 .ios => return .{
295295 .semver = .{
296 .min = .{ .major = 12, .minor = 0 },
296 .min = .{ .major = 12, .minor = 0, .patch = 0 },
297297 .max = .{ .major = 13, .minor = 4, .patch = 0 },
298298 },
299299 },
300300 .watchos => return .{
301301 .semver = .{
302 .min = .{ .major = 6, .minor = 0 },
302 .min = .{ .major = 6, .minor = 0, .patch = 0 },
303303 .max = .{ .major = 6, .minor = 2, .patch = 0 },
304304 },
305305 },
306306 .tvos => return .{
307307 .semver = .{
308 .min = .{ .major = 13, .minor = 0 },
308 .min = .{ .major = 13, .minor = 0, .patch = 0 },
309309 .max = .{ .major = 13, .minor = 4, .patch = 0 },
310310 },
311311 },
312312 .netbsd => return .{
313313 .semver = .{
314 .min = .{ .major = 8, .minor = 0 },
315 .max = .{ .major = 10, .minor = 0 },
314 .min = .{ .major = 8, .minor = 0, .patch = 0 },
315 .max = .{ .major = 10, .minor = 0, .patch = 0 },
316316 },
317317 },
318318 .openbsd => return .{
319319 .semver = .{
320 .min = .{ .major = 6, .minor = 8 },
321 .max = .{ .major = 7, .minor = 2 },
320 .min = .{ .major = 6, .minor = 8, .patch = 0 },
321 .max = .{ .major = 7, .minor = 2, .patch = 0 },
322322 },
323323 },
324324 .dragonfly => return .{
325325 .semver = .{
326 .min = .{ .major = 5, .minor = 8 },
327 .max = .{ .major = 6, .minor = 4 },
326 .min = .{ .major = 5, .minor = 8, .patch = 0 },
327 .max = .{ .major = 6, .minor = 4, .patch = 0 },
328328 },
329329 },
330330 .solaris => return .{
331331 .semver = .{
332 .min = .{ .major = 5, .minor = 11 },
333 .max = .{ .major = 5, .minor = 11 },
332 .min = .{ .major = 5, .minor = 11, .patch = 0 },
333 .max = .{ .major = 5, .minor = 11, .patch = 0 },
334334 },
335335 },
336336
337337 .linux => return .{
338338 .linux = .{
339339 .range = .{
340 .min = .{ .major = 3, .minor = 16 },
340 .min = .{ .major = 3, .minor = 16, .patch = 0 },
341341 .max = .{ .major = 5, .minor = 10, .patch = 81 },
342342 },
343 .glibc = .{ .major = 2, .minor = 19 },
343 .glibc = .{ .major = 2, .minor = 19, .patch = 0 },
344344 },
345345 },
346346
lib/std/zig.zig+1-1
......@@ -108,7 +108,7 @@ pub const BinNameOptions = struct {
108108 target: std.Target,
109109 output_mode: std.builtin.OutputMode,
110110 link_mode: ?std.builtin.LinkMode = null,
111 version: ?std.builtin.Version = null,
111 version: ?std.SemanticVersion = null,
112112};
113113
114114/// Returns the standard file system basename of a binary generated by the Zig compiler.
lib/std/zig/CrossTarget.zig+52-13
......@@ -33,7 +33,7 @@ os_version_max: ?OsVersion = null,
3333
3434/// `null` means default when cross compiling, or native when os_tag is native.
3535/// If `isGnuLibC()` is `false`, this must be `null` and is ignored.
36glibc_version: ?SemVer = null,
36glibc_version: ?SemanticVersion = null,
3737
3838/// `null` means the native C ABI, if `os_tag` is native, otherwise it means the default C ABI.
3939abi: ?Target.Abi = null,
......@@ -61,11 +61,11 @@ pub const CpuModel = union(enum) {
6161
6262pub const OsVersion = union(enum) {
6363 none: void,
64 semver: SemVer,
64 semver: SemanticVersion,
6565 windows: Target.Os.WindowsVersion,
6666};
6767
68pub const SemVer = std.builtin.Version;
68pub const SemanticVersion = std.SemanticVersion;
6969
7070pub const DynamicLinker = Target.DynamicLinker;
7171
......@@ -266,9 +266,8 @@ pub fn parse(args: ParseOptions) !CrossTarget {
266266 const abi_ver_text = abi_it.rest();
267267 if (abi_it.next() != null) {
268268 if (result.isGnuLibC()) {
269 result.glibc_version = SemVer.parse(abi_ver_text) catch |err| switch (err) {
269 result.glibc_version = parseVersion(abi_ver_text) catch |err| switch (err) {
270270 error.Overflow => return error.InvalidAbiVersion,
271 error.InvalidCharacter => return error.InvalidAbiVersion,
272271 error.InvalidVersion => return error.InvalidAbiVersion,
273272 };
274273 } else {
......@@ -353,6 +352,31 @@ pub fn parseCpuArch(args: ParseOptions) ?Target.Cpu.Arch {
353352 }
354353}
355354
355/// Parses a version with an omitted patch component, such as "1.0",
356/// which SemanticVersion.parse is not capable of.
357fn parseVersion(ver: []const u8) !SemanticVersion {
358 const parseVersionComponent = struct {
359 fn parseVersionComponent(component: []const u8) !usize {
360 return std.fmt.parseUnsigned(usize, component, 10) catch |err| {
361 switch (err) {
362 error.InvalidCharacter => return error.InvalidVersion,
363 error.Overflow => return error.Overflow,
364 }
365 };
366 }
367 }.parseVersionComponent;
368 var version_components = mem.split(u8, ver, ".");
369 const major = version_components.first();
370 const minor = version_components.next() orelse return error.InvalidVersion;
371 const patch = version_components.next() orelse "0";
372 if (version_components.next() != null) return error.InvalidVersion;
373 return .{
374 .major = try parseVersionComponent(major),
375 .minor = try parseVersionComponent(minor),
376 .patch = try parseVersionComponent(patch),
377 };
378}
379
356380/// TODO deprecated, use `std.zig.system.NativeTargetInfo.detect`.
357381pub fn getCpu(self: CrossTarget) Target.Cpu {
358382 switch (self.cpu_model) {
......@@ -534,6 +558,16 @@ pub fn isNative(self: CrossTarget) bool {
534558 return self.isNativeCpu() and self.isNativeOs() and self.isNativeAbi();
535559}
536560
561/// Formats a version with the patch component omitted if it is zero,
562/// unlike SemanticVersion.format which formats all its version components regardless.
563fn formatVersion(version: SemanticVersion, writer: anytype) !void {
564 if (version.patch == 0) {
565 try writer.print("{d}.{d}", .{ version.major, version.minor });
566 } else {
567 try writer.print("{d}.{d}.{d}", .{ version.major, version.minor, version.patch });
568 }
569}
570
537571pub fn zigTriple(self: CrossTarget, allocator: mem.Allocator) error{OutOfMemory}![]u8 {
538572 if (self.isNative()) {
539573 return allocator.dupe(u8, "native");
......@@ -552,20 +586,27 @@ pub fn zigTriple(self: CrossTarget, allocator: mem.Allocator) error{OutOfMemory}
552586 if (self.os_version_min != null or self.os_version_max != null) {
553587 switch (self.getOsVersionMin()) {
554588 .none => {},
555 .semver => |v| try result.writer().print(".{}", .{v}),
589 .semver => |v| {
590 try result.writer().writeAll(".");
591 try formatVersion(v, result.writer());
592 },
556593 .windows => |v| try result.writer().print("{s}", .{v}),
557594 }
558595 }
559596 if (self.os_version_max) |max| {
560597 switch (max) {
561598 .none => {},
562 .semver => |v| try result.writer().print("...{}", .{v}),
599 .semver => |v| {
600 try result.writer().writeAll("...");
601 try formatVersion(v, result.writer());
602 },
563603 .windows => |v| try result.writer().print("..{s}", .{v}),
564604 }
565605 }
566606
567607 if (self.glibc_version) |v| {
568 try result.writer().print("-{s}.{}", .{ @tagName(self.getAbi()), v });
608 try result.writer().print("-{s}.", .{@tagName(self.getAbi())});
609 try formatVersion(v, result.writer());
569610 } else if (self.abi) |abi| {
570611 try result.writer().print("-{s}", .{@tagName(abi)});
571612 }
......@@ -630,7 +671,7 @@ pub fn isGnuLibC(self: CrossTarget) bool {
630671
631672pub fn setGnuLibCVersion(self: *CrossTarget, major: u32, minor: u32, patch: u32) void {
632673 assert(self.isGnuLibC());
633 self.glibc_version = SemVer{ .major = major, .minor = minor, .patch = patch };
674 self.glibc_version = SemanticVersion{ .major = major, .minor = minor, .patch = patch };
634675}
635676
636677pub fn getObjectFormat(self: CrossTarget) Target.ObjectFormat {
......@@ -709,17 +750,15 @@ fn parseOs(result: *CrossTarget, diags: *ParseOptions.Diagnostics, text: []const
709750 var range_it = mem.splitSequence(u8, version_text, "...");
710751
711752 const min_text = range_it.next().?;
712 const min_ver = SemVer.parse(min_text) catch |err| switch (err) {
753 const min_ver = parseVersion(min_text) catch |err| switch (err) {
713754 error.Overflow => return error.InvalidOperatingSystemVersion,
714 error.InvalidCharacter => return error.InvalidOperatingSystemVersion,
715755 error.InvalidVersion => return error.InvalidOperatingSystemVersion,
716756 };
717757 result.os_version_min = .{ .semver = min_ver };
718758
719759 const max_text = range_it.next() orelse return;
720 const max_ver = SemVer.parse(max_text) catch |err| switch (err) {
760 const max_ver = parseVersion(max_text) catch |err| switch (err) {
721761 error.Overflow => return error.InvalidOperatingSystemVersion,
722 error.InvalidCharacter => return error.InvalidOperatingSystemVersion,
723762 error.InvalidVersion => return error.InvalidOperatingSystemVersion,
724763 };
725764 result.os_version_max = .{ .semver = max_ver };
lib/std/zig/system/NativeTargetInfo.zig+9-13
......@@ -43,24 +43,22 @@ pub fn detect(cross_target: CrossTarget) DetectError!NativeTargetInfo {
4343 const release = mem.sliceTo(&uts.release, 0);
4444 // The release field sometimes has a weird format,
4545 // `Version.parse` will attempt to find some meaningful interpretation.
46 if (std.builtin.Version.parse(release)) |ver| {
46 if (std.SemanticVersion.parse(release)) |ver| {
4747 os.version_range.linux.range.min = ver;
4848 os.version_range.linux.range.max = ver;
4949 } else |err| switch (err) {
5050 error.Overflow => {},
51 error.InvalidCharacter => {},
5251 error.InvalidVersion => {},
5352 }
5453 },
5554 .solaris => {
5655 const uts = std.os.uname();
5756 const release = mem.sliceTo(&uts.release, 0);
58 if (std.builtin.Version.parse(release)) |ver| {
57 if (std.SemanticVersion.parse(release)) |ver| {
5958 os.version_range.semver.min = ver;
6059 os.version_range.semver.max = ver;
6160 } else |err| switch (err) {
6261 error.Overflow => {},
63 error.InvalidCharacter => {},
6462 error.InvalidVersion => {},
6563 }
6664 },
......@@ -144,7 +142,7 @@ pub fn detect(cross_target: CrossTarget) DetectError!NativeTargetInfo {
144142 error.Unexpected => return error.OSVersionDetectionFail,
145143 };
146144
147 if (std.builtin.Version.parse(buf[0 .. len - 1])) |ver| {
145 if (std.SemanticVersion.parse(buf[0 .. len - 1])) |ver| {
148146 os.version_range.semver.min = ver;
149147 os.version_range.semver.max = ver;
150148 } else |_| {
......@@ -390,7 +388,7 @@ fn detectAbiAndDynamicLinker(
390388 };
391389}
392390
393fn glibcVerFromRPath(rpath: []const u8) !std.builtin.Version {
391fn glibcVerFromRPath(rpath: []const u8) !std.SemanticVersion {
394392 var dir = fs.cwd().openDir(rpath, .{}) catch |err| switch (err) {
395393 error.NameTooLong => unreachable,
396394 error.InvalidUtf8 => unreachable,
......@@ -471,7 +469,7 @@ fn glibcVerFromRPath(rpath: []const u8) !std.builtin.Version {
471469 };
472470}
473471
474fn glibcVerFromSoFile(file: fs.File) !std.builtin.Version {
472fn glibcVerFromSoFile(file: fs.File) !std.SemanticVersion {
475473 var hdr_buf: [@sizeOf(elf.Elf64_Ehdr)]u8 align(@alignOf(elf.Elf64_Ehdr)) = undefined;
476474 _ = try preadMin(file, &hdr_buf, 0, hdr_buf.len);
477475 const hdr32 = @ptrCast(*elf.Elf32_Ehdr, &hdr_buf);
......@@ -557,13 +555,12 @@ fn glibcVerFromSoFile(file: fs.File) !std.builtin.Version {
557555 const dynstr_bytes = buf[0..dynstr_size];
558556 _ = try preadMin(file, dynstr_bytes, dynstr.offset, dynstr_bytes.len);
559557 var it = mem.splitScalar(u8, dynstr_bytes, 0);
560 var max_ver: std.builtin.Version = .{ .major = 2, .minor = 2, .patch = 5 };
558 var max_ver: std.SemanticVersion = .{ .major = 2, .minor = 2, .patch = 5 };
561559 while (it.next()) |s| {
562560 if (mem.startsWith(u8, s, "GLIBC_2.")) {
563561 const chopped = s["GLIBC_".len..];
564 const ver = std.builtin.Version.parse(chopped) catch |err| switch (err) {
562 const ver = std.SemanticVersion.parse(chopped) catch |err| switch (err) {
565563 error.Overflow => return error.InvalidGnuLibCVersion,
566 error.InvalidCharacter => return error.InvalidGnuLibCVersion,
567564 error.InvalidVersion => return error.InvalidGnuLibCVersion,
568565 };
569566 switch (ver.order(max_ver)) {
......@@ -575,7 +572,7 @@ fn glibcVerFromSoFile(file: fs.File) !std.builtin.Version {
575572 return max_ver;
576573}
577574
578fn glibcVerFromLinkName(link_name: []const u8, prefix: []const u8) !std.builtin.Version {
575fn glibcVerFromLinkName(link_name: []const u8, prefix: []const u8) !std.SemanticVersion {
579576 // example: "libc-2.3.4.so"
580577 // example: "libc-2.27.so"
581578 // example: "ld-2.33.so"
......@@ -585,9 +582,8 @@ fn glibcVerFromLinkName(link_name: []const u8, prefix: []const u8) !std.builtin.
585582 }
586583 // chop off "libc-" and ".so"
587584 const link_name_chopped = link_name[prefix.len .. link_name.len - suffix.len];
588 return std.builtin.Version.parse(link_name_chopped) catch |err| switch (err) {
585 return std.SemanticVersion.parse(link_name_chopped) catch |err| switch (err) {
589586 error.Overflow => return error.InvalidGnuLibCVersion,
590 error.InvalidCharacter => return error.InvalidGnuLibCVersion,
591587 error.InvalidVersion => return error.InvalidGnuLibCVersion,
592588 };
593589}
lib/std/zig/system/darwin.zig+2-1
......@@ -2,7 +2,7 @@ const std = @import("std");
22const mem = std.mem;
33const Allocator = mem.Allocator;
44const Target = std.Target;
5const Version = std.builtin.Version;
5const Version = std.SemanticVersion;
66
77pub const macos = @import("darwin/macos.zig");
88
......@@ -69,6 +69,7 @@ pub fn getDarwinSDK(allocator: Allocator, target: Target) ?DarwinSDK {
6969 const version = Version.parse(raw_version) catch Version{
7070 .major = 0,
7171 .minor = 0,
72 .patch = 0,
7273 };
7374 break :version version;
7475 };
lib/std/zig/system/darwin/macos.zig+28-19
......@@ -74,20 +74,39 @@ pub fn detect(target_os: *Target.Os) !void {
7474 return error.OSVersionDetectionFail;
7575}
7676
77fn parseSystemVersion(buf: []const u8) !std.builtin.Version {
77fn parseSystemVersion(buf: []const u8) !std.SemanticVersion {
7878 var svt = SystemVersionTokenizer{ .bytes = buf };
7979 try svt.skipUntilTag(.start, "dict");
8080 while (true) {
8181 try svt.skipUntilTag(.start, "key");
8282 const content = try svt.expectContent();
8383 try svt.skipUntilTag(.end, "key");
84 if (std.mem.eql(u8, content, "ProductVersion")) break;
84 if (mem.eql(u8, content, "ProductVersion")) break;
8585 }
8686 try svt.skipUntilTag(.start, "string");
8787 const ver = try svt.expectContent();
8888 try svt.skipUntilTag(.end, "string");
8989
90 return std.builtin.Version.parse(ver);
90 const parseVersionComponent = struct {
91 fn parseVersionComponent(component: []const u8) !usize {
92 return std.fmt.parseUnsigned(usize, component, 10) catch |err| {
93 switch (err) {
94 error.InvalidCharacter => return error.InvalidVersion,
95 error.Overflow => return error.Overflow,
96 }
97 };
98 }
99 }.parseVersionComponent;
100 var version_components = mem.split(u8, ver, ".");
101 const major = version_components.first();
102 const minor = version_components.next() orelse return error.InvalidVersion;
103 const patch = version_components.next() orelse "0";
104 if (version_components.next() != null) return error.InvalidVersion;
105 return .{
106 .major = try parseVersionComponent(major),
107 .minor = try parseVersionComponent(minor),
108 .patch = try parseVersionComponent(patch),
109 };
91110}
92111
93112const SystemVersionTokenizer = struct {
......@@ -246,7 +265,7 @@ const SystemVersionTokenizer = struct {
246265 while (try self.next()) |tok| {
247266 switch (tok) {
248267 .tag => |tag| {
249 if (tag.kind == kind and std.mem.eql(u8, tag.name, name)) return;
268 if (tag.kind == kind and mem.eql(u8, tag.name, name)) return;
250269 },
251270 else => {},
252271 }
......@@ -297,7 +316,7 @@ test "detect" {
297316 \\</dict>
298317 \\</plist>
299318 ,
300 .{ .major = 10, .minor = 3 },
319 .{ .major = 10, .minor = 3, .patch = 0 },
301320 },
302321 .{
303322 \\<?xml version="1.0" encoding="UTF-8"?>
......@@ -361,7 +380,7 @@ test "detect" {
361380 \\</dict>
362381 \\</plist>
363382 ,
364 .{ .major = 11, .minor = 0 },
383 .{ .major = 11, .minor = 0, .patch = 0 },
365384 },
366385 .{
367386 \\<?xml version="1.0" encoding="UTF-8"?>
......@@ -383,27 +402,17 @@ test "detect" {
383402 \\</dict>
384403 \\</plist>
385404 ,
386 .{ .major = 11, .minor = 1 },
405 .{ .major = 11, .minor = 1, .patch = 0 },
387406 },
388407 };
389408
390409 inline for (cases) |case| {
391410 const ver0 = try parseSystemVersion(case[0]);
392 const ver1: std.builtin.Version = case[1];
393 try testVersionEquality(ver1, ver0);
411 const ver1: std.SemanticVersion = case[1];
412 try testing.expectEqual(@as(std.math.Order, .eq), ver0.order(ver1));
394413 }
395414}
396415
397fn testVersionEquality(expected: std.builtin.Version, got: std.builtin.Version) !void {
398 var b_expected: [64]u8 = undefined;
399 const s_expected: []const u8 = try std.fmt.bufPrint(b_expected[0..], "{}", .{expected});
400
401 var b_got: [64]u8 = undefined;
402 const s_got: []const u8 = try std.fmt.bufPrint(b_got[0..], "{}", .{got});
403
404 try testing.expectEqualStrings(s_expected, s_got);
405}
406
407416pub fn detectNativeCpuAndFeatures() ?Target.Cpu {
408417 var cpu_family: std.c.CPUFAMILY = undefined;
409418 var len: usize = @sizeOf(std.c.CPUFAMILY);
src/Compilation.zig+2-2
......@@ -615,8 +615,8 @@ pub const InitOptions = struct {
615615 stack_size_override: ?u64 = null,
616616 image_base_override: ?u64 = null,
617617 self_exe_path: ?[]const u8 = null,
618 version: ?std.builtin.Version = null,
619 compatibility_version: ?std.builtin.Version = null,
618 version: ?std.SemanticVersion = null,
619 compatibility_version: ?std.SemanticVersion = null,
620620 libc_installation: ?*const LibCInstallation = null,
621621 machine_code_model: std.builtin.CodeModel = .default,
622622 clang_preprocessor_mode: ClangPreprocessorMode = .no,
src/codegen/spirv/spec.zig+1-1
......@@ -1,6 +1,6 @@
11//! This file is auto-generated by tools/gen_spirv_spec.zig.
22
3const Version = @import("std").builtin.Version;
3const Version = @import("std").SemanticVersion;
44
55pub const Word = u32;
66pub const IdResult = struct {
src/glibc.zig+2-2
......@@ -5,7 +5,7 @@ const log = std.log;
55const fs = std.fs;
66const path = fs.path;
77const assert = std.debug.assert;
8const Version = std.builtin.Version;
8const Version = std.SemanticVersion;
99
1010const target_util = @import("target.zig");
1111const Compilation = @import("Compilation.zig");
......@@ -172,7 +172,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr
172172
173173 const target = comp.getTarget();
174174 const target_ver = target.os.version_range.linux.glibc;
175 const start_old_init_fini = target_ver.order(.{ .major = 2, .minor = 33 }) != .gt;
175 const start_old_init_fini = target_ver.order(.{ .major = 2, .minor = 33, .patch = 0 }) != .gt;
176176
177177 // In all cases in this function, we add the C compiler flags to
178178 // cache_exempt_flags rather than extra_flags, because these arguments
src/link.zig+2-2
......@@ -197,8 +197,8 @@ pub const Options = struct {
197197 /// __real_symbol.
198198 symbol_wrap_set: std.StringArrayHashMapUnmanaged(void),
199199
200 version: ?std.builtin.Version,
201 compatibility_version: ?std.builtin.Version,
200 version: ?std.SemanticVersion,
201 compatibility_version: ?std.SemanticVersion,
202202 libc_installation: ?*const LibCInstallation,
203203
204204 dwarf_format: ?std.dwarf.Format,
src/link/Elf.zig+1-1
......@@ -3414,7 +3414,7 @@ const CsuObjects = struct {
34143414 if (result.crtn) |*obj| obj.* = try fs.path.join(arena, &[_][]const u8{ crt_dir_path, obj.* });
34153415
34163416 var gccv: []const u8 = undefined;
3417 if (link_options.target.os.version_range.semver.isAtLeast(.{ .major = 5, .minor = 4 }) orelse true) {
3417 if (link_options.target.os.version_range.semver.isAtLeast(.{ .major = 5, .minor = 4, .patch = 0 }) orelse true) {
34183418 gccv = "gcc80";
34193419 } else {
34203420 gccv = "gcc54";
src/link/MachO/load_commands.zig+6-6
......@@ -204,12 +204,12 @@ pub fn writeDylibIdLC(gpa: Allocator, options: *const link.Options, lc_writer: a
204204 const emit = options.emit.?;
205205 const install_name = options.install_name orelse try emit.directory.join(gpa, &.{emit.sub_path});
206206 defer if (options.install_name == null) gpa.free(install_name);
207 const curr = options.version orelse std.builtin.Version{
207 const curr = options.version orelse std.SemanticVersion{
208208 .major = 1,
209209 .minor = 0,
210210 .patch = 0,
211211 };
212 const compat = options.compatibility_version orelse std.builtin.Version{
212 const compat = options.compatibility_version orelse std.SemanticVersion{
213213 .major = 1,
214214 .minor = 0,
215215 .patch = 0,
......@@ -217,8 +217,8 @@ pub fn writeDylibIdLC(gpa: Allocator, options: *const link.Options, lc_writer: a
217217 try writeDylibLC(.{
218218 .cmd = .ID_DYLIB,
219219 .name = install_name,
220 .current_version = curr.major << 16 | curr.minor << 8 | curr.patch,
221 .compatibility_version = compat.major << 16 | compat.minor << 8 | compat.patch,
220 .current_version = @intCast(u32, curr.major << 16 | curr.minor << 8 | curr.patch),
221 .compatibility_version = @intCast(u32, compat.major << 16 | compat.minor << 8 | compat.patch),
222222 }, lc_writer);
223223}
224224
......@@ -275,12 +275,12 @@ pub fn writeBuildVersionLC(options: *const link.Options, lc_writer: anytype) !vo
275275 const cmdsize = @sizeOf(macho.build_version_command) + @sizeOf(macho.build_tool_version);
276276 const platform_version = blk: {
277277 const ver = options.target.os.version_range.semver.min;
278 const platform_version = ver.major << 16 | ver.minor << 8;
278 const platform_version = @intCast(u32, ver.major << 16 | ver.minor << 8);
279279 break :blk platform_version;
280280 };
281281 const sdk_version = if (options.native_darwin_sdk) |sdk| blk: {
282282 const ver = sdk.version;
283 const sdk_version = ver.major << 16 | ver.minor << 8;
283 const sdk_version = @intCast(u32, ver.major << 16 | ver.minor << 8);
284284 break :blk sdk_version;
285285 } else platform_version;
286286 const is_simulator_abi = options.target.abi == .simulator;
src/main.zig+6-7
......@@ -724,9 +724,9 @@ fn buildOutputType(
724724 var dll_export_fns: ?bool = null;
725725 var single_threaded: ?bool = null;
726726 var root_src_file: ?[]const u8 = null;
727 var version: std.builtin.Version = .{ .major = 0, .minor = 0, .patch = 0 };
727 var version: std.SemanticVersion = .{ .major = 0, .minor = 0, .patch = 0 };
728728 var have_version = false;
729 var compatibility_version: ?std.builtin.Version = null;
729 var compatibility_version: ?std.SemanticVersion = null;
730730 var strip: ?bool = null;
731731 var formatted_panics: ?bool = null;
732732 var function_sections = false;
......@@ -1121,7 +1121,7 @@ fn buildOutputType(
11211121 try cssan.addIncludePath(.iframework, arg, args_iter.nextOrFatal(), false);
11221122 } else if (mem.eql(u8, arg, "--version")) {
11231123 const next_arg = args_iter.nextOrFatal();
1124 version = std.builtin.Version.parse(next_arg) catch |err| {
1124 version = std.SemanticVersion.parse(next_arg) catch |err| {
11251125 fatal("unable to parse --version '{s}': {s}", .{ next_arg, @errorName(err) });
11261126 };
11271127 have_version = true;
......@@ -2152,12 +2152,12 @@ fn buildOutputType(
21522152 try system_libs.put(linker_args_it.nextOrFatal(), .{ .weak = true });
21532153 } else if (mem.eql(u8, arg, "-compatibility_version")) {
21542154 const compat_version = linker_args_it.nextOrFatal();
2155 compatibility_version = std.builtin.Version.parse(compat_version) catch |err| {
2155 compatibility_version = std.SemanticVersion.parse(compat_version) catch |err| {
21562156 fatal("unable to parse -compatibility_version '{s}': {s}", .{ compat_version, @errorName(err) });
21572157 };
21582158 } else if (mem.eql(u8, arg, "-current_version")) {
21592159 const curr_version = linker_args_it.nextOrFatal();
2160 version = std.builtin.Version.parse(curr_version) catch |err| {
2160 version = std.SemanticVersion.parse(curr_version) catch |err| {
21612161 fatal("unable to parse -current_version '{s}': {s}", .{ curr_version, @errorName(err) });
21622162 };
21632163 have_version = true;
......@@ -2207,10 +2207,9 @@ fn buildOutputType(
22072207 } else if (mem.startsWith(u8, arg, "/version:")) {
22082208 var split_it = mem.splitBackwardsScalar(u8, arg, ':');
22092209 const version_arg = split_it.first();
2210 version = std.builtin.Version.parse(version_arg) catch |err| {
2210 version = std.SemanticVersion.parse(version_arg) catch |err| {
22112211 fatal("unable to parse /version '{s}': {s}", .{ arg, @errorName(err) });
22122212 };
2213
22142213 have_version = true;
22152214 } else {
22162215 fatal("unsupported linker arg: {s}", .{arg});
src/target.zig+7-7
......@@ -6,7 +6,7 @@ pub const ArchOsAbi = struct {
66 arch: std.Target.Cpu.Arch,
77 os: std.Target.Os.Tag,
88 abi: std.Target.Abi,
9 os_ver: ?std.builtin.Version = null,
9 os_ver: ?std.SemanticVersion = null,
1010};
1111
1212pub const available_libcs = [_]ArchOsAbi{
......@@ -16,9 +16,9 @@ pub const available_libcs = [_]ArchOsAbi{
1616 .{ .arch = .aarch64, .os = .linux, .abi = .gnu },
1717 .{ .arch = .aarch64, .os = .linux, .abi = .musl },
1818 .{ .arch = .aarch64, .os = .windows, .abi = .gnu },
19 .{ .arch = .aarch64, .os = .macos, .abi = .none, .os_ver = .{ .major = 11, .minor = 0 } },
20 .{ .arch = .aarch64, .os = .macos, .abi = .none, .os_ver = .{ .major = 12, .minor = 0 } },
21 .{ .arch = .aarch64, .os = .macos, .abi = .none, .os_ver = .{ .major = 13, .minor = 0 } },
19 .{ .arch = .aarch64, .os = .macos, .abi = .none, .os_ver = .{ .major = 11, .minor = 0, .patch = 0 } },
20 .{ .arch = .aarch64, .os = .macos, .abi = .none, .os_ver = .{ .major = 12, .minor = 0, .patch = 0 } },
21 .{ .arch = .aarch64, .os = .macos, .abi = .none, .os_ver = .{ .major = 13, .minor = 0, .patch = 0 } },
2222 .{ .arch = .armeb, .os = .linux, .abi = .gnueabi },
2323 .{ .arch = .armeb, .os = .linux, .abi = .gnueabihf },
2424 .{ .arch = .armeb, .os = .linux, .abi = .musleabi },
......@@ -71,9 +71,9 @@ pub const available_libcs = [_]ArchOsAbi{
7171 .{ .arch = .x86_64, .os = .linux, .abi = .gnux32 },
7272 .{ .arch = .x86_64, .os = .linux, .abi = .musl },
7373 .{ .arch = .x86_64, .os = .windows, .abi = .gnu },
74 .{ .arch = .x86_64, .os = .macos, .abi = .none, .os_ver = .{ .major = 11, .minor = 0 } },
75 .{ .arch = .x86_64, .os = .macos, .abi = .none, .os_ver = .{ .major = 12, .minor = 0 } },
76 .{ .arch = .x86_64, .os = .macos, .abi = .none, .os_ver = .{ .major = 13, .minor = 0 } },
74 .{ .arch = .x86_64, .os = .macos, .abi = .none, .os_ver = .{ .major = 11, .minor = 0, .patch = 0 } },
75 .{ .arch = .x86_64, .os = .macos, .abi = .none, .os_ver = .{ .major = 12, .minor = 0, .patch = 0 } },
76 .{ .arch = .x86_64, .os = .macos, .abi = .none, .os_ver = .{ .major = 13, .minor = 0, .patch = 0 } },
7777};
7878
7979pub fn libCGenericName(target: std.Target) [:0]const u8 {
test/link/macho/dylib/build.zig+1-1
......@@ -17,7 +17,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
1717
1818 const dylib = b.addSharedLibrary(.{
1919 .name = "a",
20 .version = .{ .major = 1, .minor = 0 },
20 .version = .{ .major = 1, .minor = 0, .patch = 0 },
2121 .optimize = optimize,
2222 .target = target,
2323 });
test/link/macho/needed_library/build.zig+1-1
......@@ -17,7 +17,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
1717
1818 const dylib = b.addSharedLibrary(.{
1919 .name = "a",
20 .version = .{ .major = 1, .minor = 0 },
20 .version = .{ .major = 1, .minor = 0, .patch = 0 },
2121 .optimize = optimize,
2222 .target = target,
2323 });
test/link/macho/search_strategy/build.zig+1-1
......@@ -61,7 +61,7 @@ fn createScenario(
6161
6262 const dylib = b.addSharedLibrary(.{
6363 .name = name,
64 .version = .{ .major = 1, .minor = 0 },
64 .version = .{ .major = 1, .minor = 0, .patch = 0 },
6565 .optimize = optimize,
6666 .target = target,
6767 });
test/link/macho/tls/build.zig+1-1
......@@ -17,7 +17,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
1717
1818 const lib = b.addSharedLibrary(.{
1919 .name = "a",
20 .version = .{ .major = 1, .minor = 0 },
20 .version = .{ .major = 1, .minor = 0, .patch = 0 },
2121 .optimize = optimize,
2222 .target = target,
2323 });
test/link/macho/uuid/build.zig+1-1
......@@ -62,7 +62,7 @@ fn simpleDylib(
6262) *std.Build.Step.Compile {
6363 const dylib = b.addSharedLibrary(.{
6464 .name = "test",
65 .version = .{ .major = 1, .minor = 0 },
65 .version = .{ .major = 1, .minor = 0, .patch = 0 },
6666 .optimize = optimize,
6767 .target = target,
6868 });
test/standalone/load_dynamic_library/build.zig+1-1
......@@ -13,7 +13,7 @@ pub fn build(b: *std.Build) void {
1313 const lib = b.addSharedLibrary(.{
1414 .name = "add",
1515 .root_source_file = .{ .path = "add.zig" },
16 .version = .{ .major = 1, .minor = 0 },
16 .version = .{ .major = 1, .minor = 0, .patch = 0 },
1717 .optimize = optimize,
1818 .target = target,
1919 });
test/standalone/shared_library/build.zig+1-1
......@@ -9,7 +9,7 @@ pub fn build(b: *std.Build) void {
99 const lib = b.addSharedLibrary(.{
1010 .name = "mathtest",
1111 .root_source_file = .{ .path = "mathtest.zig" },
12 .version = .{ .major = 1, .minor = 0 },
12 .version = .{ .major = 1, .minor = 0, .patch = 0 },
1313 .target = target,
1414 .optimize = optimize,
1515 });
tools/gen_spirv_spec.zig+1-1
......@@ -76,7 +76,7 @@ fn render(writer: anytype, allocator: Allocator, registry: g.CoreRegistry) !void
7676 try writer.writeAll(
7777 \\//! This file is auto-generated by tools/gen_spirv_spec.zig.
7878 \\
79 \\const Version = @import("std").builtin.Version;
79 \\const Version = @import("std").SemanticVersion;
8080 \\
8181 \\pub const Word = u32;
8282 \\pub const IdResult = struct{