Report your tool's own version¶
Use the macro¶
That is the whole change. version_info! expands
env!("CARGO_PKG_VERSION") at your call site, so it reads your crate's version.
Migrate off VersionInfo::from_env¶
VersionInfo::from_env() is deprecated as of 0.9.0 and returns rtb-app's version
rather than yours. Replace every call:
The compiler will point you at the call sites — the workspace builds with
RUSTFLAGS: "-D warnings", so a leftover from_env fails the build rather than
warning quietly.
The two are not interchangeable and the difference is not cosmetic. Self-update
verifies a freshly staged binary by comparing the version it reports against the
release tag it came from. A binary that reports the framework's version fails that
check and refuses to swap itself in — so a tool still on from_env cannot update
itself, whatever else is configured correctly.
Add the commit and build date¶
version_info! returns a plain VersionInfo, so chain the setters:
let version = rtb_app::version_info!()
.with_commit(env!("VERGEN_GIT_SHA"))
.with_date(env!("VERGEN_BUILD_TIMESTAMP"));
Both take anything that converts into a String and neither validates the shape —
with_date will happily store "yesterday". Emit them from a build.rs;
vergen and built are the usual
sources.
When the version string comes from somewhere else¶
If the version is not your CARGO_PKG_VERSION — read from a git describe, a
generated file, an environment variable at build time — from_pkg_version will parse
it, but it never fails. An unparseable string silently becomes 0.0.0:
If the input might be wrong, parse it yourself so you find out:
let parsed = semver::Version::parse(raw)
.map_err(|e| miette::miette!("build metadata carried an unparseable version: {e}"))?;
let version = VersionInfo::new(parsed);
Check what your tool actually reports¶
The failure mode here is silent, so assert it:
#[test]
fn reports_our_own_version() {
let v = rtb_app::version_info!();
assert_eq!(v.version.to_string(), env!("CARGO_PKG_VERSION"));
}
Put this test in your crate, not in a shared test helper. A test living in
rtb-app cannot tell the two behaviours apart, because there the call site and
rtb-app share a version.
Be careful with is_development¶
is_development() returns true for any pre-1.0 version, so a released, tagged
0.9.0 reports as a development build. If you are gating behaviour on "is this a
real release", is_development() is not the predicate you want until the tool
reaches 1.0.