# Specifying arbitrary crate version during Cargo build

**URL:** <https://users.rust-lang.org/t/specifying-arbitrary-crate-version-during-cargo-build/109310>\
**Category:** help\
**Created:** [April 3, 2024, 1:28pm UTC](https://users.rust-lang.org/t/specifying-arbitrary-crate-version-during-cargo-build/109310 "2024-04-03T13:28:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![blueberrycarrot](https://avatars.discourse-cdn.com/v4/letter/b/9dc877/32.png) [@blueberrycarrot](https://users.rust-lang.org/u/blueberrycarrot)\
**Post date:** [April 3, 2024, 1:28pm UTC](https://users.rust-lang.org/t/specifying-arbitrary-crate-version-during-cargo-build/109310/1 "2024-04-03T13:28:28Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![jofas](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/jofas/32/30690_2.png) [@jofas](https://users.rust-lang.org/u/jofas)\
**Post date:** [April 3, 2024, 1:32pm UTC](https://users.rust-lang.org/t/specifying-arbitrary-crate-version-during-cargo-build/109310/2 "2024-04-03T13:32:03Z")

</div>

I think I'd set the ephemeral version as an environment variable in CI and use [`env!`](https://doc.rust-lang.org/std/macro.env.html) to insert it during compile time.

---

<div class="post-metadata">

**Author:** ![Coding-Badly](https://avatars.discourse-cdn.com/v4/letter/c/58956e/32.png) [@Coding-Badly](https://users.rust-lang.org/u/Coding-Badly)\
**Post date:** [April 3, 2024, 3:28pm UTC](https://users.rust-lang.org/t/specifying-arbitrary-crate-version-during-cargo-build/109310/3 "2024-04-03T15:28:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/system/32/51372_2.png) [@system](https://users.rust-lang.org/u/system)\
**Post date:** [July 2, 2024, 3:28pm UTC](https://users.rust-lang.org/t/specifying-arbitrary-crate-version-during-cargo-build/109310/4 "2024-07-02T15:28:07Z")

</div>

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.
