Specifying arbitrary crate version during Cargo build

I'm setting up my Rust project in CI and there is a distinction between releases - where the semver is respected and increased, and temporary feature branch builds, kind of like Maven's "snapshot" versions that produce ephemeral versions. Ideally I would like that snapshot version to be visible in Clap's --help and for the version to be different every time CI runs the build, i.e. include a build number. I suspect being common this is a solved problem, but couldn't quite find a reusable solution. Help?

I think I'd set the ephemeral version as an environment variable in CI and use env! to insert it during compile time.

I stole code from Cargo to do that. If you'd like, I think I can find it then post it.