RedFlag/helper/build.rs
Fimeg 67e26be2d9 projection: begin the exact-path public epoch
The public tree and its history contain only the listed paths. Earlier projection history remains preserved internally.

Source-Sha: 913fde029b935671833254797f0f20f1eb9fabba

Policy-Sha: 913fde029b935671833254797f0f20f1eb9fabba

Tree-Digest: 180ae530c1058a2a5c89837bdce2d323ae83e669e38590ca72e75b8d92b7262f
2026-09-08 21:59:33 -04:00

28 lines
1.5 KiB
Rust

fn main() {
let bin_dir = std::env::var("REDFLAG_PACKAGE_BIN_DIR")
.unwrap_or_else(|_| "/usr/local/bin".into());
assert!(bin_dir == "/usr/local/bin" || bin_dir == "/usr/bin");
println!("cargo:rustc-env=REDFLAG_BIN_DIR={bin_dir}");
println!("cargo:rerun-if-env-changed=REDFLAG_PACKAGE_BIN_DIR");
// Cargo takes three version fields; a release identity has four. CI passes
// the validated tag version in; a build without it is a developer build
// and says the crate version, which is true of it.
let crate_version = std::env::var("CARGO_PKG_VERSION").unwrap();
let release_version = std::env::var("REDFLAG_RELEASE_VERSION")
.ok()
.filter(|v| !v.is_empty())
.unwrap_or_else(|| crate_version.clone());
// Valid identities are the crate version, or the crate version plus one
// numeric field. The prefix carries its trailing dot, so this is a field
// boundary and not a string prefix: 0.2.90.1 does not extend 0.2.9, and
// neither does 0.2.9.3.4, 0.2.9. or 0.2.9.beta.
let extends = match release_version.strip_prefix(&format!("{crate_version}.")) {
Some(suffix) => !suffix.is_empty() && suffix.bytes().all(|b| b.is_ascii_digit()),
None => release_version == crate_version,
};
if !extends {
panic!("REDFLAG_RELEASE_VERSION={release_version} does not extend crate version {crate_version}");
}
println!("cargo:rustc-env=REDFLAG_VERSION={release_version}");
println!("cargo:rerun-if-env-changed=REDFLAG_RELEASE_VERSION");
}