Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose structured Zig version at comptime #6466

Closed
3 tasks done
jayschwa opened this issue Sep 30, 2020 · 13 comments · Fixed by #7673
Closed
3 tasks done

Expose structured Zig version at comptime #6466

jayschwa opened this issue Sep 30, 2020 · 13 comments · Fixed by #7673
Labels
accepted This proposal is planned. proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Milestone

Comments

@jayschwa
Copy link
Contributor

jayschwa commented Sep 30, 2020

In a recent discussion of Zig, some new users complained about broken example code. They encountered these problems because they installed the latest tagged release of Zig (probably from their system package manager) rather than the latest development build. As the Zig ecosystem grows, this is likely to be an ongoing pain point. It will help if authors of published Zig code (outside the Zig project) have an easy way to inspect the Zig version at comptime.

@hasDecl is already a great way to perform compile-time "feature detection". However, it may not be enough if one wants to determine whether or not a file with new syntax can be imported, or if it's a version of Zig that shipped with a known bug that needs to be worked around. I propose the following changes:

Julia had a similar convention during its wild west pre-1.0 days. I maintained a package during that time, and retaining compatibility with multiple toolchain versions was helpful for end-users.

@jayschwa jayschwa added the proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. label Sep 30, 2020
@jayschwa jayschwa added this to the 0.8.0 milestone Sep 30, 2020
@andrewrk andrewrk added the accepted This proposal is planned. label Sep 30, 2020
@andrewrk andrewrk modified the milestones: 0.8.0, 0.7.0 Sep 30, 2020
@daurnimator
Copy link
Contributor

