std: replace builtin.Version with SemanticVersion#13998
Conversation
|
Ok so there's this problem where we have versions that we want to parse but they don't conform to SemVer zig/lib/std/zig/system/darwin/macos.zig Lines 378 to 382 in 3bfae2a Semantic Versioning does not accept "1.0" for example. The patch part must be specified. Edit: so I decided to implement version parsing specifically for the cases there, which wasn't very complicated at all. |
| @@ -1048,7 +1048,7 @@ fn buildOutputType( | |||
| try cssan.addIncludePath(.iframework, arg, args_iter.nextOrFatal(), false); | |||
| } else if (mem.eql(u8, arg, "--version")) { | |||
There was a problem hiding this comment.
The docs for this is "Dynamic library semver" which wasn't actually true. Now it is because it no longer accepts an omitted patch component (according to the spec "1.0" is invalid). This might cause breakage.
lib/std/zig/CrossTarget.zig
Outdated
| const major = version_components.first(); | ||
| if (major.len == 0) return error.InvalidVersion; | ||
| const minor = version_components.next() orelse return error.InvalidVersion; | ||
| const patch = version_components.next() orelse "0"; |
There was a problem hiding this comment.
This version doesn't check that there aren't additional components after the patch. Same error is repeated in zig/system/darwin/macos.zig, would it instead be better to provide a properly tested non-standard function somewhere so that other people don't repeat it by implementing their own version?
There was a problem hiding this comment.
The above brings me to this comment: where shall we put this function and its tests? It should probably be an entirely internal function. lib/std/zig/CrossTarget.zig and lib/std/zig/system/darwin/macos.zig share lib/std/zig/ so should it be lib/std/zig/version.zig or something?
There was a problem hiding this comment.
I'd either put it in SemanticVersion.zig and clearly document it as non-standard or just lib/std/zig.zig.
There was a problem hiding this comment.
Hmm I was just doing this but now I'm thinking is std.zig really the right space for this? Version parsing like that isn't really part of parsing Zig code. Doesn't really seem to fit in that file.
Well, I was gonna say another motivation of this PR was to reduce the public API surface a bit, and really, after this missing check at the end it seems to be complete now. The code really isn't that complicated.
The advantage is that now we have a single, standard way to parse a version.
For all other cases the user has to write this themselves, and it really isn't that complicated, and also only an optional patch component seems kind of specific. What if the user wants more components to be optional, etc.?
So this way it's also very formidable for the use case at hand.
So for now I went back to the way it was and fixed up the parsing in both places.
However if you can think of a better place, where ideally it doesn't get into the public std, maybe we can do it the way your proposing.
Maybe lib/std/zig/version.zig? Can we put it there publicly and then only use it in those two places and not expose it to the public std API surface?
And if we put it in std.SemanticVersion as non-standard, I think we should make it customizable and allow the minor component to be optional too, at which point maybe it gets a bit too complicated? I don't know. Maybe it's ok then.
|
Looks pretty good. Would you mind rebasing on latest master branch? |
|
Going to wait for a new master build first. |
|
Rebased. |
|
stage1/zig.h has a lot of changes. All I did was |
|
#14691 added a step that copies zig.h into stage1/ but maybe that wasn't run as part of that PR? |
|
That could very well be it. Maybe it's ok to do it here. I might split it into 3 commits at least, though. |
|
Not yet sure what's up here. Running |
Known issue, build with llvm backend enabled so that the compiler uses |
|
So I ran the |
|
Another PR of mine #14782 is hit with the exact same CI failure. Can anyone tell me the correct way to rebuild |
|
So this has some interesting build-related breaking changes: const std = @import("std");
pub fn build(b: *std.Build) void {
const optimize = b.standardOptimizeOption(.{});
const target: std.zig.CrossTarget = .{ .os_tag = .macos };
const lib = b.addSharedLibrary(.{
.name = "a",
.version = .{ .major = 1, .minor = 0 },
.optimize = optimize,
.target = target,
});The patch version component must be specified: .version = .{ .major = 1, .minor = 0, patch = 0 },Here's a shorter more nicer-looking alternative: .version = std.SemanticVersion.parse("1.0.0"),(shortness depends on what you have imported as well) In the future this might become shorter and more nicer when we have anonymous function calls like this: .version = .parse("1.0.0"),(don't remember the proposal for this) So, packages previously used I am thinking if maybe |
You only have to update zig1.wasm if the changes you made are required to build the compiler itself. I usually build zig stage4 (with a prebuilt or bootstrapped zig), then run |
|
I think this PR can be closed. |
|
Why? |
I started searching the oldest PR to find if there where some abandoned one. From the title of the PR I thought the Sorry for the noise. |
This broke with ziglang/zig#13998 so I copied the old Version struct into the file. `std.SemanticVersion` does not support parsing e.g. "2.38" because it does not allow the implicit ".0" to be dropped.
In most cases "GLIBC_2.X" strings and `/lib/libc-2.x.so` files do not contain third (`patch`) field, which causes std.SemanticVersion.parse function to return error. To fix this, we reuse [now-public] std.zig.CrossTarget.parseVersion function, which accounts for this third field and makes it 0 in case it was not found. This new behaviour is similar to std.builtin.Version.parse, which was removed in 6e84f46 Fixes regression from 6e84f46 and #13998 . Related: #17626 . Results with `zig end`: Before: `"target": "x86_64-linux.6.5.7...6.5.7-gnu.2.19",` After: `"target": "x86_64-linux.6.5.7...6.5.7-gnu.2.36",` Also, while we are here, write explicit error sets and remove duplicate logic from std.zig.system.darwin.macos.parseSystemVersion . Signed-off-by: Eric Joldasov <bratishkaerik@getgoogleoff.me>
This removes
std.builtin.Versionin favor ofstd.SemanticVersion.I don't think this is something that belongs in std.builtin.
patchfield must now always explicitly be specified and no longer defaults to 0.SemanticVersionis the same length asbuiltin.Version.parse.I took over the old tests from std.builtin.Version and added them in lib/std/SemanticVersion.zig (basically the only valuable things).
Fixes #12862