chore(version): refresh build info on demand (#7738)

* chore(version): refresh build info on demand

Introduce a `refresh-build-info` feature to `common-version` to control
whether build timestamps are updated. By default, timestamps are no longer
refreshed, and `shadow.rs` regeneration is skipped if it already exists.

This prevents the build script from invalidating incremental compilation
results when nothing else has changed. CI and release builds are updated
to explicitly enable this feature.

Signed-off-by: Lei, HUANG <mrsatangel@gmail.com>

* chore/refresh-build-info-on-demand:
 ### Update Build Configuration

 - **Remove `refresh-build-info` Feature:**
   - Removed the `refresh-build-info` feature from `action.yml`, `release.yml`, and `Cargo.toml`.
   - Updated `build.rs` to refresh timestamps by default in release builds, with an option to disable via `DISABLE_BUILD_INFO`.

 - **Modify GitHub Actions:**
   - Updated `.github/actions/build-linux-artifacts/action.yml` and `.github/workflows/release.yml` to exclude `refresh-build-info` from the `features` list.

 - **Enhance Build Script Logic:**
   - Adjusted logic in `build.rs` to handle timestamp refreshing based on build profile and environment variables.

Signed-off-by: Lei, HUANG <mrsatangel@gmail.com>

---------

Signed-off-by: Lei, HUANG <mrsatangel@gmail.com>
This commit is contained in:
Lei, HUANG
2026-03-03 10:53:51 +08:00
committed by GitHub
parent 0402f24ed8
commit be78137165

View File

@@ -21,15 +21,31 @@ use cargo_manifest::Manifest;
use shadow_rs::{BuildPattern, CARGO_METADATA, CARGO_TREE, ShadowBuilder};
fn main() -> shadow_rs::SdResult<()> {
println!(
"cargo:rustc-env=SOURCE_TIMESTAMP={}",
if let Ok(t) = get_source_time() {
format_timestamp(t)
} else {
"".to_string()
}
);
build_data::set_BUILD_TIMESTAMP();
// Refresh timestamps by default in release builds. In non-release builds (debug, bench,
// etc.), skip refreshing to preserve incremental compilation.
// Set DISABLE_BUILD_INFO=1 to force-disable refreshing even in release builds.
let profile = env::var("PROFILE").unwrap_or_default();
let disabled = env::var("DISABLE_BUILD_INFO")
.map(|v| v == "1" || v.eq_ignore_ascii_case("true"))
.unwrap_or(false);
let refresh = profile == "release" && !disabled;
println!("cargo:rerun-if-env-changed=DISABLE_BUILD_INFO");
if refresh {
println!(
"cargo:rustc-env=SOURCE_TIMESTAMP={}",
if let Ok(t) = get_source_time() {
format_timestamp(t)
} else {
"".to_string()
}
);
build_data::set_BUILD_TIMESTAMP();
} else {
println!("cargo:rustc-env=SOURCE_TIMESTAMP=");
println!("cargo:rustc-env=BUILD_TIMESTAMP=");
}
// The "CARGO_WORKSPACE_DIR" is set manually (not by Rust itself) in Cargo config file, to
// solve the problem where the "CARGO_MANIFEST_DIR" is not what we want when this repo is
@@ -54,6 +70,15 @@ fn main() -> shadow_rs::SdResult<()> {
}
let out_path = env::var("OUT_DIR")?;
let shadow_file = PathBuf::from(&out_path).join("shadow.rs");
// When not refreshing build info and the shadow.rs already exists, skip regenerating
// it entirely. shadow_rs always writes new BUILD_TIME* values which would change
// the file and invalidate incremental compilation even when nothing meaningful changed.
if !refresh && shadow_file.exists() {
println!("cargo:rerun-if-changed=build.rs");
return Ok(());
}
let _ = ShadowBuilder::builder()
.build_pattern(BuildPattern::Lazy)