From 2a200d8525bcf7aca1862661e0e80daa709da17f Mon Sep 17 00:00:00 2001 From: Clint J Edwards Date: Wed, 16 Sep 2026 19:47:59 -0600 Subject: [PATCH] [release] Allow build version to be injected at compile time This adds a new build envvar that will overwrite the default `CARGO_PKG_VERSION` and removes some of the logic we were using to generate unique build versions for dev versions. In short: * We introduce a new `PUSHPIN_BUILD_VERSION` environment variable (prefixed to not collide with CI env vars) that we use whenever we want to overwrite the build version listed in `cargo.toml`. * Building the normal way (`cargo build --release`) without any extra envvars still uses the version in `cargo.toml` as the version. * This allows us some flexibility when building final assets as to what the version string actually gets set as. Very useful when hotfixing, for downstream forks, or just generally doing things that need the version string to change but don't want `cargo.toml` to be updated. (Things like appending the date to the build version and such) * This PR also cleans up the `-dev` logic for appending dates since we're moving away from explicitly tagging out of band release builds with a `-dev` suffix. --- build.rs | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/build.rs b/build.rs index d2fd634c..869fbf51 100644 --- a/build.rs +++ b/build.rs @@ -9,31 +9,20 @@ use std::os::unix::ffi::OsStrExt; use std::path::{Path, PathBuf}; use std::process::{Command, ExitStatus, Output, Stdio}; use std::str::FromStr; -use time::macros::format_description; -use time::OffsetDateTime; const DEFAULT_PREFIX: &str = "/usr/local"; fn get_version() -> String { - let mut version = env!("CARGO_PKG_VERSION").to_string(); - - if version.ends_with("-dev") { - let format = format_description!("[year][month][day]"); - - let date_str = OffsetDateTime::now_utc().format(&format).unwrap(); - - version.push_str(&format!("-{}", date_str)); - } - - version + env::var("PUSHPIN_BUILD_VERSION").unwrap_or_else(|_| env!("CARGO_PKG_VERSION").to_string()) } fn get_version_int() -> Result> { - let version = env!("CARGO_PKG_VERSION"); + let version = + env::var("PUSHPIN_BUILD_VERSION").unwrap_or_else(|_| env!("CARGO_PKG_VERSION").to_string()); let version = match version.find('-') { Some(pos) => &version[..pos], - None => version, + None => &version, }; let mut v = 0; @@ -614,6 +603,7 @@ fn main() -> Result<(), Box> { println!("cargo:rustc-link-search={}", qt_install_libs.display()); } + println!("cargo:rerun-if-env-changed=PUSHPIN_BUILD_VERSION"); println!("cargo:rerun-if-env-changed=RELEASE"); println!("cargo:rerun-if-env-changed=PREFIX"); println!("cargo:rerun-if-env-changed=BINDIR");