The issues brought up in that discussion are due to changes in the standard library rather than ones in zig syntax (though I don't doubt people are hitting those too). IMO this goes into a discussion of how to depend on libraries; particularly ones with specific versions.

@andrewrk
Copy link
Member

andrewrk commented Sep 30, 2020

For semantic versioning compliance, it ought to be something like 0.7.0-pre+bd89bd6fd

I don't like that it forces you to choose the next version ahead of time. In many of my nodejs packages, I wouldn't know what version was next, maybe it would be a bug fix release, maybe a minor release, or maybe I would break compatibility. Right after you tag a release, you have no idea what the next one is going to be.

I suppose one could do the bump immediately upon making such a change. So if you do a bug fix commit, the version would be x.x.1-pre-foo and then if you do a commit it becomes x.1.0-pre-bar and then if you do a breaking change it becomes 2.0.0-pre-baz. So you would end up with these pseudo version strings of releases that never happened. That seems like it might confuse people.

@Rocknest
Copy link
Contributor

@andrewrk i've seen that some projects use 'x.x.999' for development builds

@jayschwa
Copy link
Contributor Author

jayschwa commented Sep 30, 2020

I don't like that it forces you to choose the next version ahead of time.

Agreed. I dislike the friction between semantic versioning and just doing something simple like git describe. Should Zig switch to that instead? For the purposes of this proposal, the version format isn't actually important. There just needs to be a way to determine if a build of Zig is older or newer than a predefined version.

@Jan200101
Copy link
Contributor

Jan200101 commented Sep 30, 2020

i've seen that some projects use 'x.x.999' for development builds

projects like glibc use is 9000 (which has caused trouble with Zig #5082) but that forces a maximum amount of patch versions though that shouldn't introduce any problems but you never know

@jayschwa
Copy link
Contributor Author

jayschwa commented Oct 2, 2020

I don't like that it forces you to choose the next version ahead of time.

It turns out the SemVer repo has a long-standing issue with vigorous debate on this topic: semver/semver#200

There was one proposal I liked, which is changing + to affect ordering and denote unstable post-release builds. (Build metadata would then be denoted by another character such as ~). However, it's highly unlikely this idea will be adopted because it would require SemVer 3.

For the SemVer 2 status quo, I think this comment is the best takeaway:

The next nightly should just be a prerelease. If you don't know what version it'll be, make it a patch prerelease. once you know it's a minor or a major, make it a prerelease of that.

For pre-1.0 Zig, I think we should just do 0.(n+1).0-dev and call it day. Sticking with SemVer for this proposal means that any version structure and parsing code will remain applicable for the future package manager.

@olivier-spinelli
Copy link

For what it worth, this may interest you: https://csemver.org/

jayschwa added a commit to jayschwa/zig that referenced this issue Oct 2, 2020
Example version: 0.7.0-dev.2028+ge9434ff8f

From a semantic versioning perspective, development builds will now be
considered different from a tagged release build and respect ordering.

Updates ziglang#6466
@mentalisttraceur
Copy link

I feel compelled to strongly emphasize that nightly/development versioning is to SemVer like a square peg is to a round hole.

SamVer communicates a few specific bits of guarantee about the public interface. When you don't have that to say, all SemVer can do is explicitly say that you are not saying it (this is what 0.* and pre-release versions in SemVer say).

I strongly encourage considering the idea of doing SemVer for official releases and not-SemVer for things like nightlies or other non-release builds where you don't actually know what the corresponding release version or public interface changes will be.

@jayschwa
Copy link
Contributor Author

jayschwa commented Oct 2, 2020

Development builds are just pre-releases, which is something that SemVer already supports.

@yamirui
Copy link

yamirui commented Oct 4, 2020

@jayschwa BNF of SemVer implies that things like build metadata go into metadata which is not part of a version at all.

As for pre-release's, its a matter of opinion, and my opinion is that current 0.6.0 is nothing like what 0.7.0 will be, and first commit post 0.7.0 is even further from 0.8.0, calling it a pre-release is an oxymoron at best.

@jayschwa
Copy link
Contributor Author

jayschwa commented Oct 4, 2020

@jayschwa BNF of SemVer implies that things like build metadata go into metadata which is not part of a version at all.

As for pre-release's, its a matter of opinion, and my opinion is that current 0.6.0 is nothing like what 0.7.0 will be, and first commit post 0.7.0 is even further from 0.8.0, calling it a pre-release is an oxymoron at best.

Things that are critical to this proposal:

  • The ability to compare Zig builds, including untagged development builds.

Constraints of SemVer (what Zig currently uses):

  • Build metadata has no affect on version comparisons.
  • Pre-release labels affect version comparisons.
  • Post-release labels don't exist.

PR #6509 works within these constraints. It twiddles a couple characters in git describe output to make it SemVer-compliant. The resulting version string isn't going to win a beauty pageant, but it will get the job done.

@Rocknest
Copy link
Contributor

Rocknest commented Oct 4, 2020

Well 0.x.x is not really a semantic versioning, only chronological. Zig's 0.x.x releases are more like 1.0.0-pre.x, since they are trying to be semantic. It could look like this

  • 1.0.0-pre.X.d.number-of-commits+metadata (d for dev)
  • 1.0.0-pre.X.f (f for final, can be anything after d)

1.0.0-pre.7.d.88+b0c5d7 < 1.0.0-pre.7.d.122+abc123 < 1.0.0-pre.7.f < 1.0.0-pre.8.d.56+678dcf < 1.0.0

Or simulate post releases:
1.0.0-pre.6.next.88+b0c5d7 < 1.0.0-pre.6.next.122+abc123 < 1.0.0-pre.7 < 1.0.0-pre.7.next.56+678dcf < 1.0.0

jayschwa added a commit to jayschwa/zig that referenced this issue Oct 5, 2020
Example version: 0.7.0-dev.2028+ge9434ff8f

From a semantic versioning perspective, development builds will now be
considered different from a tagged release build and respect ordering.

Updates ziglang#6466
jayschwa added a commit to jayschwa/zig that referenced this issue Oct 5, 2020
This will parse, format, and compare version strings following the
SemVer 2 specification. See: https://semver.org

Updates ziglang#6466
@mentalisttraceur
Copy link

So I agree that you're doing the right thing assuming those constraints, but my point here is that even if you are using SemVer and want "the ability to compare Zig builds (including untagged builds)" you don't actually have to limit yourself to just the semantics of SemVer.

I can't tell if you're making a common intuition mistake here, so I'll just make it explicit: Just because SemVer treats build metadata as irrelevant to SemVer comparison, does not mean SemVer disallows using build metadata for your comparisons in addition to SemVer. At least I see no reason why this should be the interpretation. When I read the SemVer spec, I don't see any implication that additional semantics beyond SemVer are disallowed - only what interpretations/usages are disallowed within SemVer semantics.

So what I'm saying is, if Zig uses build metadata for development releases, and provides some function in its standard library which given a Zig version number says "this is a development build" (and sorts accordingly) based on the build metadata tag rather than on the pre-release tag, then to my language/spec "lawyer" intuitions, this does not feel like a violation of SemVer, but rather a composition/layering of SemVer semantics with additional semantics.

jayschwa added a commit to jayschwa/zig that referenced this issue Oct 6, 2020
This will parse, format, and compare version strings following the
SemVer 2 specification. See: https://semver.org

Updates ziglang#6466
jayschwa added a commit to jayschwa/zig that referenced this issue Oct 7, 2020
This will parse, format, and compare version strings following the
SemVer 2 specification. See: https://semver.org

Updates ziglang#6466
jayschwa added a commit to jayschwa/zig that referenced this issue Oct 30, 2020
Example version: 0.7.0-dev.2028+ge9434ff8f

From a semantic versioning perspective, development builds will now be
considered different from a tagged release build and respect ordering.

Updates ziglang#6466
andrewrk pushed a commit that referenced this issue Nov 6, 2020
This will parse, format, and compare version strings following the
SemVer 2 specification. See: https://semver.org

Updates #6466
@andrewrk andrewrk removed this from the 0.7.0 milestone Nov 6, 2020
@andrewrk andrewrk added this to the 0.8.0 milestone Nov 6, 2020
jayschwa added a commit to jayschwa/zig that referenced this issue Dec 15, 2020
Example version: 0.8.0-dev.460+g81b343a16

From a semantic versioning perspective, development builds will now be
considered distinct from a tagged release. The number of commits added
since the last tag is included in the pre-release component.

Updates ziglang#6466
andrewrk pushed a commit that referenced this issue Dec 29, 2020
Example version: 0.8.0-dev.460+g81b343a16

From a semantic versioning perspective, development builds will now be
considered distinct from a tagged release. The number of commits added
since the last tag is included in the pre-release component.

Updates #6466
andrewrk added a commit that referenced this issue Dec 31, 2020
Updating the download page is stuck because in all cases
`zig version` is outputting 0.8.0 rather than e.g.
0.8.0-dev.716+fbf269cc4.

See #6466
jayschwa added a commit to jayschwa/zig that referenced this issue Jan 1, 2021
`git describe` is used for version string creation, but it had to be
reverted in commit 69da6ba because it was broken in CI builds.
Azure Pipelines and Drone perform shallow clones by default.
This change reconfigures them to do normal clones and fetch tags.
This adds an extra 10-20 seconds, which is negligible compared to
overall build and test time.

Related: ziglang#6466, ziglang#6509, ziglang#7601
jayschwa added a commit to jayschwa/zig that referenced this issue Jan 1, 2021
git describe is used for version string creation, but it had to be
reverted in commit 69da6ba because it was broken in CI builds.
Azure Pipelines and Drone perform shallow clones by default.
This change reconfigures them to fetch history and tags. It adds tens of
seconds, which is negligible compared to overall build and test time.

Related: ziglang#6466, ziglang#6509, ziglang#7601
jayschwa added a commit to jayschwa/zig that referenced this issue Jan 2, 2021
git describe is used for version string creation, but it had to be
reverted in commit 69da6ba because it was broken in CI builds.
Azure Pipelines and Drone perform shallow clones by default.
This change reconfigures them to fetch history and tags. It adds tens of
seconds, which is negligible compared to overall build and test time.

Related: ziglang#6466, ziglang#6509, ziglang#7601
andrewrk pushed a commit that referenced this issue Jan 2, 2021
git describe is used for version string creation, but it had to be
reverted in commit 69da6ba because it was broken in CI builds.
Azure Pipelines and Drone perform shallow clones by default.
This change reconfigures them to fetch history and tags. It adds tens of
seconds, which is negligible compared to overall build and test time.

Related: #6466, #6509, #7601
jayschwa added a commit to jayschwa/zig that referenced this issue Jan 3, 2021
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.

TODO: Add tests.

Closes ziglang#6466
aarvay pushed a commit to aarvay/zig that referenced this issue Jan 4, 2021
Example version: 0.8.0-dev.460+g81b343a16

From a semantic versioning perspective, development builds will now be
considered distinct from a tagged release. The number of commits added
since the last tag is included in the pre-release component.

Updates ziglang#6466
aarvay pushed a commit to aarvay/zig that referenced this issue Jan 4, 2021
git describe is used for version string creation, but it had to be
reverted in commit 69da6ba because it was broken in CI builds.
Azure Pipelines and Drone perform shallow clones by default.
This change reconfigures them to fetch history and tags. It adds tens of
seconds, which is negligible compared to overall build and test time.

Related: ziglang#6466, ziglang#6509, ziglang#7601
jayschwa added a commit to jayschwa/zig that referenced this issue Jan 5, 2021
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 ziglang#6466
jayschwa added a commit to jayschwa/zig that referenced this issue Jan 5, 2021
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 ziglang#6466
jayschwa added a commit to jayschwa/zig that referenced this issue Jan 5, 2021
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 ziglang#6466
jayschwa added a commit to jayschwa/zig that referenced this issue Jan 5, 2021
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 ziglang#6466
jayschwa added a commit to jayschwa/zig that referenced this issue Jan 8, 2021
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 ziglang#6466
andrewrk pushed a commit that referenced this issue Jan 9, 2021
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
dgbuckley pushed a commit to dgbuckley/zig that referenced this issue Mar 9, 2021
Example version: 0.8.0-dev.460+g81b343a16

From a semantic versioning perspective, development builds will now be
considered distinct from a tagged release. The number of commits added
since the last tag is included in the pre-release component.

Updates ziglang#6466
dgbuckley pushed a commit to dgbuckley/zig that referenced this issue Mar 9, 2021
git describe is used for version string creation, but it had to be
reverted in commit 69da6ba because it was broken in CI builds.
Azure Pipelines and Drone perform shallow clones by default.
This change reconfigures them to fetch history and tags. It adds tens of
seconds, which is negligible compared to overall build and test time.

Related: ziglang#6466, ziglang#6509, ziglang#7601
dgbuckley pushed a commit to dgbuckley/zig that referenced this issue Mar 9, 2021
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 ziglang#6466
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted This proposal is planned. proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants