build.rs 976 B

123456789101112131415161718
  1. //! Build identity for the dashboard badge.
  2. //!
  3. //! `SM121_VERSION` is passed by the add-on image build (`--build-arg` →
  4. //! `ENV` in the builder stage). Two things are needed for it to survive a
  5. //! warm cargo cache: this script must declare the env var as an input, and the
  6. //! value must reach the compiler as a *generated source*, not through
  7. //! `option_env!` alone (a cached fingerprint can otherwise keep the old
  8. //! literal). The value is echoed as a cargo warning so the CI log shows what
  9. //! the image actually got.
  10. fn main() {
  11. println!("cargo:rerun-if-env-changed=SM121_VERSION");
  12. let version = std::env::var("SM121_VERSION").unwrap_or_else(|_| "dev".into());
  13. println!("cargo:warning=SM121_VERSION={version}");
  14. let out = std::path::PathBuf::from(std::env::var("OUT_DIR").expect("OUT_DIR"))
  15. .join("build_version.rs");
  16. std::fs::write(out, format!("pub const VERSION: &str = {version:?};\n"))
  17. .expect("write build_version.rs");
  18. }