From 92c2ffa9cd091ca165da85a11198b299901ec649 Mon Sep 17 00:00:00 2001 From: Russell Gilbert Date: Sat, 28 Feb 2026 08:07:07 +0000 Subject: [PATCH] Makes build number increment conditional Introduces an `increment` Cargo feature to control the automatic incrementing of the build number during the build process. This change prevents the build number from incrementing on every build, providing more control for local development and specific release scenarios. The build number will now only increment when the `increment` feature is explicitly enabled. Adds `cargo:rerun-if-changed=src/` to ensure the build script re-runs when source files change. --- src/rustylee/Cargo.toml | 3 +++ src/rustylee/build.rs | 15 +++++++++------ src/rustylee/build_number.txt | 2 +- src/rustylee/src/brain.rs | 2 ++ 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/rustylee/Cargo.toml b/src/rustylee/Cargo.toml index 4faebf7..763492e 100644 --- a/src/rustylee/Cargo.toml +++ b/src/rustylee/Cargo.toml @@ -8,3 +8,6 @@ build = "build.rs" ctrlc = "3.5.2" tracing = "0.1" tracing-subscriber = { version = "0.3.22", features = ["env-filter", "fmt"] } + +[features] +increment = [] diff --git a/src/rustylee/build.rs b/src/rustylee/build.rs index 9699d6a..28b235c 100644 --- a/src/rustylee/build.rs +++ b/src/rustylee/build.rs @@ -1,14 +1,17 @@ use std::fs; +use std::env; fn main() { + println!("cargo:rerun-if-changed=src/"); + let pkg_version = env!("CARGO_PKG_VERSION"); - let mut content = fs::read_to_string("build_number.txt").unwrap_or("0".to_string()); + let content = fs::read_to_string("build_number.txt").unwrap_or_else(|_| "0".to_string()); let mut build_num: u32 = content.trim().parse().unwrap_or(0); - build_num += 1; - let full_version = format!("{}.{}", pkg_version, build_num); + if env::var("CARGO_FEATURE_INCREMENT").is_ok() { + build_num += 1; + let _ = fs::write("build_number.txt", build_num.to_string()); + } - fs::write("build_number.txt", build_num.to_string()).unwrap(); - - println!("cargo:rustc-env=FULL_VERSION={}", full_version); + println!("cargo:rustc-env=FULL_VERSION={}.{}", pkg_version, build_num); } \ No newline at end of file diff --git a/src/rustylee/build_number.txt b/src/rustylee/build_number.txt index 0aede4a..405e057 100644 --- a/src/rustylee/build_number.txt +++ b/src/rustylee/build_number.txt @@ -1 +1 @@ -102 \ No newline at end of file +127 \ No newline at end of file diff --git a/src/rustylee/src/brain.rs b/src/rustylee/src/brain.rs index 09980f1..503dc22 100644 --- a/src/rustylee/src/brain.rs +++ b/src/rustylee/src/brain.rs @@ -21,6 +21,8 @@ impl Brain { } } + + pub fn request_shutdown(&mut self) { if self.state == State::Running { self.state = State::Stopping;