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.
This commit is contained in:
parent
76d1311440
commit
92c2ffa9cd
4 changed files with 15 additions and 7 deletions
|
|
@ -8,3 +8,6 @@ build = "build.rs"
|
||||||
ctrlc = "3.5.2"
|
ctrlc = "3.5.2"
|
||||||
tracing = "0.1"
|
tracing = "0.1"
|
||||||
tracing-subscriber = { version = "0.3.22", features = ["env-filter", "fmt"] }
|
tracing-subscriber = { version = "0.3.22", features = ["env-filter", "fmt"] }
|
||||||
|
|
||||||
|
[features]
|
||||||
|
increment = []
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,17 @@
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
use std::env;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
println!("cargo:rerun-if-changed=src/");
|
||||||
|
|
||||||
let pkg_version = env!("CARGO_PKG_VERSION");
|
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);
|
let mut build_num: u32 = content.trim().parse().unwrap_or(0);
|
||||||
|
|
||||||
|
if env::var("CARGO_FEATURE_INCREMENT").is_ok() {
|
||||||
build_num += 1;
|
build_num += 1;
|
||||||
let full_version = format!("{}.{}", pkg_version, build_num);
|
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={}.{}", pkg_version, build_num);
|
||||||
|
|
||||||
println!("cargo:rustc-env=FULL_VERSION={}", full_version);
|
|
||||||
}
|
}
|
||||||
|
|
@ -1 +1 @@
|
||||||
102
|
127
|
||||||
|
|
@ -21,6 +21,8 @@ impl Brain {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
pub fn request_shutdown(&mut self) {
|
pub fn request_shutdown(&mut self) {
|
||||||
if self.state == State::Running {
|
if self.state == State::Running {
|
||||||
self.state = State::Stopping;
|
self.state = State::Stopping;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue