You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We're trying to set the version in a manifest regardless of what the current version is set to. Currently, this fails if the change is considered a downgrade.
Would it be possible to add a --force option to get around this?
To add some context to this. Our build scripts detect if we are building a release or internal development version of the program. If it's a development build it adds -dev-${commit_hash} to the end of the version number. This is just temporary while building. We back the Cargo.toml files up and restore them after the build. But we want the binaries to have the git commit they were built from baked into the binary and displayed on our-program --version.
Currently 2022.3-dev-012345 is considered a downgrade from 2022.3. In our case it just means "A development version, sometime after 2022.3 was released, built on commit 012345
Essentially what we really want is a solution to rust-lang/cargo#6583. But that seems unsolved also. We could potentially just inject our own version with another env var, and not rely on CARGO_PKG_VERSION.
Currently 2022.3-dev-012345 is considered a downgrade from 2022.3. In our case it just means "A development version, sometime after 2022.3 was released, built on commit 012345
Is there a reason you aren't instead committing 2022.4-dev in master? You then do development builds like normal with 2022.4-dev-012345 and then you do official release by dropping -dev.
Currently 2022.3-dev-012345 is considered a downgrade from 2022.3. In our case it just means "A development version, sometime after 2022.3 was released, built on commit 012345
Another way to frame my question is that -dev, by convention, means a pre-release development version and not a post-release development version. Some communities support post release but those are of production versions and not development (semver 2.0 doesn't recognize this though).
Instead of continuing in a bespoke manner, swimming upstream, it seems like it'd be better to align with common expectations.
Doing what you suggest requires two separate git bumps and knowing the future. One git bump to the actual stable release and then immediately a new one to {next}-dev. And it requires us to know the name of the next release. We version our product according to $current_year.$incremental_number. So if we code away and the last release was 2022.6 and 2023 arrives before we manage to produce the next release, the next release becomes 2023.1 and not 2022.7. But if we flip it we will have a bunch of 2022.7-dev builds, which is strange since that version does not and will never exist.
Our versioning scheme is similar to git describe which is of the format "newest reachable tag + how many commits has been added since + hash". It's just based on what has happened, not on what will happen.
Doing what you suggest requires two separate git bumps and knowing the future.
The extra git bump is not ideal but I'm assuming it isn't a blocker
As for knowing the future, it doesn't necessarily. Pick the next higher version and then bump from there.
Keep in mind that these costs are to avoid the cost of violating semver 2.0 (no post-release versions) which violates basic assumptions of how cargo operates (it always orders suffixes as before the version)
As supporting this feature for the purpose of this use case is streamlining incompatible behavior that will trip people up, I lean towards closing this as not planned.
You definitely have a point! We tried this and hit the next issue. Maybe you still want to close this as wontfix, but I'll describe the scenario:
We have a monorepo and share a lot of Rust code between the desktop and the Android app. However, their versioning is completely unconnected from each other. They both follow the $year.$incrementing_number format, but are otherwise not related. The third Android release this year is 2022.3 even if it comes after desktop release 2022.6 or after 2022.1. Android is quite often behind desktop in terms of number of releases (so has lower version number). So what we do is to fork master into an Android release branch. Then we inject the new Android app version into all crates and build and attach a git tag. So this often ends up being a "downgrade" in that sense. But the downgraded version is never merged back to master. master always has the latest released desktop version in it.
We currently inject our versions with sed+awk but are currently investigating using better tooling. We might resort to some other crate allowing us to inject arbitrary versions without having an opinion of if downgrades are good or bad. I'm not sure how set-version is intended to be used, but it's obviously mostly intended for crates.io releases. I'm personally not convinced why forbidding downgrades is a good thing.
Versioning libraries and applications is usually quite different. Semver basically makes no sense for applications. Yet cargo is forcing semver on applications anyway sadly.
First, to be upfront, this use case I am more sympathetic to but I still want to explore a little.
Versioning libraries and applications is usually quite different. Semver basically makes no sense for applications. Yet cargo is forcing semver on applications anyway sadly.
Or put another way, source code and end-user versioning are very different and semver doesn't always make sense for end-user versioning. What I normally seen done in these cases is that there internal version numbers and external version numbers. Splitting the version numbers like this removes any downgrade cases and allows you to inject the version as-needed without any extra cargo support.
We never bump any version for the source code's sake. We don't care about the "public" API of any crate in our repository. If we did, they would be bumped all the time, and lots of time would be wasted figuring out if the major, minor or patch version should be bumped.
Essentially, for development builds all we want to know is:
Which git commit is it built from
Approximately how old is it (thus, having the name of the newest release prior to this build is nice)
For the second bullet point. Seeing just version dev-afafaf does not tell me anything without looking into git. But 2021.9-dev-afafafa gives me a pretty good understanding of where/when it came from.
The "end-user versioning" is the only versioning we do and talk about internally also. The rest is just git.
But I have an idea. Currently we have a bespoke build.sh that does some hacking to figure out if it's a release or dev build. Then it computes the desired version and injects it in all crates' Cargo.toml before running cargo build --release. Instead of this dance maybe we should create a separate compute-product-version Rust crate that sort of does the same computation as build.sh. Then we add this new crate as a dev-dependency in all our other crates and have their build.rs do some magic and tell clap and friends to pick up the version from this computation.
Pros:
We will get the correct crate versions in standalone cargo build builds, not just from build.sh
Cons:
While building, cargo will say Compiling the-product v0.0.0 or something irrelevant, since Cargo has no idea what version it's building.
Is the version known to Cargo injected into the binary in any other way? If so, it will not get the correct version.
We'll look into our versioning and all that. But I also don't see why set-version should be so limited to not even allow a forced downgrade. Anyone applying --force to any command is supposed to know what they are doing. I'm not sure what this limitation actually protects against.
I very much believe in the idea of "make the right thing easy and the wrong things hard". Without a "right thing" use case, I do not want to make "the wrong thing" too easy that it leads people down the wrong design path.
As I said earlier, I leaned towards closing this and I think I'm going to go forward with that.
I fail to see how requiring --force is too easy to accidentally do. With your argument almost no command should have a force flag for anything. Yet, they are incredibly useful and often necessary. But OK. We have figured out a completely different way of doing versioning. So not a blocker for us any longer.
This is an annoying omission. The whole point of cargo set-version as I see it is to allow CI scripts to take control of the Cargo version number. Why should cargo-edit think it knows better than a CI script?
I very much believe in the idea of "make the right thing easy and the wrong things hard". Without a "right thing" use case, I do not want to make "the wrong thing" too easy that it leads people down the wrong design path.
As I said earlier, I leaned towards closing this and I think I'm going to go forward with that.
What a nightmare. I gotta have to throw away cargo-edit and switch to parsing x.y.z manually. Just because of cult.
Activity
faern commentedon Sep 8, 2022
To add some context to this. Our build scripts detect if we are building a release or internal development version of the program. If it's a development build it adds
-dev-${commit_hash}to the end of the version number. This is just temporary while building. We back theCargo.tomlfiles up and restore them after the build. But we want the binaries to have the git commit they were built from baked into the binary and displayed onour-program --version.Currently
2022.3-dev-012345is considered a downgrade from2022.3. In our case it just means "A development version, sometime after2022.3was released, built on commit012345faern commentedon Sep 8, 2022
Essentially what we really want is a solution to rust-lang/cargo#6583. But that seems unsolved also. We could potentially just inject our own version with another env var, and not rely on
CARGO_PKG_VERSION.epage commentedon Sep 8, 2022
Is there a reason you aren't instead committing
2022.4-devin master? You then do development builds like normal with2022.4-dev-012345and then you do official release by dropping-dev.epage commentedon Sep 8, 2022
Another way to frame my question is that
-dev, by convention, means a pre-release development version and not a post-release development version. Some communities support post release but those are of production versions and not development (semver 2.0 doesn't recognize this though).Instead of continuing in a bespoke manner, swimming upstream, it seems like it'd be better to align with common expectations.
faern commentedon Sep 9, 2022
Doing what you suggest requires two separate git bumps and knowing the future. One git bump to the actual stable release and then immediately a new one to
{next}-dev. And it requires us to know the name of the next release. We version our product according to$current_year.$incremental_number. So if we code away and the last release was2022.6and 2023 arrives before we manage to produce the next release, the next release becomes2023.1and not2022.7. But if we flip it we will have a bunch of2022.7-devbuilds, which is strange since that version does not and will never exist.Our versioning scheme is similar to
git describewhich is of the format "newest reachable tag + how many commits has been added since + hash". It's just based on what has happened, not on what will happen.epage commentedon Sep 9, 2022
The extra git bump is not ideal but I'm assuming it isn't a blocker
As for knowing the future, it doesn't necessarily. Pick the next higher version and then bump from there.
Keep in mind that these costs are to avoid the cost of violating semver 2.0 (no post-release versions) which violates basic assumptions of how cargo operates (it always orders suffixes as before the version)
As supporting this feature for the purpose of this use case is streamlining incompatible behavior that will trip people up, I lean towards closing this as not planned.
faern commentedon Sep 9, 2022
You definitely have a point! We tried this and hit the next issue. Maybe you still want to close this as wontfix, but I'll describe the scenario:
We have a monorepo and share a lot of Rust code between the desktop and the Android app. However, their versioning is completely unconnected from each other. They both follow the
$year.$incrementing_numberformat, but are otherwise not related. The third Android release this year is2022.3even if it comes after desktop release2022.6or after2022.1. Android is quite often behind desktop in terms of number of releases (so has lower version number). So what we do is to forkmasterinto an Android release branch. Then we inject the new Android app version into all crates and build and attach a git tag. So this often ends up being a "downgrade" in that sense. But the downgraded version is never merged back tomaster.masteralways has the latest released desktop version in it.We currently inject our versions with
sed+awkbut are currently investigating using better tooling. We might resort to some other crate allowing us to inject arbitrary versions without having an opinion of if downgrades are good or bad. I'm not sure howset-versionis intended to be used, but it's obviously mostly intended for crates.io releases. I'm personally not convinced why forbidding downgrades is a good thing.Versioning libraries and applications is usually quite different. Semver basically makes no sense for applications. Yet cargo is forcing semver on applications anyway sadly.
epage commentedon Sep 9, 2022
First, to be upfront, this use case I am more sympathetic to but I still want to explore a little.
Or put another way, source code and end-user versioning are very different and semver doesn't always make sense for end-user versioning. What I normally seen done in these cases is that there internal version numbers and external version numbers. Splitting the version numbers like this removes any downgrade cases and allows you to inject the version as-needed without any extra cargo support.
faern commentedon Sep 9, 2022
We never bump any version for the source code's sake. We don't care about the "public" API of any crate in our repository. If we did, they would be bumped all the time, and lots of time would be wasted figuring out if the major, minor or patch version should be bumped.
Essentially, for development builds all we want to know is:
For the second bullet point. Seeing just version
dev-afafafdoes not tell me anything without looking into git. But2021.9-dev-afafafagives me a pretty good understanding of where/when it came from.The "end-user versioning" is the only versioning we do and talk about internally also. The rest is just git.
faern commentedon Sep 9, 2022
But I have an idea. Currently we have a bespoke
build.shthat does some hacking to figure out if it's a release or dev build. Then it computes the desired version and injects it in all crates'Cargo.tomlbefore runningcargo build --release. Instead of this dance maybe we should create a separatecompute-product-versionRust crate that sort of does the same computation asbuild.sh. Then we add this new crate as adev-dependencyin all our other crates and have theirbuild.rsdo some magic and tellclapand friends to pick up the version from this computation.Pros:
cargo buildbuilds, not just frombuild.shCons:
Compiling the-product v0.0.0or something irrelevant, since Cargo has no idea what version it's building.epage commentedon Sep 9, 2022
Instead of using the
prerelease field, what if you instead used thebuildmetadata field?faern commentedon Sep 30, 2022
We'll look into our versioning and all that. But I also don't see why
set-versionshould be so limited to not even allow a forced downgrade. Anyone applying--forceto any command is supposed to know what they are doing. I'm not sure what this limitation actually protects against.epage commentedon Sep 30, 2022
I very much believe in the idea of "make the right thing easy and the wrong things hard". Without a "right thing" use case, I do not want to make "the wrong thing" too easy that it leads people down the wrong design path.
As I said earlier, I leaned towards closing this and I think I'm going to go forward with that.
faern commentedon Sep 30, 2022
I fail to see how requiring
--forceis too easy to accidentally do. With your argument almost no command should have a force flag for anything. Yet, they are incredibly useful and often necessary. But OK. We have figured out a completely different way of doing versioning. So not a blocker for us any longer.DavidAntliff commentedon Jul 29, 2024
This is an annoying omission. The whole point of
cargo set-versionas I see it is to allow CI scripts to take control of the Cargo version number. Why should cargo-edit think it knows better than a CI script?I might as well just use
sed.pronebird commentedon Jan 8, 2026
What a nightmare. I gotta have to throw away
cargo-editand switch to parsing x.y.z manually. Just because of cult.