|
@@ -1,10 +1,18 @@
|
|
|
-//! Rebuild the crate when the build identity changes.
|
|
|
|
|
|
|
+//! Build identity for the dashboard badge.
|
|
|
//!
|
|
//!
|
|
|
-//! `option_env!("SM121_VERSION")` is baked at compile time, but cargo does not
|
|
|
|
|
-//! treat an env var as an input on its own — without this line a cached build
|
|
|
|
|
-//! keeps the old value (the add-on's 1.3.6/1.3.7 images both shipped "dev"
|
|
|
|
|
-//! from a warm `target/` cache mount). `cargo:rerun-if-env-changed` makes the
|
|
|
|
|
-//! crate recompile whenever the version passed by the CI changes.
|
|
|
|
|
|
|
+//! `SM121_VERSION` is passed by the add-on image build (`--build-arg` →
|
|
|
|
|
+//! `ENV` in the builder stage). Two things are needed for it to survive a
|
|
|
|
|
+//! warm cargo cache: this script must declare the env var as an input, and the
|
|
|
|
|
+//! value must reach the compiler as a *generated source*, not through
|
|
|
|
|
+//! `option_env!` alone (a cached fingerprint can otherwise keep the old
|
|
|
|
|
+//! literal). The value is echoed as a cargo warning so the CI log shows what
|
|
|
|
|
+//! the image actually got.
|
|
|
fn main() {
|
|
fn main() {
|
|
|
println!("cargo:rerun-if-env-changed=SM121_VERSION");
|
|
println!("cargo:rerun-if-env-changed=SM121_VERSION");
|
|
|
|
|
+ let version = std::env::var("SM121_VERSION").unwrap_or_else(|_| "dev".into());
|
|
|
|
|
+ println!("cargo:warning=SM121_VERSION={version}");
|
|
|
|
|
+ let out = std::path::PathBuf::from(std::env::var("OUT_DIR").expect("OUT_DIR"))
|
|
|
|
|
+ .join("build_version.rs");
|
|
|
|
|
+ std::fs::write(out, format!("pub const VERSION: &str = {version:?};\n"))
|
|
|
|
|
+ .expect("write build_version.rs");
|
|
|
}
|
|
}
|