rust-lang / cargo

The Rust package manager
https://doc.rust-lang.org/cargo
Apache License 2.0
12.66k stars 2.4k forks source link

Possibility to set the package version dynamically #6583

Open vorner opened 5 years ago

vorner commented 5 years ago

Hello

I'm building a rust application using internal teamcity CI job. I want the build number to be part of the version of the binary (so eg. ./app --version knows from which build it came).

The only way I found so far is to let the build first edit the Cargo.toml (sed -i -e 's/^version = .*/version = "%build.version%"/' Cargo.toml), which seems ugly and fragile.

It would be great if I could somehow override the version from Cargo.toml through the command line ‒ either as a parameter or an environment variable.

Would something like that make sense? Are there plans to support it?

faern commented 4 months ago

@DavidAntliff See this comment: https://github.com/rust-lang/cargo/issues/6583#issuecomment-1783242798

Now that package.version is optional, I feel like this helps us better focus on that field being a tool for registry packages and that it might not be as relevant to products that are not being published to a registry.

You are not really supposed to put a product version into the Cargo version field, according to this comment. It's versioning for crates.io style registries.

instead encourage people to look up the marketing version of their application as they best see fit (e.g. see https://github.com/rust-lang/cargo/issues/6583#issuecomment-1702417194), rather than trying to overload package.version as both the registry version and the marketing version

It links to my previous comment about how we have solved basically the same problem you have. You will find it is much easier if you stop trying to cram the version into Cargo's version field altogether :)