Skip to content

Support downgrades in cargo set-version #782

Closed

Description

@dlon

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?

Activity

  1. faern commented on Sep 8, 2022

    @faern

    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

  2. faern commented on Sep 8, 2022

    @faern

    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.

  3. epage commented on Sep 8, 2022

    @epage
    Collaborator

    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.

  4. epage commented on Sep 8, 2022

    @epage
    Collaborator

    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.

  5. faern commented on Sep 9, 2022

    @faern

    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.

  6. epage commented on Sep 9, 2022

    @epage
    Collaborator

    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.

  7. faern commented on Sep 9, 2022

    @faern

    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.

  8. epage commented on Sep 9, 2022

    @epage
    Collaborator

    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.

  9. faern commented on Sep 9, 2022

    @faern

    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.

  10. faern commented on Sep 9, 2022

    @faern

    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.
  11. epage commented on Sep 9, 2022

    @epage
    Collaborator

    Essentially, for development builds all we want to know is:

    Instead of using the prerelease field, what if you instead used the build metadata field?

  12. faern commented on Sep 30, 2022

    @faern

    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.

  13. epage commented on Sep 30, 2022

    @epage
    Collaborator

    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.

  14. faern commented on Sep 30, 2022

    @faern

    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.

  15. DavidAntliff commented on Jul 29, 2024

    @DavidAntliff

    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 might as well just use sed.

  16. pronebird commented on Jan 8, 2026

    @pronebird

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions